Exemple #1
0
    def test_okta_verify_failure(self):
        client = okta.Okta('organization', 'username', 'password')
        client._request = mock.MagicMock(name='_request')
        client._request.return_value = MFA_WAITING_RESPONSE
        client.mfa_wait_loop = mock.MagicMock(name='mfa_wait_loop')
        client.mfa_wait_loop.return_value = None

        ret = client.okta_verify('123', 'token')
        self.assertEquals(ret, None)
Exemple #2
0
    def test_init_args_values(self):
        client = okta.Okta(organization='foo',
                           username='******',
                           password='******',
                           oktapreview=True)

        self.assertEquals(client.base_url, 'https://foo.oktapreview.com')
        self.assertEquals(client.username, 'bar')
        self.assertEquals(client.password, 'baz')
Exemple #3
0
    def test_handle_push_factors_duo_auth(self):
        client = okta.Okta('organization', 'username', 'password')
        client.duo_auth = mock.MagicMock(name='duo_auth')
        client.duo_auth.return_value = True
        duo_factor = MFA_CHALLENGE_RESPONSE_DUO_AUTH['_embedded']['factors']

        ret = client.handle_push_factors(duo_factor, 'token')

        self.assertEqual(ret, True)
        client.duo_auth.assert_has_calls([mock.call('abcd', 'token')])
Exemple #4
0
    def test_send_user_response_invalid_token(self):
        client = okta.Okta('organization', 'username', 'password')
        resp = requests.Response()
        resp.status_code = 403
        client._request = mock.MagicMock(name='_request')
        client._request.side_effect = requests.exceptions.HTTPError(
            response=resp)

        ret = client.send_user_response('fid', 'token', '123456', 'passCode')
        self.assertEqual(None, ret)
Exemple #5
0
 def test_set_token(self):
     client = okta.Okta("organization", "username", "password")
     client.session = mock.MagicMock(name="session")
     client._request = mock.MagicMock()
     client._request.return_value = {"id": "LongToken"}
     client.set_token(SUCCESS_RESPONSE)
     self.assertEqual(client.session_token, "LongToken")
     client._request.assert_has_calls([
         mock.call("/sessions", {"sessionToken": "XXXTOKENXXX"}),
     ], )
Exemple #6
0
    def test_auth_with_token(self):
        client = okta.Okta('organization', 'username', 'password')
        client._request = mock.MagicMock(name='_request')
        client._request.side_effect = [SUCCESS_RESPONSE]
        client.set_token = mock.MagicMock()

        client.auth('token')

        client._request.assert_has_calls(
            [mock.call('/authn', {'stateToken': 'token'})])
Exemple #7
0
    def test_auth_trigger_duo_auth(self):
        client = okta.Okta('organization', 'username', 'password')
        client._request = mock.MagicMock(name='_request')
        client.duo_auth = mock.MagicMock(name='duo_auth')

        client._request.side_effect = [MFA_CHALLENGE_RESPONSE_DUO_AUTH]

        ret = client.auth()
        self.assertEquals(ret, None)
        client.duo_auth.assert_has_calls([mock.call(123, 'abcd', 'token')])
Exemple #8
0
    def test_handle_push_factors_okta_verify(self):
        client = okta.Okta('organization', 'username', 'password')
        client.okta_verify = mock.MagicMock(name='okta_verify')
        client.okta_verify.return_value = True
        factor = MFA_CHALLENGE_RESPONSE_OKTA_VERIFY['_embedded']['factors']

        ret = client.handle_push_factors(factor, 'token')

        self.assertEqual(ret, True)
        client.okta_verify.assert_has_calls([mock.call('abcd', 'token')])
 def test_handle_response_factors_call(self):
     client = okta.Okta('organization', 'username', 'password')
     client.request_otp = mock.MagicMock()
     with self.assertRaises(okta.PasscodeRequired):
         client.handle_response_factors(
             MFA_CHALLENGE_CALL_OTP['_embedded']['factors'],
             'foo')
     client.request_otp.assert_has_calls([
         mock.call('abcd', 'foo', 'phone call')
     ])
Exemple #10
0
    def test_send_user_response_invalid_token(self):
        client = okta.Okta("organization", "username", "password")
        resp = requests.Response()
        resp.status_code = 403
        client._request = mock.MagicMock(name="_request")
        client._request.side_effect = requests.exceptions.HTTPError(
            response=resp, )

        ret = client.send_user_response("fid", "token", "123456", "passCode")
        self.assertEqual(None, ret)
