Skip to content

Commit 578c0a9

Browse files
committed
Tests for resend confirm email
1 parent 55682a7 commit 578c0a9

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

src/tests/test_admin.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ def test_admin(client, database):
8989
assert b'was reset' in result.data
9090

9191
# Test manual user verification
92+
result = client.post('/admin/verify', follow_redirects=True)
93+
assert b'Must provide user ID' in result.data
94+
result = client.post('/admin/verify', data={'user_id': 5}, follow_redirects=True)
95+
assert b'exist' in result.data
9296
result = client.post('/admin/verify', data={'user_id': 2}, follow_redirects=True)
9397
assert b'already verified' in result.data
9498
database.execute("UPDATE users SET verified=0 WHERE id=2")

src/tests/test_register.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,83 @@ def test_register(client, database):
138138

139139
result = client.get(f'/cancelregister/{token}', follow_redirects=True)
140140
assert b'invalid' in result.data
141+
142+
# Test resending registration email
143+
# Manually generate token to check
144+
exp = datetime.utcnow() - timedelta(seconds=1800)
145+
token = jwt.encode(
146+
{
147+
'username': 'bob',
148+
'expiration': exp.isoformat()
149+
},
150+
'testing_secret_key',
151+
algorithm='HS256'
152+
)
153+
154+
result = client.post('/auth/resend_registration_confirmation', data={
155+
'token': token
156+
}, follow_redirects=True)
157+
assert b'expired' in result.data
158+
159+
result = client.post('/auth/resend_registration_confirmation', data={
160+
'token': 'abc'
161+
}, follow_redirects=True)
162+
assert b'Invalid' in result.data
163+
164+
exp = datetime.utcnow() + timedelta(seconds=1800)
165+
token = jwt.encode(
166+
{
167+
'username': 'bob',
168+
'expiration': exp.isoformat()
169+
},
170+
'testing_secret_key',
171+
algorithm='HS256'
172+
)
173+
174+
result = client.post('/auth/resend_registration_confirmation', data={
175+
'token': token
176+
}, follow_redirects=True)
177+
assert b'doesn\'t exist' in result.data
178+
179+
token = jwt.encode(
180+
{
181+
'username': 'testing',
182+
'expiration': exp.isoformat()
183+
},
184+
'testing_secret_key',
185+
algorithm='HS256'
186+
)
187+
result = client.post('/auth/resend_registration_confirmation', data={
188+
'token': token
189+
})
190+
assert result.data == b'/login'
191+
assert result.status_code == 302
192+
193+
result = client.post('/register', data={
194+
'username': 'unverified',
195+
'password': 'unverified',
196+
'confirmation': 'unverified',
197+
'email': '[email protected]'
198+
}, follow_redirects=True)
199+
assert result.status_code == 200
200+
assert b'Resend' in result.data
201+
token = jwt.encode(
202+
{
203+
'username': 'unverified',
204+
'expiration': exp.isoformat()
205+
},
206+
'testing_secret_key',
207+
algorithm='HS256'
208+
)
209+
result = client.post('/auth/resend_registration_confirmation', data={
210+
'token': token
211+
})
212+
assert result.data == b'OK'
213+
result = client.post('/auth/resend_registration_confirmation', data={
214+
'token': token
215+
})
216+
assert result.data == b'OK'
217+
result = client.post('/auth/resend_registration_confirmation', data={
218+
'token': token
219+
})
220+
assert b'too many times' in result.data

0 commit comments

Comments
 (0)