Skip to content

Commit

Permalink
Dependency updates (#785)
Browse files Browse the repository at this point in the history
Includes a number of fixes for Starlette API and test client changes.
  • Loading branch information
mxsasha authored Apr 25, 2023
1 parent b0d8db9 commit 024867c
Show file tree
Hide file tree
Showing 9 changed files with 400 additions and 358 deletions.
10 changes: 5 additions & 5 deletions irrd/server/http/tests/test_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def test_endpoint(self, monkeypatch):
mock_handler.send_notification_target_reports.assert_called_once()
mock_handler.reset_mock()

response_delete = client.delete("/v1/submit/", data=ujson.dumps(data))
response_delete = client.request("DELETE", "/v1/submit/", data=ujson.dumps(data))
assert response_delete.status_code == 200
assert response_delete.text == '{"response":true}'
mock_handler.load_change_submission.assert_called_once_with(
Expand All @@ -200,13 +200,13 @@ def test_endpoint(self, monkeypatch):
mock_handler.send_notification_target_reports.assert_called_once()
mock_handler.reset_mock()

response_invalid_format = client.post("/v1/submit/", data='{"invalid": true}')
response_invalid_format = client.post("/v1/submit/", content='{"invalid": true}')
assert response_invalid_format.status_code == 400
assert "field required" in response_invalid_format.text
mock_handler.load_change_submission.assert_not_called()
mock_handler.send_notification_target_reports.assert_not_called()

response_invalid_json = client.post("/v1/submit/", data="invalid")
response_invalid_json = client.post("/v1/submit/", content="invalid")
assert response_invalid_json.status_code == 400
assert "expect" in response_invalid_json.text.lower()
mock_handler.load_change_submission.assert_not_called()
Expand Down Expand Up @@ -235,10 +235,10 @@ def test_endpoint(self, monkeypatch):
)
mock_handler.reset_mock()

response_invalid_format = client.post("/v1/suspension/", data='{"invalid": true}')
response_invalid_format = client.post("/v1/suspension/", content='{"invalid": true}')
assert response_invalid_format.status_code == 400
assert "field required" in response_invalid_format.text

response_invalid_json = client.post("/v1/suspension/", data="invalid")
response_invalid_json = client.post("/v1/suspension/", content="invalid")
assert response_invalid_json.status_code == 400
assert "expect" in response_invalid_json.text.lower()
4 changes: 2 additions & 2 deletions irrd/webui/auth/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ async def endpoint_wrapper(*args, **kwargs):
next_redir = quote_plus(next_redir, safe="/")

if not request.auth.is_authenticated:
redir_url = request.url_for("ui:auth:login") + "?next=" + next_redir
redir_url = request.url_for("ui:auth:login").replace_query_params(next=next_redir)
return RedirectResponse(redir_url, status_code=302)

if mfa_check and not request.session.get(MFA_COMPLETE_SESSION_KEY):
redir_url = request.url_for("ui:auth:mfa_authenticate") + "?next=" + next_redir
redir_url = request.url_for("ui:auth:mfa_authenticate").replace_query_params(next=next_redir)
return RedirectResponse(redir_url, status_code=302)

return await func(*args, **kwargs)
Expand Down
2 changes: 1 addition & 1 deletion irrd/webui/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</head>

{% macro nav_link(endpoint, name) %}
{% if request.url.__str__().startswith(url_for(endpoint)) %}
{% if request.url == url_for(endpoint) %}
<li class="nav-item"><a class="nav-link active" aria-current="page"
href="{{ url_for(endpoint) }}">{{ name }}</a></li>
{% else %}
Expand Down
8 changes: 4 additions & 4 deletions irrd/webui/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def test_login_requirement(self, test_client, irrd_db_session_with_user):
return
self.pre_login(session_provider, user)
response = test_client.get(self.url)
assert response.url.startswith("http://testserver/ui/auth/login/")
assert response.url.path == "/ui/auth/login/"

def test_mfa_requirement(self, test_client, irrd_db_session_with_user):
session_provider, user = irrd_db_session_with_user
Expand All @@ -61,13 +61,13 @@ def test_mfa_requirement(self, test_client, irrd_db_session_with_user):
self.pre_login(session_provider, user)
self._login(test_client, user)
response = test_client.get("/ui/user/")
assert response.url.startswith("http://testserver/ui/auth/mfa-authenticate/")
assert response.url.path == "/ui/auth/mfa-authenticate/"

def _login(self, test_client, user, password=SAMPLE_USER_PASSWORD):
response = test_client.post(
"/ui/auth/login/",
data={"email": user.email, "password": password},
allow_redirects=False,
follow_redirects=False,
)
assert response.status_code == 302

Expand All @@ -81,7 +81,7 @@ def _verify_mfa(self, test_client):
response = test_client.post(
"/ui/auth/mfa-authenticate/",
data={"token": pyotp.TOTP(SAMPLE_USER_TOTP_TOKEN).now()},
allow_redirects=False,
follow_redirects=False,
)
assert response.status_code == 302

Expand Down
52 changes: 26 additions & 26 deletions irrd/webui/tests/test_auth_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ def test_rate_limit(self, test_client, irrd_db_session_with_user, config_overrid
response = test_client.post(
self.url,
data={"email": user.email, "password": "incorrect"},
allow_redirects=False,
follow_redirects=False,
)
# This might already hit the limit from previous tests
assert response.status_code in [200, 403]

response = test_client.post(
self.url,
data={"email": user.email, "password": "incorrect"},
allow_redirects=False,
follow_redirects=False,
)
assert response.status_code == 403

Expand All @@ -44,14 +44,14 @@ def test_login_valid_mfa_pending(self, test_client, irrd_db_session_with_user):
response = test_client.post(
self.url,
data={"email": user.email, "password": SAMPLE_USER_PASSWORD},
allow_redirects=False,
follow_redirects=False,
)
assert response.status_code == 302
assert response.headers["Location"].endswith("/ui/auth/mfa-authenticate/")

# Check that MFA is still pending
response = test_client.get("/ui/user/")
assert response.url.startswith("http://testserver/ui/auth/mfa-authenticate/")
assert response.url.path == "/ui/auth/mfa-authenticate/"

def test_login_valid_no_mfa(self, test_client, irrd_db_session_with_user):
session_provider, user = irrd_db_session_with_user
Expand All @@ -61,21 +61,21 @@ def test_login_valid_no_mfa(self, test_client, irrd_db_session_with_user):
response = test_client.post(
self.url,
data={"email": user.email, "password": SAMPLE_USER_PASSWORD},
allow_redirects=False,
follow_redirects=False,
)
assert response.status_code == 302
assert response.headers["Location"].endswith("/ui/")

# Check that MFA is not pending
response = test_client.get("/ui/user/")
assert response.url.startswith("http://testserver/ui/user/")
assert response.url.path == "/ui/user/"

def test_login_invalid(self, test_client, irrd_db_session_with_user):
session_provider, user = irrd_db_session_with_user
response = test_client.post(
self.url,
data={"email": user.email, "password": "incorrect"},
allow_redirects=False,
follow_redirects=False,
)
assert response.status_code == 200
assert "Invalid account" in response.text
Expand Down Expand Up @@ -110,7 +110,7 @@ def test_create_valid(self, test_client_with_smtp, irrd_db_session_with_user):
response = test_client.post(
self.url,
data={"email": new_user_email, "name": "name"},
allow_redirects=False,
follow_redirects=False,
)
assert response.status_code == 302

Expand All @@ -132,7 +132,7 @@ def test_create_invalid_email_exists(self, test_client_with_smtp, irrd_db_sessio
response = test_client.post(
self.url,
data={"email": user.email, "name": "name"},
allow_redirects=False,
follow_redirects=False,
)
assert response.status_code == 200
assert "account with this email" in response.text
Expand All @@ -150,7 +150,7 @@ def test_create_invalid_missing_required(self, test_client_with_smtp, irrd_db_se
response = test_client.post(
self.url,
data={},
allow_redirects=False,
follow_redirects=False,
)
assert response.status_code == 200
assert "This field is required" in response.text
Expand All @@ -177,7 +177,7 @@ def test_request_valid(self, test_client_with_smtp, irrd_db_session_with_user):
response = test_client.post(
self.url,
data={"email": user.email},
allow_redirects=False,
follow_redirects=False,
)
assert response.status_code == 302

Expand All @@ -192,7 +192,7 @@ def test_request_unknown_user(self, test_client_with_smtp, irrd_db_session_with_
response = test_client.post(
self.url,
data={"email": "[email protected]"},
allow_redirects=False,
follow_redirects=False,
)
assert response.status_code == 302
assert not smtpd.messages
Expand Down Expand Up @@ -220,7 +220,7 @@ def test_valid(self, test_client_with_smtp, irrd_db_session_with_user):
"new_password_confirmation": new_password,
"current_password": SAMPLE_USER_PASSWORD,
},
allow_redirects=False,
follow_redirects=False,
)
assert response.status_code == 302
self._login(test_client, user, new_password)
Expand All @@ -241,7 +241,7 @@ def test_invalid_too_long(self, test_client_with_smtp, irrd_db_session_with_user
"new_password_confirmation": new_password,
"current_password": SAMPLE_USER_PASSWORD,
},
allow_redirects=False,
follow_redirects=False,
)
assert response.status_code == 200
assert "too long" in response.text
Expand All @@ -262,7 +262,7 @@ def test_invalid_current_password(self, test_client_with_smtp, irrd_db_session_w
"new_password_confirmation": new_password,
"current_password": "invalid",
},
allow_redirects=False,
follow_redirects=False,
)
assert response.status_code == 200
assert "Incorrect password." in response.text
Expand All @@ -284,7 +284,7 @@ def test_invalid_password_mismatch(self, test_client_with_smtp, irrd_db_session_
"new_password_confirmation": new_password2,
"current_password": SAMPLE_USER_PASSWORD,
},
allow_redirects=False,
follow_redirects=False,
)
assert response.status_code == 200
assert "do not match" in response.text
Expand All @@ -303,7 +303,7 @@ def test_invalid_weak_password(self, test_client_with_smtp, irrd_db_session_with
"new_password_confirmation": "a",
"current_password": SAMPLE_USER_PASSWORD,
},
allow_redirects=False,
follow_redirects=False,
)
assert response.status_code == 200
assert "not strong enough" in response.text
Expand All @@ -323,7 +323,7 @@ def test_invalid_missing_field(self, test_client_with_smtp, irrd_db_session_with
"new_password": new_password,
"new_password_confirmation": new_password,
},
allow_redirects=False,
follow_redirects=False,
)
assert response.status_code == 200
assert "This field is required." in response.text
Expand Down Expand Up @@ -355,7 +355,7 @@ def test_valid(self, test_client_with_smtp, irrd_db_session_with_user):
"name": new_name,
"current_password": SAMPLE_USER_PASSWORD,
},
allow_redirects=False,
follow_redirects=False,
)
assert response.status_code == 302

