diff options
Diffstat (limited to 'tests/test_auth_password.py')
-rw-r--r-- | tests/test_auth_password.py | 189 |
1 files changed, 93 insertions, 96 deletions
diff --git a/tests/test_auth_password.py b/tests/test_auth_password.py index 7c2064a..fc7bb2b 100644 --- a/tests/test_auth_password.py +++ b/tests/test_auth_password.py @@ -4,38 +4,81 @@ from fxa.errors import ClientError from api import * -@pytest.mark.parametrize("args", [ - { 'email': "", 'oldAuthPW': '00' * 32 }, - { 'email': "test0@test", 'oldAuthPW': '00' }, - { 'email': "test0@test", 'oldAuthPW': '00' * 32, 'extra': 0 }, -]) -def test_change_start_invalid(account, args): - with pytest.raises(ClientError) as e: - account.post_a("/password/change/start", args) - assert e.value.details == { - 'code': 400, - 'errno': 107, - 'error': 'Bad Request', - 'message': 'invalid parameter in request body' - } - -def test_change_start_badaccount(account): - with pytest.raises(ClientError) as e: - account.post_a("/password/change/start", { 'email': "test0@test", 'oldAuthPW': '00' * 32 }) - assert e.value.details == { - 'code': 400, - 'errno': 102, - 'error': 'Bad Request', - 'message': 'unknown account' - } - with pytest.raises(ClientError) as e: - account.post_a("/password/change/start", { 'email': account.email.upper(), 'oldAuthPW': '00' * 32 }) - assert e.value.details == { - 'code': 400, - 'errno': 120, - 'error': 'Bad Request', - 'message': 'incorrect email case' - } +class TestPasswordInvalid: + @pytest.mark.parametrize("args", [ + { 'email': "", 'oldAuthPW': '00' * 32 }, + { 'email': "test0@test", 'oldAuthPW': '00' }, + { 'email': "test0@test", 'oldAuthPW': '00' * 32, 'extra': 0 }, + ]) + def test_change_start_invalid(self, account, args): + with pytest.raises(ClientError) as e: + account.post_a("/password/change/start", args) + assert e.value.details == { + 'code': 400, + 'errno': 107, + 'error': 'Bad Request', + 'message': 'invalid parameter in request body' + } + + def test_change_start_badaccount(self, account): + with pytest.raises(ClientError) as e: + account.post_a("/password/change/start", { 'email': "test0@test", 'oldAuthPW': '00' * 32 }) + assert e.value.details == { + 'code': 400, + 'errno': 102, + 'error': 'Bad Request', + 'message': 'unknown account' + } + with pytest.raises(ClientError) as e: + account.post_a("/password/change/start", { 'email': account.email.upper(), 'oldAuthPW': '00' * 32 }) + assert e.value.details == { + 'code': 400, + 'errno': 120, + 'error': 'Bad Request', + 'message': 'incorrect email case' + } + + def test_change_start_badpw(self, account): + with pytest.raises(ClientError) as e: + account.post_a("/password/change/start", { 'email': account.email, 'oldAuthPW': '00' * 32 }) + assert e.value.details == { + 'code': 400, + 'errno': 103, + 'error': 'Bad Request', + 'message': 'incorrect password' + } + + @pytest.mark.parametrize("args", [ + { 'email': "" }, + { 'email': "test0@test", 'extra': 0 }, + ]) + def test_forgot_start_invalid(self, account, args): + with pytest.raises(ClientError) as e: + account.post_a("/password/forgot/send_code", args) + assert e.value.details == { + 'code': 400, + 'errno': 107, + 'error': 'Bad Request', + 'message': 'invalid parameter in request body' + } + + def test_change_forgot_badaccount(self, account): + with pytest.raises(ClientError) as e: + account.post_a("/password/forgot/send_code", { 'email': "test0@test" }) + assert e.value.details == { + 'code': 400, + 'errno': 102, + 'error': 'Bad Request', + 'message': 'unknown account' + } + with pytest.raises(ClientError) as e: + account.post_a("/password/forgot/send_code", { 'email': account.email.upper() }) + assert e.value.details == { + 'code': 400, + 'errno': 120, + 'error': 'Bad Request', + 'message': 'incorrect email case' + } def test_change_start_unverified(unverified_account): with pytest.raises(ClientError) as e: @@ -50,16 +93,6 @@ def test_change_start_unverified(unverified_account): 'message': 'unverified account' } -def test_change_start_badpw(account): - with pytest.raises(ClientError) as e: - account.post_a("/password/change/start", { 'email': account.email, 'oldAuthPW': '00' * 32 }) - assert e.value.details == { - 'code': 400, - 'errno': 103, - 'error': 'Bad Request', - 'message': 'incorrect password' - } - @pytest.fixture def change_token(account): pw = auth_pw(account.email, "") @@ -67,20 +100,21 @@ def change_token(account): assert 'keyFetchToken' in resp return PasswordChange(account.client, resp['passwordChangeToken']) -@pytest.mark.parametrize("args", [ - { 'authPW': '00', 'wrapKb': '00' * 32, 'sessionToken': '00' * 32, }, - { 'authPW': '00' * 32, 'wrapKb': '00', 'sessionToken': '00' * 32, }, - { 'authPW': '00' * 32, 'wrapKb': '00' * 32, 'sessionToken': '00', }, -]) -def test_change_finish_invalid(change_token, args): - with pytest.raises(ClientError) as e: - change_token.post_a("/password/change/finish", args) - assert e.value.details == { - 'code': 400, - 'errno': 107, - 'error': 'Bad Request', - 'message': 'invalid parameter in request body' - } +class TestChangeInvalid: + @pytest.mark.parametrize("args", [ + { 'authPW': '00', 'wrapKb': '00' * 32, 'sessionToken': '00' * 32, }, + { 'authPW': '00' * 32, 'wrapKb': '00', 'sessionToken': '00' * 32, }, + { 'authPW': '00' * 32, 'wrapKb': '00' * 32, 'sessionToken': '00', }, + ]) + def test_change_finish_invalid(self, change_token, args): + with pytest.raises(ClientError) as e: + change_token.post_a("/password/change/finish", args) + assert e.value.details == { + 'code': 400, + 'errno': 107, + 'error': 'Bad Request', + 'message': 'invalid parameter in request body' + } def test_change_finish(account, change_token, mail_server): pw = auth_pw(account.email, "new") @@ -124,38 +158,6 @@ def test_change_finish_twice(account, change_token, mail_server): 'message': 'invalid request signature' } -@pytest.mark.parametrize("args", [ - { 'email': "" }, - { 'email': "test0@test", 'extra': 0 }, -]) -def test_forgot_start_invalid(account, args): - with pytest.raises(ClientError) as e: - account.post_a("/password/forgot/send_code", args) - assert e.value.details == { - 'code': 400, - 'errno': 107, - 'error': 'Bad Request', - 'message': 'invalid parameter in request body' - } - -def test_change_forgot_badaccount(account): - with pytest.raises(ClientError) as e: - account.post_a("/password/forgot/send_code", { 'email': "test0@test" }) - assert e.value.details == { - 'code': 400, - 'errno': 102, - 'error': 'Bad Request', - 'message': 'unknown account' - } - with pytest.raises(ClientError) as e: - account.post_a("/password/forgot/send_code", { 'email': account.email.upper() }) - assert e.value.details == { - 'code': 400, - 'errno': 120, - 'error': 'Bad Request', - 'message': 'incorrect email case' - } - def test_change_forgot_unverified(unverified_account): with pytest.raises(ClientError) as e: unverified_account.post_a("/password/forgot/send_code", { 'email': unverified_account.email }) @@ -180,8 +182,6 @@ def test_forgot_finish_invalid(change_token, args): } def test_forgot_finish_badcode(account, forgot_token, mail_server): - (to, body) = mail_server.wait() - assert account.email in to with pytest.raises(ClientError) as e: resp = forgot_token.post_a("/password/forgot/verify_code", { 'code': '' }) assert e.value.details == { @@ -192,17 +192,14 @@ def test_forgot_finish_badcode(account, forgot_token, mail_server): } def test_forgot_finish(account, forgot_token, mail_server): - (to, body) = mail_server.wait() - assert account.email in to - resp = forgot_token.post_a("/password/forgot/verify_code", { 'code': body.strip() }) + resp = forgot_token.post_a("/password/forgot/verify_code", { 'code': forgot_token.code }) assert 'accountResetToken' in resp def test_forgot_finish_twice(account, forgot_token, mail_server): - (to, body) = mail_server.wait() - forgot_token.post_a("/password/forgot/verify_code", { 'code': body.strip() }) + forgot_token.post_a("/password/forgot/verify_code", { 'code': forgot_token.code }) with pytest.raises(ClientError) as e: - forgot_token.post_a("/password/forgot/verify_code", { 'code': body.strip() }) + forgot_token.post_a("/password/forgot/verify_code", { 'code': forgot_token.code }) assert e.value.details == { 'code': 401, 'errno': 109, |