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

Method TestJWTFileReader_ReadToken_InvalidJWT

credentials/jwt/file_reader_test.go:77–123  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

75}
76
77func (s) TestJWTFileReader_ReadToken_InvalidJWT(t *testing.T) {
78 now := time.Now().Truncate(time.Second)
79 tests := []struct {
80 name string
81 tokenContent string
82 wantErr error
83 }{
84 {
85 name: "valid_token_without_expiration",
86 tokenContent: createTestJWT(t, time.Time{}),
87 wantErr: errJWTValidation,
88 },
89 {
90 name: "expired_token",
91 tokenContent: createTestJWT(t, now.Add(-time.Hour)),
92 wantErr: errJWTValidation,
93 },
94 {
95 name: "malformed_JWT_not_enough_parts",
96 tokenContent: "invalid.jwt",
97 wantErr: errJWTValidation,
98 },
99 {
100 name: "malformed_JWT_invalid_base64",
101 tokenContent: "header.invalid_base64!@#.signature",
102 wantErr: errJWTValidation,
103 },
104 {
105 name: "malformed_JWT_invalid_JSON",
106 tokenContent: createInvalidJWT(t),
107 wantErr: errJWTValidation,
108 },
109 }
110
111 for _, tt := range tests {
112 t.Run(tt.name, func(t *testing.T) {
113 tokenFile := writeTempFile(t, "token", tt.tokenContent)
114
115 reader := jwtFileReader{tokenFilePath: tokenFile}
116 if _, _, err := reader.readToken(); err == nil {
117 t.Fatal("ReadToken() expected error, got nil")
118 } else if !errors.Is(err, tt.wantErr) {
119 t.Fatalf("ReadToken() error = %v, want error %v", err, tt.wantErr)
120 }
121 })
122 }
123}
124
125func (s) TestJWTFileReader_ReadToken_ValidToken(t *testing.T) {
126 now := time.Now().Truncate(time.Second)

Callers

nothing calls this directly

Calls 9

readTokenMethod · 0.95
createInvalidJWTFunction · 0.85
NowMethod · 0.80
IsMethod · 0.80
createTestJWTFunction · 0.70
writeTempFileFunction · 0.70
AddMethod · 0.65
FatalMethod · 0.65
FatalfMethod · 0.65

Tested by

no test coverage detected