Skip to content

Commit 4f04dc8

Browse files
committed
add test cases
1 parent 65b9774 commit 4f04dc8

File tree

18 files changed

+330
-0
lines changed

18 files changed

+330
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
function getSecret() {
2+
return "secret"
3+
}
4+
5+
const DoValidate = false
6+
module.exports = {getSecret, DoValidate}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const expressjwt = require("express-jwt");
2+
var {getSecret} = require('./Config.js');
3+
app.get(
4+
"/protected",
5+
expressjwt.expressjwt({secret: getSecret(), algorithms: ["HS256"]}),
6+
function (req, res) {
7+
if (!req.auth.admin) return res.sendStatus(401);
8+
res.sendStatus(200);
9+
}
10+
);
11+
expressjwt.expressjwt({
12+
secret: Buffer.from(getSecret(), "base64"),
13+
algorithms: ["RS256"],
14+
});
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
nodes
2+
| Config.js:2:12:2:19 | "secret" |
3+
| Config.js:2:12:2:19 | "secret" |
4+
| ExpressJWT.js:5:36:5:46 | getSecret() |
5+
| ExpressJWT.js:5:36:5:46 | getSecret() |
6+
| ExpressJWT.js:12:13:12:46 | Buffer. ... ase64") |
7+
| ExpressJWT.js:12:13:12:46 | Buffer. ... ase64") |
8+
| ExpressJWT.js:12:25:12:35 | getSecret() |
9+
| jwtConstantKey.js:5:46:5:56 | getSecret() |
10+
| jwtConstantKey.js:5:46:5:56 | getSecret() |
11+
| jwtConstantKey.js:6:43:6:53 | getSecret() |
12+
| jwtConstantKey.js:6:43:6:53 | getSecret() |
13+
| jwtConstantKey.js:12:68:12:104 | new Tex ... cret()) |
14+
| jwtConstantKey.js:12:68:12:104 | new Tex ... cret()) |
15+
| jwtConstantKey.js:12:93:12:103 | getSecret() |
16+
| jwtConstantKey.js:21:7:29:25 | spki |
17+
| jwtConstantKey.js:21:14:29:25 | `-----B ... Y-----` |
18+
| jwtConstantKey.js:21:14:29:25 | `-----B ... Y-----` |
19+
| jwtConstantKey.js:34:9:34:52 | publicKey |
20+
| jwtConstantKey.js:34:21:34:52 | await j ... i, alg) |
21+
| jwtConstantKey.js:34:43:34:46 | spki |
22+
| jwtConstantKey.js:35:65:35:73 | publicKey |
23+
| jwtConstantKey.js:35:65:35:73 | publicKey |
24+
| jwtConstantKey.js:51:42:51:52 | getSecret() |
25+
| jwtConstantKey.js:51:42:51:59 | getSecret() + "fj" |
26+
| jwtConstantKey.js:51:42:51:59 | getSecret() + "fj" |
27+
| jwtConstantKey.js:51:42:51:59 | getSecret() + "fj" |
28+
| jwtConstantKey.js:51:56:51:59 | "fj" |
29+
| jwtConstantKey.js:51:56:51:59 | "fj" |
30+
| jwtNoVerification.js:5:46:5:56 | getSecret() |
31+
| jwtNoVerification.js:5:46:5:56 | getSecret() |
32+
| jwtNoVerification.js:19:26:19:36 | getSecret() |
33+
| jwtNoVerification.js:19:26:19:36 | getSecret() |
34+
| koaJWT.js:29:22:29:32 | getSecret() |
35+
| koaJWT.js:29:22:29:32 | getSecret() |
36+
| netxAuth.js:10:13:10:23 | getSecret() |
37+
| netxAuth.js:10:13:10:23 | getSecret() |
38+
| passportJWT.js:6:20:6:30 | getSecret() |
39+
| passportJWT.js:6:20:6:30 | getSecret() |
40+
edges
41+
| Config.js:2:12:2:19 | "secret" | ExpressJWT.js:5:36:5:46 | getSecret() |
42+
| Config.js:2:12:2:19 | "secret" | ExpressJWT.js:5:36:5:46 | getSecret() |
43+
| Config.js:2:12:2:19 | "secret" | ExpressJWT.js:5:36:5:46 | getSecret() |
44+
| Config.js:2:12:2:19 | "secret" | ExpressJWT.js:5:36:5:46 | getSecret() |
45+
| Config.js:2:12:2:19 | "secret" | ExpressJWT.js:12:25:12:35 | getSecret() |
46+
| Config.js:2:12:2:19 | "secret" | ExpressJWT.js:12:25:12:35 | getSecret() |
47+
| Config.js:2:12:2:19 | "secret" | jwtConstantKey.js:5:46:5:56 | getSecret() |
48+
| Config.js:2:12:2:19 | "secret" | jwtConstantKey.js:5:46:5:56 | getSecret() |
49+
| Config.js:2:12:2:19 | "secret" | jwtConstantKey.js:5:46:5:56 | getSecret() |
50+
| Config.js:2:12:2:19 | "secret" | jwtConstantKey.js:5:46:5:56 | getSecret() |
51+
| Config.js:2:12:2:19 | "secret" | jwtConstantKey.js:6:43:6:53 | getSecret() |
52+
| Config.js:2:12:2:19 | "secret" | jwtConstantKey.js:6:43:6:53 | getSecret() |
53+
| Config.js:2:12:2:19 | "secret" | jwtConstantKey.js:6:43:6:53 | getSecret() |
54+
| Config.js:2:12:2:19 | "secret" | jwtConstantKey.js:6:43:6:53 | getSecret() |
55+
| Config.js:2:12:2:19 | "secret" | jwtConstantKey.js:12:93:12:103 | getSecret() |
56+
| Config.js:2:12:2:19 | "secret" | jwtConstantKey.js:12:93:12:103 | getSecret() |
57+
| Config.js:2:12:2:19 | "secret" | jwtConstantKey.js:51:42:51:52 | getSecret() |
58+
| Config.js:2:12:2:19 | "secret" | jwtConstantKey.js:51:42:51:52 | getSecret() |
59+
| Config.js:2:12:2:19 | "secret" | jwtNoVerification.js:5:46:5:56 | getSecret() |
60+
| Config.js:2:12:2:19 | "secret" | jwtNoVerification.js:5:46:5:56 | getSecret() |
61+
| Config.js:2:12:2:19 | "secret" | jwtNoVerification.js:5:46:5:56 | getSecret() |
62+
| Config.js:2:12:2:19 | "secret" | jwtNoVerification.js:5:46:5:56 | getSecret() |
63+
| Config.js:2:12:2:19 | "secret" | jwtNoVerification.js:19:26:19:36 | getSecret() |
64+
| Config.js:2:12:2:19 | "secret" | jwtNoVerification.js:19:26:19:36 | getSecret() |
65+
| Config.js:2:12:2:19 | "secret" | jwtNoVerification.js:19:26:19:36 | getSecret() |
66+
| Config.js:2:12:2:19 | "secret" | jwtNoVerification.js:19:26:19:36 | getSecret() |
67+
| Config.js:2:12:2:19 | "secret" | koaJWT.js:29:22:29:32 | getSecret() |
68+
| Config.js:2:12:2:19 | "secret" | koaJWT.js:29:22:29:32 | getSecret() |
69+
| Config.js:2:12:2:19 | "secret" | koaJWT.js:29:22:29:32 | getSecret() |
70+
| Config.js:2:12:2:19 | "secret" | koaJWT.js:29:22:29:32 | getSecret() |
71+
| Config.js:2:12:2:19 | "secret" | netxAuth.js:10:13:10:23 | getSecret() |
72+
| Config.js:2:12:2:19 | "secret" | netxAuth.js:10:13:10:23 | getSecret() |
73+
| Config.js:2:12:2:19 | "secret" | netxAuth.js:10:13:10:23 | getSecret() |
74+
| Config.js:2:12:2:19 | "secret" | netxAuth.js:10:13:10:23 | getSecret() |
75+
| Config.js:2:12:2:19 | "secret" | passportJWT.js:6:20:6:30 | getSecret() |
76+
| Config.js:2:12:2:19 | "secret" | passportJWT.js:6:20:6:30 | getSecret() |
77+
| Config.js:2:12:2:19 | "secret" | passportJWT.js:6:20:6:30 | getSecret() |
78+
| Config.js:2:12:2:19 | "secret" | passportJWT.js:6:20:6:30 | getSecret() |
79+
| ExpressJWT.js:12:25:12:35 | getSecret() | ExpressJWT.js:12:13:12:46 | Buffer. ... ase64") |
80+
| ExpressJWT.js:12:25:12:35 | getSecret() | ExpressJWT.js:12:13:12:46 | Buffer. ... ase64") |
81+
| jwtConstantKey.js:12:93:12:103 | getSecret() | jwtConstantKey.js:12:68:12:104 | new Tex ... cret()) |
82+
| jwtConstantKey.js:12:93:12:103 | getSecret() | jwtConstantKey.js:12:68:12:104 | new Tex ... cret()) |
83+
| jwtConstantKey.js:21:7:29:25 | spki | jwtConstantKey.js:34:43:34:46 | spki |
84+
| jwtConstantKey.js:21:14:29:25 | `-----B ... Y-----` | jwtConstantKey.js:21:7:29:25 | spki |
85+
| jwtConstantKey.js:21:14:29:25 | `-----B ... Y-----` | jwtConstantKey.js:21:7:29:25 | spki |
86+
| jwtConstantKey.js:34:9:34:52 | publicKey | jwtConstantKey.js:35:65:35:73 | publicKey |
87+
| jwtConstantKey.js:34:9:34:52 | publicKey | jwtConstantKey.js:35:65:35:73 | publicKey |
88+
| jwtConstantKey.js:34:21:34:52 | await j ... i, alg) | jwtConstantKey.js:34:9:34:52 | publicKey |
89+
| jwtConstantKey.js:34:43:34:46 | spki | jwtConstantKey.js:34:21:34:52 | await j ... i, alg) |
90+
| jwtConstantKey.js:51:42:51:52 | getSecret() | jwtConstantKey.js:51:42:51:59 | getSecret() + "fj" |
91+
| jwtConstantKey.js:51:42:51:52 | getSecret() | jwtConstantKey.js:51:42:51:59 | getSecret() + "fj" |
92+
| jwtConstantKey.js:51:56:51:59 | "fj" | jwtConstantKey.js:51:42:51:59 | getSecret() + "fj" |
93+
| jwtConstantKey.js:51:56:51:59 | "fj" | jwtConstantKey.js:51:42:51:59 | getSecret() + "fj" |
94+
| jwtConstantKey.js:51:56:51:59 | "fj" | jwtConstantKey.js:51:42:51:59 | getSecret() + "fj" |
95+
| jwtConstantKey.js:51:56:51:59 | "fj" | jwtConstantKey.js:51:42:51:59 | getSecret() + "fj" |
96+
#select
97+
| ExpressJWT.js:5:36:5:46 | getSecret() | Config.js:2:12:2:19 | "secret" | ExpressJWT.js:5:36:5:46 | getSecret() | this $@. is used as a secret key | Config.js:2:12:2:19 | "secret" | Constant |
98+
| ExpressJWT.js:12:13:12:46 | Buffer. ... ase64") | Config.js:2:12:2:19 | "secret" | ExpressJWT.js:12:13:12:46 | Buffer. ... ase64") | this $@. is used as a secret key | Config.js:2:12:2:19 | "secret" | Constant |
99+
| jwtConstantKey.js:5:46:5:56 | getSecret() | Config.js:2:12:2:19 | "secret" | jwtConstantKey.js:5:46:5:56 | getSecret() | this $@. is used as a secret key | Config.js:2:12:2:19 | "secret" | Constant |
100+
| jwtConstantKey.js:6:43:6:53 | getSecret() | Config.js:2:12:2:19 | "secret" | jwtConstantKey.js:6:43:6:53 | getSecret() | this $@. is used as a secret key | Config.js:2:12:2:19 | "secret" | Constant |
101+
| jwtConstantKey.js:12:68:12:104 | new Tex ... cret()) | Config.js:2:12:2:19 | "secret" | jwtConstantKey.js:12:68:12:104 | new Tex ... cret()) | this $@. is used as a secret key | Config.js:2:12:2:19 | "secret" | Constant |
102+
| jwtConstantKey.js:35:65:35:73 | publicKey | jwtConstantKey.js:21:14:29:25 | `-----B ... Y-----` | jwtConstantKey.js:35:65:35:73 | publicKey | this $@. is used as a secret key | jwtConstantKey.js:21:14:29:25 | `-----B ... Y-----` | Constant |
103+
| jwtConstantKey.js:51:42:51:59 | getSecret() + "fj" | Config.js:2:12:2:19 | "secret" | jwtConstantKey.js:51:42:51:59 | getSecret() + "fj" | this $@. is used as a secret key | Config.js:2:12:2:19 | "secret" | Constant |
104+
| jwtConstantKey.js:51:42:51:59 | getSecret() + "fj" | jwtConstantKey.js:51:56:51:59 | "fj" | jwtConstantKey.js:51:42:51:59 | getSecret() + "fj" | this $@. is used as a secret key | jwtConstantKey.js:51:56:51:59 | "fj" | Constant |
105+
| jwtNoVerification.js:5:46:5:56 | getSecret() | Config.js:2:12:2:19 | "secret" | jwtNoVerification.js:5:46:5:56 | getSecret() | this $@. is used as a secret key | Config.js:2:12:2:19 | "secret" | Constant |
106+
| jwtNoVerification.js:19:26:19:36 | getSecret() | Config.js:2:12:2:19 | "secret" | jwtNoVerification.js:19:26:19:36 | getSecret() | this $@. is used as a secret key | Config.js:2:12:2:19 | "secret" | Constant |
107+
| koaJWT.js:29:22:29:32 | getSecret() | Config.js:2:12:2:19 | "secret" | koaJWT.js:29:22:29:32 | getSecret() | this $@. is used as a secret key | Config.js:2:12:2:19 | "secret" | Constant |
108+
| netxAuth.js:10:13:10:23 | getSecret() | Config.js:2:12:2:19 | "secret" | netxAuth.js:10:13:10:23 | getSecret() | this $@. is used as a secret key | Config.js:2:12:2:19 | "secret" | Constant |
109+
| passportJWT.js:6:20:6:30 | getSecret() | Config.js:2:12:2:19 | "secret" | passportJWT.js:6:20:6:30 | getSecret() | this $@. is used as a secret key | Config.js:2:12:2:19 | "secret" | Constant |
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// jsonwebtoken
2+
const jwtJsonwebtoken = require('jsonwebtoken');
3+
const {getSecret} = require('./Config.js');
4+
const payloads = {foo: 'bar'}
5+
const token = jwtJsonwebtoken.sign(payloads, getSecret());
6+
console.log(jwtJsonwebtoken.verify(token, getSecret()))
7+
8+
// jose
9+
const jose = require('jose')
10+
11+
async function startSymmetric() {
12+
const {payload, protectedHeader} = await jose.jwtVerify(token, new TextEncoder().encode(getSecret()))
13+
return {
14+
payload, protectedHeader
15+
}
16+
}
17+
18+
startSymmetric().then(result => console.log(result))
19+
20+
const alg = 'RS256'
21+
const spki = `-----BEGIN PUBLIC KEY-----
22+
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwhYOFK2Ocbbpb/zVypi9
23+
SeKiNUqKQH0zTKN1+6fpCTu6ZalGI82s7XK3tan4dJt90ptUPKD2zvxqTzFNfx4H
24+
HHsrYCf2+FMLn1VTJfQazA2BvJqAwcpW1bqRUEty8tS/Yv4hRvWfQPcc2Gc3+/fQ
25+
OOW57zVy+rNoJc744kb30NjQxdGp03J2S3GLQu7oKtSDDPooQHD38PEMNnITf0pj
26+
+KgDPjymkMGoJlO3aKppsjfbt/AH6GGdRghYRLOUwQU+h+ofWHR3lbYiKtXPn5dN
27+
24kiHy61e3VAQ9/YAZlwXC/99GGtw/NpghFAuM4P1JDn0DppJldy3PGFC0GfBCZA
28+
SwIDAQAB
29+
-----END PUBLIC KEY-----`
30+
const jwt2 =
31+
'eyJhbGciOiJSUzI1NiJ9.eyJ1cm46ZXhhbXBsZTpjbGFpbSI6dHJ1ZSwiaWF0IjoxNjY5MDU2NDg4LCJpc3MiOiJ1cm46ZXhhbXBsZTppc3N1ZXIiLCJhdWQiOiJ1cm46ZXhhbXBsZTphdWRpZW5jZSJ9.gXrPZ3yM_60dMXGE69dusbpzYASNA-XIOwsb5D5xYnSxyj6_D6OR_uR_1vqhUm4AxZxcrH1_-XJAve9HCw8az_QzHcN-nETt-v6stCsYrn6Bv1YOc-mSJRZ8ll57KVqLbCIbjKwerNX5r2_Qg2TwmJzQdRs-AQDhy-s_DlJd8ql6wR4n-kDZpar-pwIvz4fFIN0Fj57SXpAbLrV6Eo4Byzl0xFD8qEYEpBwjrMMfxCZXTlAVhAq6KCoGlDTwWuExps342-0UErEtyIqDnDGcrfNWiUsoo8j-29IpKd-w9-C388u-ChCxoHz--H8WmMSZzx3zTXsZ5lXLZ9IKfanDKg'
32+
33+
async function startRSA() {
34+
var publicKey = await jose.importSPKI(spki, alg)
35+
var {payload, protectedHeader} = await jose.jwtVerify(jwt2, publicKey, {
36+
issuer: 'urn:example:issuer',
37+
audience: 'urn:example:audience',
38+
})
39+
console.log(protectedHeader)
40+
console.log(payload)
41+
}
42+
43+
startRSA()
44+
// additional step
45+
console.log("jose.base64url.decode()", Buffer.from(jose.base64url.decode(token), "base64").toString())
46+
47+
// jwt-simple
48+
const jwt_simple = require('jwt-simple');
49+
// var secret = Buffer.from('fe1a1915a379f3be5394b64d14794932', 'hex')
50+
// decode
51+
const decoded = jwt_simple.decode(token, getSecret() + "fj");
52+
console.log("jwt_simple:", decoded); //=> { foo: 'bar' }

0 commit comments

Comments
 (0)