Exemple #11
0
    def test_mfa_wait_loop_timeout(self):
        client = okta.Okta('organization', 'username', 'password')
        client._request = mock.MagicMock(name='_request')
        client._request.side_effect = [
            MFA_WAITING_RESPONSE,
            KeyboardInterrupt
        ]
        data = {'fid': '123', 'stateToken': 'token'}

        ret = client.mfa_wait_loop(MFA_WAITING_RESPONSE, data, sleep=0)
        self.assertEquals(ret, None)
Exemple #12
0
    def test_duo_auth_failure(self, duo_mock, process_mock, _web_mock,
                              _sleep_mock):
        client = okta.Okta('organization', 'username', 'password')
        client._request = mock.MagicMock(name='_request')
        client._request.return_value = MFA_WAITING_RESPONSE
        process_mock.start.return_value = None
        client.mfa_wait_loop = mock.MagicMock(name='mfa_wait_loop')
        client.mfa_wait_loop.return_value = None

        ret = client.duo_auth('123', 'token')
        self.assertEquals(ret, None)
Exemple #13
0
    def test_send_user_response_unknown_error(self):
        client = okta.Okta("organization", "username", "password")
        resp = requests.Response()
        resp.status_code = 500
        resp.body = "Something bad happened"
        client._request = mock.MagicMock(name="_request")
        client._request.side_effect = requests.exceptions.HTTPError(
            response=resp, )

        with self.assertRaises(okta.UnknownError):
            client.send_user_response("fid", "token", "123456", "passCode")
Exemple #14
0
    def test_send_user_response_retries_exceeded(self):
        client = okta.Okta("organization", "username", "password")
        resp = requests.Response()
        resp.status_code = 401
        resp.body = "Too many failures"
        client._request = mock.MagicMock(name="_request")
        client._request.side_effect = requests.exceptions.HTTPError(
            response=resp, )

        with self.assertRaises(okta.UnknownError):
            client.send_user_response("fid", "token", "123456", "passCode")
Exemple #15
0
    def test_set_token_skip_if_exists(self):
        client = okta.Okta('organization', 'username', 'password')
        client.session_token = 'woot'
        client.session = mock.MagicMock(name='session')
        client._request = mock.MagicMock()
        client._request.return_value = {'id': 'LongToken'}

        client.set_token(SUCCESS_RESPONSE)

        self.assertEqual(client.session_token, 'woot')
        assert not client._request.called
Exemple #16
0
    def test_set_token_skip_if_exists(self):
        client = okta.Okta("organization", "username", "password")
        client.session_token = "woot"
        client.session = mock.MagicMock(name="session")
        client._request = mock.MagicMock()
        client._request.return_value = {"id": "LongToken"}

        client.set_token(SUCCESS_RESPONSE)

        self.assertEqual(client.session_token, "woot")
        assert not client._request.called
Exemple #17
0
    def test_init_args_values(self):
        client = okta.Okta(
            organization="foo",
            username="******",
            password="******",
            oktapreview=True,
        )

        self.assertEqual(client.base_url, "https://foo.oktapreview.com")
        self.assertEqual(client.username, "bar")
        self.assertEqual(client.password, "baz")
Exemple #18
0
    def test_auth_trigger_okta_verify_canceled(self):
        client = okta.Okta('organization', 'username', 'password')
        client._request = mock.MagicMock(name='_request')
        client.okta_verify_with_push = mock.MagicMock(
            name='okta_verify_with_push')
        client.okta_verify_with_push.side_effect = KeyboardInterrupt

        client._request.side_effect = [MFA_CHALLENGE_RESPONSE_OKTA_VERIFY]

        with self.assertRaises(okta.UnknownError):
            client.auth()
Exemple #19
0
    def test_mfa_wait_loop_timeout(self):
        client = okta.Okta("organization", "username", "password")
        client._request = mock.MagicMock(name="_request")
        client._request.side_effect = [
            MFA_WAITING_RESPONSE,
            KeyboardInterrupt,
        ]
        data = {"fid": "123", "stateToken": "token"}

        with self.assertRaises(KeyboardInterrupt):
            client.mfa_wait_loop(MFA_WAITING_RESPONSE, data, sleep=0)
Exemple #20
0
 def test_handle_response_factors_call(self):
     client = okta.Okta("organization", "username", "password")
     client.request_otp = mock.MagicMock()
     with self.assertRaises(okta.PasscodeRequired):
         client.handle_response_factors(
             MFA_CHALLENGE_CALL_OTP["_embedded"]["factors"],
             "foo",
         )
     client.request_otp.assert_has_calls([
         mock.call("abcd", "foo", "phone call"),
     ], )
Exemple #21
0
    def test_auth_call_error(self):
        client = okta.Okta("organization", "username", "password")
        resp = requests.Response()
        resp.status_code = 403
        resp.body = "Bad Password"
        client._request = mock.MagicMock(name="_request")
        client._request.side_effect = requests.exceptions.HTTPError(
            response=resp, )

        with self.assertRaises(requests.exceptions.HTTPError):
            client.auth()
