make forwarding_addresses mandatory when creating member (#97)
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
Closes #96. Reviewed-on: #97
This commit is contained in:
parent
968f0815c7
commit
65688c72da
|
@ -36,7 +36,7 @@ def create_user():
|
|||
terms = get_terms_for_new_user(terms)
|
||||
elif type(non_member_terms) is int:
|
||||
non_member_terms = get_terms_for_new_user(non_member_terms)
|
||||
for attr in ['uid', 'cn', 'given_name', 'sn']:
|
||||
for attr in ['uid', 'cn', 'given_name', 'sn', 'forwarding_addresses']:
|
||||
if not body.get(attr):
|
||||
raise BadRequest(f"Attribute '{attr}' is missing or empty")
|
||||
|
||||
|
|
|
@ -11,19 +11,24 @@ from ceo.cli import cli
|
|||
|
||||
|
||||
def mysql_attempt_connection(host, username, password):
|
||||
# Sometimes, when running the tests locally, I've observed a race condition
|
||||
# where another client can't "see" a database right after we create it.
|
||||
# I only observed this after upgrading the containers to bullseye (MariaDB
|
||||
# version: 10.5.18).
|
||||
time.sleep(0.05)
|
||||
time.sleep(0.5)
|
||||
with connect(
|
||||
host=host,
|
||||
user=username,
|
||||
password=password,
|
||||
) as con, con.cursor() as cur:
|
||||
cur.execute("SHOW DATABASES")
|
||||
response = cur.fetchall()
|
||||
assert len(response) == 2
|
||||
found = False
|
||||
# Sometimes, when running the tests locally, I've observed a race condition
|
||||
# where another client can't "see" a database right after we create it.
|
||||
# I only observed this after upgrading the containers to bullseye.
|
||||
for _ in range(4):
|
||||
cur.execute("SHOW DATABASES")
|
||||
response = cur.fetchall()
|
||||
if len(response) == 2:
|
||||
found = True
|
||||
break
|
||||
time.sleep(0.25)
|
||||
assert found
|
||||
|
||||
with pytest.raises(ProgrammingError):
|
||||
cur.execute("CREATE DATABASE new_db")
|
||||
|
|
|
@ -111,6 +111,7 @@ def test_api_next_uid(cfg, client, create_user_result):
|
|||
'sn': 'Two',
|
||||
'program': 'Math',
|
||||
'terms': ['s2021'],
|
||||
'forwarding_addresses': ['test2@uwaterloo.internal']
|
||||
})
|
||||
assert data[-1]['status'] == 'completed'
|
||||
result = data[-1]['result']
|
||||
|
@ -121,6 +122,19 @@ def test_api_next_uid(cfg, client, create_user_result):
|
|||
client.delete('/api/members/test2')
|
||||
|
||||
|
||||
def test_api_create_user_without_forwarding_addresses(cfg, client):
|
||||
status, data = client.post('/api/members', json={
|
||||
'uid': 'test3',
|
||||
'cn': 'Test Three',
|
||||
'given_name': 'Test',
|
||||
'sn': 'Three',
|
||||
'program': 'Math',
|
||||
'terms': ['s2023'],
|
||||
})
|
||||
assert status == 400
|
||||
assert data['error'] == "BadRequest: Attribute 'forwarding_addresses' is missing or empty"
|
||||
|
||||
|
||||
def test_api_get_user(cfg, client, create_user_result):
|
||||
old_data = create_user_result.copy()
|
||||
uid = old_data['uid']
|
||||
|
@ -252,8 +266,8 @@ def test_api_reset_password(client, create_user_result):
|
|||
def test_authz_check(client, create_user_result):
|
||||
# non-staff members may not create users
|
||||
status, data = client.post('/api/members', json={
|
||||
'uid': 'test1', 'cn': 'Test One', 'given_name': 'Test',
|
||||
'sn': 'One', 'terms': ['s2021'],
|
||||
'uid': 'test1', 'cn': 'Test One', 'given_name': 'Test', 'sn': 'One',
|
||||
'terms': ['s2021'], 'forwarding_addresses': ['test1@uwaterloo.internal']
|
||||
}, principal='regular1')
|
||||
assert status == 403
|
||||
|
||||
|
@ -268,8 +282,8 @@ def test_authz_check(client, create_user_result):
|
|||
|
||||
# If we're syscom but we don't pass credentials, the request should fail
|
||||
_, data = client.post('/api/members', json={
|
||||
'uid': 'test1', 'cn': 'Test One', 'given_name': 'Test',
|
||||
'sn': 'One', 'terms': ['s2021'],
|
||||
'uid': 'test1', 'cn': 'Test One', 'given_name': 'Test', 'sn': 'One',
|
||||
'terms': ['s2021'], 'forwarding_addresses': ['test1@uwaterloo.internal']
|
||||
}, principal='ctdalek', delegate=False)
|
||||
assert data[-1]['status'] == 'aborted'
|
||||
|
||||
|
|
|
@ -507,6 +507,7 @@ def new_user_gen(
|
|||
'sn': 'Doe',
|
||||
'program': 'Math',
|
||||
'terms': [str(Term.current())],
|
||||
'forwarding_addresses': [f'{uid}@uwaterloo.internal']
|
||||
})
|
||||
assert status == 200
|
||||
assert data[-1]['status'] == 'completed'
|
||||
|
|
Loading…
Reference in New Issue