TestRedactFetchBlob tests that a request to fetchBlob that gets redirected to a URL that contains sensitive information has that information redacted if the subsequent request fails.
(t *testing.T)
| 223 | // to a URL that contains sensitive information has that information redacted |
| 224 | // if the subsequent request fails. |
| 225 | func TestRedactFetchBlob(t *testing.T) { |
| 226 | ctx := context.Background() |
| 227 | f := fetcher{ |
| 228 | target: mustNewTag(t, "original.com/repo:latest").Context(), |
| 229 | client: &http.Client{ |
| 230 | Transport: errTransport{}, |
| 231 | }, |
| 232 | } |
| 233 | h, err := v1.NewHash(fakeDigest) |
| 234 | if err != nil { |
| 235 | t.Fatal("NewHash:", err) |
| 236 | } |
| 237 | if _, err := f.fetchBlob(ctx, 0, h); err == nil { |
| 238 | t.Fatalf("fetchBlob: expected error, got nil") |
| 239 | } else if !strings.Contains(err.Error(), "access_token=REDACTED") { |
| 240 | t.Fatalf("fetchBlob: expected error to contain redacted access token, got %v", err) |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | type errTransport struct{} |
| 245 |
nothing calls this directly
no test coverage detected
searching dependent graphs…