Exemple #22
0
    def test_duo_auth_failure(self, _duo_mock, _sleep_mock):
        client = okta.Okta("organization", "username", "password")
        client._request = mock.MagicMock(name="_request")
        client._request.return_value = MFA_WAITING_RESPONSE
        client.mfa_wait_loop = mock.MagicMock(name="mfa_wait_loop")
        client.mfa_wait_loop.return_value = None
        client.mfa_callback = mock.MagicMock()
        client.duo_factor = "push"

        ret = client.duo_auth("123", "token")
        self.assertEqual(ret, None)
Exemple #23
0
    def test_handle_mfa_response_trigger_duo_auth(self):
        client = okta.Okta('organization', 'username', 'password')
        client.handle_push_factors = mock.MagicMock(
            name='handle_push_factors')
        client.handle_push_factors.return_value = True

        client.handle_mfa_response(MFA_CHALLENGE_RESPONSE_DUO_AUTH)
        client.handle_push_factors.assert_has_calls([
            mock.call([{'factorType': 'web', 'provider': 'DUO', 'id': 'abcd'}],
                      'token')
        ])
Exemple #24
0
    def test_auth_call_error(self):
        client = okta.Okta('organization', 'username', 'password')
        resp = requests.Response()
        resp.status_code = 403
        resp.body = 'Bad Password'
        client._request = mock.MagicMock(name='_request')
        client._request.side_effect = requests.exceptions.HTTPError(
            response=resp)

        with self.assertRaises(requests.exceptions.HTTPError):
            client.auth()
Exemple #25
0
    def test_duo_auth_failure(self, _duo_mock, _sleep_mock):
        client = okta.Okta('organization', 'username', 'password')
        client._request = mock.MagicMock(name='_request')
        client._request.return_value = MFA_WAITING_RESPONSE
        client.mfa_wait_loop = mock.MagicMock(name='mfa_wait_loop')
        client.mfa_wait_loop.return_value = None
        client.mfa_callback = mock.MagicMock()
        client.duo_factor = "push"

        ret = client.duo_auth('123', 'token')
        self.assertEqual(ret, None)
Exemple #26
0
    def test_send_user_response_unknown_error(self):
        client = okta.Okta('organization', 'username', 'password')
        resp = requests.Response()
        resp.status_code = 500
        resp.body = 'Something bad happened'
        client._request = mock.MagicMock(name='_request')
        client._request.side_effect = requests.exceptions.HTTPError(
            response=resp)

        with self.assertRaises(okta.UnknownError):
            client.send_user_response('fid', 'token', '123456', 'passCode')
Exemple #27
0
    def test_send_user_response_retries_exceeded(self):
        client = okta.Okta('organization', 'username', 'password')
        resp = requests.Response()
        resp.status_code = 401
        resp.body = 'Too many failures'
        client._request = mock.MagicMock(name='_request')
        client._request.side_effect = requests.exceptions.HTTPError(
            response=resp)

        with self.assertRaises(okta.UnknownError):
            client.send_user_response('fid', 'token', '123456', 'passCode')
Exemple #28
0
    def test_auth_trigger_okta_verify(self):
        client = okta.Okta('organization', 'username', 'password')
        client._request = mock.MagicMock(name='_request')
        client.okta_verify_with_push = mock.MagicMock(
            name='okta_verify_with_push')

        client._request.side_effect = [MFA_CHALLENGE_RESPONSE_OKTA_VERIFY]

        ret = client.auth()
        self.assertEquals(ret, None)
        client.okta_verify_with_push.assert_has_calls(
            [mock.call('abcd', 'token')])
Exemple #29
0
    def test_handle_push_factors_okta_verify(self):
        client = okta.Okta("organization", "username", "password")
        client.okta_verify = mock.MagicMock(name="okta_verify")
        client.okta_verify.return_value = True
        factor = MFA_CHALLENGE_RESPONSE_OKTA_VERIFY["_embedded"]["factors"]

        ret = client.handle_push_factors(factor, "token")

        self.assertEqual(ret, True)
        client.okta_verify.assert_has_calls([
            mock.call("abcd", "token"),
        ], )
Exemple #30
0
    def test_handle_push_factors_duo_auth(self):
        client = okta.Okta("organization", "username", "password")
        client.duo_auth = mock.MagicMock(name="duo_auth")
        client.duo_auth.return_value = True
        duo_factor = MFA_CHALLENGE_RESPONSE_DUO_AUTH["_embedded"]["factors"]

        ret = client.handle_push_factors(duo_factor, "token")

        self.assertEqual(ret, True)
        client.duo_auth.assert_has_calls([
            mock.call("abcd", "token"),
        ], )