Software /
code /
prosody
Annotate
spec/util_jwt_spec.lua @ 12711:9e9f158d6699
util.paseto: Export similar API to new util.jwt for ease and consistency
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Mon, 11 Jul 2022 14:09:16 +0100 |
parent | 12704:31a2bd84191d |
child | 12736:ad4ab01f9b11 |
rev | line source |
---|---|
10660
c4ded3be7cc0
util.jwt: Basic JSON Web Token library supporting HS256 tokens
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
1 local jwt = require "util.jwt"; |
12700
899c057781cd
spec: Move test crypto keys to a shared file for clarity and easy maintenance
Matthew Wild <mwild1@gmail.com>
parents:
12699
diff
changeset
|
2 local test_keys = require "spec.inputs.test_keys"; |
10660
c4ded3be7cc0
util.jwt: Basic JSON Web Token library supporting HS256 tokens
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
3 |
12704
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
4 local array = require "util.array"; |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
5 local iter = require "util.iterators"; |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
6 local set = require "util.set"; |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
7 |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
8 -- Ignore long lines. We have some long tokens embedded here. |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
9 --luacheck: ignore 631 |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
10 |
10660
c4ded3be7cc0
util.jwt: Basic JSON Web Token library supporting HS256 tokens
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
11 describe("util.jwt", function () |
c4ded3be7cc0
util.jwt: Basic JSON Web Token library supporting HS256 tokens
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
12 it("validates", function () |
c4ded3be7cc0
util.jwt: Basic JSON Web Token library supporting HS256 tokens
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
13 local key = "secret"; |
c4ded3be7cc0
util.jwt: Basic JSON Web Token library supporting HS256 tokens
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
14 local token = jwt.sign(key, { payload = "this" }); |
c4ded3be7cc0
util.jwt: Basic JSON Web Token library supporting HS256 tokens
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
15 assert.string(token); |
c4ded3be7cc0
util.jwt: Basic JSON Web Token library supporting HS256 tokens
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
16 local ok, parsed = jwt.verify(key, token); |
c4ded3be7cc0
util.jwt: Basic JSON Web Token library supporting HS256 tokens
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
17 assert.truthy(ok) |
c4ded3be7cc0
util.jwt: Basic JSON Web Token library supporting HS256 tokens
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
18 assert.same({ payload = "this" }, parsed); |
12699
b3d0c1457584
util.jwt: Add support for RSA-based algorithms (RS256, PS256)
Matthew Wild <mwild1@gmail.com>
parents:
12696
diff
changeset
|
19 |
b3d0c1457584
util.jwt: Add support for RSA-based algorithms (RS256, PS256)
Matthew Wild <mwild1@gmail.com>
parents:
12696
diff
changeset
|
20 |
b3d0c1457584
util.jwt: Add support for RSA-based algorithms (RS256, PS256)
Matthew Wild <mwild1@gmail.com>
parents:
12696
diff
changeset
|
21 |
10660
c4ded3be7cc0
util.jwt: Basic JSON Web Token library supporting HS256 tokens
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
22 end); |
c4ded3be7cc0
util.jwt: Basic JSON Web Token library supporting HS256 tokens
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
23 it("rejects invalid", function () |
c4ded3be7cc0
util.jwt: Basic JSON Web Token library supporting HS256 tokens
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
24 local key = "secret"; |
c4ded3be7cc0
util.jwt: Basic JSON Web Token library supporting HS256 tokens
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
25 local token = jwt.sign("wrong", { payload = "this" }); |
c4ded3be7cc0
util.jwt: Basic JSON Web Token library supporting HS256 tokens
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
26 assert.string(token); |
10661
4eee1aaa9405
util.jwt: Remove unused return value from tests [luacheck]
Kim Alvefur <zash@zash.se>
parents:
10660
diff
changeset
|
27 local ok = jwt.verify(key, token); |
10660
c4ded3be7cc0
util.jwt: Basic JSON Web Token library supporting HS256 tokens
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
28 assert.falsy(ok) |
c4ded3be7cc0
util.jwt: Basic JSON Web Token library supporting HS256 tokens
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
29 end); |
12696
27a72982e331
util.jwt: Add support/tests for ES256 via improved API and using util.crypto
Matthew Wild <mwild1@gmail.com>
parents:
10661
diff
changeset
|
30 |
12704
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
31 local function jwt_reference_token(token) |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
32 return { |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
33 name = "jwt.io reference"; |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
34 token; |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
35 { -- payload |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
36 sub = "1234567890"; |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
37 name = "John Doe"; |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
38 admin = true; |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
39 iat = 1516239022; |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
40 }; |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
41 }; |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
42 end |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
43 |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
44 local untested_algorithms = set.new(array.collect(iter.keys(jwt._algorithms))); |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
45 |
12701
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
46 local test_cases = { |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
47 { |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
48 algorithm = "HS256"; |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
49 keys = { |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
50 { "your-256-bit-secret", "your-256-bit-secret" }; |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
51 { "another-secret", "another-secret" }; |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
52 }; |
12704
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
53 |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
54 jwt_reference_token [[eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJhZG1pbiI6dHJ1ZX0.F-cvL2RcfQhUtCavIM7q7zYE8drmj2LJk0JRkrS6He4]]; |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
55 }; |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
56 { |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
57 algorithm = "HS384"; |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
58 keys = { |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
59 { "your-384-bit-secret", "your-384-bit-secret" }; |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
60 { "another-secret", "another-secret" }; |
12701
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
61 }; |
12704
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
62 |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
63 jwt_reference_token [[eyJhbGciOiJIUzM4NCIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWUsImlhdCI6MTUxNjIzOTAyMn0.bQTnz6AuMJvmXXQsVPrxeQNvzDkimo7VNXxHeSBfClLufmCVZRUuyTwJF311JHuh]]; |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
64 }; |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
65 { |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
66 algorithm = "HS512"; |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
67 keys = { |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
68 { "your-512-bit-secret", "your-512-bit-secret" }; |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
69 { "another-secret", "another-secret" }; |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
70 }; |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
71 |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
72 jwt_reference_token [[eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWUsImlhdCI6MTUxNjIzOTAyMn0.VFb0qJ1LRg_4ujbZoRMXnVkUgiuKq5KxWqNdbKq_G9Vvz-S1zZa9LPxtHWKa64zDl2ofkT8F6jBt_K4riU-fPg]]; |
12701
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
73 }; |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
74 { |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
75 algorithm = "ES256"; |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
76 keys = { |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
77 { test_keys.ecdsa_private_pem, test_keys.ecdsa_public_pem }; |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
78 { test_keys.alt_ecdsa_private_pem, test_keys.alt_ecdsa_public_pem }; |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
79 }; |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
80 { |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
81 name = "jwt.io reference"; |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
82 [[eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWUsImlhdCI6MTUxNjIzOTAyMn0.tyh-VfuzIxCyGYDlkBA7DfyjrqmSHu6pQ2hoZuFqUSLPNY2N0mpHb3nk5K17HWP_3cYHBw7AhHale5wky6-sVA]]; |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
83 { -- payload |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
84 sub = "1234567890"; |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
85 name = "John Doe"; |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
86 admin = true; |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
87 iat = 1516239022; |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
88 }; |
12699
b3d0c1457584
util.jwt: Add support for RSA-based algorithms (RS256, PS256)
Matthew Wild <mwild1@gmail.com>
parents:
12696
diff
changeset
|
89 }; |
12701
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
90 }; |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
91 { |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
92 algorithm = "RS256"; |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
93 keys = { |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
94 { test_keys.rsa_private_pem, test_keys.rsa_public_pem }; |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
95 { test_keys.alt_rsa_private_pem, test_keys.alt_rsa_public_pem }; |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
96 }; |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
97 { |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
98 name = "jwt.io reference"; |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
99 [[eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWUsImlhdCI6MTUxNjIzOTAyMn0.NHVaYe26MbtOYhSKkoKYdFVomg4i8ZJd8_-RU8VNbftc4TSMb4bXP3l3YlNWACwyXPGffz5aXHc6lty1Y2t4SWRqGteragsVdZufDn5BlnJl9pdR_kdVFUsra2rWKEofkZeIC4yWytE58sMIihvo9H1ScmmVwBcQP6XETqYd0aSHp1gOa9RdUPDvoXQ5oqygTqVtxaDr6wUFKrKItgBMzWIdNZ6y7O9E0DhEPTbE9rfBo6KTFsHAZnMg4k68CDp2woYIaXbmYTWcvbzIuHO7_37GT79XdIwkm95QJ7hYC9RiwrV7mesbY4PAahERJawntho0my942XheVLmGwLMBkQ]]; |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
100 { -- payload |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
101 sub = "1234567890"; |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
102 name = "John Doe"; |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
103 admin = true; |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
104 iat = 1516239022; |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
105 }; |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
106 }; |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
107 }; |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
108 { |
12704
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
109 algorithm = "RS384"; |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
110 keys = { |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
111 { test_keys.rsa_private_pem, test_keys.rsa_public_pem }; |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
112 { test_keys.alt_rsa_private_pem, test_keys.alt_rsa_public_pem }; |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
113 }; |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
114 |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
115 jwt_reference_token [[eyJhbGciOiJSUzM4NCIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWUsImlhdCI6MTUxNjIzOTAyMn0.o1hC1xYbJolSyh0-bOY230w22zEQSk5TiBfc-OCvtpI2JtYlW-23-8B48NpATozzMHn0j3rE0xVUldxShzy0xeJ7vYAccVXu2Gs9rnTVqouc-UZu_wJHkZiKBL67j8_61L6SXswzPAQu4kVDwAefGf5hyYBUM-80vYZwWPEpLI8K4yCBsF6I9N1yQaZAJmkMp_Iw371Menae4Mp4JusvBJS-s6LrmG2QbiZaFaxVJiW8KlUkWyUCns8-qFl5OMeYlgGFsyvvSHvXCzQrsEXqyCdS4tQJd73ayYA4SPtCb9clz76N1zE5WsV4Z0BYrxeb77oA7jJhh994RAPzCG0hmQ]]; |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
116 }; |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
117 { |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
118 algorithm = "RS512"; |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
119 keys = { |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
120 { test_keys.rsa_private_pem, test_keys.rsa_public_pem }; |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
121 { test_keys.alt_rsa_private_pem, test_keys.alt_rsa_public_pem }; |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
122 }; |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
123 |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
124 jwt_reference_token [[eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWUsImlhdCI6MTUxNjIzOTAyMn0.jYW04zLDHfR1v7xdrW3lCGZrMIsVe0vWCfVkN2DRns2c3MN-mcp_-RE6TN9umSBYoNV-mnb31wFf8iun3fB6aDS6m_OXAiURVEKrPFNGlR38JSHUtsFzqTOj-wFrJZN4RwvZnNGSMvK3wzzUriZqmiNLsG8lktlEn6KA4kYVaM61_NpmPHWAjGExWv7cjHYupcjMSmR8uMTwN5UuAwgW6FRstCJEfoxwb0WKiyoaSlDuIiHZJ0cyGhhEmmAPiCwtPAwGeaL1yZMcp0p82cpTQ5Qb-7CtRov3N4DcOHgWYk6LomPR5j5cCkePAz87duqyzSMpCB0mCOuE3CU2VMtGeQ]]; |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
125 }; |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
126 { |
12701
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
127 algorithm = "PS256"; |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
128 keys = { |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
129 { test_keys.rsa_private_pem, test_keys.rsa_public_pem }; |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
130 { test_keys.alt_rsa_private_pem, test_keys.alt_rsa_public_pem }; |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
131 }; |
12704
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
132 |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
133 jwt_reference_token [[eyJhbGciOiJQUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWUsImlhdCI6MTUxNjIzOTAyMn0.iOeNU4dAFFeBwNj6qdhdvm-IvDQrTa6R22lQVJVuWJxorJfeQww5Nwsra0PjaOYhAMj9jNMO5YLmud8U7iQ5gJK2zYyepeSuXhfSi8yjFZfRiSkelqSkU19I-Ja8aQBDbqXf2SAWA8mHF8VS3F08rgEaLCyv98fLLH4vSvsJGf6ueZSLKDVXz24rZRXGWtYYk_OYYTVgR1cg0BLCsuCvqZvHleImJKiWmtS0-CymMO4MMjCy_FIl6I56NqLE9C87tUVpo1mT-kbg5cHDD8I7MjCW5Iii5dethB4Vid3mZ6emKjVYgXrtkOQ-JyGMh6fnQxEFN1ft33GX2eRHluK9eg]]; |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
134 }; |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
135 { |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
136 algorithm = "PS384"; |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
137 keys = { |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
138 { test_keys.rsa_private_pem, test_keys.rsa_public_pem }; |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
139 { test_keys.alt_rsa_private_pem, test_keys.alt_rsa_public_pem }; |
12701
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
140 }; |
12704
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
141 |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
142 jwt_reference_token [[eyJhbGciOiJQUzM4NCIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWUsImlhdCI6MTUxNjIzOTAyMn0.Lfe_aCQme_gQpUk9-6l9qesu0QYZtfdzfy08w8uqqPH_gnw-IVyQwyGLBHPFBJHMbifdSMxPjJjkCD0laIclhnBhowILu6k66_5Y2z78GHg8YjKocAvB-wSUiBhuV6hXVxE5emSjhfVz2OwiCk2bfk2hziRpkdMvfcITkCx9dmxHU6qcEIsTTHuH020UcGayB1-IoimnjTdCsV1y4CMr_ECDjBrqMdnontkqKRIM1dtmgYFsJM6xm7ewi_ksG_qZHhaoBkxQ9wq9OVQRGiSZYowCp73d2BF3jYMhdmv2JiaUz5jRvv6lVU7Quq6ylVAlSPxeov9voYHO1mgZFCY1kQ]]; |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
143 }; |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
144 { |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
145 algorithm = "PS512"; |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
146 keys = { |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
147 { test_keys.rsa_private_pem, test_keys.rsa_public_pem }; |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
148 { test_keys.alt_rsa_private_pem, test_keys.alt_rsa_public_pem }; |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
149 }; |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
150 |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
151 jwt_reference_token [[eyJhbGciOiJQUzUxMiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWUsImlhdCI6MTUxNjIzOTAyMn0.J5W09-rNx0pt5_HBiydR-vOluS6oD-RpYNa8PVWwMcBDQSXiw6-EPW8iSsalXPspGj3ouQjAnOP_4-zrlUUlvUIt2T79XyNeiKuooyIFvka3Y5NnGiOUBHWvWcWp4RcQFMBrZkHtJM23sB5D7Wxjx0-HFeNk-Y3UJgeJVhg5NaWXypLkC4y0ADrUBfGAxhvGdRdULZivfvzuVtv6AzW6NRuEE6DM9xpoWX_4here-yvLS2YPiBTZ8xbB3axdM99LhES-n52lVkiX5AWg2JJkEROZzLMpaacA_xlbUz_zbIaOaoqk8gB5oO7kI6sZej3QAdGigQy-hXiRnW_L98d4GQ]]; |
12701
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
152 }; |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
153 }; |
12696
27a72982e331
util.jwt: Add support/tests for ES256 via improved API and using util.crypto
Matthew Wild <mwild1@gmail.com>
parents:
10661
diff
changeset
|
154 |
12701
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
155 local function do_verify_test(algorithm, verifying_key, token, expect_payload) |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
156 local verify = jwt.new_verifier(algorithm, verifying_key); |
12696
27a72982e331
util.jwt: Add support/tests for ES256 via improved API and using util.crypto
Matthew Wild <mwild1@gmail.com>
parents:
10661
diff
changeset
|
157 |
12701
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
158 assert.is_string(token); |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
159 local result = {verify(token)}; |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
160 if expect_payload then |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
161 assert.same({ |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
162 true; -- success |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
163 expect_payload; -- payload |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
164 }, result); |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
165 else |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
166 assert.same({ |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
167 false; |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
168 "signature-mismatch"; |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
169 }, result); |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
170 end |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
171 end |
12696
27a72982e331
util.jwt: Add support/tests for ES256 via improved API and using util.crypto
Matthew Wild <mwild1@gmail.com>
parents:
10661
diff
changeset
|
172 |
12701
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
173 local function do_sign_verify_test(algorithm, signing_key, verifying_key, expect_success, expect_token) |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
174 local sign = jwt.new_signer(algorithm, signing_key); |
12699
b3d0c1457584
util.jwt: Add support for RSA-based algorithms (RS256, PS256)
Matthew Wild <mwild1@gmail.com>
parents:
12696
diff
changeset
|
175 |
12701
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
176 local test_payload = { |
12699
b3d0c1457584
util.jwt: Add support for RSA-based algorithms (RS256, PS256)
Matthew Wild <mwild1@gmail.com>
parents:
12696
diff
changeset
|
177 sub = "1234567890"; |
b3d0c1457584
util.jwt: Add support for RSA-based algorithms (RS256, PS256)
Matthew Wild <mwild1@gmail.com>
parents:
12696
diff
changeset
|
178 name = "John Doe"; |
b3d0c1457584
util.jwt: Add support for RSA-based algorithms (RS256, PS256)
Matthew Wild <mwild1@gmail.com>
parents:
12696
diff
changeset
|
179 admin = true; |
b3d0c1457584
util.jwt: Add support for RSA-based algorithms (RS256, PS256)
Matthew Wild <mwild1@gmail.com>
parents:
12696
diff
changeset
|
180 iat = 1516239022; |
12701
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
181 }; |
12699
b3d0c1457584
util.jwt: Add support for RSA-based algorithms (RS256, PS256)
Matthew Wild <mwild1@gmail.com>
parents:
12696
diff
changeset
|
182 |
12701
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
183 local token = sign(test_payload); |
12699
b3d0c1457584
util.jwt: Add support for RSA-based algorithms (RS256, PS256)
Matthew Wild <mwild1@gmail.com>
parents:
12696
diff
changeset
|
184 |
12701
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
185 if expect_token then |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
186 assert.equal(expect_token, token); |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
187 end |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
188 |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
189 do_verify_test(algorithm, verifying_key, token, expect_success and test_payload or false); |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
190 end |
12699
b3d0c1457584
util.jwt: Add support for RSA-based algorithms (RS256, PS256)
Matthew Wild <mwild1@gmail.com>
parents:
12696
diff
changeset
|
191 |
b3d0c1457584
util.jwt: Add support for RSA-based algorithms (RS256, PS256)
Matthew Wild <mwild1@gmail.com>
parents:
12696
diff
changeset
|
192 |
12701
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
193 for _, algorithm_tests in ipairs(test_cases) do |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
194 local algorithm = algorithm_tests.algorithm; |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
195 local keypairs = algorithm_tests.keys; |
12704
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
196 |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
197 untested_algorithms:remove(algorithm); |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
198 |
12701
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
199 describe(algorithm, function () |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
200 it("can do basic sign and verify", function () |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
201 for _, keypair in ipairs(keypairs) do |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
202 local signing_key, verifying_key = keypair[1], keypair[2]; |
12704
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
203 do_sign_verify_test(algorithm, signing_key, verifying_key, true); |
12701
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
204 end |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
205 end); |
12699
b3d0c1457584
util.jwt: Add support for RSA-based algorithms (RS256, PS256)
Matthew Wild <mwild1@gmail.com>
parents:
12696
diff
changeset
|
206 |
12701
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
207 if #keypairs >= 2 then |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
208 it("rejects invalid tokens", function () |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
209 do_sign_verify_test(algorithm, keypairs[1][1], keypairs[2][2], false); |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
210 end); |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
211 else |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
212 pending("rejects invalid tokens", function () |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
213 error("Needs at least 2 key pairs"); |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
214 end); |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
215 end |
12699
b3d0c1457584
util.jwt: Add support for RSA-based algorithms (RS256, PS256)
Matthew Wild <mwild1@gmail.com>
parents:
12696
diff
changeset
|
216 |
12701
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
217 if #algorithm_tests > 0 then |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
218 for test_n, test_case in ipairs(algorithm_tests) do |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
219 it("can verify "..(test_case.name or (("test case %d"):format(test_n))), function () |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
220 do_verify_test( |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
221 algorithm, |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
222 test_case.verifying_key or keypairs[1][2], |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
223 test_case[1], |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
224 test_case[2] |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
225 ); |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
226 end); |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
227 end |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
228 else |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
229 pending("can verify reference tokens", function () |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
230 error("No test tokens provided"); |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
231 end); |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
232 end |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
233 end); |
8e402a2ae1b8
util.jwt: Overhaul of tests to use declarative approach
Matthew Wild <mwild1@gmail.com>
parents:
12700
diff
changeset
|
234 end |
12704
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
235 |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
236 for algorithm in untested_algorithms do |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
237 pending(algorithm.." tests", function () end); |
31a2bd84191d
util.jwt: All the algorithms (+ all the tests!)
Matthew Wild <mwild1@gmail.com>
parents:
12701
diff
changeset
|
238 end |
10660
c4ded3be7cc0
util.jwt: Basic JSON Web Token library supporting HS256 tokens
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
239 end); |
c4ded3be7cc0
util.jwt: Basic JSON Web Token library supporting HS256 tokens
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
240 |