diff options
author | Tulio Casagrande <tcasagra@thoughtworks.com> | 2017-04-05 17:58:32 -0300 |
---|---|---|
committer | Tulio Casagrande <tcasagra@thoughtworks.com> | 2017-04-05 18:00:52 -0300 |
commit | af941920c84b1b1ee5f630993eba0d2d3699aa61 (patch) | |
tree | 2a829d4ba4c570966e4de660ff51f9b1e2cbb5dd /service/test/unit/resources | |
parent | a96ed27ff6fa99132c16860fc908156aa2b44134 (diff) |
[#934] Add back-end password validation
Diffstat (limited to 'service/test/unit/resources')
-rw-r--r-- | service/test/unit/resources/test_account_recovery_resource.py | 43 |
1 files changed, 40 insertions, 3 deletions
diff --git a/service/test/unit/resources/test_account_recovery_resource.py b/service/test/unit/resources/test_account_recovery_resource.py index cd9acae7..bdae15b6 100644 --- a/service/test/unit/resources/test_account_recovery_resource.py +++ b/service/test/unit/resources/test_account_recovery_resource.py @@ -14,14 +14,12 @@ # You should have received a copy of the GNU Affero General Public License # along with Pixelated. If not, see <http://www.gnu.org/licenses/>. -import os - from mock import MagicMock from twisted.trial import unittest from twisted.web.test.requesthelper import DummyRequest from twisted.internet import defer -from pixelated.resources.account_recovery_resource import AccountRecoveryResource +from pixelated.resources.account_recovery_resource import AccountRecoveryResource, InvalidPasswordError from test.unit.resources import DummySite @@ -46,6 +44,8 @@ class TestAccountRecoveryResource(unittest.TestCase): def test_post_returns_successfully(self): request = DummyRequest(['/account-recovery']) request.method = 'POST' + request.content = MagicMock() + request.content.getvalue.return_value = '{"password": "12345678", "confirmPassword": "12345678"}' d = self.web.get(request) def assert_successful_response(_): @@ -53,3 +53,40 @@ class TestAccountRecoveryResource(unittest.TestCase): d.addCallback(assert_successful_response) return d + + def test_get_post_form(self): + request = MagicMock() + request.content.getvalue.return_value = '{"userCode": "abc", "password": "123", "confirmPassword": "456"}' + form = self.resource._get_post_form(request) + + self.assertEqual(form.get('userCode'), 'abc') + self.assertEqual(form.get('password'), '123') + self.assertEqual(form.get('confirmPassword'), '456') + + def test_validate_password_successfully(self): + request = MagicMock() + request.content.getvalue.return_value = '{"password": "12345678", "confirmPassword": "12345678"}' + + d = self.resource._validate_password(request) + + def assert_successful(success): + self.assertEqual(success, 'Done!') + + d.addCallback(assert_successful) + return d + + @defer.inlineCallbacks + def test_validate_password_failed_by_confirmation(self): + request = MagicMock() + request.content.getvalue.return_value = '{"password": "12345678", "confirmPassword": "1234"}' + + with self.assertRaises(InvalidPasswordError): + yield self.resource._validate_password(request) + + @defer.inlineCallbacks + def test_validate_password_failed_by_length(self): + request = MagicMock() + request.content.getvalue.return_value = '{"password": "1234", "confirmPassword": "1234"}' + + with self.assertRaises(InvalidPasswordError): + yield self.resource._validate_password(request) |