Skip to content

Commit a20ccaa

Browse files
committed
fix tests
1 parent eb5662c commit a20ccaa

9 files changed

Lines changed: 25 additions & 24 deletions

File tree

apps/e2e/tests/backend/endpoints/api/v1/auth/oauth/authorize.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ it("should not redirect the user to the OAuth provider with the right arguments
5050

5151
it("should be able to fetch the inner callback URL by following the OAuth provider redirects", async ({ expect }) => {
5252
const { innerCallbackUrl } = await Auth.OAuth.getInnerCallbackUrl();
53-
expect(innerCallbackUrl.origin).toBe("http://localhost:STACK_PORT_PREFIX02");
53+
expect(innerCallbackUrl.origin).toBe("http://localhost:<$STACK_PORT_PREFIX>02");
5454
expect(innerCallbackUrl.pathname).toBe("/api/v1/auth/oauth/callback/spotify");
5555
});
5656

apps/e2e/tests/backend/endpoints/api/v1/integrations/custom/oauth.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,15 @@ async function authorize(projectId: string) {
7575
NiceResponse {
7676
"status": 307,
7777
"headers": Headers {
78-
"location": "http://localhost:STACK_PORT_PREFIX02/api/v1/integrations/custom/oauth/idp/auth?response_type=code&client_id=custom-local&redirect_uri=%3Cstripped+query+param%3E&state=%3Cstripped+query+param%3E&code_challenge=%3Cstripped+query+param%3E&code_challenge_method=S256&scope=openid",
78+
"location": "http://localhost:<$STACK_PORT_PREFIX>02/api/v1/integrations/custom/oauth/idp/auth?response_type=code&client_id=custom-local&redirect_uri=%3Cstripped+query+param%3E&state=%3Cstripped+query+param%3E&code_challenge=%3Cstripped+query+param%3E&code_challenge_method=S256&scope=openid",
7979
<some fields may have been hidden>,
8080
},
8181
},
8282
NiceResponse {
8383
"status": 303,
84-
"body": "Redirecting to <a href=\\"http://localhost:STACK_PORT_PREFIX02/api/v1/integrations/custom/oauth/idp/interaction/<stripped interaction UID>\\">http://localhost:STACK_PORT_PREFIX02/api/v1/integrations/custom/oauth/idp/interaction/<stripped interaction UID></a>.",
84+
"body": "Redirecting to <a href=\\"http://localhost:<$STACK_PORT_PREFIX>02/api/v1/integrations/custom/oauth/idp/interaction/<stripped interaction UID>\\">http://localhost:<$STACK_PORT_PREFIX>02/api/v1/integrations/custom/oauth/idp/interaction/<stripped interaction UID></a>.",
8585
"headers": Headers {
86-
"location": "http://localhost:STACK_PORT_PREFIX02/api/v1/integrations/custom/oauth/idp/interaction/<stripped interaction UID>",
86+
"location": "http://localhost:<$STACK_PORT_PREFIX>02/api/v1/integrations/custom/oauth/idp/interaction/<stripped interaction UID>",
8787
"set-cookie": <setting cookie "_interaction" at path "/api/v1/integrations/custom/oauth/idp/interaction/<stripped interaction UID>" to <stripped cookie value>>,
8888
"set-cookie": <setting cookie "_interaction.sig" at path "/api/v1/integrations/custom/oauth/idp/interaction/<stripped interaction UID>" to <stripped cookie value>>,
8989
"set-cookie": <setting cookie "_interaction_resume" at path "/api/v1/integrations/custom/oauth/idp/auth/<stripped auth UID>" to <stripped cookie value>>,
@@ -93,9 +93,9 @@ async function authorize(projectId: string) {
9393
},
9494
NiceResponse {
9595
"status": 307,
96-
"body": "http://localhost:STACK_PORT_PREFIX01/integrations/custom/confirm?interaction_uid=%3Cstripped+query+param%3E&amp=",
96+
"body": "http://localhost:<$STACK_PORT_PREFIX>01/integrations/custom/confirm?interaction_uid=%3Cstripped+query+param%3E&amp=",
9797
"headers": Headers {
98-
"location": "http://localhost:STACK_PORT_PREFIX01/integrations/custom/confirm?interaction_uid=%3Cstripped+query+param%3E&external_project_name=custom-project",
98+
"location": "http://localhost:<$STACK_PORT_PREFIX>01/integrations/custom/confirm?interaction_uid=%3Cstripped+query+param%3E&external_project_name=custom-project",
9999
<some fields may have been hidden>,
100100
},
101101
},
@@ -130,7 +130,7 @@ async function authorize(projectId: string) {
130130
NiceResponse {
131131
"status": 303,
132132
"headers": Headers {
133-
"location": "http://localhost:STACK_PORT_PREFIX02/api/v1/integrations/custom/oauth/idp/auth/<stripped auth UID>",
133+
"location": "http://localhost:<$STACK_PORT_PREFIX>02/api/v1/integrations/custom/oauth/idp/auth/<stripped auth UID>",
134134
<some fields may have been hidden>,
135135
},
136136
},
@@ -169,7 +169,7 @@ it(`should not redirect to the incorrect callback URL`, async ({}) => {
169169
NiceResponse {
170170
"status": 307,
171171
"headers": Headers {
172-
"location": "http://localhost:STACK_PORT_PREFIX02/api/v1/integrations/custom/oauth/idp/auth?response_type=code&client_id=custom-local&redirect_uri=%3Cstripped+query+param%3E&state=%3Cstripped+query+param%3E&code_challenge=%3Cstripped+query+param%3E&code_challenge_method=S256&scope=openid",
172+
"location": "http://localhost:<$STACK_PORT_PREFIX>02/api/v1/integrations/custom/oauth/idp/auth?response_type=code&client_id=custom-local&redirect_uri=%3Cstripped+query+param%3E&state=%3Cstripped+query+param%3E&code_challenge=%3Cstripped+query+param%3E&code_challenge_method=S256&scope=openid",
173173
<some fields may have been hidden>,
174174
},
175175
},
@@ -178,7 +178,7 @@ it(`should not redirect to the incorrect callback URL`, async ({}) => {
178178
"body": {
179179
"error": "invalid_redirect_uri",
180180
"error_description": "redirect_uri did not match any of the client's registered redirect_uris",
181-
"iss": "http://localhost:STACK_PORT_PREFIX02/api/v1/integrations/custom/oauth/idp",
181+
"iss": "http://localhost:<$STACK_PORT_PREFIX>02/api/v1/integrations/custom/oauth/idp",
182182
"state": "eyJkZXRhaWxzIjp7ImV4dGVybmFsX3Byb2plY3RfbmFtZSI6ImN1c3RvbS1wcm9qZWN0In19",
183183
},
184184
"headers": Headers { <some fields may have been hidden> },

apps/e2e/tests/backend/endpoints/api/v1/integrations/custom/projects/transfer.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ async function initiateTransfer(projectId: string) {
1717
expect(response).toMatchInlineSnapshot(`
1818
NiceResponse {
1919
"status": 200,
20-
"body": { "confirmation_url": "http://localhost:STACK_PORT_PREFIX01/integrations/custom/projects/transfer/confirm?code=%3Cstripped+query+param%3E" },
20+
"body": { "confirmation_url": "http://localhost:<$STACK_PORT_PREFIX>01/integrations/custom/projects/transfer/confirm?code=%3Cstripped+query+param%3E" },
2121
"headers": Headers { <some fields may have been hidden> },
2222
}
2323
`);

apps/e2e/tests/backend/endpoints/api/v1/integrations/neon/oauth.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,15 @@ async function authorize(projectId: string) {
7575
NiceResponse {
7676
"status": 307,
7777
"headers": Headers {
78-
"location": "http://localhost:STACK_PORT_PREFIX02/api/v1/integrations/neon/oauth/idp/auth?response_type=code&client_id=neon-local&redirect_uri=%3Cstripped+query+param%3E&state=%3Cstripped+query+param%3E&code_challenge=%3Cstripped+query+param%3E&code_challenge_method=S256&scope=openid",
78+
"location": "http://localhost:<$STACK_PORT_PREFIX>02/api/v1/integrations/neon/oauth/idp/auth?response_type=code&client_id=neon-local&redirect_uri=%3Cstripped+query+param%3E&state=%3Cstripped+query+param%3E&code_challenge=%3Cstripped+query+param%3E&code_challenge_method=S256&scope=openid",
7979
<some fields may have been hidden>,
8080
},
8181
},
8282
NiceResponse {
8383
"status": 303,
84-
"body": "Redirecting to <a href=\\"http://localhost:STACK_PORT_PREFIX02/api/v1/integrations/neon/oauth/idp/interaction/<stripped interaction UID>\\">http://localhost:STACK_PORT_PREFIX02/api/v1/integrations/neon/oauth/idp/interaction/<stripped interaction UID></a>.",
84+
"body": "Redirecting to <a href=\\"http://localhost:<$STACK_PORT_PREFIX>02/api/v1/integrations/neon/oauth/idp/interaction/<stripped interaction UID>\\">http://localhost:<$STACK_PORT_PREFIX>02/api/v1/integrations/neon/oauth/idp/interaction/<stripped interaction UID></a>.",
8585
"headers": Headers {
86-
"location": "http://localhost:STACK_PORT_PREFIX02/api/v1/integrations/neon/oauth/idp/interaction/<stripped interaction UID>",
86+
"location": "http://localhost:<$STACK_PORT_PREFIX>02/api/v1/integrations/neon/oauth/idp/interaction/<stripped interaction UID>",
8787
"set-cookie": <setting cookie "_interaction" at path "/api/v1/integrations/neon/oauth/idp/interaction/<stripped interaction UID>" to <stripped cookie value>>,
8888
"set-cookie": <setting cookie "_interaction.sig" at path "/api/v1/integrations/neon/oauth/idp/interaction/<stripped interaction UID>" to <stripped cookie value>>,
8989
"set-cookie": <setting cookie "_interaction_resume" at path "/api/v1/integrations/neon/oauth/idp/auth/<stripped auth UID>" to <stripped cookie value>>,
@@ -93,9 +93,9 @@ async function authorize(projectId: string) {
9393
},
9494
NiceResponse {
9595
"status": 307,
96-
"body": "http://localhost:STACK_PORT_PREFIX01/integrations/neon/confirm?interaction_uid=%3Cstripped+query+param%3E&amp=",
96+
"body": "http://localhost:<$STACK_PORT_PREFIX>01/integrations/neon/confirm?interaction_uid=%3Cstripped+query+param%3E&amp=",
9797
"headers": Headers {
98-
"location": "http://localhost:STACK_PORT_PREFIX01/integrations/neon/confirm?interaction_uid=%3Cstripped+query+param%3E&external_project_name=neon-project",
98+
"location": "http://localhost:<$STACK_PORT_PREFIX>01/integrations/neon/confirm?interaction_uid=%3Cstripped+query+param%3E&external_project_name=neon-project",
9999
<some fields may have been hidden>,
100100
},
101101
},
@@ -130,7 +130,7 @@ async function authorize(projectId: string) {
130130
NiceResponse {
131131
"status": 303,
132132
"headers": Headers {
133-
"location": "http://localhost:STACK_PORT_PREFIX02/api/v1/integrations/neon/oauth/idp/auth/<stripped auth UID>",
133+
"location": "http://localhost:<$STACK_PORT_PREFIX>02/api/v1/integrations/neon/oauth/idp/auth/<stripped auth UID>",
134134
<some fields may have been hidden>,
135135
},
136136
},
@@ -169,7 +169,7 @@ it(`should not redirect to the incorrect callback URL`, async ({}) => {
169169
NiceResponse {
170170
"status": 307,
171171
"headers": Headers {
172-
"location": "http://localhost:STACK_PORT_PREFIX02/api/v1/integrations/neon/oauth/idp/auth?response_type=code&client_id=neon-local&redirect_uri=%3Cstripped+query+param%3E&state=%3Cstripped+query+param%3E&code_challenge=%3Cstripped+query+param%3E&code_challenge_method=S256&scope=openid",
172+
"location": "http://localhost:<$STACK_PORT_PREFIX>02/api/v1/integrations/neon/oauth/idp/auth?response_type=code&client_id=neon-local&redirect_uri=%3Cstripped+query+param%3E&state=%3Cstripped+query+param%3E&code_challenge=%3Cstripped+query+param%3E&code_challenge_method=S256&scope=openid",
173173
<some fields may have been hidden>,
174174
},
175175
},
@@ -178,7 +178,7 @@ it(`should not redirect to the incorrect callback URL`, async ({}) => {
178178
"body": {
179179
"error": "invalid_redirect_uri",
180180
"error_description": "redirect_uri did not match any of the client's registered redirect_uris",
181-
"iss": "http://localhost:STACK_PORT_PREFIX02/api/v1/integrations/neon/oauth/idp",
181+
"iss": "http://localhost:<$STACK_PORT_PREFIX>02/api/v1/integrations/neon/oauth/idp",
182182
"state": "eyJkZXRhaWxzIjp7Im5lb25fcHJvamVjdF9uYW1lIjoibmVvbi1wcm9qZWN0In19",
183183
},
184184
"headers": Headers { <some fields may have been hidden> },

apps/e2e/tests/backend/endpoints/api/v1/integrations/neon/projects/transfer.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ async function initiateTransfer(projectId: string) {
1717
expect(response).toMatchInlineSnapshot(`
1818
NiceResponse {
1919
"status": 200,
20-
"body": { "confirmation_url": "http://localhost:STACK_PORT_PREFIX01/integrations/neon/projects/transfer/confirm?code=%3Cstripped+query+param%3E" },
20+
"body": { "confirmation_url": "http://localhost:<$STACK_PORT_PREFIX>01/integrations/neon/projects/transfer/confirm?code=%3Cstripped+query+param%3E" },
2121
"headers": Headers { <some fields may have been hidden> },
2222
}
2323
`);

apps/e2e/tests/backend/endpoints/api/v1/payments/create-purchase-url.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ it("should allow valid product_id", async ({ expect }) => {
315315
});
316316
expect(response.status).toBe(200);
317317
const body = response.body as { url: string };
318-
expect(body.url).toMatch(new RegExp(`^https?:\\/\\/localhost:${withPortPrefix("01")}\/purchase\/[a-z0-9-_]+\?return_url=`));
318+
expect(body.url).toMatch(new RegExp(`^https?:\/\/localhost:${withPortPrefix("01")}\/purchase\/[a-z0-9-_]+\\?return_url=`));
319319
const urlObj = new URL(body.url);
320320
const returnUrl = urlObj.searchParams.get("return_url");
321321
expect(returnUrl).toBe("http://stack-test.localhost/after-purchase");

apps/e2e/tests/backend/endpoints/api/v1/users.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ describe("with client access", () => {
720720
profile_image_url: "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==",
721721
},
722722
});
723-
expect(response.body.profile_image_url).toMatchInlineSnapshot(`"http://localhost:STACK_PORT_PREFIX21/stack-storage/user-profile-images/<stripped UUID>.gif"`);
723+
expect(response.body.profile_image_url).toMatchInlineSnapshot(`"http://localhost:<$STACK_PORT_PREFIX>21/stack-storage/user-profile-images/<stripped UUID>.gif"`);
724724
});
725725

726726
it("should not be able to update profile image url with invalid base64", async ({ expect }) => {

apps/e2e/tests/helpers/ports.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const getPortPrefix = () => process.env.STACK_PORT_PREFIX ?? "81";
1+
export const getPortPrefix = () => process.env.STACK_PORT_PREFIX ?? "81";
22

33
/**
44
* Returns the port with the configured prefix and provided suffix.

apps/e2e/tests/snapshot-serializer.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { typedIncludes } from "@stackframe/stack-shared/dist/utils/arrays";
33
import { StackAssertionError } from "@stackframe/stack-shared/dist/utils/errors";
44
import { nicify } from "@stackframe/stack-shared/dist/utils/strings";
55
import { SnapshotSerializer } from "vitest";
6+
import { getPortPrefix } from "./helpers/ports";
67

78
const hideHeaders = [
89
"access-control-allow-headers",
@@ -101,7 +102,7 @@ const keyedCookieNamePrefixes = [
101102

102103
const stringRegexReplacements = [
103104
[/(\/integrations\/(neon|custom)\/oauth\/idp\/(interaction|auth)\/)[a-zA-Z0-9_-]+/gi, "$1<stripped $3 UID>"],
104-
[/localhost\:(\d+)(\d\d)/gi, "localhost:<$$STACK_PORT_PREFIX>$2"],
105+
[new RegExp(`localhost\:${getPortPrefix()}`, "gi"), "localhost:<$$STACK_PORT_PREFIX>"],
105106
] as const;
106107

107108

@@ -161,7 +162,7 @@ const snapshotSerializer: SnapshotSerializer = {
161162
}
162163

163164
// Strip URL query params
164-
const urlRegexHeuristic = /(?:(?:https?|ftp|file):\/\/|www\.|ftp\.)(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[-A-Z0-9+&@#\/%=~_|$?!:,.])*(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[A-Z0-9+&@#\/%=~_|$])/igm;
165+
const urlRegexHeuristic = /(?:(?:https?|ftp|file):\/\/|www\.|ftp\.)(?:\([-A-Z0-9+&@#\/%=~_|$<>?!:,.]*\)|[-A-Z0-9+&@#\/%=~_|<>$?!:,.])*(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[A-Z0-9+&@#\/%=~_|$])/igm;
165166
if (typeof value === "string") {
166167
for (const urlMatch of value.matchAll(urlRegexHeuristic)) {
167168
const questionMarkIndex = urlMatch[0].indexOf("?");

0 commit comments

Comments
 (0)