MCPcopy Index your code
hub / github.com/coder/coder / TestJWE

Function TestJWE

coderd/jwtutils/jwt_test.go:261–350  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

259}
260
261func TestJWE(t *testing.T) {
262 t.Parallel()
263
264 t.Run("WrongKeyAlgorithm", func(t *testing.T) {
265 t.Parallel()
266
267 var (
268 ctx = testutil.Context(t, testutil.WaitShort)
269 key = newKey(t, 32)
270 )
271
272 token, err := jwtutils.Encrypt(ctx, key, jwt.Claims{})
273 require.NoError(t, err)
274
275 var actual testClaims
276 err = jwtutils.Decrypt(ctx, key, token, &actual, withKeyAlgorithm(jose.A128GCMKW))
277 require.Error(t, err)
278 })
279
280 t.Run("WrongContentyEncryption", func(t *testing.T) {
281 t.Parallel()
282
283 var (
284 ctx = testutil.Context(t, testutil.WaitShort)
285 key = newKey(t, 32)
286 )
287
288 token, err := jwtutils.Encrypt(ctx, key, jwt.Claims{})
289 require.NoError(t, err)
290
291 var actual testClaims
292 err = jwtutils.Decrypt(ctx, key, token, &actual, withContentEncryptionAlgorithm(jose.A128GCM))
293 require.Error(t, err)
294 })
295
296 t.Run("CustomClaims", func(t *testing.T) {
297 t.Parallel()
298
299 var (
300 ctx = testutil.Context(t, testutil.WaitShort)
301 key = newKey(t, 32)
302 )
303
304 expected := testClaims{
305 MyClaim: "my_value",
306 }
307
308 token, err := jwtutils.Encrypt(ctx, key, expected)
309 require.NoError(t, err)
310
311 var actual testClaims
312 err = jwtutils.Decrypt(ctx, key, token, &actual, withDecryptExpected(jwt.Expected{}))
313 require.NoError(t, err)
314 require.Equal(t, expected, actual)
315 })
316
317 t.Run("WithKeycache", func(t *testing.T) {
318 t.Parallel()

Callers

nothing calls this directly

Calls 15

ContextFunction · 0.92
EncryptFunction · 0.92
DecryptFunction · 0.92
NewDBFunction · 0.92
CryptoKeyFunction · 0.92
LoggerFunction · 0.92
NewEncryptionCacheFunction · 0.92
newKeyFunction · 0.85
withKeyAlgorithmFunction · 0.85
withDecryptExpectedFunction · 0.85
RunMethod · 0.65

Tested by

no test coverage detected