Skip to content

Commit bacdcd2

Browse files
authored
cover all algs for Builder (#110)
1 parent f65c7c6 commit bacdcd2

File tree

1 file changed

+67
-16
lines changed

1 file changed

+67
-16
lines changed

build_test.go

+67-16
Original file line numberDiff line numberDiff line change
@@ -12,37 +12,88 @@ import (
1212
)
1313

1414
func TestBuild(t *testing.T) {
15-
f := func(signer Signer, claims interface{}, want string) {
15+
f := func(signer Signer, verifier Verifier, claims interface{}) {
1616
t.Helper()
1717

18-
token, err := BuildBytes(signer, claims)
18+
token, err := Build(signer, claims)
1919
if err != nil {
2020
t.Error(err)
2121
}
2222

23-
raw := string(token)
24-
if raw != want {
25-
t.Errorf("want %v,\n got %v", want, raw)
23+
errVerify := verifier.Verify(token.Payload(), token.Signature())
24+
if errVerify != nil {
25+
t.Error(errVerify)
2626
}
2727
}
2828

2929
f(
30-
mustSigner(NewSignerHS(HS256, []byte("test-key-256"))),
31-
&StandardClaims{
32-
ID: "just an id",
33-
Audience: Audience([]string{"audience"}),
34-
},
35-
`eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJqdXN0IGFuIGlkIiwiYXVkIjoiYXVkaWVuY2UifQ.t5oEdZGp0Qbth7lo5fZlV_o4-r9gMoYBSktXbarjWoo`,
30+
mustSigner(NewSignerEdDSA(ed25519PrivateKey)),
31+
mustVerifier(NewVerifierEdDSA(ed25519PublicKey)),
32+
"i-am-already-a-claims",
33+
)
34+
35+
f(
36+
mustSigner(NewSignerHS(HS256, hsKey256)),
37+
mustVerifier(NewVerifierHS(HS256, hsKey256)),
38+
"i-am-already-a-claims",
39+
)
40+
f(
41+
mustSigner(NewSignerHS(HS384, hsKey384)),
42+
mustVerifier(NewVerifierHS(HS384, hsKey384)),
43+
"i-am-already-a-claims",
44+
)
45+
f(
46+
mustSigner(NewSignerHS(HS512, hsKey512)),
47+
mustVerifier(NewVerifierHS(HS512, hsKey512)),
48+
"i-am-already-a-claims",
49+
)
50+
51+
f(
52+
mustSigner(NewSignerRS(RS256, rsaPrivateKey256)),
53+
mustVerifier(NewVerifierRS(RS256, rsaPublicKey256)),
54+
"i-am-already-a-claims",
55+
)
56+
f(
57+
mustSigner(NewSignerRS(RS384, rsaPrivateKey384)),
58+
mustVerifier(NewVerifierRS(RS384, rsaPublicKey384)),
59+
"i-am-already-a-claims",
60+
)
61+
f(
62+
mustSigner(NewSignerRS(RS512, rsaPrivateKey512)),
63+
mustVerifier(NewVerifierRS(RS512, rsaPublicKey512)),
64+
"i-am-already-a-claims",
65+
)
66+
67+
f(
68+
mustSigner(NewSignerES(ES256, ecdsaPrivateKey256)),
69+
mustVerifier(NewVerifierES(ES256, ecdsaPublicKey256)),
70+
"i-am-already-a-claims",
71+
)
72+
f(
73+
mustSigner(NewSignerES(ES384, ecdsaPrivateKey384)),
74+
mustVerifier(NewVerifierES(ES384, ecdsaPublicKey384)),
75+
"i-am-already-a-claims",
76+
)
77+
f(
78+
mustSigner(NewSignerES(ES512, ecdsaPrivateKey521)),
79+
mustVerifier(NewVerifierES(ES512, ecdsaPublicKey521)),
80+
"i-am-already-a-claims",
81+
)
82+
83+
f(
84+
mustSigner(NewSignerPS(PS256, rsaPrivateKey256)),
85+
mustVerifier(NewVerifierPS(PS256, rsaPublicKey256)),
86+
"i-am-already-a-claims",
3687
)
3788
f(
38-
mustSigner(NewSignerHS(HS256, []byte("test-key-256"))),
89+
mustSigner(NewSignerPS(PS384, rsaPrivateKey384)),
90+
mustVerifier(NewVerifierPS(PS384, rsaPublicKey384)),
3991
"i-am-already-a-claims",
40-
`eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.aS1hbS1hbHJlYWR5LWEtY2xhaW1z.CLeN9xtQ9afr2_niL2JmurspYVwxDe0LxffAba3Wr9g`,
4192
)
4293
f(
43-
mustSigner(NewSignerHS(HS256, []byte("test-key-256"))),
44-
[]byte("i-am-already-a-claims"),
45-
`eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.aS1hbS1hbHJlYWR5LWEtY2xhaW1z.CLeN9xtQ9afr2_niL2JmurspYVwxDe0LxffAba3Wr9g`,
94+
mustSigner(NewSignerPS(PS512, rsaPrivateKey512)),
95+
mustVerifier(NewVerifierPS(PS512, rsaPublicKey512)),
96+
"i-am-already-a-claims",
4697
)
4798
}
4899

0 commit comments

Comments
 (0)