-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pydantic has an unusual default behaviour when you set a `default` value for `Field`: ``` validate_default bool | None If True, apply validation to the default value every time you create an instance. Otherwise, for performance reasons, the default value of the field is trusted and not validated. ``` https://docs.pydantic.dev/latest/api/fields/ This was leading to a validation bypass when the fields that specified an invalid default value were not being set. We fix that bug, but also add extra validation that checks if the `author` matches the email address and refactoring of the authentication logic.
- Loading branch information
Showing
10 changed files
with
80 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
VERSION = "0.6.0rc0" | ||
VERSION = "0.7.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,6 +71,7 @@ def create_session_token(account_id: str, role: str) -> str: | |
"exp": now + 10 * 86400, | ||
"aud": "user_auth", | ||
"account_id": account_id, | ||
"email_address": "[email protected]", | ||
"login_time": None, | ||
"role": role, | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
import time | ||
|
||
from oonirun import models | ||
from oonirun.routers.oonirun import utcnow_seconds | ||
from oonirun.routers.v2 import utcnow_seconds | ||
import pytest | ||
|
||
import sqlalchemy as sa | ||
|
@@ -26,7 +26,7 @@ | |
"it": "integ-test descrizione breve in italiano", | ||
}, | ||
"icon": "myicon", | ||
"author": "integ-test author", | ||
"author": "[email protected]", | ||
"nettests": [ | ||
{ | ||
"inputs": [ | ||
|
@@ -85,7 +85,31 @@ def test_get_root(client): | |
assert r.status_code == 200 | ||
|
||
|
||
def test_oonirun_author_validation(client, client_with_user_role): | ||
z = deepcopy(SAMPLE_OONIRUN) | ||
z["name"] = "integ-test name in English" | ||
del z["author"] | ||
r = client_with_user_role.post("/api/v2/oonirun/links", json=z) | ||
assert r.status_code == 422, "empty author should be rejected" | ||
|
||
z["author"] = "not an author" | ||
r = client_with_user_role.post("/api/v2/oonirun/links", json=z) | ||
assert r.status_code != 200, "invalid author is rejected" | ||
|
||
z["author"] = "[email protected]" | ||
r = client_with_user_role.post("/api/v2/oonirun/links", json=z) | ||
assert r.status_code != 200, "invalid author is rejected" | ||
|
||
z["author"] = "[email protected]" | ||
r = client_with_user_role.post("/api/v2/oonirun/links", json=z) | ||
assert r.status_code == 200, "valid author is OK" | ||
|
||
|
||
def test_oonirun_validation(client, client_with_user_role): | ||
z = deepcopy(SAMPLE_OONIRUN) | ||
r = client.post("/api/v2/oonirun/links", json=z) | ||
assert r.status_code != 200, "unauthenticated requests are rejected" | ||
|
||
z = deepcopy(SAMPLE_OONIRUN) | ||
r = client_with_user_role.post("/api/v2/oonirun/links", json=z) | ||
assert r.status_code == 422, "empty name should be rejected" | ||
|
@@ -116,6 +140,13 @@ def test_oonirun_not_found(client, client_with_user_role): | |
assert str(j["oonirun_link_id"]).startswith("10") | ||
oonirun_link_id = r.json()["oonirun_link_id"] | ||
|
||
# try to change the email to a different value | ||
j["author"] = "[email protected]" | ||
r = client_with_user_role.put(f"/api/v2/oonirun/links/{oonirun_link_id}", json=j) | ||
assert r.status_code != 200, r.json() | ||
|
||
# Expire the link | ||
j["author"] = "[email protected]" | ||
j["expiration_date"] = (utcnow_seconds() + timedelta(minutes=-1)).strftime( | ||
"%Y-%m-%dT%H:%M:%S.%fZ" | ||
) | ||
|