def test_validate_security_context_oauth2ex(self):
        '''This test case ensures that security context validation oauth2 errors are bubbled up.'''

        ex = OAuth2Error(error_code=-1)

        with self.assertRaises(OAuth2Error) as ctx:
            self._test_validate_security_context_template(side_effect=ex)

        self.assertEqual(ex, ctx.exception)
Exemple #2
0
    def test_controller_validatesecurity_oauth2ex(self):
        '''This test case ensures that oauth 2 exceptions occuring during context validation are bubbled up.'''

        ex = OAuth2Error(error_code=-1)

        with self.assertRaises(OAuth2Error) as ctx:
            self._test_controller_validatesecurity_template(side_effect=ex)

        self.assertEqual(ex, ctx.exception)
Exemple #3
0
    def test_authenticate_passwordhasher_oauth2ex(self):
        '''This test case ensures oauth2 exceptions raised by password hasher are bubbled up.'''

        ex = OAuth2Error(error_code=-1)

        with self.assertRaises(OAuth2Error) as ctx:
            self._test_authenticate_passwordhasher_ex(ex)

        self.assertEqual(ex, ctx.exception)
Exemple #4
0
    def test_authenticate_encrypt_oauth2ex(self):
        '''This test case ensures oauth2 exceptions raised during token encryption are bubbled up.'''

        ex = OAuth2Error(error_code=-1)

        with self.assertRaises(OAuth2Error) as ctx:
            self._test_authenticate_encrypt_ex(ex)

        self.assertEqual(ex, ctx.exception)
    def test_server_error_form(self):
        '''This test case ensures generic oauth2 errors are casted to internal server redirect responses.'''

        ex = OAuth2Error(error_code=232, msg="Unexpected error", http_code=500)

        self._test_exception_form(ex,
                                  error="server_error",
                                  description=urllib.parse.quote(str(ex)),
                                  uri=self._calculate_expected_uri(ex.error_code),
                                  return_url="/example/cb#triplex=abcd")
    def test_server_error_json(self):
        '''This test case ensures generic oauth2 errors are casted to internal server error.'''

        ex = OAuth2Error(error_code=232, msg="Unexpected error", http_code=500)

        body = self._test_exception_json(ex)

        self._assert_error_response(error="server_error",
                                    description=str(ex),
                                    uri=self._calculate_expected_uri(ex.error_code),
                                    body=body)
    def test_generate_factory_oauth2ex(self):
        '''This test case ensures all oauth2 exceptions raised from factory class are bubbled up.'''

        ex = OAuth2Error(error_code=-1)

        self._tokens_factory.get_generator = Mock(side_effect=ex)

        with self.assertRaises(OAuth2Error) as ctx:
            self._tokens_service.generate({}, "unknown")

        self.assertEqual(ex, ctx.exception)
    def test_invalidate_generator_oauth2ex(self):
        '''This test case ensures generator oauth2 exceptions are bubbled up.'''

        token = Token({"type": "mock-type"})

        ex = OAuth2Error(error_code=-1)

        self._tokens_generator.invalidate = Mock(side_effect=ex)

        with self.assertRaises(OAuth2Error) as ctx:
            self._tokens_service.invalidate(token)

        self.assertEqual(ex, ctx.exception)
    def test_generate_generator_oauth2ex(self):
        '''This test case ensures generator oauth2 exceptions are bubbled up.'''

        token_type = "mock-type"
        token_desc = {"client_id": "abc", "test_attr": 1}

        ex = OAuth2Error(error_code=-1)

        self._tokens_generator.generate = Mock(side_effect=ex)

        with self.assertRaises(OAuth2Error) as ctx:
            self._tokens_service.generate(token_desc, token_type)

        self.assertEqual(ex, ctx.exception)