@dax-crafta/auth 2.1.7 → 2.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.mocharc.cjs +6 -0
- package/README.md +167 -274
- package/image.png +0 -0
- package/package.json +6 -2
- package/src/index.d.ts +8 -1
- package/src/index.js +75 -7
- package/src/middlewares/auth.middleware.js +30 -9
- package/src/models/user.js +2 -1
- package/src/services/audit.service.js +66 -0
- package/src/services/auth.service.js +36 -9
- package/src/services/role.service.js +5 -0
- package/src/services/session.service.js +46 -5
- package/src/services/webhook.service.js +42 -1
- package/src/utils/email.js +4 -3
- package/src/utils/password-policy.js +6 -1
- package/src/utils/password-strength.js +68 -0
- package/test/01-register-login.test.js +134 -0
- package/test/02-password-reset.test.js +50 -0
- package/test/03-2fa.test.js +54 -0
- package/test/04-rbac.test.js +51 -0
- package/test/05-audit-webhook.test.js +78 -0
- package/test/06-sessions.test.js +36 -0
- package/test/07-error-normalization.test.js +64 -0
- package/test/08-cors-health.test.js +45 -0
- package/test/09-passwordless.test.js +40 -0
- package/test/10-webhook-signing.test.js +37 -0
- package/test/helpers.js +130 -0
- package/test/run-tests.js +94 -0
- package/test/tiny-test.js +68 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tiny test harness — supports describe()/it() with async assertions.
|
|
3
|
+
* Drop-in replacement for the mocha BDD interface. No dependencies.
|
|
4
|
+
*/
|
|
5
|
+
const assert = require('assert');
|
|
6
|
+
|
|
7
|
+
let passed = 0;
|
|
8
|
+
let failed = 0;
|
|
9
|
+
const failures = [];
|
|
10
|
+
let pendingTests = [];
|
|
11
|
+
|
|
12
|
+
function describe(name, fn) {
|
|
13
|
+
console.log(`\n ${name}`);
|
|
14
|
+
fn();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function it(name, fn) {
|
|
18
|
+
pendingTests.push({ name, fn });
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async function runPending() {
|
|
22
|
+
// Reset DB BEFORE before() so test data created in before() survives.
|
|
23
|
+
// Also ensures MongoDB connection is established (auth() connects async).
|
|
24
|
+
if (global.__resetDb) { await global.__resetDb(); }
|
|
25
|
+
|
|
26
|
+
// Run before hooks — this is where buildApp() registers Mongoose models
|
|
27
|
+
if (global.__before) { await global.__before(); }
|
|
28
|
+
|
|
29
|
+
for (const test of pendingTests) {
|
|
30
|
+
try {
|
|
31
|
+
await test.fn();
|
|
32
|
+
console.log(` ✓ ${test.name}`);
|
|
33
|
+
passed += 1;
|
|
34
|
+
} catch (err) {
|
|
35
|
+
console.log(` ✗ ${test.name}`);
|
|
36
|
+
console.log(` ${err.message}`);
|
|
37
|
+
failures.push({ name: test.name, err });
|
|
38
|
+
failed += 1;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (global.__after) { await global.__after(); }
|
|
42
|
+
|
|
43
|
+
// Reset for next file
|
|
44
|
+
pendingTests = [];
|
|
45
|
+
global.__before = null;
|
|
46
|
+
global.__after = null;
|
|
47
|
+
global.__resetDb = null;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function before(fn) {
|
|
51
|
+
global.__before = fn;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function after(fn) {
|
|
55
|
+
global.__after = fn;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function getStats() {
|
|
59
|
+
return { passed, failed, failures };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function resetStats() {
|
|
63
|
+
passed = 0;
|
|
64
|
+
failed = 0;
|
|
65
|
+
failures.length = 0;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
module.exports = { describe, it, before, after, runPending, getStats, resetStats };
|