@jskit-ai/console-core 0.1.87 → 0.1.88
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/package.descriptor.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export default Object.freeze({
|
|
2
2
|
packageVersion: 1,
|
|
3
3
|
packageId: "@jskit-ai/console-core",
|
|
4
|
-
version: "0.1.
|
|
4
|
+
version: "0.1.88",
|
|
5
5
|
kind: "runtime",
|
|
6
6
|
description: "Console runtime: console settings schema, bootstrap flags, actions, and HTTP routes.",
|
|
7
7
|
dependsOn: [
|
package/package.json
CHANGED
|
@@ -40,8 +40,9 @@ function createConsoleAuthServiceDecorator({ consoleService } = {}) {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
return Object.freeze(
|
|
43
|
-
Object.
|
|
44
|
-
|
|
43
|
+
Object.defineProperty(Object.create(authService), "authenticateRequest", {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
value: async function authenticateRequest(request, ...args) {
|
|
45
46
|
const authResult = await authService.authenticateRequest(request, ...args);
|
|
46
47
|
if (consoleOwnerInitialized) {
|
|
47
48
|
return authResult;
|
|
@@ -63,3 +63,56 @@ test("console auth service decorator leaves unauthenticated session reads alone"
|
|
|
63
63
|
|
|
64
64
|
assert.equal(result.authenticated, false);
|
|
65
65
|
});
|
|
66
|
+
|
|
67
|
+
test("console auth service decorator safely shadows authenticateRequest on a frozen service", async () => {
|
|
68
|
+
const calls = [];
|
|
69
|
+
const ownerSeeds = [];
|
|
70
|
+
const originalAuthenticateRequest = async function authenticateRequest(request, ...args) {
|
|
71
|
+
calls.push({ request, args });
|
|
72
|
+
return {
|
|
73
|
+
authenticated: true,
|
|
74
|
+
profile: {
|
|
75
|
+
id: request.profileId
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
const originalAuthService = Object.freeze({
|
|
80
|
+
authenticateRequest: originalAuthenticateRequest,
|
|
81
|
+
readMarker() {
|
|
82
|
+
return "original-service";
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
const decorator = createConsoleAuthServiceDecorator({
|
|
86
|
+
consoleService: {
|
|
87
|
+
async ensureInitialConsoleMember(userId) {
|
|
88
|
+
ownerSeeds.push(String(userId || ""));
|
|
89
|
+
return String(userId || "");
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
const decoratedAuthService = decorator.decorateAuthService(originalAuthService);
|
|
95
|
+
const result = await decoratedAuthService.authenticateRequest(
|
|
96
|
+
{
|
|
97
|
+
profileId: "42",
|
|
98
|
+
url: "/api/session"
|
|
99
|
+
},
|
|
100
|
+
"forwarded-argument"
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
assert.equal(Object.isFrozen(originalAuthService), true);
|
|
104
|
+
assert.equal(Object.isFrozen(decoratedAuthService), true);
|
|
105
|
+
assert.equal(Object.getPrototypeOf(decoratedAuthService), originalAuthService);
|
|
106
|
+
assert.equal(originalAuthService.authenticateRequest, originalAuthenticateRequest);
|
|
107
|
+
assert.equal(decoratedAuthService.readMarker(), "original-service");
|
|
108
|
+
assert.equal(result.profile.id, "42");
|
|
109
|
+
assert.deepEqual(ownerSeeds, ["42"]);
|
|
110
|
+
assert.equal(calls.length, 1);
|
|
111
|
+
assert.deepEqual(calls[0].args, ["forwarded-argument"]);
|
|
112
|
+
assert.deepEqual(Object.getOwnPropertyDescriptor(decoratedAuthService, "authenticateRequest"), {
|
|
113
|
+
configurable: false,
|
|
114
|
+
enumerable: true,
|
|
115
|
+
value: decoratedAuthService.authenticateRequest,
|
|
116
|
+
writable: false
|
|
117
|
+
});
|
|
118
|
+
});
|