Skip to content

Commit

Permalink
Fix regression bug for bad token
Browse files Browse the repository at this point in the history
  • Loading branch information
pcmxgti committed Mar 25, 2022
1 parent cdd21b1 commit 2742c19
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ pytest-cov
pytest-env
pytest-mock
pytest-ordering
requests-mock
semver
tox
22 changes: 22 additions & 0 deletions tests/unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from unittest.mock import Mock

import pytest
import requests_mock
import semver


Expand Down Expand Up @@ -389,6 +390,27 @@ def test_bad_mfa_provider_type(mocker, sample_headers):
)


def test_okta_verify_api_method():
"""Test whether verify_api_method returns the correct data."""
from tokendito.okta import okta_verify_api_method

url = "https://acme.org"
with requests_mock.Mocker() as m:
data = {"response": "ok"}
m.post(url, json=data, status_code=200)
assert okta_verify_api_method(url, data) == data

with pytest.raises(SystemExit) as error, requests_mock.Mocker() as m:
data = "pytest_bad_datatype"
m.post(url, text=data, status_code=403)
assert okta_verify_api_method(url, data) == error

with pytest.raises(SystemExit) as error, requests_mock.Mocker() as m:
data = {"response": "incorrect", "errorCode": "0xdeadbeef"}
m.post(url, json=data, status_code=403)
assert okta_verify_api_method("http://acme.org", data) == error


def test_login_error_code_parser():
"""Test whether message on specific status equal."""
from tokendito.okta import login_error_code_parser, _status_dict
Expand Down
4 changes: 4 additions & 0 deletions tokendito/okta.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ def okta_verify_api_method(url, payload, headers=None):
logger.error(f"Received invalid type of response {type(response.text)} from {url}")
sys.exit(1)

if "errorCode" in ret:
login_error_code_parser(ret["errorCode"])
sys.exit(1)

return ret


Expand Down

0 comments on commit 2742c19

Please sign in to comment.