Beispiel #1
0
def test_get_response_1():
    def mock_prompter(prompt):
        return ""

    authenticator = OktaAuthenticator(mock_prompter)
    with pytest.raises(SAMLError):
        authenticator.get_response("")
Beispiel #2
0
def test_get_response():
    authenticator = OktaAuthenticator(None)
    if sys.version_info >= (3, 0):
        ips = "builtins.input"
    else:
        ips = "__builtin__.raw_input"

    with mock.patch(ips, return_value=""):
        with pytest.raises(SAMLError):
            authenticator.get_response("")
    with mock.patch(ips, return_value="fake input"):
        response = authenticator.get_response("")
        assert response == "fake input"
Beispiel #3
0
def test_get_assertion_from_response(mock_requests_session, assertion):
    authenticator = OktaAuthenticator(None)
    session_token = {
        'sessionToken': '1234',
    }
    assertion_form = '<form><input name="SAMLResponse" value="%s"/></form>'
    assertion_form = assertion_form % assertion.decode('ascii')
    assertion_response = mock.Mock(spec=requests.Response,
                                   status_code=200,
                                   text=assertion_form)
    mock_requests_session.get.return_value = assertion_response
    result = authenticator.get_assertion_from_response("endpoint",
                                                       session_token)
    assert result == assertion
Beispiel #4
0
def test_process_mfa_verification_5():
    parsed = {
        "_embedded": {
            "factors": [{
                "factorType": "sms",
                "_links": {
                    "verify": {
                        "href": "href"
                    }
                }
            }]
        },
        "stateToken": "statetoken"
    }
    authenticator = OktaAuthenticator(None)
    with mock.patch("awsprocesscreds.saml.OktaAuthenticator.process_mfa_sms",
                    return_value="mock_call"):
        result = authenticator.process_mfa_verification("endpoint", parsed)
        assert result == "mock_call"
Beispiel #5
0
def test_process_mfa_verification_1():
    parsed = {
        "_embedded": {
            "factors": [{
                "factorType": "unsupported",
                "_links": {
                    "verify": {
                        "href": "href"
                    }
                }
            }, {
                "factorType": "unsupported"
            }]
        },
        "stateToken": "statetoken"
    }
    authenticator = OktaAuthenticator(None)
    with mock.patch("awsprocesscreds.saml.OktaAuthenticator.get_mfa_choice",
                    return_value=1):
        with pytest.raises(SAMLError):
            authenticator.process_mfa_verification("endpoint", parsed)
Beispiel #6
0
def okta_auth(prompter, mock_requests_session):
    return OktaAuthenticator(prompter, mock_requests_session)