Skip to content

Commit a3ba134

Browse files
committed
update callers of setupIntegrationManager
1 parent a0909b4 commit a3ba134

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

pkg/oauth/oauth_flow_integration_test.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func newMockTokenServerError(t *testing.T) *httptest.Server {
8080

8181
// setupIntegrationManager creates a Manager with a fake credential helper and a
8282
// DCR client whose TokenEndpoint and AuthorizationEndpoint point to mockServerURL.
83-
func setupIntegrationManager(t *testing.T, serverName, tokenEndpointURL, authEndpointURL string) (*Manager, dcr.Client) {
83+
func setupIntegrationManager(t *testing.T, serverName, tokenEndpointURL string) (*Manager, dcr.Client) {
8484
t.Helper()
8585
helper := newFakeCredentialHelper()
8686
manager := NewManager(helper)
@@ -90,7 +90,7 @@ func setupIntegrationManager(t *testing.T, serverName, tokenEndpointURL, authEnd
9090
ProviderName: serverName,
9191
ClientID: "test-client-id-integration",
9292
ClientName: "MCP Gateway - " + serverName,
93-
AuthorizationEndpoint: authEndpointURL,
93+
AuthorizationEndpoint: "https://auth.example.com/authorize",
9494
TokenEndpoint: tokenEndpointURL,
9595
ResourceURL: "https://api.example.com",
9696
ScopesSupported: []string{"read", "write"},
@@ -117,7 +117,7 @@ func TestIntegration_FullCEOAuthFlow_HappyPath(t *testing.T) {
117117

118118
// Setup manager with DCR client pointing to mock token endpoint
119119
serverName := "integration-test-server"
120-
manager, dcrClient := setupIntegrationManager(t, serverName, tokenServer.URL, "https://auth.example.com/authorize")
120+
manager, dcrClient := setupIntegrationManager(t, serverName, tokenServer.URL)
121121

122122
// Start callback server
123123
callbackServer, err := NewCallbackServer()
@@ -150,7 +150,9 @@ func TestIntegration_FullCEOAuthFlow_HappyPath(t *testing.T) {
150150

151151
// Simulate OAuth provider redirect to callback server
152152
callbackState := fmt.Sprintf("mcp-gateway:%d:%s", callbackServer.Port(), baseState)
153-
callbackResp, err := http.Get(fmt.Sprintf("http://localhost:%d/callback?code=mock-auth-code&state=%s", callbackServer.Port(), callbackState))
153+
callbackReq, err := http.NewRequestWithContext(context.Background(), http.MethodGet, fmt.Sprintf("http://localhost:%d/callback?code=mock-auth-code&state=%s", callbackServer.Port(), callbackState), nil)
154+
require.NoError(t, err)
155+
callbackResp, err := http.DefaultClient.Do(callbackReq)
154156
require.NoError(t, err)
155157
defer callbackResp.Body.Close()
156158
assert.Equal(t, http.StatusOK, callbackResp.StatusCode)
@@ -193,7 +195,7 @@ func TestIntegration_CEOAuthFlow_TokenExchangeFailure(t *testing.T) {
193195
tokenServer := newMockTokenServerError(t)
194196

195197
serverName := "exchange-error-server"
196-
manager, dcrClient := setupIntegrationManager(t, serverName, tokenServer.URL, "https://auth.example.com/authorize")
198+
manager, dcrClient := setupIntegrationManager(t, serverName, tokenServer.URL)
197199

198200
// Build auth URL
199201
authURL, baseState, _, err := manager.BuildAuthorizationURL(
@@ -231,10 +233,12 @@ func TestIntegration_CEOAuthFlow_CallbackError(t *testing.T) {
231233
time.Sleep(50 * time.Millisecond)
232234

233235
// Simulate OAuth provider returning error
234-
resp, err := http.Get(fmt.Sprintf(
236+
errReq, err := http.NewRequestWithContext(context.Background(), http.MethodGet, fmt.Sprintf(
235237
"http://localhost:%d/callback?error=access_denied&error_description=User+denied+access",
236238
callbackServer.Port(),
237-
))
239+
), nil)
240+
require.NoError(t, err)
241+
resp, err := http.DefaultClient.Do(errReq)
238242
require.NoError(t, err)
239243
defer resp.Body.Close()
240244
assert.Equal(t, http.StatusBadRequest, resp.StatusCode)
@@ -281,7 +285,7 @@ func TestIntegration_CEOAuthFlow_StateValidation(t *testing.T) {
281285
tokenServer, _ := newMockTokenServer(t)
282286

283287
serverName := "state-validation-server"
284-
manager, _ := setupIntegrationManager(t, serverName, tokenServer.URL, "https://auth.example.com/authorize")
288+
manager, _ := setupIntegrationManager(t, serverName, tokenServer.URL)
285289

286290
// Generate two states
287291
_, baseState1, _, err := manager.BuildAuthorizationURL(
@@ -331,7 +335,7 @@ func TestIntegration_CEOAuthFlow_PKCEVerification(t *testing.T) {
331335
tokenServer, rec := newMockTokenServer(t)
332336

333337
serverName := "pkce-test-server"
334-
manager, _ := setupIntegrationManager(t, serverName, tokenServer.URL, "https://auth.example.com/authorize")
338+
manager, _ := setupIntegrationManager(t, serverName, tokenServer.URL)
335339

336340
// Build auth URL and capture verifier
337341
_, baseState, verifier, err := manager.BuildAuthorizationURL(
@@ -403,7 +407,7 @@ func TestIntegration_CEOAuthFlow_RevokeToken(t *testing.T) {
403407
tokenServer, _ := newMockTokenServer(t)
404408

405409
serverName := "revoke-test-server"
406-
manager, dcrClient := setupIntegrationManager(t, serverName, tokenServer.URL, "https://auth.example.com/authorize")
410+
manager, dcrClient := setupIntegrationManager(t, serverName, tokenServer.URL)
407411

408412
// Build auth URL and exchange to get a stored token
409413
_, baseState, _, err := manager.BuildAuthorizationURL(

0 commit comments

Comments
 (0)