1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
import pytest
from fxa.errors import ClientError
from api import *
class TestUnverified:
def test_status_unverified(self, unverified_account):
resp = unverified_account.get_a("/recovery_email/status")
assert resp == {
'email': unverified_account.email,
'emailVerified': False,
'sessionVerified': False,
'verified': False
}
@pytest.mark.parametrize("args,code,errno,error,message", [
({ 'uid': '00', 'code': "" },
400, 107, 'Bad Request', 'invalid parameter in request body'),
({ 'id': '00' * 16, 'code': 0 },
400, 107, 'Bad Request', 'invalid parameter in request body'),
({ 'id': '00' * 16, 'code': "", 'extra': 0 },
400, 107, 'Bad Request', 'invalid parameter in request body'),
])
def test_verify_code_invalid(self, unverified_account, args, code, errno, error, message):
with pytest.raises(ClientError) as e:
unverified_account.post_a("/recovery_email/verify_code", args)
assert e.value.details == {'code': code, 'errno': errno, 'error': error, 'message': message}
class TestVerified:
def test_status_noauth(self, client, refresh_token):
with pytest.raises(ClientError) as e:
client.post_a("/recovery_email/status")
assert e.value.details == {
'code': 401,
'errno': 109,
'error': 'Unauthorized',
'message': 'invalid request signature'
}
with pytest.raises(ClientError) as e:
refresh_token.post_a("/recovery_email/status")
assert e.value.details == {
'code': 401,
'errno': 109,
'error': 'Unauthorized',
'message': 'invalid request signature'
}
def test_status_verified(self, account):
resp = account.get_a("/recovery_email/status")
assert resp == {
'email': account.email,
'emailVerified': True,
'sessionVerified': True,
'verified': True
}
def test_verify_code(self, account):
# fixture does all the work
pass
def test_verify_code_reuse(client, mail_server):
s = client.create_account("test@test", "")
(to, body) = mail_server.wait()
assert to == ["test@test"]
data = json.loads(base64.urlsafe_b64decode(body.split("#/verify/", maxsplit=1)[1]).decode('utf8'))
s.post_a('/recovery_email/verify_code', { 'uid': data['uid'], 'code': data['code'] })
with pytest.raises(ClientError) as e:
s.post_a('/recovery_email/verify_code', { 'uid': data['uid'], 'code': data['code'] })
s.destroy_account("test@test", "")
assert e.value.details == {
'code': 400,
'errno': 105,
'error': 'Bad Request',
'message': 'invalid verification code'
}
def test_resend_code(client, mail_server):
s = client.create_account("test@test", "")
(to, body) = mail_server.wait()
assert to == ["test@test"]
data = json.loads(base64.urlsafe_b64decode(body.split("#/verify/", maxsplit=1)[1]).decode('utf8'))
s.post_a('/recovery_email/resend_code', {})
(to2, body2) = mail_server.wait()
assert to == to2
assert body == body2
s.post_a('/recovery_email/verify_code', { 'uid': data['uid'], 'code': data['code'] })
with pytest.raises(ClientError) as e:
s.post_a('/recovery_email/resend_code', {})
(to, body) = mail_server.wait()
assert to == ["test@test"]
data = json.loads(base64.urlsafe_b64decode(body.split("#/verify/", maxsplit=1)[1]).decode('utf8'))
s.destroy_account("test@test", "")
assert e.value.details == {
'code': 400,
'errno': 105,
'error': 'Bad Request',
'message': 'invalid verification code'
}
|