MCPcopy
hub / github.com/grpc/grpc-go / TestGetRequestMetadataSuccess

Method TestGetRequestMetadataSuccess

credentials/sts/sts_test.go:242–280  ·  view source on GitHub ↗

TestGetRequestMetadataSuccess verifies the successful case of sending an token exchange request and processing the response.

(t *testing.T)

Source from the content-addressed store, hash-verified

240// TestGetRequestMetadataSuccess verifies the successful case of sending an
241// token exchange request and processing the response.
242func (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

Callers

nothing calls this directly

Calls 9

overrideSubjectTokenGoodFunction · 0.85
overrideHTTPClientGoodFunction · 0.85
receiveAndCompareRequestFunction · 0.85
createTestContextFunction · 0.85
NewCredentialsFunction · 0.70
FatalfMethod · 0.65
GetRequestMetadataMethod · 0.65
EqualMethod · 0.65
FatalMethod · 0.65

Tested by

no test coverage detected