Skip to content
quarry Artifact [5f25a951c2]
Login

Artifact [5f25a951c2]

Artifact 5f25a951c21c1fbc887ccc57c0af15a4bc71d92aa2ae007ff6401bbefd10dc40:


package api

import (
	"errors"
	"strings"
	"testing"
)

// account.add and account.passwd are the two ops that take a plaintext
// password, and an error is the one value that reliably reaches a log,
// an HTTP body and a terminal at once. A store error that quotes what it
// was given must not carry the secret out with it.
func TestScrubRemovesTheSecret(t *testing.T) {
	err := errors.New(`oltp: rejected value "hunter2 correct horse" for account`)
	got := scrub(err, "hunter2 correct horse")

	if strings.Contains(got, "hunter2") {
		t.Fatalf("the password survived scrubbing: %q", got)
	}
	if !strings.Contains(got, "[redacted]") {
		t.Errorf("nothing marked as removed: %q", got)
	}
	if !strings.Contains(got, "oltp: rejected value") {
		t.Errorf("scrub destroyed the diagnostic: %q", got)
	}
	// An empty secret must not turn every error into redaction soup.
	if scrub(err, "") != err.Error() {
		t.Error("empty secret altered the message")
	}
}