(t *testing.T)
| 9 | ) |
| 10 | |
| 11 | func TestRedaction(t *testing.T) { |
| 12 | tests := []struct { |
| 13 | name string |
| 14 | msg string |
| 15 | want string |
| 16 | env []string |
| 17 | }{ |
| 18 | { |
| 19 | name: "replaces env var value with its name", |
| 20 | env: []string{"DB_PASS=foobar123"}, |
| 21 | msg: "wrong password foobar123", |
| 22 | want: "wrong password DB_PASS", |
| 23 | }, |
| 24 | { |
| 25 | name: "handles env var value with equals sign", |
| 26 | env: []string{"SECRET=user=foo"}, |
| 27 | msg: "wrong password for user=foo", |
| 28 | want: "wrong password for SECRET", |
| 29 | }, |
| 30 | { |
| 31 | name: "leaves original msg unchanged", |
| 32 | env: []string{}, |
| 33 | msg: "wrong password foobar123", |
| 34 | want: "wrong password foobar123", |
| 35 | }, |
| 36 | { |
| 37 | name: "handles env var with empty value", |
| 38 | env: []string{"DB_PASS="}, |
| 39 | msg: "wrong password foobar123", |
| 40 | want: "wrong password foobar123", |
| 41 | }, |
| 42 | { |
| 43 | name: "does not redact skipped env variables - AWS", |
| 44 | env: []string{"AWS_REGION=us-west-1"}, |
| 45 | msg: "us-west-1: sample log", |
| 46 | want: "us-west-1: sample log", |
| 47 | }, |
| 48 | { |
| 49 | name: "does not redact skipped env variables - HOME", |
| 50 | env: []string{"HOME=/root"}, |
| 51 | msg: "sample log /root", |
| 52 | want: "sample log /root", |
| 53 | }, |
| 54 | { |
| 55 | name: "does not redact skipped env variables - _CQ_TEAM_NAME", |
| 56 | env: []string{"_CQ_TEAM_NAME=team"}, |
| 57 | msg: "wrong api key for team", |
| 58 | want: "wrong api key for team", |
| 59 | }, |
| 60 | { |
| 61 | name: "does not redact variables with values of less than 4 characters", |
| 62 | env: []string{"DB_PASS=123"}, |
| 63 | msg: "wrong password foobar123", |
| 64 | want: "wrong password foobar123", |
| 65 | }, |
| 66 | { |
| 67 | name: "does redact CLOUDQUERY_API_KEY", |
| 68 | env: []string{"CLOUDQUERY_API_KEY=cqtk_test"}, |
nothing calls this directly
no test coverage detected