(t *testing.T)
| 99 | } |
| 100 | |
| 101 | func TestIsUnmatchedAuthErr(t *testing.T) { |
| 102 | tests := []struct { |
| 103 | name string |
| 104 | st *status.Status |
| 105 | want bool |
| 106 | }{ |
| 107 | { |
| 108 | name: "generic 401/Unauthenticated error is caught", |
| 109 | st: status.New(codes.Unauthenticated, "some auth error"), |
| 110 | want: true, |
| 111 | }, |
| 112 | { |
| 113 | name: "JWT token expired (Unauthenticated) is caught", |
| 114 | st: toGRPCStatus(jwtMiddleware.ErrTokenExpired), |
| 115 | want: true, |
| 116 | }, |
| 117 | { |
| 118 | name: "PermissionDenied is NOT caught", |
| 119 | st: status.New(codes.PermissionDenied, "forbidden"), |
| 120 | want: false, |
| 121 | }, |
| 122 | { |
| 123 | name: "OK status is NOT caught", |
| 124 | st: status.New(codes.OK, ""), |
| 125 | want: false, |
| 126 | }, |
| 127 | { |
| 128 | name: "Internal error is NOT caught", |
| 129 | st: status.New(codes.Internal, "internal server error"), |
| 130 | want: false, |
| 131 | }, |
| 132 | { |
| 133 | name: "NotFound is NOT caught", |
| 134 | st: status.New(codes.NotFound, "not found"), |
| 135 | want: false, |
| 136 | }, |
| 137 | } |
| 138 | |
| 139 | for _, tt := range tests { |
| 140 | t.Run(tt.name, func(t *testing.T) { |
| 141 | got := isUnmatchedAuthErr(tt.st) |
| 142 | assert.Equal(t, tt.want, got, "isUnmatchedAuthErr()") |
| 143 | }) |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | // TestKratosErrorsIsMasksJWTErrors demonstrates the bug that motivates our |
| 148 | // Message-based comparison: Kratos errors.Is() only compares Code and Reason. |
nothing calls this directly
no test coverage detected