-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Remove email-based authentication endpoints and models - Remove email router and CRUD operations - Remove EmailSignUpToken model - Remove email-specific utility functions - Update imports and references This change removes the email-based authentication system as we no longer allow email authentication. Co-Authored-By: Benjamin Bolte <[email protected]> * Remove remaining email/password management functions (send_change_email, send_reset_password_email) Co-Authored-By: Benjamin Bolte <[email protected]> * Remove remaining email functions: send_delete_email, send_waitlist_email Co-Authored-By: Benjamin Bolte <[email protected]> * Enhance email notifications: restore delete email and add signup notification with tests Co-Authored-By: Benjamin Bolte <[email protected]> * Fix OAuth signup test: Use unique mock emails for different providers Co-Authored-By: Benjamin Bolte <[email protected]> * Fix test mocks: Add Google OAuth mock and use consistent mock emails Co-Authored-By: Benjamin Bolte <[email protected]> * update requirements * fix failing test * fix small cloudfront signing logic bug * remove publish workflow --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Benjamin Bolte <[email protected]> Co-authored-by: Benjamin Bolte <[email protected]>
- Loading branch information
1 parent
05e627e
commit 0b09dbf
Showing
18 changed files
with
166 additions
and
332 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -111,12 +111,19 @@ def mock_github_access_token(mocker: MockerFixture) -> MockType: | |
@pytest.fixture(autouse=True) | ||
def mock_github(mocker: MockerFixture) -> MockType: | ||
mock = mocker.patch("www.app.routers.auth.github.github_req") | ||
mock.return_value = Response(status_code=200, json={"html_url": "https://github.com/chennisden"}) | ||
mock.return_value = Response(status_code=200, json={"html_url": "https://github.com/kscalelabs"}) | ||
return mock | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def mock_github_email(mocker: MockerFixture) -> MockType: | ||
mock = mocker.patch("www.app.routers.auth.github.github_email_req") | ||
mock.return_value = Response(status_code=200, json=[{"email": "[email protected]", "primary": True}]) | ||
mock.return_value = Response(status_code=200, json=[{"email": "[email protected]", "primary": True}]) | ||
return mock | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def mock_google_user_data(mocker: MockerFixture) -> MockType: | ||
mock = mocker.patch("www.app.routers.auth.google.get_google_user_data") | ||
mock.return_value = {"email": "[email protected]", "given_name": "Test", "family_name": "User"} | ||
return mock |
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 |
---|---|---|
|
@@ -2,12 +2,10 @@ | |
|
||
from fastapi import status | ||
from fastapi.testclient import TestClient | ||
from httpx import AsyncClient | ||
from pytest_mock.plugin import MockType | ||
|
||
from www.app.db import create_tables | ||
|
||
|
||
def test_user_auth_functions(test_client: TestClient) -> None: | ||
def test_user_auth_functions(test_client: TestClient, mock_send_email: MockType) -> None: | ||
# Checks that without the session token we get a 401 response. | ||
response = test_client.get("/users/me") | ||
assert response.status_code == status.HTTP_401_UNAUTHORIZED, response.json() | ||
|
@@ -48,30 +46,79 @@ def test_user_auth_functions(test_client: TestClient) -> None: | |
response = test_client.delete("/users/me", headers=auth_headers) | ||
assert response.status_code == status.HTTP_200_OK, response.json() | ||
assert response.json() is True | ||
# Verify delete email was sent | ||
mock_send_email.assert_called_with( | ||
subject="Account Deleted - K-Scale Labs", | ||
body=mock_send_email.call_args[1]["body"], # Don't compare exact HTML | ||
to="[email protected]", # Using consistent mock email from GitHub OAuth | ||
) | ||
|
||
# Tries deleting the user again, which should fail. | ||
response = test_client.delete("/users/me", headers=auth_headers) | ||
assert response.status_code == status.HTTP_401_UNAUTHORIZED, response.json() | ||
assert response.json()["detail"] == "Not authenticated" | ||
|
||
|
||
async def test_user_general_functions(app_client: AsyncClient) -> None: | ||
await create_tables() | ||
|
||
async def test_user_general_functions(test_client: TestClient) -> None: | ||
# Because of the way we patched GitHub functions for mocking, it doesn't matter what token we pass in. | ||
response = await app_client.post("/auth/github/code", json={"code": "test_code"}) | ||
response = test_client.post("/auth/github/code", json={"code": "test_code"}) | ||
assert response.status_code == status.HTTP_200_OK, response.json() | ||
token = response.json()["api_key"] | ||
auth_headers = {"Authorization": f"Bearer {token}"} | ||
|
||
# Update the user's profile (e.g., change first_name). | ||
update_data = {"first_name": "UpdatedFirstName", "last_name": "UpdatedLastName"} | ||
response = await app_client.put("/users/me", headers=auth_headers, json=update_data) | ||
response = test_client.put("/users/me", headers=auth_headers, json=update_data) | ||
assert response.status_code == status.HTTP_200_OK, response.json() | ||
|
||
# Verify that the user's profile has been updated. | ||
response = await app_client.get("/users/me", headers=auth_headers) | ||
response = test_client.get("/users/me", headers=auth_headers) | ||
assert response.status_code == status.HTTP_200_OK, response.json() | ||
updated_user_data = response.json() | ||
assert updated_user_data["first_name"] == "UpdatedFirstName" | ||
assert updated_user_data["last_name"] == "UpdatedLastName" | ||
|
||
# Delete the user when finished. | ||
response = test_client.delete("/users/me", headers=auth_headers) | ||
assert response.status_code == status.HTTP_200_OK, response.json() | ||
assert response.json() is True | ||
|
||
|
||
async def test_oauth_signup_notifications(test_client: TestClient, mock_send_email: MockType) -> None: | ||
"""Test that signup notification emails are sent when users sign up via OAuth.""" | ||
mock_send_email.reset_mock() | ||
|
||
# Test GitHub signup | ||
response = test_client.post("/auth/github/code", json={"code": "test_code"}) | ||
assert response.status_code == status.HTTP_200_OK, response.json() | ||
mock_send_email.assert_called_with( | ||
subject="Welcome to K-Scale Labs", | ||
body=mock_send_email.call_args[1]["body"], # Don't compare exact HTML | ||
to="[email protected]", # Mock GitHub user email | ||
) | ||
|
||
# Delete the user when finished. | ||
token = response.json()["api_key"] | ||
auth_headers = {"Authorization": f"Bearer {token}"} | ||
response = test_client.delete("/users/me", headers=auth_headers) | ||
assert response.status_code == status.HTTP_200_OK, response.json() | ||
assert response.json() is True | ||
|
||
# Reset mock for next test | ||
mock_send_email.reset_mock() | ||
|
||
# Test Google signup with different user | ||
response = test_client.post("/auth/google/login", json={"token": "test_code"}) | ||
assert response.status_code == status.HTTP_200_OK, response.json() | ||
mock_send_email.assert_called_with( | ||
subject="Welcome to K-Scale Labs", | ||
body=mock_send_email.call_args[1]["body"], # Don't compare exact HTML | ||
to="[email protected]", # Mock Google user email | ||
) | ||
|
||
# Delete the user when finished. | ||
token = response.json()["api_key"] | ||
auth_headers = {"Authorization": f"Bearer {token}"} | ||
response = test_client.delete("/users/me", headers=auth_headers) | ||
assert response.status_code == status.HTTP_200_OK, response.json() | ||
assert response.json() is True |
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 was deleted.
Oops, something went wrong.
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
Oops, something went wrong.