Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure URL Validation explicitly disabled #355

Merged
merged 1 commit into from
Feb 24, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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