Skip to content

Commit 414536c

Browse files
claude[bot]N2D4
andcommitted
Fix test issues: replace JSON utils, remove unused imports, fix config
- Replace JSON.parse/JSON.stringify with parseJson/stringifyJson utilities - Remove unused localRedirectUrl imports from OAuth test files - Remove debug console.log statement in passkey test - Fix syntax error in OAuth wildcard test (missing closing brace) - Set proper allowLocalhost configuration values - Add proper imports for JSON utilities Co-authored-by: Konsti Wohlwend <N2D4@users.noreply.github.com>
1 parent 3eb48f1 commit 414536c

File tree

3 files changed

+33
-34
lines changed

3 files changed

+33
-34
lines changed

apps/e2e/tests/backend/endpoints/api/v1/auth/oauth/exact-domain-matching.test.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { describe } from "vitest";
2-
import { it, localRedirectUrl } from "../../../../../../helpers";
2+
import { it } from "../../../../../../helpers";
33
import { Auth, InternalApiKey, Project, niceBackendFetch } from "../../../../../backend-helpers";
4+
import { stringifyJson } from "@stackframe/stack-shared/dist/utils/json";
45

56
describe("OAuth with exact domain matching", () => {
67
it("should allow OAuth with exact matching domain", async ({ expect }) => {
@@ -19,7 +20,7 @@ describe("OAuth with exact domain matching", () => {
1920
'x-stack-admin-access-token': adminAccessToken,
2021
},
2122
body: {
22-
config_override_string: JSON.stringify({
23+
config_override_string: stringifyJson({
2324
'domains.trustedDomains.exact': {
2425
baseUrl: 'http://localhost:8107',
2526
handlerPath: '/handler',
@@ -52,7 +53,7 @@ describe("OAuth with exact domain matching", () => {
5253
'x-stack-admin-access-token': adminAccessToken,
5354
},
5455
body: {
55-
config_override_string: JSON.stringify({
56+
config_override_string: stringifyJson({
5657
'domains.trustedDomains.production': {
5758
baseUrl: 'https://app.production.com',
5859
handlerPath: '/auth/handler',
@@ -85,7 +86,7 @@ describe("OAuth with exact domain matching", () => {
8586
'x-stack-admin-access-token': adminAccessToken,
8687
},
8788
body: {
88-
config_override_string: JSON.stringify({
89+
config_override_string: stringifyJson({
8990
'domains.trustedDomains.subdomain': {
9091
baseUrl: 'https://app.example.com',
9192
handlerPath: '/handler',
@@ -118,7 +119,7 @@ describe("OAuth with exact domain matching", () => {
118119
'x-stack-admin-access-token': adminAccessToken,
119120
},
120121
body: {
121-
config_override_string: JSON.stringify({
122+
config_override_string: stringifyJson({
122123
'domains.trustedDomains.withport': {
123124
baseUrl: 'http://localhost:3000',
124125
handlerPath: '/handler',
@@ -151,7 +152,7 @@ describe("OAuth with exact domain matching", () => {
151152
'x-stack-admin-access-token': adminAccessToken,
152153
},
153154
body: {
154-
config_override_string: JSON.stringify({
155+
config_override_string: stringifyJson({
155156
'domains.trustedDomains.https': {
156157
baseUrl: 'https://localhost:8107',
157158
handlerPath: '/handler',
@@ -184,7 +185,7 @@ describe("OAuth with exact domain matching", () => {
184185
'x-stack-admin-access-token': adminAccessToken,
185186
},
186187
body: {
187-
config_override_string: JSON.stringify({
188+
config_override_string: stringifyJson({
188189
'domains.trustedDomains.withpath': {
189190
baseUrl: 'http://localhost:8107',
190191
handlerPath: '/auth/oauth/callback', // Different path than default /handler
@@ -217,7 +218,7 @@ describe("OAuth with exact domain matching", () => {
217218
'x-stack-admin-access-token': adminAccessToken,
218219
},
219220
body: {
220-
config_override_string: JSON.stringify({
221+
config_override_string: stringifyJson({
221222
'domains.trustedDomains.prod': {
222223
baseUrl: 'https://app.production.com',
223224
handlerPath: '/handler',
@@ -257,7 +258,7 @@ describe("OAuth with exact domain matching", () => {
257258
'x-stack-admin-access-token': adminAccessToken,
258259
},
259260
body: {
260-
config_override_string: JSON.stringify({
261+
config_override_string: stringifyJson({
261262
'domains.trustedDomains.prod': {
262263
baseUrl: 'https://app.production.com',
263264
handlerPath: '/handler',

apps/e2e/tests/backend/endpoints/api/v1/auth/oauth/wildcard-domains.test.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { describe } from "vitest";
2-
import { it, localRedirectUrl } from "../../../../../../helpers";
2+
import { it } from "../../../../../../helpers";
33
import { Auth, InternalApiKey, Project, niceBackendFetch } from "../../../../../backend-helpers";
4+
import { parseJson, stringifyJson } from "@stackframe/stack-shared/dist/utils/json";
45

56
describe("OAuth with wildcard domains", () => {
67
it("should work with exact domain configuration", async ({ expect }) => {
@@ -19,12 +20,12 @@ describe("OAuth with wildcard domains", () => {
1920
'x-stack-admin-access-token': adminAccessToken,
2021
},
2122
body: {
22-
config_override_string: JSON.stringify({
23+
config_override_string: stringifyJson({
2324
'domains.trustedDomains.exact': {
2425
baseUrl: 'http://localhost:8107',
2526
handlerPath: '/handler',
2627
},
27-
'domains.allowLocalhost': true,
28+
'domains.allowLocalhost': false,
2829
}),
2930
},
3031
});
@@ -51,7 +52,7 @@ describe("OAuth with wildcard domains", () => {
5152
'x-stack-admin-access-token': adminAccessToken,
5253
},
5354
body: {
54-
config_override_string: JSON.stringify({
55+
config_override_string: stringifyJson({
5556
'domains.trustedDomains.exact': {
5657
baseUrl: 'https://app.example.com',
5758
handlerPath: '/handler',
@@ -84,7 +85,7 @@ describe("OAuth with wildcard domains", () => {
8485
'x-stack-admin-access-token': adminAccessToken,
8586
},
8687
body: {
87-
config_override_string: JSON.stringify({
88+
config_override_string: stringifyJson({
8889
'domains.trustedDomains.wildcard': {
8990
baseUrl: 'http://*.localhost:8107',
9091
handlerPath: '/handler',
@@ -116,7 +117,7 @@ describe("OAuth with wildcard domains", () => {
116117
'x-stack-admin-access-token': adminAccessToken,
117118
},
118119
body: {
119-
config_override_string: JSON.stringify({
120+
config_override_string: stringifyJson({
120121
'domains.trustedDomains.wildcard': {
121122
baseUrl: 'https://*.example.com',
122123
handlerPath: '/handler',
@@ -149,7 +150,7 @@ describe("OAuth with wildcard domains", () => {
149150
'x-stack-admin-access-token': adminAccessToken,
150151
},
151152
body: {
152-
config_override_string: JSON.stringify({
153+
config_override_string: stringifyJson({
153154
'domains.trustedDomains.double': {
154155
baseUrl: 'http://**.localhost:8107',
155156
handlerPath: '/handler',
@@ -181,7 +182,7 @@ describe("OAuth with wildcard domains", () => {
181182
'x-stack-admin-access-token': adminAccessToken,
182183
},
183184
body: {
184-
config_override_string: JSON.stringify({
185+
config_override_string: stringifyJson({
185186
'domains.trustedDomains.double': {
186187
baseUrl: 'https://**.example.org', // Different TLD - won't match localhost
187188
handlerPath: '/handler',
@@ -214,7 +215,7 @@ describe("OAuth with wildcard domains", () => {
214215
'x-stack-admin-access-token': adminAccessToken,
215216
},
216217
body: {
217-
config_override_string: JSON.stringify({
218+
config_override_string: stringifyJson({
218219
'domains.trustedDomains.prefix': {
219220
baseUrl: 'http://local*:8107', // Should match localhost
220221
handlerPath: '/handler',
@@ -246,7 +247,7 @@ describe("OAuth with wildcard domains", () => {
246247
'x-stack-admin-access-token': adminAccessToken,
247248
},
248249
body: {
249-
config_override_string: JSON.stringify({
250+
config_override_string: stringifyJson({
250251
'domains.trustedDomains.prefix': {
251252
baseUrl: 'http://api-*:8107', // Won't match localhost
252253
handlerPath: '/handler',
@@ -269,7 +270,6 @@ describe("OAuth with wildcard domains", () => {
269270
oauth_providers: [{ id: "spotify", type: "shared" }],
270271
}
271272
});
272-
});
273273
await InternalApiKey.createAndSetProjectKeys();
274274
// Configure multiple domains, only one matches
275275
const configResponse = await niceBackendFetch("/api/v1/internal/config/override", {
@@ -279,7 +279,7 @@ describe("OAuth with wildcard domains", () => {
279279
'x-stack-admin-access-token': adminAccessToken,
280280
},
281281
body: {
282-
config_override_string: JSON.stringify({
282+
config_override_string: stringifyJson({
283283
'domains.trustedDomains.prod': {
284284
baseUrl: 'https://app.production.com',
285285
handlerPath: '/handler',
@@ -308,7 +308,7 @@ describe("OAuth with wildcard domains", () => {
308308
});
309309
expect(getResponse.status).toBe(200);
310310

311-
const config = JSON.parse(getResponse.body.config_string);
311+
const config = parseJson(getResponse.body.config_string);
312312
expect(Object.keys(config.domains.trustedDomains).length).toBe(3);
313313
});
314314
});

apps/e2e/tests/backend/endpoints/api/v1/auth/passkey/wildcard-domains.test.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { describe } from "vitest";
22
import { it } from "../../../../../../helpers";
33
import { Auth, InternalApiKey, Project, niceBackendFetch } from "../../../../../backend-helpers";
4+
import { parseJson, stringifyJson } from "@stackframe/stack-shared/dist/utils/json";
45

56
describe("Passkey with wildcard domains", () => {
67
it("should store wildcard domains in config correctly", async ({ expect }) => {
@@ -18,7 +19,7 @@ describe("Passkey with wildcard domains", () => {
1819
'x-stack-admin-access-token': adminAccessToken,
1920
},
2021
body: {
21-
config_override_string: JSON.stringify({
22+
config_override_string: stringifyJson({
2223
'domains.trustedDomains.exact': {
2324
baseUrl: 'https://app.example.com',
2425
handlerPath: '/handler',
@@ -54,7 +55,7 @@ describe("Passkey with wildcard domains", () => {
5455
});
5556
expect(getResponse.status).toBe(200);
5657

57-
const config = JSON.parse(getResponse.body.config_string);
58+
const config = parseJson(getResponse.body.config_string);
5859
expect(config.domains.trustedDomains).toMatchObject({
5960
'exact': {
6061
baseUrl: 'https://app.example.com',
@@ -96,7 +97,7 @@ describe("Passkey with wildcard domains", () => {
9697
method: "PATCH",
9798
accessType: "admin",
9899
body: {
99-
config_override_string: JSON.stringify({
100+
config_override_string: stringifyJson({
100101
'domains.trustedDomains.wildcard': {
101102
baseUrl: 'http://*:8103', // Will match http://localhost:8103 and any host on port 8103
102103
handlerPath: '/',
@@ -149,9 +150,6 @@ describe("Passkey with wildcard domains", () => {
149150
},
150151
});
151152

152-
if (registerResponse.status !== 200) {
153-
console.log("Register failed with:", registerResponse.body);
154-
}
155153
expect(registerResponse.status).toBe(200);
156154
expect(registerResponse.body).toHaveProperty("user_handle");
157155
});
@@ -175,7 +173,7 @@ describe("Passkey with wildcard domains", () => {
175173
method: "PATCH",
176174
accessType: "admin",
177175
body: {
178-
config_override_string: JSON.stringify({
176+
config_override_string: stringifyJson({
179177
'domains.trustedDomains.double': {
180178
baseUrl: 'http://**host:8103', // Will match localhost:8103
181179
handlerPath: '/',
@@ -237,7 +235,7 @@ describe("Passkey with wildcard domains", () => {
237235
method: "PATCH",
238236
accessType: "admin",
239237
body: {
240-
config_override_string: JSON.stringify({
238+
config_override_string: stringifyJson({
241239
'domains.trustedDomains.exact': {
242240
baseUrl: 'https://app.production.com',
243241
handlerPath: '/handler',
@@ -315,7 +313,7 @@ describe("Passkey with wildcard domains", () => {
315313
method: "PATCH",
316314
accessType: "admin",
317315
body: {
318-
config_override_string: JSON.stringify({
316+
config_override_string: stringifyJson({
319317
'domains.trustedDomains.wildcard': {
320318
baseUrl: 'https://*.example.com',
321319
handlerPath: '/handler',
@@ -387,7 +385,7 @@ describe("Passkey with wildcard domains", () => {
387385
method: "PATCH",
388386
accessType: "admin",
389387
body: {
390-
config_override_string: JSON.stringify({
388+
config_override_string: stringifyJson({
391389
'domains.trustedDomains.wildcard': {
392390
baseUrl: 'http://*:8103', // Will match localhost:8103
393391
handlerPath: '/',
@@ -448,7 +446,7 @@ describe("Passkey with wildcard domains", () => {
448446
'x-stack-admin-access-token': adminAccessToken,
449447
},
450448
body: {
451-
config_override_string: JSON.stringify({
449+
config_override_string: stringifyJson({
452450
'domains.trustedDomains.complex1': {
453451
baseUrl: 'https://api-*.*.example.com',
454452
handlerPath: '/handler',
@@ -476,7 +474,7 @@ describe("Passkey with wildcard domains", () => {
476474
});
477475
expect(getResponse.status).toBe(200);
478476

479-
const config = JSON.parse(getResponse.body.config_string);
477+
const config = parseJson(getResponse.body.config_string);
480478
expect(config.domains.trustedDomains.complex1.baseUrl).toBe('https://api-*.*.example.com');
481479
expect(config.domains.trustedDomains.complex2.baseUrl).toBe('https://**.api.example.com');
482480
expect(config.domains.trustedDomains.complex3.baseUrl).toBe('https://*-staging.example.com');

0 commit comments

Comments
 (0)