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

fix: incorrect https warning on credential flow #972

Merged
merged 1 commit into from
Feb 8, 2025
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,7 @@ func TestClientLogCallbacks(t *testing.T) {
Get(ts.URL + "/profile")
assertNil(t, err)
assertNotNil(t, resp)
assertEqual(t, int64(50), resp.Size())
assertEqual(t, int64(66), resp.Size())
assertEqual(t, true, strings.Contains(lb.String(), "Overwriting an existing on-debug-log callback from=resty.dev/v3.TestClientLogCallbacks.func1 to=resty.dev/v3.TestClientLogCallbacks.func2"))
}

Expand Down
2 changes: 1 addition & 1 deletion middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ func addCredentials(c *Client, r *Request) error {
}

if !c.IsDisableWarn() && credentialsAdded {
if strings.HasPrefix(r.URL, "http") {
if r.RawRequest.URL.Scheme == "http" {
r.log.Warnf("Using sensitive credentials in HTTP mode is not secure. Use HTTPS")
}
}
Expand Down
37 changes: 37 additions & 0 deletions request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2381,6 +2381,43 @@ func TestRequestFuncs(t *testing.T) {
assertEqual(t, "TestGet: text response", resp.String())
}

func TestHTTPWarnGH970(t *testing.T) {
lookupText := "Using sensitive credentials in HTTP mode is not secure. Use HTTPS"

t.Run("SSL used", func(t *testing.T) {
ts := createAuthServerTLSOptional(t, true)
defer ts.Close()

c, lb := dcldb()
c.SetBaseURL(ts.URL).
SetTLSClientConfig(&tls.Config{InsecureSkipVerify: true})

res, err := c.R().
SetAuthToken("004DDB79-6801-4587-B976-F093E6AC44FF").
Get("/profile")

assertNil(t, err)
assertEqual(t, true, strings.Contains(res.String(), "profile fetch successful"))
assertEqual(t, false, strings.Contains(lb.String(), lookupText))
})

t.Run("non-SSL used", func(t *testing.T) {
ts := createAuthServerTLSOptional(t, false)
defer ts.Close()

c, lb := dcldb()
c.SetBaseURL(ts.URL)

res, err := c.R().
SetAuthToken("004DDB79-6801-4587-B976-F093E6AC44FF").
Get("/profile")

assertNil(t, err)
assertEqual(t, true, strings.Contains(res.String(), "profile fetch successful"))
assertEqual(t, true, strings.Contains(lb.String(), lookupText))
})
}

// This test methods exist for test coverage purpose
// to validate the getter and setter
func TestRequestSettingsCoverage(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion resty_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ func createAuthServerTLSOptional(t *testing.T, useTLS bool) *httptest.Server {
}

if strings.Contains(auth, "004DDB79-6801-4587-B976-F093E6AC44FF") {
_, _ = w.Write([]byte(`{ "id": "success", "message": "login successful" }`))
_, _ = w.Write([]byte(`{ "username": "auth_test", "message": "profile fetch successful" }`))
}
}

Expand Down