0001-tests-add-cache-clearance-autouse-fixture-41813.patch
tests/auth_fc/conftest.py | ||
---|---|---|
19 | 19 |
import django_webtest |
20 | 20 | |
21 | 21 |
from django.contrib.auth import get_user_model |
22 |
from django.core.cache import cache |
|
22 | 23 |
from django_rbac.utils import get_ou_model |
24 | ||
25 |
from authentic2 import hooks as a2_hooks |
|
26 |
from authentic2.manager.utils import get_ou_count |
|
23 | 27 |
from authentic2_auth_fc.models import FcAccount |
24 | 28 | |
25 | 29 | |
... | ... | |
102 | 106 |
email='ecartman@southpark.org', ou=ou_southpark, federation=CARTMAN_FC_INFO) |
103 | 107 | |
104 | 108 | |
109 |
@pytest.fixture(autouse=True) |
|
110 |
def clear_cache(): |
|
111 |
OU = get_ou_model() |
|
112 | ||
113 |
cache.clear() |
|
114 |
for cached_el in (OU.cached, a2_hooks.get_hooks, get_ou_count): |
|
115 |
cached_el.cache.clear() |
|
116 | ||
117 | ||
105 | 118 |
class AllHook(object): |
106 | 119 |
def __init__(self): |
107 | 120 |
self.calls = {} |
108 |
from authentic2 import hooks |
|
109 |
hooks.get_hooks.cache.clear() |
|
110 | 121 | |
111 | 122 |
def __call__(self, hook_name, *args, **kwargs): |
112 | 123 |
calls = self.calls.setdefault(hook_name, []) |
tests/conftest.py | ||
---|---|---|
22 | 22 |
import django_webtest |
23 | 23 | |
24 | 24 |
from django.contrib.auth import get_user_model |
25 |
from django.core.cache import cache |
|
25 | 26 |
from django_rbac.utils import get_ou_model, get_role_model |
26 | 27 |
from django.conf import settings |
27 | 28 |
from django.utils.six.moves.urllib import parse as urlparse |
28 | 29 | |
29 | 30 |
from pytest_django.migrations import DisableMigrations |
30 | 31 | |
32 |
from authentic2 import hooks as a2_hooks |
|
31 | 33 |
from authentic2.models import Service |
34 |
from authentic2.utils.evaluate import BaseExpressionValidator |
|
32 | 35 |
from authentic2.a2_rbac.utils import get_default_ou |
36 |
from authentic2.manager.utils import get_ou_count |
|
37 |
from authentic2_auth_oidc.utils import get_providers |
|
38 |
from authentic2_auth_oidc.utils import get_provider_by_issuer |
|
39 |
from authentic2_auth_oidc.utils import has_providers |
|
33 | 40 |
from authentic2_idp_oidc.models import OIDCClient |
34 | 41 |
from authentic2.authentication import OIDCUser |
35 | 42 | |
... | ... | |
267 | 274 |
return locals().get(request.param) |
268 | 275 | |
269 | 276 | |
277 |
@pytest.fixture(autouse=True) |
|
278 |
def clear_cache(): |
|
279 |
OU = get_ou_model() |
|
280 | ||
281 |
cache.clear() |
|
282 |
BaseExpressionValidator.__call__.cache_clear() |
|
283 |
for cached_el in (OU.cached, a2_hooks.get_hooks, get_providers, |
|
284 |
get_provider_by_issuer, get_ou_count, has_providers): |
|
285 |
cached_el.cache.clear() |
|
286 | ||
287 | ||
270 | 288 |
class AllHook(object): |
271 | 289 |
def __init__(self): |
272 | 290 |
self.calls = {} |
273 |
from authentic2 import hooks |
|
274 |
hooks.get_hooks.cache.clear() |
|
275 | 291 | |
276 | 292 |
def __call__(self, hook_name, *args, **kwargs): |
277 | 293 |
calls = self.calls.setdefault(hook_name, []) |
tests/test_auth_oidc.py | ||
---|---|---|
153 | 153 |
idtoken_algo=OIDCProvider._meta.get_field('idtoken_algo').default, |
154 | 154 |
jwkset=None, |
155 | 155 |
claims_parameter_supported=False): |
156 |
from authentic2_auth_oidc.utils import get_provider, get_provider_by_issuer |
|
157 |
get_provider.cache.clear() |
|
158 |
get_provider_by_issuer.cache.clear() |
|
159 | 156 | |
160 | 157 |
if jwkset is not None: |
161 | 158 |
jwkset = json.loads(jwkset.export()) |
... | ... | |
453 | 450 |
def test_sso(app, caplog, code, oidc_provider, oidc_provider_jwkset, hooks): |
454 | 451 |
OU = get_ou_model() |
455 | 452 |
cassis = OU.objects.create(name='Cassis', slug='cassis') |
456 |
OU.cached.cache.clear() |
|
457 | 453 | |
458 | 454 |
response = app.get('/admin/').maybe_follow() |
459 | 455 |
assert oidc_provider.name in response.text |
... | ... | |
567 | 563 | |
568 | 564 | |
569 | 565 |
def test_show_on_login_page(app, oidc_provider): |
570 |
# we have a 5 seconds cache on list of providers, we have to work around it |
|
571 |
get_providers.cache.clear() |
|
572 |
has_providers.cache.clear() |
|
573 | 566 |
response = app.get('/login/') |
574 | 567 |
assert 'oidc-a-oididp' in response.text |
575 | 568 | |
... | ... | |
586 | 579 | |
587 | 580 |
def test_strategy_find_uuid(app, caplog, code, oidc_provider, oidc_provider_jwkset, simple_user): |
588 | 581 | |
589 |
get_providers.cache.clear() |
|
590 |
has_providers.cache.clear() |
|
591 | 582 |
# no mapping please |
592 | 583 |
OIDCClaimMapping.objects.all().delete() |
593 | 584 |
oidc_provider.strategy = oidc_provider.STRATEGY_FIND_UUID |
... | ... | |
674 | 665 |
def test_invalid_kid(app, caplog, code, oidc_provider_rsa, |
675 | 666 |
oidc_provider_jwkset, simple_user): |
676 | 667 | |
677 |
get_providers.cache.clear() |
|
678 |
has_providers.cache.clear() |
|
679 | 668 |
# no mapping please |
680 | 669 |
OIDCClaimMapping.objects.all().delete() |
681 | 670 | |
... | ... | |
701 | 690 | |
702 | 691 | |
703 | 692 |
def test_templated_claim_mapping(app, caplog, code, oidc_provider, oidc_provider_jwkset): |
704 |
get_providers.cache.clear() |
|
705 |
has_providers.cache.clear() |
|
706 | 693 | |
707 | 694 |
Attribute.objects.create( |
708 | 695 |
name='pro_phone', |
tests/test_idp_oidc.py | ||
---|---|---|
25 | 25 | |
26 | 26 |
import utils |
27 | 27 | |
28 |
from django.core.cache import cache |
|
29 | 28 |
from django.core.urlresolvers import reverse |
30 | 29 |
from django.core.files import File |
31 | 30 |
from django.db import connection |
... | ... | |
1290 | 1289 | |
1291 | 1290 | |
1292 | 1291 |
def test_credentials_grant(app, oidc_client, admin, simple_user): |
1293 |
cache.clear() |
|
1294 | 1292 |
oidc_client.authorization_flow = OIDCClient.FLOW_RESOURCE_OWNER_CRED |
1295 | 1293 |
oidc_client.scope = 'openid' |
1296 | 1294 |
oidc_client.save() |
... | ... | |
1342 | 1340 |
app, oidc_client, admin, simple_user, oidc_settings, freezer): |
1343 | 1341 |
freezer.move_to('2020-01-01') |
1344 | 1342 | |
1345 |
cache.clear() |
|
1346 | 1343 |
oidc_client.authorization_flow = OIDCClient.FLOW_RESOURCE_OWNER_CRED |
1347 | 1344 |
oidc_client.save() |
1348 | 1345 |
token_url = make_url('oidc-token') |
... | ... | |
1366 | 1363 |
app, oidc_client, admin, simple_user, oidc_settings, freezer): |
1367 | 1364 |
freezer.move_to('2020-01-01') |
1368 | 1365 | |
1369 |
cache.clear() |
|
1370 | 1366 |
oidc_client.authorization_flow = OIDCClient.FLOW_RESOURCE_OWNER_CRED |
1371 | 1367 |
oidc_client.save() |
1372 | 1368 |
token_url = make_url('oidc-token') |
... | ... | |
1388 | 1384 |
app, oidc_client, admin, simple_user, settings, freezer): |
1389 | 1385 |
freezer.move_to('2020-01-01') |
1390 | 1386 | |
1391 |
cache.clear() |
|
1392 | 1387 |
settings.A2_LOGIN_EXPONENTIAL_RETRY_TIMEOUT_DURATION = 2 |
1393 | 1388 |
oidc_client.authorization_flow = OIDCClient.FLOW_RESOURCE_OWNER_CRED |
1394 | 1389 |
oidc_client.save() |
... | ... | |
1419 | 1414 | |
1420 | 1415 |
def test_credentials_grant_invalid_flow( |
1421 | 1416 |
app, oidc_client, admin, simple_user, settings): |
1422 |
cache.clear() |
|
1423 | 1417 |
params = { |
1424 | 1418 |
'client_id': oidc_client.client_id, |
1425 | 1419 |
'client_secret': oidc_client.client_secret, |
... | ... | |
1435 | 1429 | |
1436 | 1430 |
def test_credentials_grant_invalid_client( |
1437 | 1431 |
app, oidc_client, admin, simple_user, settings): |
1438 |
cache.clear() |
|
1439 | 1432 |
oidc_client.authorization_flow = OIDCClient.FLOW_RESOURCE_OWNER_CRED |
1440 | 1433 |
oidc_client.save() |
1441 | 1434 |
params = { |
... | ... | |
1453 | 1446 | |
1454 | 1447 |
def test_credentials_grant_unauthz_client( |
1455 | 1448 |
app, oidc_client, admin, simple_user, settings): |
1456 |
cache.clear() |
|
1457 | 1449 |
params = { |
1458 | 1450 |
'client_id': oidc_client.client_id, |
1459 | 1451 |
'client_secret': oidc_client.client_secret, |
... | ... | |
1469 | 1461 | |
1470 | 1462 |
def test_credentials_grant_invalid_content_type( |
1471 | 1463 |
app, oidc_client, admin, simple_user, settings): |
1472 |
cache.clear() |
|
1473 | 1464 |
oidc_client.authorization_flow = OIDCClient.FLOW_RESOURCE_OWNER_CRED |
1474 | 1465 |
oidc_client.save() |
1475 | 1466 |
params = { |
... | ... | |
1490 | 1481 | |
1491 | 1482 |
def test_credentials_grant_ou_selection_simple( |
1492 | 1483 |
app, oidc_client, admin, user_ou1, user_ou2, ou1, ou2, settings): |
1493 |
cache.clear() |
|
1494 | 1484 |
oidc_client.authorization_flow = OIDCClient.FLOW_RESOURCE_OWNER_CRED |
1495 | 1485 |
oidc_client.save() |
1496 | 1486 |
params = { |
... | ... | |
1511 | 1501 | |
1512 | 1502 |
def test_credentials_grant_ou_selection_username_not_unique( |
1513 | 1503 |
app, oidc_client, admin, user_ou1, admin_ou2, ou1, ou2, settings): |
1514 |
cache.clear() |
|
1515 | 1504 |
settings.A2_USERNAME_IS_UNIQUE = False |
1516 | 1505 |
oidc_client.authorization_flow = OIDCClient.FLOW_RESOURCE_OWNER_CRED |
1517 | 1506 |
oidc_client.save() |
... | ... | |
1539 | 1528 | |
1540 | 1529 |
def test_credentials_grant_ou_selection_username_not_unique_wrong_ou( |
1541 | 1530 |
app, oidc_client, admin, user_ou1, admin_ou2, ou1, ou2, settings): |
1542 |
cache.clear() |
|
1543 | 1531 |
settings.A2_USERNAME_IS_UNIQUE = False |
1544 | 1532 |
oidc_client.authorization_flow = OIDCClient.FLOW_RESOURCE_OWNER_CRED |
1545 | 1533 |
oidc_client.save() |
... | ... | |
1562 | 1550 | |
1563 | 1551 |
def test_credentials_grant_ou_selection_invalid_ou( |
1564 | 1552 |
app, oidc_client, admin, user_ou1, settings): |
1565 |
cache.clear() |
|
1566 | 1553 |
params = { |
1567 | 1554 |
'client_id': oidc_client.client_id, |
1568 | 1555 |
'client_secret': oidc_client.client_secret, |
tests/test_manager.py | ||
---|---|---|
69 | 69 | |
70 | 70 | |
71 | 71 |
def test_manager_create_role(superuser_or_admin, app): |
72 |
# clear cache from previous runs |
|
73 |
from authentic2.manager.utils import get_ou_count |
|
74 |
get_ou_count.cache.cache = {} |
|
75 | ||
76 | 72 |
non_admin_roles = Role.objects.exclude(slug__startswith='_') |
77 | 73 | |
78 | 74 |
ou_add = login(app, superuser_or_admin, reverse('a2-manager-role-add')) |
... | ... | |
185 | 181 | |
186 | 182 | |
187 | 183 |
def test_manager_create_user(superuser_or_admin, app, settings): |
188 |
# clear cache from previous runs |
|
189 |
from authentic2.manager.utils import get_ou_count |
|
190 |
get_ou_count.cache.clear() |
|
191 | ||
192 | 184 |
ou1 = OU.objects.create(name='OU1', slug='ou1') |
193 | 185 |
ou2 = OU.objects.create(name='OU2', slug='ou2', email_is_unique=True) |
194 | 186 | |
195 |
- |