forked from bnoguchi/everyauth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpassword.tobi.js
143 lines (129 loc) · 4.81 KB
/
password.tobi.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
var tobi = require('tobi')
, expect = require('expect.js')
require('./util/expect.js');
describe('password', function () {
var app, browser;
beforeEach( function () {
delete require.cache[require.resolve('./app')]
app = require('./app');
tobi.Browser.browsers = {};
var everyauth = require('../index');
everyauth.debug = false;
browser = tobi.createBrowser(3000, 'local.host');
browser.userAgent = 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.100 Safari/534.30';
});
afterEach( function () {
app.close();
});
describe('registration', function () {
it('should succeed if provided with a username and password', function (done) {
browser.get('/register', function (res, $) {
$('form')
.fill({ email: '[email protected]', password: 'pass' })
.submit( function (res, $) {
expect(res).to.have.status(200);
expect($('h2')).to.have.text('Authenticated');
expect($('h2')).to.not.have.text('Not Authenticated');
done();
});
});
});
describe('failing', function () {
it('should fail if no email, no password', function (done) {
browser.get('/register', function (res, $) {
$('form')
.fill({ email: '', password: '' })
.submit( function (res, $) {
expect(res).to.have.status(200);
expect($('#errors li:first')).to.have.text('Missing email');
expect($('#errors li:eq(1)')).to.have.text('Missing password');
done();
});
});
// TODO Add case of person trying to take an existing login
});
it('should fail with an invalid email, non-empty password', function (done) {
browser.get('/register', function (res, $) {
$('form')
.fill({ email: 'newuser', password: 'pass' })
.submit( function (res, $) {
expect(res).to.have.status(200);
expect($('#errors')).to.have.text('Please correct your email.');
done();
});
});
});
it('should fail with an invalid email, no password', function (done) {
browser.get('/register', function (res, $) {
$('form')
.fill({ email: 'newuser', password: '' })
.submit( function (res, $) {
expect(res).to.have.status(200);
expect($('#errors li:first')).to.have.text('Please correct your email.');
expect($('#errors li:eq(1)')).to.have.text('Missing password');
done();
});
});
});
it('should fail with a valid email, no password', function (done) {
browser.get('/register', function (res, $) {
$('form')
.fill({ email: '[email protected]', password: '' })
.submit( function (res, $) {
expect(res).to.have.status(200);
expect($('#errors')).to.have.text('Missing password');
done();
});
});
});
});
});
describe('login', function () {
it('should succeed with the right email + password', function (done) {
browser.get('/login', function (res, $) {
$('form')
.fill({ email: '[email protected]', password: 'password' })
.submit( function (res, $) {
expect(res).to.have.status(200);
expect($('h2')).to.have.text('Authenticated');
expect($('h2')).to.not.have.text('Not Authenticated');
done();
});
});
});
describe('failing', function () {
it('should fail with the wrong password', function (done) {
browser.get('/login', function (res, $) {
$('form')
.fill({ email: '[email protected]', password: 'wrongpassword' })
.submit( function (res, $) {
expect(res).to.have.status(200);
expect($('#errors')).to.have.text('Login failed');
done();
});
});
});
it('should fail with an empty password', function (done) {
browser.get('/login', function (res, $) {
$('form')
.fill({ email: '[email protected]', password: '' })
.submit( function (res, $) {
expect($('#errors')).to.have.text('Missing password');
done();
});
});
});
it('should fail with no email, no password', function (done) {
browser.get('/login', function (res, $) {
$('form')
.fill({ email: '', password: '' })
.submit( function (res, $) {
expect($('#errors li:first')).to.have.text('Missing login');
expect($('#errors li:eq(1)')).to.have.text('Missing password');
done();
});
});
});
});
});
});