(t *testing.T)
| 75 | } |
| 76 | |
| 77 | func (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 | |
| 125 | func (s) TestJWTFileReader_ReadToken_ValidToken(t *testing.T) { |
| 126 | now := time.Now().Truncate(time.Second) |
nothing calls this directly
no test coverage detected