@jskit-ai/auth-web 0.2.5 → 0.2.6
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.json +1 -1
- package/src/test/playwright.js +6 -3
- package/test/playwright.test.js +44 -1
package/package.json
CHANGED
package/src/test/playwright.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { DEV_AUTH_SECRET_HEADER } from "@jskit-ai/auth-core/server/devAuth";
|
|
2
2
|
import { AUTH_PATHS } from "@jskit-ai/auth-core/shared/authPaths";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
function defaultLocalBaseUrl() {
|
|
5
|
+
const port = String(process.env.PLAYWRIGHT_PORT || "").trim() || "4173";
|
|
6
|
+
return `http://127.0.0.1:${port}`;
|
|
7
|
+
}
|
|
5
8
|
|
|
6
9
|
function resolveLocalBaseUrl(value) {
|
|
7
|
-
const baseUrl = String(value ||
|
|
10
|
+
const baseUrl = String(value || defaultLocalBaseUrl()).trim().replace(/\/+$/u, "");
|
|
8
11
|
let url;
|
|
9
12
|
try {
|
|
10
13
|
url = new URL(baseUrl);
|
|
@@ -42,7 +45,7 @@ async function loginAsExistingUser(page, {
|
|
|
42
45
|
email = "",
|
|
43
46
|
userId = "",
|
|
44
47
|
secret = process.env.AUTH_DEV_BYPASS_SECRET,
|
|
45
|
-
baseURL = process.env.PLAYWRIGHT_BASE_URL ||
|
|
48
|
+
baseURL = process.env.PLAYWRIGHT_BASE_URL || defaultLocalBaseUrl()
|
|
46
49
|
} = {}) {
|
|
47
50
|
const context = page?.context?.();
|
|
48
51
|
if (!context?.request) {
|
package/test/playwright.test.js
CHANGED
|
@@ -20,7 +20,23 @@ function createResponse({ status = 200, body = {} } = {}) {
|
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
function setPlaywrightEnv(context, env) {
|
|
24
|
+
const names = ["PLAYWRIGHT_BASE_URL", "PLAYWRIGHT_PORT"];
|
|
25
|
+
const previous = names.map((name) => [name, process.env[name]]);
|
|
26
|
+
context.after(() => {
|
|
27
|
+
for (const [name, value] of previous) {
|
|
28
|
+
if (value === undefined) delete process.env[name];
|
|
29
|
+
else process.env[name] = value;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
for (const name of names) {
|
|
33
|
+
if (env[name] === undefined) delete process.env[name];
|
|
34
|
+
else process.env[name] = env[name];
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
test("local Playwright login exchanges CSRF and the private secret in the page context", async (context) => {
|
|
39
|
+
setPlaywrightEnv(context, {});
|
|
24
40
|
const calls = [];
|
|
25
41
|
const request = {
|
|
26
42
|
async get(url) {
|
|
@@ -66,6 +82,33 @@ test("local Playwright login exchanges CSRF and the private secret in the page c
|
|
|
66
82
|
]);
|
|
67
83
|
});
|
|
68
84
|
|
|
85
|
+
test("local Playwright login follows PLAYWRIGHT_PORT when no base URL is given", async (context) => {
|
|
86
|
+
const urls = [];
|
|
87
|
+
const request = {
|
|
88
|
+
async get(url) {
|
|
89
|
+
urls.push(url);
|
|
90
|
+
return createResponse({ body: { csrfToken: "csrf-test" } });
|
|
91
|
+
},
|
|
92
|
+
async post(url) {
|
|
93
|
+
urls.push(url);
|
|
94
|
+
return createResponse({ body: { ok: true, userId: "7" } });
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
const page = {
|
|
98
|
+
context() {
|
|
99
|
+
return { request };
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
setPlaywrightEnv(context, { PLAYWRIGHT_PORT: "4183" });
|
|
103
|
+
|
|
104
|
+
await loginAsExistingUser(page, { email: "ada@example.com", secret: "private-test-secret" });
|
|
105
|
+
|
|
106
|
+
assert.deepEqual(urls, [
|
|
107
|
+
"http://127.0.0.1:4183/api/session",
|
|
108
|
+
"http://127.0.0.1:4183/api/dev-auth/login-as"
|
|
109
|
+
]);
|
|
110
|
+
});
|
|
111
|
+
|
|
69
112
|
test("local Playwright login refuses to send the private secret to a managed URL", async () => {
|
|
70
113
|
let requestCount = 0;
|
|
71
114
|
const page = {
|