TestGetRequestMetadataSuccess verifies the successful case of sending an token exchange request and processing the response.
(t *testing.T)
| 240 | // TestGetRequestMetadataSuccess verifies the successful case of sending an |
| 241 | // token exchange request and processing the response. |
| 242 | func (s) TestGetRequestMetadataSuccess(t *testing.T) { |
| 243 | defer overrideSubjectTokenGood()() |
| 244 | fc, cancel := overrideHTTPClientGood() |
| 245 | defer cancel() |
| 246 | |
| 247 | creds, err := NewCredentials(goodOptions) |
| 248 | if err != nil { |
| 249 | t.Fatalf("NewCredentials(%v) = %v", goodOptions, err) |
| 250 | } |
| 251 | |
| 252 | errCh := make(chan error, 1) |
| 253 | go receiveAndCompareRequest(fc.ReqChan, errCh) |
| 254 | |
| 255 | ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) |
| 256 | defer cancel() |
| 257 | |
| 258 | gotMetadata, err := creds.GetRequestMetadata(createTestContext(ctx, credentials.PrivacyAndIntegrity), "") |
| 259 | if err != nil { |
| 260 | t.Fatalf("creds.GetRequestMetadata() = %v", err) |
| 261 | } |
| 262 | if !cmp.Equal(gotMetadata, goodMetadata) { |
| 263 | t.Fatalf("creds.GetRequestMetadata() = %v, want %v", gotMetadata, goodMetadata) |
| 264 | } |
| 265 | if err := <-errCh; err != nil { |
| 266 | t.Fatal(err) |
| 267 | } |
| 268 | |
| 269 | // Make another call to get request metadata and this should return contents |
| 270 | // from the cache. This will fail if the credentials tries to send a fresh |
| 271 | // request here since we have not configured our fakeClient to return any |
| 272 | // response on retries. |
| 273 | gotMetadata, err = creds.GetRequestMetadata(createTestContext(ctx, credentials.PrivacyAndIntegrity), "") |
| 274 | if err != nil { |
| 275 | t.Fatalf("creds.GetRequestMetadata() = %v", err) |
| 276 | } |
| 277 | if !cmp.Equal(gotMetadata, goodMetadata) { |
| 278 | t.Fatalf("creds.GetRequestMetadata() = %v, want %v", gotMetadata, goodMetadata) |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | // TestGetRequestMetadataBadSecurityLevel verifies the case where the |
| 283 | // securityLevel specified in the context passed to GetRequestMetadata is not |
nothing calls this directly
no test coverage detected