Mercurial > prosody-hg
comparison spec/util_jwt_spec.lua @ 10660:c4ded3be7cc0
util.jwt: Basic JSON Web Token library supporting HS256 tokens
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Mon, 24 Feb 2020 01:24:25 +0100 |
| parents | |
| children | 4eee1aaa9405 |
comparison
equal
deleted
inserted
replaced
| 10659:8f95308c3c45 | 10660:c4ded3be7cc0 |
|---|---|
| 1 local jwt = require "util.jwt"; | |
| 2 | |
| 3 describe("util.jwt", function () | |
| 4 it("validates", function () | |
| 5 local key = "secret"; | |
| 6 local token = jwt.sign(key, { payload = "this" }); | |
| 7 assert.string(token); | |
| 8 local ok, parsed = jwt.verify(key, token); | |
| 9 assert.truthy(ok) | |
| 10 assert.same({ payload = "this" }, parsed); | |
| 11 end); | |
| 12 it("rejects invalid", function () | |
| 13 local key = "secret"; | |
| 14 local token = jwt.sign("wrong", { payload = "this" }); | |
| 15 assert.string(token); | |
| 16 local ok, err = jwt.verify(key, token); | |
| 17 assert.falsy(ok) | |
| 18 end); | |
| 19 end); | |
| 20 |
