#68 Added some forgot password tests

master
Keith Irwin 2018-01-21 01:41:59 +00:00
parent a3957264c0
commit b06e72f40c
No known key found for this signature in database
GPG Key ID: 378933C743E2BBC0
2 changed files with 25 additions and 6 deletions

View File

@ -246,6 +246,7 @@ module.exports = (app, passport) => {
app.route('/login/forgot')
// Check if user is already logged in
// TODO: Write test for this situation
.all((req, res, next) => {
if (req.isAuthenticated()) loginCallback(req, res)
else next()
@ -264,6 +265,7 @@ module.exports = (app, passport) => {
// Check if somebody has that email
User.findOne({'email': req.body.email})
.then((user) => {
// No user with that email
if (!user) {
// Don't let on that no such user exists, to prevent dictionary attacks

View File

@ -161,15 +161,32 @@ describe('Authentication', () => {
})
// TODO: Create test for forgetten password
// it('Forgets password', async () => {
it('Loads forgot password page', async () => {
let res = await request.get('/login/forgot')
chai.expect(res).html.to.have.status(200)
})
// })
// TODO: Test already-logged-in forgot password requests
// TODO: Create test for changing forgetten password
// it('Changes forgotten password', async () => {
// TODO: Test invalid and fuzzed forgot password requests
// })
it('Sends valid forgot password request', async () => {
// Responds with 200
let res = await request.post('/login/forgot')
.type('form').send({
email: TEST_EMAIL,
})
chai.expect(res).html.to.have.status(200)
// Assert password was set
})
//it('Changes forgotten password', async () => {
// TODO: Create test for changing forgetten password
//})
// Finally log in successfully
after( () => {