(t *testing.T)
| 137 | } |
| 138 | |
| 139 | func TestRedactForLog(t *testing.T) { |
| 140 | tests := []struct { |
| 141 | query string |
| 142 | want string |
| 143 | }{ |
| 144 | { |
| 145 | query: "CREATE PERSISTENT SECRET my_s3 (TYPE s3, KEY_ID 'AKIA…', SECRET 'hunter2')", |
| 146 | want: "CREATE PERSISTENT SECRET my_s3 (…redacted)", |
| 147 | }, |
| 148 | { |
| 149 | query: "create or replace secret s (TYPE s3, SECRET 'x')", |
| 150 | want: "create or replace secret s (…redacted)", |
| 151 | }, |
| 152 | { |
| 153 | query: "-- note\nCREATE SECRET (TYPE s3, SECRET 'x')", |
| 154 | want: "-- note\nCREATE SECRET (…redacted)", |
| 155 | }, |
| 156 | { |
| 157 | // Redaction must track the tokenizer, not a flat prefix list: |
| 158 | // extra whitespace between keywords must still redact. |
| 159 | query: "CREATE PERSISTENT\nSECRET s (TYPE s3, SECRET 'hunter2')", |
| 160 | want: "CREATE PERSISTENT\nSECRET s (…redacted)", |
| 161 | }, |
| 162 | { |
| 163 | // ... and comments between keywords. |
| 164 | query: "CREATE /*c*/ PERSISTENT SECRET s (TYPE s3, SECRET 'hunter2')", |
| 165 | want: "CREATE /*c*/ PERSISTENT SECRET s (…redacted)", |
| 166 | }, |
| 167 | { |
| 168 | // Multi-statement strings with a secret-DDL head drop everything |
| 169 | // after the head (the trailing statements go with the options). |
| 170 | query: "CREATE PERSISTENT SECRET s (TYPE s3, SECRET 'x'); SELECT 1", |
| 171 | want: "CREATE PERSISTENT SECRET s (…redacted)", |
| 172 | }, |
| 173 | { |
| 174 | query: "CREATE SECRET IF NOT EXISTS foo (TYPE s3, SECRET 'x')", |
| 175 | want: "CREATE SECRET IF NOT EXISTS foo (…redacted)", |
| 176 | }, |
| 177 | { |
| 178 | query: "DROP PERSISTENT SECRET my_s3", |
| 179 | want: "DROP PERSISTENT SECRET my_s3", |
| 180 | }, |
| 181 | { |
| 182 | query: "SELECT 'CREATE SECRET' FROM t", |
| 183 | want: "SELECT 'CREATE SECRET' FROM t", |
| 184 | }, |
| 185 | { |
| 186 | query: "CREATE SECRETIVE_TABLE (id INT)", |
| 187 | want: "CREATE SECRETIVE_TABLE (id INT)", |
| 188 | }, |
| 189 | } |
| 190 | for _, tt := range tests { |
| 191 | if got := RedactForLog(tt.query); got != tt.want { |
| 192 | t.Errorf("RedactForLog(%q) = %q, want %q", tt.query, got, tt.want) |
| 193 | } |
| 194 | } |
| 195 | } |
| 196 |
nothing calls this directly
no test coverage detected