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

Method TestGetRequestMetadataBadSubjectTokenRead

credentials/sts/sts_test.go:414–443  ·  view source on GitHub ↗

TestGetRequestMetadataBadSubjectTokenRead verifies the scenario where the attempt to read the subjectToken fails.

(t *testing.T)

Source from the content-addressed store, hash-verified

412// TestGetRequestMetadataBadSubjectTokenRead verifies the scenario where the
413// attempt to read the subjectToken fails.
414func (s) TestGetRequestMetadataBadSubjectTokenRead(t *testing.T) {
415 defer overrideSubjectTokenError()()
416 fc, cancel := overrideHTTPClientGood()
417 defer cancel()
418
419 creds, err := NewCredentials(goodOptions)
420 if err != nil {
421 t.Fatalf("NewCredentials(%v) = %v", goodOptions, err)
422 }
423
424 errCh := make(chan error, 1)
425 go func() {
426 ctx, cancel := context.WithTimeout(context.Background(), defaultTestShortTimeout)
427 defer cancel()
428 if _, err := fc.ReqChan.Receive(ctx); err != context.DeadlineExceeded {
429 errCh <- err
430 return
431 }
432 errCh <- nil
433 }()
434
435 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
436 defer cancel()
437 if _, err := creds.GetRequestMetadata(createTestContext(ctx, credentials.PrivacyAndIntegrity), ""); err == nil {
438 t.Fatal("creds.GetRequestMetadata() succeeded when expected to fail")
439 }
440 if err := <-errCh; err != nil {
441 t.Fatal(err)
442 }
443}
444
445func (s) TestNewCredentials(t *testing.T) {
446 tests := []struct {

Callers

nothing calls this directly

Calls 8

overrideHTTPClientGoodFunction · 0.85
createTestContextFunction · 0.85
NewCredentialsFunction · 0.70
FatalfMethod · 0.65
GetRequestMetadataMethod · 0.65
FatalMethod · 0.65
ReceiveMethod · 0.45

Tested by

no test coverage detected