-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_module_options.py
More file actions
58 lines (46 loc) · 1.55 KB
/
test_module_options.py
File metadata and controls
58 lines (46 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from datetime import timedelta
import pytest
from ellar.testing import Test
from ellar_jwt import JWTModule, JWTService
def test_jwt_module_configuration_case_1():
tm = Test.create_test_module(
modules=[
JWTModule.setup(
algorithm="HS256",
signing_secret_key="no_secret",
issuer="https://ellar.com",
lifetime=timedelta(minutes=30),
leeway=timedelta(minutes=30),
audience="openid-client-id",
)
]
)
jwt_service: JWTService = tm.get(JWTService)
token = jwt_service.sign({"sub": "23"})
payload = jwt_service.decode(token)
assert payload["sub"] == "23"
def test_jwt_module_configuration_case_2():
tm = Test.create_test_module(
modules=[JWTModule.register_setup()],
config_module={
"JWT_CONFIG": {
"algorithm": "HS256",
"signing_secret_key": "no_secret",
"issuer": "https://ellar.com",
"lifetime": timedelta(minutes=30),
"leeway": None,
}
},
)
jwt_service: JWTService = tm.get(JWTService)
token = jwt_service.sign({"sub": "23"})
payload = jwt_service.decode(token)
assert payload["sub"] == "23"
def test_jwt_module_configuration_case_2_fails():
tm = Test.create_test_module(
modules=[JWTModule.register_setup()],
)
with pytest.raises(
RuntimeError, match="Could not find `JWT_CONFIG` in application config."
):
tm.get(JWTService)