Skip to content

Commit 56f2f8c

Browse files
committed
(workflows) Add basic JWT validation test
Signed-off-by: Denys Fedoryshchenko <[email protected]>
1 parent c3a9509 commit 56f2f8c

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

.github/workflows/main.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,9 @@ jobs:
6060
- name: Run basic YAML validation
6161
run: |
6262
python tests/validate_yaml.py
63+
64+
- name: Run basic JWT test
65+
run: |
66+
pip install PyJWT
67+
pip install toml
68+
python tests/validate_jwt.py

tests/validate_jwt.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Validate a JWT generated by jwt_generator.py.
4+
This script uses the tool, generate jwt, then decodes the JWT and verifies its signature using a secret key.
5+
"""
6+
import jwt
7+
import sys
8+
import argparse
9+
import subprocess
10+
11+
def test1():
12+
secret = "secret"
13+
14+
expected_token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwZXJtaXNzaW9ucyI6WyJjaGVja291dCIsInRlc3RyZXRyeSIsInBhdGNoc2V0Il0sImVtYWlsIjoidGVzdEB0ZXN0LmNvbSJ9.aL-yk5WVZKbzhPbN28KhjRONaae_2dGxsknwCXvuIHI"
15+
result = subprocess.run(
16+
["python3", "tools/jwt_generator.py", "--secret", secret, "--email", email],
17+
capture_output=True,
18+
text=True
19+
)
20+
if result.returncode != 0:
21+
print("Error generating JWT token:", result.stderr)
22+
sys.exit(1)
23+
jwt_token = None
24+
# iterate over lines
25+
for line in result.stdout.splitlines():
26+
if line.startswith("JWT token:"):
27+
jwt_token = line.strip().split(": ")[1]
28+
# extract the token from the output
29+
break
30+
else:
31+
print("JWT token not found in output")
32+
sys.exit(1)
33+
34+
assert jwt_token == expected_token, f"Expected {expected_token}, but got {jwt_token}"
35+
36+
def main():
37+
test1()
38+
print("Test 1 passed: JWT token generated successfully.")
39+
40+
if __name__ == "__main__":
41+
main()
42+
print("All tests passed.")

0 commit comments

Comments
 (0)