Skip to content

Commit

Permalink
feat: add support for sanitized headers in HeadersValidator and updat…
Browse files Browse the repository at this point in the history
…e tests accordingly
  • Loading branch information
areknoster committed Sep 20, 2024
1 parent c4185aa commit e6122ba
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@
# vendor/

.DS_Store
.aider*
4 changes: 3 additions & 1 deletion request_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,11 @@ func HeadersValidator() RequestValidator {
recordedHeaders := recorded.Headers.Clone()
recordedHeaders.Del("User-Agent")
recordedHeaders.Del("Content-Length")

for key := range recordedHeaders {
recordedHeader, gotHeader := recordedHeaders.Get(key), got.Headers.Get(key)
if recordedHeader == "SANITIZED" {
continue

Check warning on line 88 in request_validator.go

View check run for this annotation

Codecov / codecov/patch

request_validator.go#L88

Added line #L88 was not covered by tests
}
if recordedHeader != gotHeader {
t.Errorf("expected header '%s' to be '%s', got '%s'", key, recordedHeader, gotHeader)
}
Expand Down
7 changes: 7 additions & 0 deletions request_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ func TestRequestValidators(t *testing.T) {
got: RequestData{Headers: http.Header{"Key1": []string{"Value2"}}},
expectErr: true,
},
{
name: "HeadersValidator_Sanitized",
validator: HeadersValidator(),
recorded: RequestData{Headers: http.Header{"Key1": []string{"Value1"}}},
got: RequestData{Headers: http.Header{"Key1": []string{"SANITIZED"}}},
expectErr: false,
},
}

for _, tc := range testCases {
Expand Down

0 comments on commit e6122ba

Please sign in to comment.