Skip to content

Commit

Permalink
update test_push_approval
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernando Aureliano da Silva Maia committed Oct 20, 2023
1 parent 7b22273 commit 2775e51
Showing 1 changed file with 16 additions and 27 deletions.
43 changes: 16 additions & 27 deletions tests/unit/test_okta.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ def test_mfa_challenge_with_no_mfas(sample_headers, sample_json_response):
@pytest.mark.parametrize(
"return_value,side_effect,expected",
[
({"status": "SUCCESS", "sessionToken": "pytest"}, None, 2),
({"status": "SUCCESS", "sessionToken": "pytest", "factorResult": "SUCCESS"}, None, 2),
({"status": "SUCCESS", "sessionToken": "pytest"}, None, 0),
({"status": "SUCCESS", "sessionToken": "pytest", "factorResult": "SUCCESS"}, None, 0),
({"status": "MFA_CHALLENGE", "factorResult": "REJECTED"}, None, 2),
({"status": "MFA_CHALLENGE", "factorResult": "TIMEOUT"}, None, 2),
({"status": "UNKNOWN", "factorResult": "UNKNOWN"}, None, 2),
Expand Down Expand Up @@ -288,33 +288,22 @@ def test_push_approval(mocker, return_value, side_effect, expected):
"""Test push approval."""
from tokendito import okta

mock_responses = [
{"status": "SUCCESS", "sessionToken": "some_token"},
{"status": "WAITING", "factorResult": "WAITING"},
]
challenge_url = "https://pytest/api/v1/authn/factors/factorid/verify"
payload = {"some_key": "some_value"}

for mock_response in mock_responses:
mfa_challenge_url = "https://pytest/api/v1/authn/factors/factorid/verify"
payload = {"some_key": "some_value"}
mocker.patch.object(HTTP_client, "post", return_value=return_value, side_effect=side_effect)
mocker.patch("time.sleep", return_value=None)

mocker.patch.object(
HTTP_client, "post", return_value=mock_response, side_effect=side_effect
)
mocker.patch("time.sleep", return_value=None)

try:
ret = okta.push_approval(mfa_challenge_url, payload)

if "status" in return_value and return_value["status"] == "SUCCESS":
assert ret["status"] == "SUCCESS"

elif "factorResult" in return_value and return_value["factorResult"] == "WAITING":
assert (
ret["status"] == "SUCCESS"
) # This assumes that the function treats "WAITING" as a "SUCCESS"

except SystemExit as e:
assert e.code == expected
if "status" in return_value and return_value["status"] == "SUCCESS":
ret = okta.push_approval(challenge_url, payload)
assert ret["status"] == "SUCCESS"
elif "factorResult" in return_value and return_value["factorResult"] == "WAITING":
ret = okta.push_approval(challenge_url, payload)
assert ret["status"] == "SUCCESS"
else:
with pytest.raises(SystemExit) as err:
okta.push_approval(challenge_url, payload)
assert err.value.code == expected


@pytest.mark.parametrize(
Expand Down

0 comments on commit 2775e51

Please sign in to comment.