Skip to content

Commit

Permalink
Ensure URL Validation explicitly disabled
Browse files Browse the repository at this point in the history
Previously, when the validator was omitted, URL validation will be silently
skipped. Having an explicit parameter should help avoid accidental omission.

stacked-commit: true
  • Loading branch information
msuozzo committed Feb 21, 2025
1 parent 2644c41 commit d4def5f
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions internal/httpx/httpxtest/mockclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ type Call struct {
}

type MockClient struct {
Calls []Call
URLValidator func(expected, actual string)
callCount int
Calls []Call
URLValidator func(expected, actual string)
SkipURLValidation bool
callCount int
}

func (m *MockClient) Do(req *http.Request) (*http.Response, error) {
Expand All @@ -27,6 +28,11 @@ func (m *MockClient) Do(req *http.Request) (*http.Response, error) {
call := m.Calls[m.callCount]
m.callCount++

if !m.SkipURLValidation && (m.URLValidator == nil) {
panic("URL validation requested but not configured")
} else if m.SkipURLValidation && (m.URLValidator != nil) {
panic("URL validation disabled but configured")
}
if m.URLValidator != nil {
if call.Method != "" {
m.URLValidator(call.Method+" "+call.URL, req.Method+" "+req.URL.String())
Expand Down

0 comments on commit d4def5f

Please sign in to comment.