forked from openiap/opencore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAuth.test.ts
More file actions
53 lines (51 loc) · 2.32 KB
/
Copy pathAuth.test.ts
File metadata and controls
53 lines (51 loc) · 2.32 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
var wtf = require('wtfnode');
const path = require("path");
const env = path.join(process.cwd(), 'config', '.env');
require("dotenv").config({ path: env }); // , debug: false
import { suite, test, timeout } from '@testdeck/mocha';
import { Message } from "../OpenFlow/src/Messages/Message";
import { Config } from "../OpenFlow/src/Config";
import { DatabaseConnection } from '../OpenFlow/src/DatabaseConnection';
import assert = require('assert');
import { Logger } from '../OpenFlow/src/Logger';
import { Auth } from '../OpenFlow/src/Auth';
import { NoderedUtil, SigninMessage } from '@openiap/openflow-api';
@suite class auth_test {
@timeout(10000)
async before() {
Config.workitem_queue_monitoring_enabled = false;
Config.disablelogging();
Logger.configure(true, true);
Config.db = new DatabaseConnection(Config.mongodb_url, Config.mongodb_db, false);
await Config.db.connect(null);
}
async after() {
await Logger.shutdown();
// wtf.dump()
}
@test async 'ValidateByPassword'() {
await assert.rejects(async () => {
await Auth.ValidateByPassword("testuser", null, null);
}, "Did not fail on null password")
await assert.rejects(async () => {
await Auth.ValidateByPassword(null, "testuser", null);
}, "Did not fail on null username")
var user1 = await Auth.ValidateByPassword("testuser", "testuser", null);
assert.notStrictEqual(user1, null, "Failed validating valid username and password")
assert.strictEqual(user1.username, "testuser", "returned user has wrong username")
var user2 = await Auth.ValidateByPassword("testuser", "not-my-password", null);
assert.strictEqual(user2, null, "Did not fail on wrong password")
}
@test async 'test full login'() {
var q: any = new SigninMessage();
var msg = new Message();
msg.command = "signin";
q.username = "testuser"; q.password = "testuser";
msg.data = JSON.stringify(q);
await msg.Signin(null, null);
q = JSON.parse(msg.data);
assert.strictEqual(NoderedUtil.IsNullEmpty(q.user), false, "Sigin returned no data")
assert.strictEqual(q.user.username, "testuser", "Sigin did not return testuser user object")
}
}
// cls | ./node_modules/.bin/_mocha 'test/**/Auth.test.ts'