Software /
code /
prosody
Annotate
spec/util_paseto_spec.lua @ 12712:719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Unfortunately there are only a few relevant ones, but they did help catch some
bugs.
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Mon, 11 Jul 2022 14:10:07 +0100 |
child | 12713:52eead170bb8 |
rev | line source |
---|---|
12712
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 -- Ignore long lines in this file |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 --luacheck: ignore 631 |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 describe("util.paseto", function () |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 local paseto = require "util.paseto"; |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 local json = require "util.json"; |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 local function parse_test_cases(json_test_cases) |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 local input_cases = json.decode(json_test_cases); |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 local output_cases = {}; |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 for _, case in ipairs(input_cases) do |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 assert.is_string(case.name, "Bad test case: expected name"); |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 assert.is_nil(output_cases[case.name], "Bad test case: duplicate name"); |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 output_cases[case.name] = function () |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 local verify_key = paseto.v4_public.import_public_key(case["public-key-pem"]); |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 local payload, err = paseto.v4_public.verify(case.token, verify_key, case.footer, case["implicit-assertion"]); |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 if case["expect-fail"] then |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 assert.is_nil(payload); |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 else |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 assert.is_nil(err); |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 assert.same(json.decode(case.payload), payload); |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 end |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 end; |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 end |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 return output_cases; |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 end |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 describe("v4.public", function () |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 local test_cases = parse_test_cases [=[[ |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 { |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 "name": "4-S-1", |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 "expect-fail": false, |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 "public-key": "1eb9dbbbbc047c03fd70604e0071f0987e16b28b757225c11f00415d0e20b1a2", |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 "secret-key": "b4cbfb43df4ce210727d953e4a713307fa19bb7d9f85041438d9e11b942a37741eb9dbbbbc047c03fd70604e0071f0987e16b28b757225c11f00415d0e20b1a2", |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 "secret-key-seed": "b4cbfb43df4ce210727d953e4a713307fa19bb7d9f85041438d9e11b942a3774", |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 "secret-key-pem": "-----BEGIN PRIVATE KEY-----\nMC4CAQAwBQYDK2VwBCIEILTL+0PfTOIQcn2VPkpxMwf6Gbt9n4UEFDjZ4RuUKjd0\n-----END PRIVATE KEY-----", |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 "public-key-pem": "-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEAHrnbu7wEfAP9cGBOAHHwmH4Wsot1ciXBHwBBXQ4gsaI=\n-----END PUBLIC KEY-----", |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 "token": "v4.public.eyJkYXRhIjoidGhpcyBpcyBhIHNpZ25lZCBtZXNzYWdlIiwiZXhwIjoiMjAyMi0wMS0wMVQwMDowMDowMCswMDowMCJ9bg_XBBzds8lTZShVlwwKSgeKpLT3yukTw6JUz3W4h_ExsQV-P0V54zemZDcAxFaSeef1QlXEFtkqxT1ciiQEDA", |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 "payload": "{\"data\":\"this is a signed message\",\"exp\":\"2022-01-01T00:00:00+00:00\"}", |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 "footer": "", |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 "implicit-assertion": "" |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 }, |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 { |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 "name": "4-S-2", |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 "expect-fail": false, |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
46 "public-key": "1eb9dbbbbc047c03fd70604e0071f0987e16b28b757225c11f00415d0e20b1a2", |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
47 "secret-key": "b4cbfb43df4ce210727d953e4a713307fa19bb7d9f85041438d9e11b942a37741eb9dbbbbc047c03fd70604e0071f0987e16b28b757225c11f00415d0e20b1a2", |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
48 "secret-key-seed": "b4cbfb43df4ce210727d953e4a713307fa19bb7d9f85041438d9e11b942a3774", |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
49 "secret-key-pem": "-----BEGIN PRIVATE KEY-----\nMC4CAQAwBQYDK2VwBCIEILTL+0PfTOIQcn2VPkpxMwf6Gbt9n4UEFDjZ4RuUKjd0\n-----END PRIVATE KEY-----", |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
50 "public-key-pem": "-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEAHrnbu7wEfAP9cGBOAHHwmH4Wsot1ciXBHwBBXQ4gsaI=\n-----END PUBLIC KEY-----", |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
51 "token": "v4.public.eyJkYXRhIjoidGhpcyBpcyBhIHNpZ25lZCBtZXNzYWdlIiwiZXhwIjoiMjAyMi0wMS0wMVQwMDowMDowMCswMDowMCJ9v3Jt8mx_TdM2ceTGoqwrh4yDFn0XsHvvV_D0DtwQxVrJEBMl0F2caAdgnpKlt4p7xBnx1HcO-SPo8FPp214HDw.eyJraWQiOiJ6VmhNaVBCUDlmUmYyc25FY1Q3Z0ZUaW9lQTlDT2NOeTlEZmdMMVc2MGhhTiJ9", |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
52 "payload": "{\"data\":\"this is a signed message\",\"exp\":\"2022-01-01T00:00:00+00:00\"}", |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
53 "footer": "{\"kid\":\"zVhMiPBP9fRf2snEcT7gFTioeA9COcNy9DfgL1W60haN\"}", |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
54 "implicit-assertion": "" |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
55 }, |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
56 { |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
57 "name": "4-S-3", |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
58 "expect-fail": false, |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
59 "public-key": "1eb9dbbbbc047c03fd70604e0071f0987e16b28b757225c11f00415d0e20b1a2", |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
60 "secret-key": "b4cbfb43df4ce210727d953e4a713307fa19bb7d9f85041438d9e11b942a37741eb9dbbbbc047c03fd70604e0071f0987e16b28b757225c11f00415d0e20b1a2", |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
61 "secret-key-seed": "b4cbfb43df4ce210727d953e4a713307fa19bb7d9f85041438d9e11b942a3774", |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
62 "secret-key-pem": "-----BEGIN PRIVATE KEY-----\nMC4CAQAwBQYDK2VwBCIEILTL+0PfTOIQcn2VPkpxMwf6Gbt9n4UEFDjZ4RuUKjd0\n-----END PRIVATE KEY-----", |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
63 "public-key-pem": "-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEAHrnbu7wEfAP9cGBOAHHwmH4Wsot1ciXBHwBBXQ4gsaI=\n-----END PUBLIC KEY-----", |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
64 "token": "v4.public.eyJkYXRhIjoidGhpcyBpcyBhIHNpZ25lZCBtZXNzYWdlIiwiZXhwIjoiMjAyMi0wMS0wMVQwMDowMDowMCswMDowMCJ9NPWciuD3d0o5eXJXG5pJy-DiVEoyPYWs1YSTwWHNJq6DZD3je5gf-0M4JR9ipdUSJbIovzmBECeaWmaqcaP0DQ.eyJraWQiOiJ6VmhNaVBCUDlmUmYyc25FY1Q3Z0ZUaW9lQTlDT2NOeTlEZmdMMVc2MGhhTiJ9", |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
65 "payload": "{\"data\":\"this is a signed message\",\"exp\":\"2022-01-01T00:00:00+00:00\"}", |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
66 "footer": "{\"kid\":\"zVhMiPBP9fRf2snEcT7gFTioeA9COcNy9DfgL1W60haN\"}", |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
67 "implicit-assertion": "{\"test-vector\":\"4-S-3\"}" |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
68 }]]=]; |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
69 for name, test in pairs(test_cases) do |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
70 it("test case "..name, test); |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
71 end |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
72 |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
73 describe("basic sign/verify", function () |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
74 local function new_keypair() |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
75 local kp = paseto.v4_public.new_keypair(); |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
76 return kp.private_key:export(), kp.public_key:export(); |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
77 end |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
78 |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
79 local privkey1, pubkey1 = new_keypair(); |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
80 local privkey2, pubkey2 = new_keypair(); |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
81 local sign1, verify1 = paseto.v4_public.init(privkey1, pubkey1); |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
82 local sign2, verify2 = paseto.v4_public.init(privkey2, pubkey2); |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
83 |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
84 it("works", function () |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
85 local payload = { foo = "hello world", b = { 1, 2, 3 } }; |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
86 |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
87 local tok1 = sign1(payload); |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
88 assert.same(payload, verify1(tok1)); |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
89 assert.is_nil(verify2(tok1)); |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
90 |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
91 local tok2 = sign2(payload); |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
92 assert.same(payload, verify2(tok2)); |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
93 assert.is_nil(verify1(tok2)); |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
94 end); |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
95 |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
96 it("rejects tokens if implicit assertion fails", function () |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
97 local payload = { foo = "hello world", b = { 1, 2, 3 } }; |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
98 local tok = sign1(payload, nil, "my-custom-assertion"); |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
99 assert.is_nil(verify1(tok, nil, "my-incorrect-assertion")); |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
100 assert.is_nil(verify1(tok, nil, nil)); |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
101 assert.same(payload, verify1(tok, nil, "my-custom-assertion")); |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
102 end); |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
103 end); |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
104 end); |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
105 |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
106 describe("pae", function () |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
107 it("encodes correctly", function () |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
108 -- These test cases are taken from the PASETO docs |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
109 -- https://github.com/paseto-standard/paseto-spec/blob/master/docs/01-Protocol-Versions/Common.md |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
110 assert.equal("\x00\x00\x00\x00\x00\x00\x00\x00", paseto.pae{}); |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
111 assert.equal("\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", paseto.pae{''}); |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
112 assert.equal("\x01\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00test", paseto.pae{'test'}); |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
113 assert.has_errors(function () |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
114 paseto.pae("test"); |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
115 end); |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
116 end); |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
117 end); |
719a72f14e90
util.paseto: Add tests based on official PASETO test vectors
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
118 end); |