|
14 | 14 |
|
15 | 15 | @pytest.fixture |
16 | 16 | def token_credentials(): |
17 | | - return TokenCredentials('test/eckey.pem', '1QBCDJ9RST', '3Z24IP123A') |
| 17 | + return TokenCredentials( |
| 18 | + auth_key_path='test/eckey.pem', |
| 19 | + auth_key_id='1QBCDJ9RST', |
| 20 | + team_id='3Z24IP123A', |
| 21 | + token_lifetime=30, # seconds |
| 22 | + ) |
18 | 23 |
|
19 | 24 |
|
20 | 25 | def test_token_expiration(token_credentials): |
21 | | - # As long as the token lifetime hasn't elapsed, this should work. To |
22 | | - # be really careful, we should check how much time has elapsed to |
23 | | - # know if it fail. But, either way, we'd have to come up with a good |
24 | | - # lifetime for future tests... |
25 | | - |
26 | | - with freeze_time('2012-01-14'): |
27 | | - expiring_header = token_credentials.get_authorization_header(TOPIC) |
28 | | - |
29 | | - new_header = token_credentials.get_authorization_header(TOPIC) |
30 | | - assert expiring_header != new_header |
| 26 | + with freeze_time('2012-01-14 12:00:00'): |
| 27 | + header1 = token_credentials.get_authorization_header(TOPIC) |
| 28 | + |
| 29 | + # 20 seconds later, before expiration, same JWT |
| 30 | + with freeze_time('2012-01-14 12:00:20'): |
| 31 | + header2 = token_credentials.get_authorization_header(TOPIC) |
| 32 | + assert header1 == header2 |
| 33 | + |
| 34 | + # 35 seconds later, after expiration, new JWT |
| 35 | + with freeze_time('2012-01-14 12:00:40'): |
| 36 | + header3 = token_credentials.get_authorization_header(TOPIC) |
| 37 | + assert header3 != header1 |
0 commit comments