forked from HHS/TANF-app
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
410ce8f
commit 8274434
Showing
6 changed files
with
88 additions
and
5 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
44 changes: 44 additions & 0 deletions
44
tdrs-backend/tdpservice/users/test/test_api/test_login_redirect_oidc.py
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#LoginRedirectAMS | ||
from unittest import mock | ||
from tdpservice.users.api.login_redirect_oidc import LoginRedirectAMS | ||
|
||
@mock.patch("requests.get") | ||
def test_get_ams_configuration(requests_get_mock): | ||
"""Test the LoginRedirectAMS class.""" | ||
requests_get_mock.return_value.status_code = 200 | ||
requests_get_mock.return_value.json.return_value = {"key": "test"} | ||
returned_value = LoginRedirectAMS.get_ams_configuration() | ||
assert returned_value == {"key": "test"} | ||
|
||
# Test if the configuration is not returned | ||
requests_get_mock.return_value.status_code = 500 | ||
returned_value = LoginRedirectAMS.get_ams_configuration() | ||
assert returned_value is None | ||
|
||
@mock.patch("requests.get") | ||
@mock.patch("secrets.token_hex") | ||
def test_LoginRedirectAMS_get(secrets_token_hex_mock, requests_get_mock): | ||
"""Test the LoginRedirectAMS class.""" | ||
class DummyRequest: | ||
session = { | ||
"state_nonce_tracker": "dummy_state_nonce_tracker" | ||
} | ||
requests_get_mock.return_value.status_code = 200 | ||
requests_get_mock.return_value.json.return_value = {"authorization_endpoint": "dummy_authorization_endpoint"} | ||
|
||
secrets_token_hex_mock.return_value = "dummy_state_nonce" | ||
|
||
login_redirect_ams = LoginRedirectAMS() | ||
|
||
response = login_redirect_ams.get(DummyRequest) | ||
assert response.url == "dummy_authorization_endpoint?client_id=&nonce=dummy_state_nonce&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fv1%2Foidc%2Fams&response_type=code&state=dummy_state_nonce&scope=openid+email" | ||
|
||
|
||
# Test if the AMS server is down | ||
requests_get_mock.return_value.status_code = 500 | ||
login_redirect_ams = LoginRedirectAMS() | ||
response = login_redirect_ams.get("request") | ||
print('____ response', response.__dict__) | ||
assert response.status_code == 500 | ||
|
||
|
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Your Business</title> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
</head> | ||
<body> | ||
<!--# if expr="$status = 502" --> | ||
<h1>We are updating our website "##STATUS##"</h1> | ||
<p>This is only for a few seconds, you will be redirected. $status</p> | ||
<!--# else --> | ||
<h1><!--# echo var="status" default="" --> <!--# echo var="status_text" default="Something goes wrong" --></h1> | ||
<!--# endif --> | ||
|
||
</body> | ||
</html> |