-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathjwtrefreshtoken_test.py
64 lines (56 loc) · 1.96 KB
/
jwtrefreshtoken_test.py
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
59
60
61
62
63
64
from datetime import datetime, timedelta
from unittest.mock import patch
from nav.models.api import JWTRefreshToken
class TestIsActive:
def test_when_token_activates_in_the_future_it_should_return_false(self):
now = datetime.now()
token = JWTRefreshToken(
name="testtoken",
hash="dummyhash",
expires=now + timedelta(hours=1),
activates=now + timedelta(hours=1),
)
assert not token.is_active()
def test_when_token_expired_in_the_past_it_should_return_false(self):
now = datetime.now()
token = JWTRefreshToken(
name="testtoken",
hash="dummyhash",
expires=now - timedelta(hours=1),
activates=now - timedelta(hours=1),
)
assert not token.is_active()
def test_when_token_activated_in_the_past_and_expires_in_the_future_it_should_return_true(
self,
):
now = datetime.now()
token = JWTRefreshToken(
name="testtoken",
hash="dummyhash",
expires=now + timedelta(hours=1),
activates=now - timedelta(hours=1),
)
assert token.is_active()
def test_when_token_activates_now_and_expires_in_the_future_it_should_return_true(
self,
):
now = datetime.now()
token = JWTRefreshToken(
name="testtoken",
hash="dummyhash",
expires=now + timedelta(hours=1),
activates=now,
)
# Make sure the value we use for `activates` here matches
# the `now` value in jwtgen.is_active
with patch('nav.web.jwtgen.get_now', return_value=now):
assert token.is_active()
def test_string_representation_should_match_name():
now = datetime.now()
token = JWTRefreshToken(
name="testtoken",
hash="dummyhash",
expires=now + timedelta(hours=1),
activates=now - timedelta(hours=1),
)
assert str(token) == token.name