88 "net/http/httptest"
99 "testing"
1010 "time"
11-
11+
1212 "github.com/mark3labs/mcp-go/mcp"
1313)
1414
@@ -65,11 +65,11 @@ func TestStreamableHTTP_WithOAuth(t *testing.T) {
6565
6666 // Create OAuth config
6767 oauthConfig := OAuthConfig {
68- ClientID : "test-client" ,
69- RedirectURI : "http://localhost:8085/callback" ,
70- Scopes : []string {"mcp.read" , "mcp.write" },
71- TokenStore : tokenStore ,
72- PKCEEnabled : true ,
68+ ClientID : "test-client" ,
69+ RedirectURI : "http://localhost:8085/callback" ,
70+ Scopes : []string {"mcp.read" , "mcp.write" },
71+ TokenStore : tokenStore ,
72+ PKCEEnabled : true ,
7373 }
7474
7575 // Create StreamableHTTP with OAuth
@@ -82,7 +82,7 @@ func TestStreamableHTTP_WithOAuth(t *testing.T) {
8282 if ! transport .IsOAuthEnabled () {
8383 t .Errorf ("Expected IsOAuthEnabled() to return true" )
8484 }
85-
85+
8686 // Verify the OAuth handler is set
8787 if transport .GetOAuthHandler () == nil {
8888 t .Errorf ("Expected GetOAuthHandler() to return a handler" )
@@ -94,48 +94,48 @@ func TestStreamableHTTP_WithOAuth(t *testing.T) {
9494 ID : mcp .NewRequestId (1 ),
9595 Method : "test" ,
9696 })
97-
97+
9898 // Verify the error is an OAuthAuthorizationRequiredError
9999 if err == nil {
100100 t .Fatalf ("Expected error on first request, got nil" )
101101 }
102-
102+
103103 var oauthErr * OAuthAuthorizationRequiredError
104104 if ! errors .As (err , & oauthErr ) {
105105 t .Fatalf ("Expected OAuthAuthorizationRequiredError, got %T: %v" , err , err )
106106 }
107-
107+
108108 // Verify the error has the handler
109109 if oauthErr .Handler == nil {
110110 t .Errorf ("Expected OAuthAuthorizationRequiredError to have a handler" )
111111 }
112-
112+
113113 // Verify the server received the first request
114114 if requestCount != 1 {
115115 t .Errorf ("Expected server to receive 1 request, got %d" , requestCount )
116116 }
117-
117+
118118 // Second request should succeed
119119 response , err := transport .SendRequest (context .Background (), JSONRPCRequest {
120120 JSONRPC : "2.0" ,
121121 ID : mcp .NewRequestId (2 ),
122122 Method : "test" ,
123123 })
124-
124+
125125 if err != nil {
126126 t .Fatalf ("Failed to send second request: %v" , err )
127127 }
128-
128+
129129 // Verify the response
130130 var resultStr string
131131 if err := json .Unmarshal (response .Result , & resultStr ); err != nil {
132132 t .Fatalf ("Failed to unmarshal result: %v" , err )
133133 }
134-
134+
135135 if resultStr != "success" {
136136 t .Errorf ("Expected result to be 'success', got %v" , resultStr )
137137 }
138-
138+
139139 // Verify the server received the Authorization header
140140 if authHeaderReceived != "Bearer test-token" {
141141 t .Errorf ("Expected server to receive Authorization header 'Bearer test-token', got '%s'" , authHeaderReceived )
@@ -155,11 +155,11 @@ func TestStreamableHTTP_WithOAuth_Unauthorized(t *testing.T) {
155155
156156 // Create OAuth config
157157 oauthConfig := OAuthConfig {
158- ClientID : "test-client" ,
159- RedirectURI : "http://localhost:8085/callback" ,
160- Scopes : []string {"mcp.read" , "mcp.write" },
161- TokenStore : tokenStore ,
162- PKCEEnabled : true ,
158+ ClientID : "test-client" ,
159+ RedirectURI : "http://localhost:8085/callback" ,
160+ Scopes : []string {"mcp.read" , "mcp.write" },
161+ TokenStore : tokenStore ,
162+ PKCEEnabled : true ,
163163 }
164164
165165 // Create StreamableHTTP with OAuth
@@ -215,4 +215,4 @@ func TestStreamableHTTP_IsOAuthEnabled(t *testing.T) {
215215 if ! transport2 .IsOAuthEnabled () {
216216 t .Errorf ("Expected IsOAuthEnabled() to return true" )
217217 }
218- }
218+ }
0 commit comments