Expand Down Expand Up @@ -383,7 +383,7 @@ def test_invalid_current_password(self, test_client_with_smtp, irrd_db_session_w
"name": new_name,
"current_password": "invalid",
},
allow_redirects=False,
follow_redirects=False,
)
assert response.status_code == 200
assert "Incorrect password." in response.text
Expand All @@ -406,7 +406,7 @@ def test_invalid_email(self, test_client_with_smtp, irrd_db_session_with_user):
"name": "new name",
"current_password": SAMPLE_USER_PASSWORD,
},
allow_redirects=False,
follow_redirects=False,
)
assert response.status_code == 200
assert "Invalid email address" in response.text
Expand Down Expand Up @@ -449,7 +449,7 @@ def test_valid_reset(self, test_client_with_smtp, irrd_db_session_with_user):
response = test_client.post(
url,
data={"new_password": new_password, "new_password_confirmation": new_password},
allow_redirects=False,
follow_redirects=False,
)
assert response.status_code == 302
self._login(test_client, user, new_password)
Expand All @@ -465,7 +465,7 @@ def test_valid_reset_initial(self, test_client_with_smtp, irrd_db_session_with_u
response = test_client.post(
url,
data={"new_password": new_password, "new_password_confirmation": new_password},
allow_redirects=False,
follow_redirects=False,
)
assert response.status_code == 302
self._login(test_client, user, new_password)
Expand All @@ -481,7 +481,7 @@ def test_invalid_password_mismatch(self, test_client_with_smtp, irrd_db_session_
response = test_client.post(
url,
data={"new_password": new_password, "new_password_confirmation": new_password2},
allow_redirects=False,
follow_redirects=False,
)
assert response.status_code == 200
assert "do not match" in response.text
Expand All @@ -496,7 +496,7 @@ def test_invalid_password_weak(self, test_client_with_smtp, irrd_db_session_with
response = test_client.post(
url,
data={"new_password": "a", "new_password_confirmation": "a"},
allow_redirects=False,
follow_redirects=False,
)
assert response.status_code == 200
assert "not strong enough" in response.text
Expand All @@ -514,7 +514,7 @@ def test_invalid_missing_required(self, test_client_with_smtp, irrd_db_session_w
data={
"new_password": new_password,
},
allow_redirects=False,
follow_redirects=False,
)
assert response.status_code == 200
assert "This field is required." in response.text
Expand Down
Loading

0 comments on commit 024867c

Please sign in to comment.