-
Notifications
You must be signed in to change notification settings - Fork 4
/
test.js
65 lines (59 loc) · 1.64 KB
/
test.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
var assert = require('assert');
describe("RedisAuth", function () {
var RedisAuth = require('./index');
var auth = RedisAuth({}, {});
describe("#adduser", function () {
it("adds users", function (done) {
auth.adduser('test', 'secret', function (err, user) {
assert.ifError(err);
assert.equal(user, 'test');
done();
});
});
});
describe("replace user", function () {
before(function (done) {
auth.adduser('test', 'secret', function (err, user) {
assert.ifError(err);
done();
});
});
it("replaces password", function (done) {
auth.adduser('test', 'new_secret', function (err, user) {
assert.ifError(err);
assert.equal(user, 'test');
auth.authenticate('test', 'new_secret', function (err, groups) {
assert.ifError(err);
done();
});
});
});
});
describe("#authenticate", function (done) {
before(function (done) {
auth.adduser('test', 'secret', function (err, user) {
assert.ifError(err);
done();
});
});
it("validates existing users", function (done) {
auth.authenticate('test', 'secret', function (err, groups) {
assert.ifError(err);
assert(groups);
done();
});
});
it("fails if wrong password", function (done) {
auth.authenticate('test', 'no-secret', function (err, groups) {
assert(err);
done();
});
});
it("fails if user doesnt exist", function (done) {
auth.authenticate('john', 'secret', function (err, groups) {
assert(err);
done();
});
});
});
});