2014-02-03 15:55:09 -05:00
|
|
|
require '../common'
|
2014-02-02 18:02:47 -05:00
|
|
|
request = require 'request'
|
2014-04-22 22:27:39 -04:00
|
|
|
User = require '../../../server/users/User'
|
2014-02-02 18:02:47 -05:00
|
|
|
|
|
|
|
urlLogin = getURL('/auth/login')
|
|
|
|
urlReset = getURL('/auth/reset')
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
describe '/auth/whoami', ->
|
|
|
|
it 'returns 200', (done) ->
|
2014-06-11 16:21:11 -04:00
|
|
|
request.get(getURL('/auth/whoami'), (err, response) ->
|
2014-01-03 13:32:13 -05:00
|
|
|
expect(response).toBeDefined()
|
|
|
|
expect(response.statusCode).toBe(200)
|
|
|
|
done()
|
|
|
|
)
|
|
|
|
|
|
|
|
describe '/auth/login', ->
|
|
|
|
|
|
|
|
it 'clears Users first', (done) ->
|
2014-04-23 12:19:07 -04:00
|
|
|
clearModels [User], (err) ->
|
|
|
|
throw err if err
|
2014-02-24 23:27:38 -05:00
|
|
|
request.get getURL('/auth/whoami'), ->
|
|
|
|
throw err if err
|
|
|
|
done()
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
it 'finds no user', (done) ->
|
2014-02-02 18:02:47 -05:00
|
|
|
req = request.post(urlLogin, (error, response) ->
|
2014-01-03 13:32:13 -05:00
|
|
|
expect(response).toBeDefined()
|
|
|
|
expect(response.statusCode).toBe(401)
|
|
|
|
done()
|
|
|
|
)
|
|
|
|
form = req.form()
|
|
|
|
form.append('username', 'scott@gmail.com')
|
|
|
|
form.append('password', 'nada')
|
|
|
|
|
|
|
|
it 'creates a user', (done) ->
|
|
|
|
req = request.post(getURL('/db/user'),
|
|
|
|
(error, response) ->
|
|
|
|
expect(response).toBeDefined()
|
|
|
|
expect(response.statusCode).toBe(200)
|
|
|
|
done()
|
|
|
|
)
|
|
|
|
form = req.form()
|
|
|
|
form.append('email', 'scott@gmail.com')
|
|
|
|
form.append('password', 'nada')
|
|
|
|
|
|
|
|
it 'finds that created user', (done) ->
|
2014-02-02 18:02:47 -05:00
|
|
|
req = request.post(urlLogin, (error, response) ->
|
2014-01-03 13:32:13 -05:00
|
|
|
expect(response).toBeDefined()
|
|
|
|
expect(response.statusCode).toBe(200)
|
|
|
|
done()
|
|
|
|
)
|
|
|
|
form = req.form()
|
|
|
|
form.append('username', 'scott@gmail.com')
|
|
|
|
form.append('password', 'nada')
|
|
|
|
|
|
|
|
it 'rejects wrong passwords', (done) ->
|
2014-02-02 18:02:47 -05:00
|
|
|
req = request.post(urlLogin, (error, response) ->
|
2014-01-03 13:32:13 -05:00
|
|
|
expect(response.statusCode).toBe(401)
|
2014-04-08 17:10:50 -04:00
|
|
|
expect(response.body.indexOf("wrong")).toBeGreaterThan(-1)
|
2014-01-03 13:32:13 -05:00
|
|
|
done()
|
|
|
|
)
|
|
|
|
form = req.form()
|
|
|
|
form.append('username', 'scott@gmail.com')
|
|
|
|
form.append('password', 'blahblah')
|
|
|
|
|
|
|
|
it 'is completely case insensitive', (done) ->
|
2014-02-02 18:02:47 -05:00
|
|
|
req = request.post(urlLogin, (error, response) ->
|
2014-01-03 13:32:13 -05:00
|
|
|
expect(response.statusCode).toBe(200)
|
|
|
|
done()
|
|
|
|
)
|
|
|
|
form = req.form()
|
|
|
|
form.append('username', 'scoTT@gmaIL.com')
|
2014-02-02 18:02:47 -05:00
|
|
|
form.append('password', 'NaDa')
|
|
|
|
|
|
|
|
|
|
|
|
describe '/auth/reset', ->
|
|
|
|
passwordReset = ''
|
|
|
|
|
|
|
|
it 'emails require', (done) ->
|
|
|
|
req = request.post(urlReset, (error, response) ->
|
|
|
|
expect(response).toBeDefined()
|
|
|
|
expect(response.statusCode).toBe(422)
|
|
|
|
done()
|
|
|
|
)
|
|
|
|
form = req.form()
|
|
|
|
form.append('username', 'scott@gmail.com')
|
|
|
|
|
|
|
|
it 'can\'t reset an unknow user', (done) ->
|
|
|
|
req = request.post(urlReset, (error, response) ->
|
|
|
|
expect(response).toBeDefined()
|
|
|
|
expect(response.statusCode).toBe(404)
|
|
|
|
done()
|
|
|
|
)
|
|
|
|
form = req.form()
|
|
|
|
form.append('email', 'unknow')
|
|
|
|
|
2014-02-24 23:27:38 -05:00
|
|
|
it 'resets user password', (done) ->
|
2014-02-02 18:02:47 -05:00
|
|
|
req = request.post(urlReset, (error, response) ->
|
|
|
|
expect(response).toBeDefined()
|
|
|
|
expect(response.statusCode).toBe(200)
|
|
|
|
expect(response.body).toBeDefined()
|
|
|
|
passwordReset = response.body
|
|
|
|
done()
|
|
|
|
)
|
|
|
|
form = req.form()
|
|
|
|
form.append('email', 'scott@gmail.com')
|
|
|
|
|
|
|
|
it 'can login after resetting', (done) ->
|
|
|
|
req = request.post(urlLogin, (error, response) ->
|
|
|
|
expect(response).toBeDefined()
|
|
|
|
expect(response.statusCode).toBe(200)
|
|
|
|
done()
|
|
|
|
)
|
|
|
|
form = req.form()
|
|
|
|
form.append('username', 'scott@gmail.com')
|
|
|
|
form.append('password', passwordReset)
|
|
|
|
|
|
|
|
it 'resetting password is not permanent', (done) ->
|
|
|
|
req = request.post(urlLogin, (error, response) ->
|
|
|
|
expect(response).toBeDefined()
|
|
|
|
expect(response.statusCode).toBe(401)
|
|
|
|
done()
|
|
|
|
)
|
|
|
|
form = req.form()
|
|
|
|
form.append('username', 'scott@gmail.com')
|
|
|
|
form.append('password', passwordReset)
|
|
|
|
|
|
|
|
|
|
|
|
it 'can still login with old password', (done) ->
|
|
|
|
req = request.post(urlLogin, (error, response) ->
|
|
|
|
expect(response).toBeDefined()
|
|
|
|
expect(response.statusCode).toBe(200)
|
|
|
|
done()
|
|
|
|
)
|
|
|
|
form = req.form()
|
|
|
|
form.append('username', 'scott@gmail.com')
|
|
|
|
form.append('password', 'nada')
|
2014-04-22 22:27:39 -04:00
|
|
|
|
|
|
|
describe '/auth/unsubscribe', ->
|
2014-04-23 12:19:07 -04:00
|
|
|
it 'clears Users first', (done) ->
|
|
|
|
clearModels [User], (err) ->
|
|
|
|
throw err if err
|
|
|
|
request.get getURL('/auth/whoami'), ->
|
|
|
|
throw err if err
|
|
|
|
done()
|
2014-04-22 22:27:39 -04:00
|
|
|
|
|
|
|
it 'removes just recruitment emails if you include ?recruitNotes=1', (done) ->
|
|
|
|
loginJoe (joe) ->
|
|
|
|
url = getURL('/auth/unsubscribe?recruitNotes=1&email='+joe.get('email'))
|
|
|
|
request.get url, (error, response) ->
|
|
|
|
expect(response.statusCode).toBe(200)
|
|
|
|
user = User.findOne(joe.get('_id')).exec (err, user) ->
|
|
|
|
expect(user.get('emails').recruitNotes.enabled).toBe(false)
|
2014-04-23 12:53:46 -04:00
|
|
|
expect(user.isEmailSubscriptionEnabled('generalNews')).toBeTruthy()
|
2014-04-22 22:27:39 -04:00
|
|
|
done()
|