diff options
author | Tulio Casagrande <tcasagra@thoughtworks.com> | 2017-02-20 14:37:37 -0300 |
---|---|---|
committer | Tulio Casagrande <tcasagra@thoughtworks.com> | 2017-02-21 13:32:05 -0300 |
commit | fa21608801f8d2ef710d4c28abbb558883afeaf7 (patch) | |
tree | 009db4bb064b077a231a1abe4de212bceb20928b /service/test | |
parent | bfd85dff6b086abae1c16014e318c89cba929b66 (diff) |
[#907] Translate auth error message on login
with @anikarni
Diffstat (limited to 'service/test')
-rw-r--r-- | service/test/integration/test_multi_user_login.py | 9 | ||||
-rw-r--r-- | service/test/unit/resources/test_login_resource.py | 15 |
2 files changed, 12 insertions, 12 deletions
diff --git a/service/test/integration/test_multi_user_login.py b/service/test/integration/test_multi_user_login.py index fe456583..b04a4e9e 100644 --- a/service/test/integration/test_multi_user_login.py +++ b/service/test/integration/test_multi_user_login.py @@ -13,7 +13,6 @@ # # You should have received a copy of the GNU Affero General Public License # along with Pixelated. If not, see <http://www.gnu.org/licenses/>. -from mock import patch from twisted.internet import defer @@ -47,8 +46,8 @@ class MultiUserLoginTest(MultiUserSoledadTestBase): self.assertEquals(val, response[key]) @defer.inlineCallbacks - def test_wrong_credentials_cannot_access_resources(self): + def test_wrong_credentials_is_redirected_to_login(self): response, login_request = self.app_test_client.login('username', 'wrong_password') - response_str = yield response - self.assertEqual(401, login_request.responseCode) - self.assertIn('Invalid username or password', login_request.written) + yield response + self.assertEqual(302, login_request.responseCode) + self.assertIn('/login?auth-error', login_request.uri) diff --git a/service/test/unit/resources/test_login_resource.py b/service/test/unit/resources/test_login_resource.py index bd0f9122..733583a3 100644 --- a/service/test/unit/resources/test_login_resource.py +++ b/service/test/unit/resources/test_login_resource.py @@ -203,22 +203,23 @@ class TestLoginPOST(unittest.TestCase): return d @patch('pixelated.config.leap.BootstrapUserServices.setup') + @patch('twisted.web.util.redirectTo') @patch('pixelated.authentication.Authenticator.authenticate') - def test_should_return_form_back_with_error_message_when_login_fails(self, mock_authenticate, - mock_user_bootstrap_setup): + def test_should_redirect_to_login_with_error_flag_when_login_fails(self, mock_authenticate, + mock_redirect, + mock_user_bootstrap_setup): mock_authenticate.side_effect = UnauthorizedLogin() + mock_redirect.return_value = "mocked redirection" d = self.web.get(self.request) - def assert_error_response_and_user_services_not_setup(_): + def assert_redirected_to_login(_): mock_authenticate.assert_called_once_with(self.username, self.password) - self.assertEqual(401, self.request.responseCode) - written_response = ''.join(self.request.written) - self.assertIn('Invalid username or password', written_response) + mock_redirect.assert_called_once_with('/login?auth-error', self.request) self.assertFalse(mock_user_bootstrap_setup.called) self.assertFalse(self.resource.get_session(self.request).is_logged_in()) - d.addCallback(assert_error_response_and_user_services_not_setup) + d.addCallback(assert_redirected_to_login) return d @patch('pixelated.config.leap.BootstrapUserServices.setup') |