@@ -138,3 +138,83 @@ def test_register(client, database):
138
138
139
139
result = client .get (f'/cancelregister/{ token } ' , follow_redirects = True )
140
140
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
+
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