fix(bonfire): mask secret flag values that start with a dash (WR-11)
This commit is contained in:
@@ -219,10 +219,11 @@ func TestWithExitCode(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestWrongDirectoryMasksSecrets (WR-08): the wrong-directory Try line
|
||||
// replaces the value of every flag named like a password, secret, token or
|
||||
// key with ***, in both the "--flag value" and "--flag=value" forms, and
|
||||
// keeps every other argument.
|
||||
// TestWrongDirectoryMasksSecrets (WR-08, WR-11): the wrong-directory Try
|
||||
// line replaces the value of every flag named like a password, secret,
|
||||
// token or key with ***, in both the "--flag value" and "--flag=value"
|
||||
// forms and whatever the value's first character, and keeps every other
|
||||
// argument; only a following "--" is not taken as the value.
|
||||
func TestWrongDirectoryMasksSecrets(t *testing.T) {
|
||||
plainEnv(t)
|
||||
root := t.TempDir()
|
||||
@@ -244,7 +245,12 @@ func TestWrongDirectoryMasksSecrets(t *testing.T) {
|
||||
{[]string{"sync", "--api-token=t0k3n"}, "cd ..; {bin} sync --api-token=***"},
|
||||
{[]string{"sync", "--key", "k3y", "acme blog"}, "cd ..; {bin} sync --key *** 'acme blog'"},
|
||||
{[]string{"sync", "--PASSWD", "hunter2"}, "cd ..; {bin} sync --PASSWD ***"},
|
||||
{[]string{"sync", "--token", "--force"}, "cd ..; {bin} sync --token --force"},
|
||||
// pflag takes the next argument as the value of a non-boolean
|
||||
// flag even when it starts with "-": "--force" is the token here.
|
||||
{[]string{"sync", "--token", "--force"}, "cd ..; {bin} sync --token ***"},
|
||||
{[]string{"admin:create", "--email", "a@b.c", "--password", "-Xk9!q"}, "cd ..; {bin} admin:create --email a@b.c --password ***"},
|
||||
{[]string{"sync", "--client-secret", "-s3cr3t", "--verbose"}, "cd ..; {bin} sync --client-secret *** --verbose"},
|
||||
{[]string{"sync", "--token", "--", "x"}, "cd ..; {bin} sync --token -- x"},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
got := wrongDirectory("acme", fail, tc.args, sub)
|
||||
@@ -255,7 +261,7 @@ func TestWrongDirectoryMasksSecrets(t *testing.T) {
|
||||
if hint.Try != tc.want {
|
||||
t.Errorf("%q: Try = %q, want %q", tc.args, hint.Try, tc.want)
|
||||
}
|
||||
for _, secret := range []string{"hunter2", "s3cr3t", "t0k3n", "k3y"} {
|
||||
for _, secret := range []string{"hunter2", "s3cr3t", "t0k3n", "k3y", "-Xk9", "-s3cr3t"} {
|
||||
if strings.Contains(hint.Try, secret) {
|
||||
t.Errorf("%q: Try line repeats %q: %q", tc.args, secret, hint.Try)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user