Skip to content

Commit 0293217

Browse files
committed
chore: update test for oauthserver
1 parent 396f007 commit 0293217

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

internal/api/oauthserver/authorize_test.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,23 @@ func TestValidateRequestOriginEdgeCases(t *testing.T) {
136136
tokenService := tokens.NewService(globalConfig, hooksMgr)
137137
server := NewServer(globalConfig, conn, tokenService)
138138

139-
t.Run("Origin with different port should be allowed (hostname matching)", func(t *testing.T) {
139+
t.Run("Origin with different port on non-localhost should be rejected", func(t *testing.T) {
140140
req := httptest.NewRequest(http.MethodGet, "/test", nil)
141141
req.Header.Set("Origin", "https://example.com:8080")
142142

143-
// Should pass because hostname matches (IsRedirectURLValid allows different ports)
143+
// Must be rejected: port mismatch on a non-loopback host.
144+
// RFC 8252 Section 7.3 variable-port exception only applies to localhost.
145+
err := server.validateRequestOrigin(req)
146+
assert.Error(t, err)
147+
assert.Contains(t, err.Error(), "unauthorized request origin")
148+
})
149+
150+
t.Run("Origin with different port on localhost should be allowed (RFC 8252 Section 7.3)", func(t *testing.T) {
151+
req := httptest.NewRequest(http.MethodGet, "/test", nil)
152+
req.Header.Set("Origin", "http://localhost:9999")
153+
154+
// Must be allowed: RFC 8252 Section 7.3 requires variable port support for
155+
// loopback redirect URIs used by native apps.
144156
err := server.validateRequestOrigin(req)
145157
assert.NoError(t, err)
146158
})

0 commit comments

Comments
 (0)