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

Function TestClaims

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

Source from the content-addressed store, hash-verified

21)
22
23func TestClaims(t *testing.T) {
24 t.Parallel()
25
26 type tokenType struct {
27 Name string
28 KeySize int
29 Sign bool
30 }
31
32 types := []tokenType{
33 {
34 Name: "JWE",
35 Sign: false,
36 KeySize: 32,
37 },
38 {
39 Name: "JWS",
40 Sign: true,
41 KeySize: 64,
42 },
43 }
44
45 type testcase struct {
46 name string
47 claims jwtutils.Claims
48 expectedClaims jwt.Expected
49 expectedErr error
50 }
51
52 cases := []testcase{
53 {
54 name: "OK",
55 claims: jwt.Claims{
56 Issuer: "coder",
57 Subject: "user@coder.com",
58 Audience: jwt.Audience{"coder"},
59 Expiry: jwt.NewNumericDate(time.Now().Add(time.Hour)),
60 IssuedAt: jwt.NewNumericDate(time.Now()),
61 NotBefore: jwt.NewNumericDate(time.Now()),
62 },
63 },
64 {
65 name: "WrongIssuer",
66 claims: jwt.Claims{
67 Issuer: "coder",
68 Subject: "user@coder.com",
69 Audience: jwt.Audience{"coder"},
70 Expiry: jwt.NewNumericDate(time.Now().Add(time.Hour)),
71 IssuedAt: jwt.NewNumericDate(time.Now()),
72 NotBefore: jwt.NewNumericDate(time.Now()),
73 },
74 expectedClaims: jwt.Expected{
75 Issuer: "coder2",
76 },
77 expectedErr: jwt.ErrInvalidIssuer,
78 },
79 {
80 name: "WrongSubject",

Callers

nothing calls this directly

Calls 11

ContextFunction · 0.92
SignFunction · 0.92
EncryptFunction · 0.92
VerifyFunction · 0.92
DecryptFunction · 0.92
newKeyFunction · 0.85
withVerifyExpectedFunction · 0.85
withDecryptExpectedFunction · 0.85
AddMethod · 0.65
RunMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected