@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jskit-ai/auth-web",
3
- "version": "0.2.5",
3
+ "version": "0.2.6",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "test": "node --test --test-concurrency=1"
@@ -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
- const DEFAULT_LOCAL_BASE_URL = "http://127.0.0.1:4173";
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 || DEFAULT_LOCAL_BASE_URL).trim().replace(/\/+$/u, "");
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 || DEFAULT_LOCAL_BASE_URL
48
+ baseURL = process.env.PLAYWRIGHT_BASE_URL || defaultLocalBaseUrl()
46
49
  } = {}) {
47
50
  const context = page?.context?.();
48
51
  if (!context?.request) {
@@ -20,7 +20,23 @@ function createResponse({ status = 200, body = {} } = {}) {
20
20
  };
21
21
  }
22
22
 
23
- test("local Playwright login exchanges CSRF and the private secret in the page context", async () => {
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 = {