-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathchangePwd.spec.js
More file actions
70 lines (64 loc) · 2.19 KB
/
changePwd.spec.js
File metadata and controls
70 lines (64 loc) · 2.19 KB
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
/* eslint-env jest */
const { user } = require('../lib');
const { generateRandomString, ConnectionFactory } = require('./setup-database');
describe('changePwd()', () => {
let conn;
beforeEach(() => {
conn = ConnectionFactory();
conn.config({});
});
it('should fail trying to change a password (char[]) from an non-existent user', () =>
user.changePassword(conn, 'user', 'password', 'password').then(res => {
expect(res.status).toEqual(404);
}));
it('should allow a user to change a password with the current password', () => {
const username = generateRandomString();
const password = generateRandomString();
const newPassword = generateRandomString();
return user
.create(conn, { username, password })
.then(res => {
expect(res.status).toBe(201);
// Switch to new user
conn.config({ username, password });
return user.changePassword(conn, username, '', newPassword);
})
.then(res => {
expect(res.status).toEqual(400);
return user.changePassword(conn, username, newPassword, newPassword);
})
.then(res => {
expect(res.status).toEqual(403);
return user.changePassword(conn, username, password, newPassword);
})
.then(res => {
expect(res.status).toEqual(200);
// Switch to new user
conn.config({ username, password: newPassword });
return user.token(conn);
})
.then(res => {
expect(res.status).toEqual(200);
});
});
it('should allow a superuser to change the password without the current password', () => {
const username = generateRandomString();
const password = generateRandomString();
const newPassword = generateRandomString();
return user
.create(conn, { username, password })
.then(res => {
expect(res.status).toEqual(201);
return user.changePassword(conn, username, '', newPassword);
})
.then(res => {
expect(res.status).toEqual(200);
// Switch to new user
conn.config({ username, password: newPassword });
return user.token(conn);
})
.then(res => {
expect(res.status).toEqual(200);
});
});
});