Skip to content

Commit

Permalink
Tests for resend confirm email
Browse files Browse the repository at this point in the history
  • Loading branch information
jdabtieu committed May 24, 2024
1 parent 55682a7 commit 578c0a9
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ def test_admin(client, database):
assert b'was reset' in result.data

# Test manual user verification
result = client.post('/admin/verify', follow_redirects=True)
assert b'Must provide user ID' in result.data
result = client.post('/admin/verify', data={'user_id': 5}, follow_redirects=True)
assert b'exist' in result.data
result = client.post('/admin/verify', data={'user_id': 2}, follow_redirects=True)
assert b'already verified' in result.data
database.execute("UPDATE users SET verified=0 WHERE id=2")
Expand Down
80 changes: 80 additions & 0 deletions src/tests/test_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,83 @@ def test_register(client, database):

result = client.get(f'/cancelregister/{token}', follow_redirects=True)
assert b'invalid' in result.data

# Test resending registration email
# Manually generate token to check
exp = datetime.utcnow() - timedelta(seconds=1800)
token = jwt.encode(
{
'username': 'bob',
'expiration': exp.isoformat()
},
'testing_secret_key',
algorithm='HS256'
)

result = client.post('/auth/resend_registration_confirmation', data={
'token': token
}, follow_redirects=True)
assert b'expired' in result.data

result = client.post('/auth/resend_registration_confirmation', data={
'token': 'abc'
}, follow_redirects=True)
assert b'Invalid' in result.data

exp = datetime.utcnow() + timedelta(seconds=1800)
token = jwt.encode(
{
'username': 'bob',
'expiration': exp.isoformat()
},
'testing_secret_key',
algorithm='HS256'
)

result = client.post('/auth/resend_registration_confirmation', data={
'token': token
}, follow_redirects=True)
assert b'doesn\'t exist' in result.data

token = jwt.encode(
{
'username': 'testing',
'expiration': exp.isoformat()
},
'testing_secret_key',
algorithm='HS256'
)
result = client.post('/auth/resend_registration_confirmation', data={
'token': token
})
assert result.data == b'/login'
assert result.status_code == 302

result = client.post('/register', data={
'username': 'unverified',
'password': 'unverified',
'confirmation': 'unverified',
'email': '[email protected]'
}, follow_redirects=True)
assert result.status_code == 200
assert b'Resend' in result.data
token = jwt.encode(
{
'username': 'unverified',
'expiration': exp.isoformat()
},
'testing_secret_key',
algorithm='HS256'
)
result = client.post('/auth/resend_registration_confirmation', data={
'token': token
})
assert result.data == b'OK'
result = client.post('/auth/resend_registration_confirmation', data={
'token': token
})
assert result.data == b'OK'
result = client.post('/auth/resend_registration_confirmation', data={
'token': token
})
assert b'too many times' in result.data

Check warning on line 220 in src/tests/test_register.py

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

W292 no newline at end of file

Check warning on line 220 in src/tests/test_register.py

View workflow job for this annotation

GitHub Actions / build (windows-latest)

W292 no newline at end of file

0 comments on commit 578c0a9

Please sign in to comment.