|
@ -10,15 +10,15 @@ middleware_module = 'corvus.middleware.authentication_middleware' |
|
|
@patch(middleware_module + '.authentication_service.is_valid_password') |
|
|
@patch(middleware_module + '.authentication_service.is_valid_password') |
|
|
@patch(middleware_module + '.user_service.find_by_name') |
|
|
@patch(middleware_module + '.user_service.find_by_name') |
|
|
def test_authenticate_with_password_happy_path( |
|
|
def test_authenticate_with_password_happy_path( |
|
|
mock_user_service: MagicMock, |
|
|
|
|
|
mock_authentication_service: MagicMock, |
|
|
|
|
|
|
|
|
mock_find_by_name: MagicMock, |
|
|
|
|
|
mock_is_valid_password: MagicMock, |
|
|
mock_g: MagicMock): |
|
|
mock_g: MagicMock): |
|
|
mock_g.user = Mock() |
|
|
mock_g.user = Mock() |
|
|
mock_user_service.return_value = Mock() |
|
|
|
|
|
mock_authentication_service.return_value = True |
|
|
|
|
|
|
|
|
mock_find_by_name.return_value = Mock() |
|
|
|
|
|
mock_is_valid_password.return_value = True |
|
|
assert authenticate_with_password('test', 'test') |
|
|
assert authenticate_with_password('test', 'test') |
|
|
mock_user_service.assert_called_once() |
|
|
|
|
|
mock_authentication_service.assert_called_once() |
|
|
|
|
|
|
|
|
mock_find_by_name.assert_called_once() |
|
|
|
|
|
mock_is_valid_password.assert_called_once() |
|
|
mock_g.user.assert_not_called() |
|
|
mock_g.user.assert_not_called() |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -26,15 +26,15 @@ def test_authenticate_with_password_happy_path( |
|
|
@patch(middleware_module + '.authentication_service.is_valid_password') |
|
|
@patch(middleware_module + '.authentication_service.is_valid_password') |
|
|
@patch(middleware_module + '.user_service.find_by_name') |
|
|
@patch(middleware_module + '.user_service.find_by_name') |
|
|
def test_authenticate_with_password_no_user( |
|
|
def test_authenticate_with_password_no_user( |
|
|
mock_user_service: MagicMock, |
|
|
|
|
|
mock_authentication_service: MagicMock, |
|
|
|
|
|
|
|
|
mock_find_by_name: MagicMock, |
|
|
|
|
|
mock_is_valid_password: MagicMock, |
|
|
mock_g: MagicMock): |
|
|
mock_g: MagicMock): |
|
|
mock_g.user = Mock() |
|
|
mock_g.user = Mock() |
|
|
mock_user_service.return_value = None |
|
|
|
|
|
mock_authentication_service.return_value = True |
|
|
|
|
|
|
|
|
mock_find_by_name.return_value = None |
|
|
|
|
|
mock_is_valid_password.return_value = True |
|
|
assert not authenticate_with_password('test', 'test') |
|
|
assert not authenticate_with_password('test', 'test') |
|
|
mock_user_service.assert_called_once() |
|
|
|
|
|
mock_authentication_service.assert_not_called() |
|
|
|
|
|
|
|
|
mock_find_by_name.assert_called_once() |
|
|
|
|
|
mock_is_valid_password.assert_not_called() |
|
|
mock_g.user.assert_not_called() |
|
|
mock_g.user.assert_not_called() |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -42,91 +42,91 @@ def test_authenticate_with_password_no_user( |
|
|
@patch(middleware_module + '.authentication_service.is_valid_password') |
|
|
@patch(middleware_module + '.authentication_service.is_valid_password') |
|
|
@patch(middleware_module + '.user_service.find_by_name') |
|
|
@patch(middleware_module + '.user_service.find_by_name') |
|
|
def test_authenticate_with_password_invalid_password( |
|
|
def test_authenticate_with_password_invalid_password( |
|
|
mock_user_service: MagicMock, |
|
|
|
|
|
mock_authentication_service: MagicMock, |
|
|
|
|
|
|
|
|
mock_find_by_name: MagicMock, |
|
|
|
|
|
mock_is_valid_password: MagicMock, |
|
|
mock_g: MagicMock): |
|
|
mock_g: MagicMock): |
|
|
mock_g.user = Mock() |
|
|
mock_g.user = Mock() |
|
|
mock_user_service.return_value = Mock() |
|
|
|
|
|
mock_authentication_service.return_value = False |
|
|
|
|
|
|
|
|
mock_find_by_name.return_value = Mock() |
|
|
|
|
|
mock_is_valid_password.return_value = False |
|
|
assert not authenticate_with_password('test', 'test') |
|
|
assert not authenticate_with_password('test', 'test') |
|
|
mock_user_service.assert_called_once() |
|
|
|
|
|
mock_authentication_service.assert_called_once() |
|
|
|
|
|
|
|
|
mock_find_by_name.assert_called_once() |
|
|
|
|
|
mock_is_valid_password.assert_called_once() |
|
|
mock_g.user.assert_not_called() |
|
|
mock_g.user.assert_not_called() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@patch(middleware_module + '.g') |
|
|
@patch(middleware_module + '.g') |
|
|
@patch(middleware_module + '.authentication_service.is_valid_token') |
|
|
|
|
|
|
|
|
@patch(middleware_module + '.user_token_service.is_valid_token') |
|
|
@patch(middleware_module + '.user_token_service.find_by_user_and_token') |
|
|
@patch(middleware_module + '.user_token_service.find_by_user_and_token') |
|
|
@patch(middleware_module + '.user_service.find_by_name') |
|
|
@patch(middleware_module + '.user_service.find_by_name') |
|
|
def test_authenticate_with_token_happy_path( |
|
|
def test_authenticate_with_token_happy_path( |
|
|
mock_user_service: MagicMock, |
|
|
|
|
|
mock_user_token_service: MagicMock, |
|
|
|
|
|
mock_authentication_service: MagicMock, |
|
|
|
|
|
|
|
|
mock_find_by_name: MagicMock, |
|
|
|
|
|
mock_find_by_user_and_token: MagicMock, |
|
|
|
|
|
mock_is_valid_token: MagicMock, |
|
|
mock_g: MagicMock): |
|
|
mock_g: MagicMock): |
|
|
mock_g.user = Mock() |
|
|
mock_g.user = Mock() |
|
|
mock_user_service.return_value = Mock() |
|
|
|
|
|
mock_user_token_service.return_value = Mock() |
|
|
|
|
|
mock_authentication_service.return_value = True |
|
|
|
|
|
|
|
|
mock_find_by_name.return_value = Mock() |
|
|
|
|
|
mock_find_by_user_and_token.return_value = Mock() |
|
|
|
|
|
mock_is_valid_token.return_value = True |
|
|
assert authenticate_with_token('test', 'test') |
|
|
assert authenticate_with_token('test', 'test') |
|
|
mock_user_service.assert_called_once() |
|
|
|
|
|
mock_user_token_service.assert_called_once() |
|
|
|
|
|
mock_authentication_service.assert_called_once() |
|
|
|
|
|
|
|
|
mock_find_by_name.assert_called_once() |
|
|
|
|
|
mock_find_by_user_and_token.assert_called_once() |
|
|
|
|
|
mock_is_valid_token.assert_called_once() |
|
|
mock_g.user.assert_not_called() |
|
|
mock_g.user.assert_not_called() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@patch(middleware_module + '.g') |
|
|
@patch(middleware_module + '.g') |
|
|
@patch(middleware_module + '.authentication_service.is_valid_token') |
|
|
|
|
|
|
|
|
@patch(middleware_module + '.user_token_service.is_valid_token') |
|
|
@patch(middleware_module + '.user_token_service.find_by_user_and_token') |
|
|
@patch(middleware_module + '.user_token_service.find_by_user_and_token') |
|
|
@patch(middleware_module + '.user_service.find_by_name') |
|
|
@patch(middleware_module + '.user_service.find_by_name') |
|
|
def test_authenticate_with_token_no_user( |
|
|
def test_authenticate_with_token_no_user( |
|
|
mock_user_service: MagicMock, |
|
|
|
|
|
mock_user_token_service: MagicMock, |
|
|
|
|
|
mock_authentication_service: MagicMock, |
|
|
|
|
|
|
|
|
mock_find_by_name: MagicMock, |
|
|
|
|
|
mock_find_by_user_and_token: MagicMock, |
|
|
|
|
|
mock_is_valid_token: MagicMock, |
|
|
mock_g: MagicMock): |
|
|
mock_g: MagicMock): |
|
|
mock_g.user = Mock() |
|
|
mock_g.user = Mock() |
|
|
mock_user_service.return_value = None |
|
|
|
|
|
|
|
|
mock_find_by_name.return_value = None |
|
|
assert not authenticate_with_token('test', 'test') |
|
|
assert not authenticate_with_token('test', 'test') |
|
|
mock_user_service.assert_called_once() |
|
|
|
|
|
mock_user_token_service.assert_not_called() |
|
|
|
|
|
mock_authentication_service.assert_not_called() |
|
|
|
|
|
|
|
|
mock_find_by_name.assert_called_once() |
|
|
|
|
|
mock_find_by_user_and_token.assert_not_called() |
|
|
|
|
|
mock_is_valid_token.assert_not_called() |
|
|
mock_g.user.assert_not_called() |
|
|
mock_g.user.assert_not_called() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@patch(middleware_module + '.g') |
|
|
@patch(middleware_module + '.g') |
|
|
@patch(middleware_module + '.authentication_service.is_valid_token') |
|
|
|
|
|
|
|
|
@patch(middleware_module + '.user_token_service.is_valid_token') |
|
|
@patch(middleware_module + '.user_token_service.find_by_user_and_token') |
|
|
@patch(middleware_module + '.user_token_service.find_by_user_and_token') |
|
|
@patch(middleware_module + '.user_service.find_by_name') |
|
|
@patch(middleware_module + '.user_service.find_by_name') |
|
|
def test_authenticate_with_token_no_user_token( |
|
|
def test_authenticate_with_token_no_user_token( |
|
|
mock_user_service: MagicMock, |
|
|
|
|
|
mock_user_token_service: MagicMock, |
|
|
|
|
|
mock_authentication_service: MagicMock, |
|
|
|
|
|
|
|
|
mock_find_by_name: MagicMock, |
|
|
|
|
|
mock_find_by_user_and_token: MagicMock, |
|
|
|
|
|
mock_is_valid_token: MagicMock, |
|
|
mock_g: MagicMock): |
|
|
mock_g: MagicMock): |
|
|
mock_g.user = Mock() |
|
|
mock_g.user = Mock() |
|
|
mock_user_service.return_value = Mock() |
|
|
|
|
|
mock_user_token_service.return_value = None |
|
|
|
|
|
mock_authentication_service.return_value = False |
|
|
|
|
|
|
|
|
mock_find_by_name.return_value = Mock() |
|
|
|
|
|
mock_find_by_user_and_token.return_value = None |
|
|
|
|
|
mock_is_valid_token.return_value = False |
|
|
assert not authenticate_with_token('test', 'test') |
|
|
assert not authenticate_with_token('test', 'test') |
|
|
mock_user_service.assert_called_once() |
|
|
|
|
|
mock_user_token_service.assert_called_once() |
|
|
|
|
|
mock_authentication_service.assert_called_once() |
|
|
|
|
|
|
|
|
mock_find_by_name.assert_called_once() |
|
|
|
|
|
mock_find_by_user_and_token.assert_called_once() |
|
|
|
|
|
mock_is_valid_token.assert_called_once() |
|
|
mock_g.user.assert_not_called() |
|
|
mock_g.user.assert_not_called() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@patch(middleware_module + '.g') |
|
|
@patch(middleware_module + '.g') |
|
|
@patch(middleware_module + '.authentication_service.is_valid_token') |
|
|
|
|
|
|
|
|
@patch(middleware_module + '.user_token_service.is_valid_token') |
|
|
@patch(middleware_module + '.user_token_service.find_by_user_and_token') |
|
|
@patch(middleware_module + '.user_token_service.find_by_user_and_token') |
|
|
@patch(middleware_module + '.user_service.find_by_name') |
|
|
@patch(middleware_module + '.user_service.find_by_name') |
|
|
def test_authenticate_with_token_invalid_token( |
|
|
def test_authenticate_with_token_invalid_token( |
|
|
mock_user_service: MagicMock, |
|
|
|
|
|
mock_user_token_service: MagicMock, |
|
|
|
|
|
mock_authentication_service: MagicMock, |
|
|
|
|
|
|
|
|
mock_find_by_name: MagicMock, |
|
|
|
|
|
mock_find_by_user_and_token: MagicMock, |
|
|
|
|
|
mock_is_valid_token: MagicMock, |
|
|
mock_g: MagicMock): |
|
|
mock_g: MagicMock): |
|
|
mock_g.user = Mock() |
|
|
mock_g.user = Mock() |
|
|
mock_user_service.return_value = Mock() |
|
|
|
|
|
mock_user_token_service.return_value = Mock() |
|
|
|
|
|
mock_authentication_service.return_value = False |
|
|
|
|
|
|
|
|
mock_find_by_name.return_value = Mock() |
|
|
|
|
|
mock_find_by_user_and_token.return_value = Mock() |
|
|
|
|
|
mock_is_valid_token.return_value = False |
|
|
assert not authenticate_with_token('test', 'test') |
|
|
assert not authenticate_with_token('test', 'test') |
|
|
mock_user_service.assert_called_once() |
|
|
|
|
|
mock_user_token_service.assert_called_once() |
|
|
|
|
|
mock_authentication_service.assert_called_once() |
|
|
|
|
|
|
|
|
mock_find_by_name.assert_called_once() |
|
|
|
|
|
mock_find_by_user_and_token.assert_called_once() |
|
|
|
|
|
mock_is_valid_token.assert_called_once() |
|
|
mock_g.user.assert_not_called() |
|
|
mock_g.user.assert_not_called() |