TestIsWrappedErrGRPCWireRoundTrip verifies that isWrappedErr works after a full gRPC wire round-trip: KratosError -> GRPCStatus -> proto bytes -> gRPC status.FromError -> isWrappedErr. This simulates the actual path an error takes from the server through a gRPC transport to the CLI client.
(t *testing.T)
| 168 | // status.FromError -> isWrappedErr. This simulates the actual path an error |
| 169 | // takes from the server through a gRPC transport to the CLI client. |
| 170 | func TestIsWrappedErrGRPCWireRoundTrip(t *testing.T) { |
| 171 | sentinels := []*kratosErrors.Error{ |
| 172 | jwtMiddleware.ErrTokenExpired, |
| 173 | jwtMiddleware.ErrTokenInvalid, |
| 174 | jwtMiddleware.ErrTokenParseFail, |
| 175 | jwtMiddleware.ErrMissingJwtToken, |
| 176 | } |
| 177 | |
| 178 | for _, sentinel := range sentinels { |
| 179 | t.Run(sentinel.Message, func(t *testing.T) { |
| 180 | // Step 1: Convert Kratos error to gRPC status (server side) |
| 181 | grpcSt := sentinel.GRPCStatus() |
| 182 | |
| 183 | // Step 2: Serialize to the wire format (proto bytes) |
| 184 | proto := grpcSt.Proto() |
| 185 | require.NotNil(t, proto, "gRPC status proto should not be nil") |
| 186 | |
| 187 | // Step 3: Deserialize from proto back into a gRPC status (client side) |
| 188 | roundTripped := status.FromProto(proto) |
| 189 | require.NotNil(t, roundTripped, "round-tripped status should not be nil") |
| 190 | |
| 191 | // Step 4: Verify isWrappedErr still matches after the full round-trip |
| 192 | assert.True(t, isWrappedErr(roundTripped, sentinel), |
| 193 | "isWrappedErr should match %q after gRPC wire round-trip", sentinel.Message) |
| 194 | |
| 195 | // Step 5: Verify it does NOT match a different sentinel after round-trip |
| 196 | for _, other := range sentinels { |
| 197 | if other == sentinel { |
| 198 | continue |
| 199 | } |
| 200 | assert.False(t, isWrappedErr(roundTripped, other), |
| 201 | "isWrappedErr should NOT match %q against %q after round-trip", |
| 202 | sentinel.Message, other.Message) |
| 203 | } |
| 204 | }) |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | // TestJWTSentinelMessageCanary asserts the exact Message strings of the JWT |
| 209 | // sentinel errors we depend on. If a Kratos update changes these strings |
nothing calls this directly
no test coverage detected