Skip to content

Commit 87c7030

Browse files
committed
feat(iam): Revive tests around querying users
Now we can change the implementation, and have our mistakes (hopefully) reflected in the test output. Jira: IAM-1793
1 parent 7404051 commit 87c7030

File tree

2 files changed

+108
-0
lines changed

2 files changed

+108
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Mozilla-IAM template for configuration of the Mozilla Change Integration Service
2+
3+
[cis]
4+
# Is the environment running locally, production, staging, or test.
5+
environment=mock
6+
7+
# AssumeRole arn is required even locally. Use a dummy fixture if you do not have a role setup.
8+
assume_role_arn=arn:aws:iam::123456789000:role/demo-assume-role-test
9+
10+
# Set these parameters if you are running locally.
11+
seed_api_data=true
12+
13+
[person_api]
14+
jwt_validation=false
15+
advanced_search=true
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
"""
2+
A simplification of the existing v2_api tests. We reuse Dynamo and the users we
3+
create across each test, since otherwise it'll take a while.
4+
5+
See `DEBT` notes for where I ran into weirdness.
6+
7+
Run with:
8+
9+
pytest --log-cli-level=DEBUG tests/test_v2_api_pagination.py
10+
11+
"""
12+
13+
import logging
14+
import os
15+
16+
import pytest
17+
import boto3
18+
from moto import mock_aws
19+
from tests.fake_auth0 import FakeBearer, json_form_of_pk
20+
21+
from cis_identity_vault import vault
22+
23+
logging.basicConfig(level=logging.INFO, format="%(asctime)s:%(levelname)s:%(name)s:%(message)s")
24+
25+
# Set to the level where logs become interesting, otherwise our log output
26+
# becomes too verbose. A pain while testing iteratively.
27+
logging.getLogger("boto3").setLevel(logging.INFO)
28+
logging.getLogger("botocore").setLevel(logging.WARNING)
29+
logging.getLogger("faker").setLevel(logging.INFO)
30+
logging.getLogger("everett").setLevel(logging.INFO)
31+
logging.getLogger("urllib3").setLevel(logging.INFO)
32+
logging.getLogger("responses").setLevel(logging.WARNING)
33+
logging.getLogger("cis_profile").setLevel(logging.INFO)
34+
logging.getLogger("cis_identity_vault.parallel_dynamo").setLevel(logging.INFO)
35+
36+
logger = logging.getLogger(__name__)
37+
38+
39+
# Re-use our AWS mocks module-wide. Related to `identity_vault`.
40+
def setup_module(module):
41+
module.mock = mock_aws(config={"core": {"service_whitelist": ["dynamodb"]}})
42+
module.mock.start()
43+
44+
45+
def teardown_module(module):
46+
module.mock.stop()
47+
48+
49+
@pytest.fixture(scope="module")
50+
def environment():
51+
with pytest.MonkeyPatch.context() as monkeypatch:
52+
monkeypatch.setenv("CIS_CONFIG_INI", "tests/mozilla-cis-mock.ini")
53+
monkeypatch.setenv("AWS_DEFAULT_REGION", "us-west-2")
54+
yield monkeypatch
55+
56+
57+
# Slow, so reuse across the module.
58+
@pytest.fixture(scope="module")
59+
def identity_vault(environment):
60+
vault_client = vault.IdentityVault()
61+
vault_client.connect()
62+
vault_client.create()
63+
vault_client.find_or_create()
64+
# DEBT: requires side-effects.
65+
from cis_profile_retrieval_service.common import seed
66+
# DEBT?: doesn't seemingly generate only `number_of_fake_users` users.
67+
# DEBT: doesn't generate `ad|Mozilla-LDAP` users.
68+
seed(number_of_fake_users=128)
69+
return (boto3.client("dynamodb"), boto3.resource("dynamodb"))
70+
71+
72+
@pytest.fixture
73+
def app(environment, monkeypatch):
74+
bearer = FakeBearer()
75+
token = bearer.generate_bearer_with_scope("display:all search:all")
76+
headers = {
77+
"Authorization": f"Bearer {token}"
78+
}
79+
monkeypatch.setattr("cis_profile_retrieval_service.idp.get_jwks", lambda: json_form_of_pk)
80+
# DEBT: requires side-effects.
81+
from cis_profile_retrieval_service import v2_api
82+
v2_api.app.testing = True
83+
return (headers, v2_api.app.test_client())
84+
85+
86+
def test_existing(identity_vault, app):
87+
headers, client = app
88+
# DEBT: see note above, about not generating `ad|Mozilla-LDAP` users.
89+
results = client.get(
90+
"/v2/users/id/all?connectionMethod=github&active=True",
91+
headers=headers,
92+
follow_redirects=True,
93+
)

0 commit comments

Comments
 (0)