(t *testing.T)
| 980 | } |
| 981 | |
| 982 | func TestStreamableClientOAuth_401(t *testing.T) { |
| 983 | ctx := context.Background() |
| 984 | oauthHandler := &mockOAuthHandler{token: nil} |
| 985 | |
| 986 | fake := &fakeStreamableServer{ |
| 987 | t: t, |
| 988 | responses: fakeResponses{ |
| 989 | {"POST", "", methodInitialize, ""}: { |
| 990 | header: header{ |
| 991 | "Content-Type": "application/json", |
| 992 | sessionIDHeader: "123", |
| 993 | }, |
| 994 | body: jsonBody(t, initResp), |
| 995 | }, |
| 996 | }, |
| 997 | } |
| 998 | verifier := func(ctx context.Context, token string, req *http.Request) (*auth.TokenInfo, error) { |
| 999 | // Accept any token. |
| 1000 | return &auth.TokenInfo{Expiration: time.Now().Add(time.Hour)}, nil |
| 1001 | } |
| 1002 | httpServer := httptest.NewServer(auth.RequireBearerToken(verifier, nil)(fake)) |
| 1003 | t.Cleanup(httpServer.Close) |
| 1004 | |
| 1005 | transport := &StreamableClientTransport{ |
| 1006 | Endpoint: httpServer.URL, |
| 1007 | OAuthHandler: oauthHandler, |
| 1008 | } |
| 1009 | client := NewClient(testImpl, nil) |
| 1010 | _, err := client.Connect(ctx, transport, nil) |
| 1011 | if err == nil || !strings.Contains(err.Error(), "Unauthorized") { |
| 1012 | t.Fatalf("client.Connect() error does not contain 'Unauthorized': %v", err) |
| 1013 | } |
| 1014 | |
| 1015 | if !oauthHandler.authorizeCalled { |
| 1016 | t.Errorf("expected Authorize to be called") |
| 1017 | } |
| 1018 | } |
| 1019 | |
| 1020 | // blockingCountingOAuthHandler is an OAuthHandler that blocks inside |
| 1021 | // Authorize until the caller's context is cancelled, then returns a custom |
nothing calls this directly
no test coverage detected
searching dependent graphs…