Skip to content

Commit

Permalink
clean up dupes / missing test
Browse files Browse the repository at this point in the history
  • Loading branch information
pcmxgti committed Oct 17, 2023
1 parent d763794 commit 25a7f5a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 52 deletions.
21 changes: 21 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,24 @@ def config_file(tmp_path_factory):
"""Generate a path for a temporary ini file that multiple tests can share."""
path = tmp_path_factory.mktemp("pytest") / "pytest.ini"
return path


@pytest.fixture
def sample_json_response():
"""Return a response from okta server."""
from okta_response_simulation import empty_dict
from okta_response_simulation import error_dict
from okta_response_simulation import no_auth_methods
from okta_response_simulation import no_mfa
from okta_response_simulation import no_mfa_no_session_token
from okta_response_simulation import with_mfa

okta_fixture_data = {
"okta_response_no_auth_methods": no_auth_methods,
"okta_response_empty": empty_dict,
"okta_response_error": error_dict,
"okta_response_no_mfa": no_mfa,
"okta_response_no_mfa_no_session_token": no_mfa_no_session_token,
"okta_response_mfa": with_mfa,
}
return okta_fixture_data
12 changes: 12 additions & 0 deletions tests/unit/test_aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,15 @@ def test_select_assumeable_role_no_tiles():
with pytest.raises(SystemExit) as err:
aws.select_assumeable_role(tiles)
assert err.value.code == 1


@pytest.mark.parametrize("status_code", [(400), (401), (404), (500), (503)])
def test_authenticate_to_roles(status_code, monkeypatch):
"""Test if function return correct response."""
import requests
from tokendito.aws import authenticate_to_roles

mock_get = {"status_code": status_code, "text": "response"}
monkeypatch.setattr(requests, "get", mock_get)
with pytest.raises(SystemExit) as error:
assert authenticate_to_roles([("http://test.url.com", "")], "secret_session_token") == error
52 changes: 0 additions & 52 deletions tests/unit/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,11 @@
from datetime import datetime
import os
import sys
from unittest.mock import Mock

import pytest
import requests_mock


@pytest.fixture
def sample_json_response():
"""Return a response from okta server."""
from okta_response_simulation import empty_dict
from okta_response_simulation import error_dict
from okta_response_simulation import no_auth_methods
from okta_response_simulation import no_mfa
from okta_response_simulation import no_mfa_no_session_token
from okta_response_simulation import with_mfa

okta_fixture_data = {
"okta_response_no_auth_methods": no_auth_methods,
"okta_response_empty": empty_dict,
"okta_response_error": error_dict,
"okta_response_no_mfa": no_mfa,
"okta_response_no_mfa_no_session_token": no_mfa_no_session_token,
"okta_response_mfa": with_mfa,
}
return okta_fixture_data


@pytest.mark.xfail(
sys.platform == "win32", reason="Windows does not always handle NULL stdin correctly."
)
Expand Down Expand Up @@ -660,36 +638,6 @@ def test_incorrect_role_arn():
assert select_role_arn(authenticated_tiles) == error


def test_get_duo_sid(mocker):
"""Check if got sid correct."""
from tokendito.config import config
from tokendito.duo import get_duo_sid

test_duo_info = {
"okta_factor": "okta_factor",
"factor_id": 1234,
"state_token": 12345,
"okta_callback_url": "http://test.okta.href",
"tx": "fdsafdsa",
"tile_sig": "fdsfdfds",
"parent": f"{config.okta['org']}/signin/verify/duo/web",
"host": "test_host",
"sid": "",
"version": "3.7",
}

test_url = "http://test.token.dito?sid=testval"
duo_api_response = Mock()
duo_api_response.url = test_url

mocker.patch("tokendito.duo.duo_api_post", return_value=duo_api_response)

duo_sid_info, duo_auth_response = get_duo_sid(test_duo_info)

assert duo_sid_info["sid"] == "testval"
assert duo_auth_response.url == test_url


def test_loglevel_collected_from_env(monkeypatch):
"""Ensure that the loglevel collected from env vars."""
from argparse import Namespace
Expand Down

0 comments on commit 25a7f5a

Please sign in to comment.