We cannot cache the full expiration for an app specific token, as it would include the datetime when the cache is created, rather than now
Fixes https://jira.coreos.com/browse/QUAY-819
This commit is contained in:
parent
ccef3bffe9
commit
6228ab5a51
2 changed files with 40 additions and 6 deletions
|
@ -1,7 +1,9 @@
|
|||
from datetime import datetime
|
||||
from mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
from data.model import config as _config
|
||||
from data import model
|
||||
from data.model.appspecifictoken import create_token, revoke_token, access_valid_token
|
||||
from data.model.appspecifictoken import gc_expired_tokens, get_expiring_tokens
|
||||
|
@ -75,3 +77,33 @@ def test_expiring_soon(initialized_db):
|
|||
expiring_soon = get_expiring_tokens(user, convert_to_timedelta('49h'))
|
||||
assert expiring_soon
|
||||
assert len(expiring_soon) == 2
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def app_config():
|
||||
with patch.dict(_config.app_config, {}, clear=True):
|
||||
yield _config.app_config
|
||||
|
||||
@pytest.mark.parametrize('expiration', [
|
||||
(None),
|
||||
('10m'),
|
||||
('10d'),
|
||||
('10w'),
|
||||
])
|
||||
@pytest.mark.parametrize('default_expiration', [
|
||||
(None),
|
||||
('10m'),
|
||||
('10d'),
|
||||
('10w'),
|
||||
])
|
||||
def test_create_access_token(expiration, default_expiration, initialized_db, app_config):
|
||||
user = model.user.get_user('devtable')
|
||||
expiration_date = datetime.now() + convert_to_timedelta(expiration) if expiration else None
|
||||
with patch.dict(_config.app_config, {}, clear=True):
|
||||
app_config['APP_SPECIFIC_TOKEN_EXPIRATION'] = default_expiration
|
||||
if expiration:
|
||||
exp_token = create_token(user, 'Some token', expiration=expiration_date)
|
||||
assert exp_token.expiration == expiration_date
|
||||
else:
|
||||
exp_token = create_token(user, 'Some token')
|
||||
assert (exp_token.expiration is None) == (default_expiration is None)
|
||||
|
|
Reference in a new issue