forked from openiap/opencore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogger.test.ts
More file actions
84 lines (81 loc) · 3.52 KB
/
Copy pathLogger.test.ts
File metadata and controls
84 lines (81 loc) · 3.52 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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 { Config } from "../OpenFlow/src/Config";
import { DatabaseConnection } from '../OpenFlow/src/DatabaseConnection';
import assert = require('assert');
import { Logger } from '../OpenFlow/src/Logger';
import { NoderedUtil } from '@openiap/openflow-api';
import { Auth } from '../OpenFlow/src/Auth';
import { i_license_data } from '../OpenFlow/src/commoninterfaces';
@suite class logger_test {
@timeout(10000)
async before() {
Config.workitem_queue_monitoring_enabled = false;
Config.disablelogging();
Logger.configure(true, false);
Config.db = new DatabaseConnection(Config.mongodb_url, Config.mongodb_db, false);
await Config.db.connect(null);
}
async after() {
await Logger.shutdown();
}
@test async 'test info'() {
// assert.ok(!NoderedUtil.IsNullUndefinded(Logger.myFormat), "Logger missing winston error formatter");
var ofid = Logger.ofid();
assert.strictEqual(NoderedUtil.IsNullEmpty(ofid), false);
}
@test async 'v1_lic'() {
const months: number = 1;
const data: i_license_data = {} as any;
let template = Logger.License.template_v1;
data.licenseVersion = 1;
data.email = "test@user.com";
var dt = new Date(new Date().toISOString());
dt.setMonth(dt.getMonth() + months);
data.expirationDate = dt.toISOString() as any;
const licenseFileContent = Logger.License.generate({
privateKeyPath: 'config/private_key.pem',
template,
data: data
});
Config.license_key = Buffer.from(licenseFileContent).toString('base64');
Logger.License.validate();
assert.strictEqual(Logger.License.validlicense, true);
assert.strictEqual(Logger.License.data.email, "test@user.com");
}
@test async 'v2_lic'() {
const months: number = 1;
const data: i_license_data = {} as any;
let template = Logger.License.template_v2;
let ofid = Logger.License.ofid(false);
assert.ok(!NoderedUtil.IsNullEmpty(ofid));
data.licenseVersion = 2;
data.email = "test@user.com";
data.domain = "localhost.openiap.io"
Config.domain = "localhost.openiap.io";
var dt = new Date(new Date().toISOString());
dt.setMonth(dt.getMonth() + months);
data.expirationDate = dt.toISOString() as any;
const licenseFileContent = Logger.License.generate({
privateKeyPath: 'config/private_key.pem',
template,
data: data
});
var lic = Logger.License;
Config.license_key = Buffer.from(licenseFileContent).toString('base64');
Logger.License.validate();
assert.strictEqual(Logger.License.validlicense, true);
assert.strictEqual(Logger.License.data.email, "test@user.com");
assert.strictEqual(Logger.License.data.domain, "localhost.openiap.io");
Config.domain = "notlocalhost.openiap.io";
assert.throws(lic.validate.bind(lic), Error);
assert.strictEqual(Logger.License.validlicense, false);
assert.strictEqual(Logger.License.data.domain, "localhost.openiap.io");
let ofid2 = Logger.License.ofid(true);
assert.ok(!NoderedUtil.IsNullEmpty(ofid2));
assert.notStrictEqual(ofid, ofid2);
}
}
// cls | ./node_modules/.bin/_mocha 'test/**/Logger.test.ts'