forked from stack-auth/stack
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
299 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
SERVER_BASE_URL= | ||
DASHBOARD_BASE_URL= | ||
BACKEND_BASE_URL= | ||
INTERNAL_PROJECT_ID= | ||
INTERNAL_PROJECT_CLIENT_KEY= | ||
INTERNAL_PROJECT_SERVER_KEY= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
SERVER_BASE_URL=http://localhost:8101 | ||
DASHBOARD_BASE_URL=http://localhost:8101 | ||
BACKEND_BASE_URL=http://localhost:8102 | ||
INTERNAL_PROJECT_ID=internal | ||
INTERNAL_PROJECT_CLIENT_KEY=this-publishable-client-key-is-for-local-development-only | ||
INTERNAL_PROJECT_SERVER_KEY=this-secret-server-key-is-for-local-development-only |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { BACKEND_BASE_URL, NiceResponse, niceFetch } from "../helpers"; | ||
|
||
export function niceBackendFetch(url: string, options?: RequestInit): Promise<NiceResponse> { | ||
const res = niceFetch(new URL(url, BACKEND_BASE_URL), options); | ||
return res; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { describe, expect, test } from "vitest"; | ||
import { niceBackendFetch } from "../../../backend-helpers"; | ||
|
||
describe("Backend index page", () => { | ||
test("Main Page", async () => { | ||
const response = await niceBackendFetch("/api/v1"); | ||
expect(response).toMatchInlineSnapshot(` | ||
Check failure on line 7 in apps/e2e/tests/backend/endpoints/api/v1/index.test.ts GitHub Actions / build (20.x)tests/backend/endpoints/api/v1/index.test.ts > Backend index page > Main Page
|
||
NiceResponse { | ||
"status": 200, | ||
"headers": _Headers { | ||
"x-stack-request-id": <stripped header 'x-stack-request-id'>, | ||
<several headers hidden>, | ||
}, | ||
"body": "Welcome to the Stack API endpoint! Please refer to the documentation at https://docs.stack-auth.com.\\n\\nAuthentication: None", | ||
} | ||
`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { SnapshotSerializer } from "vitest"; | ||
import { Nicifiable, nicify } from "@stackframe/stack-shared/dist/utils/strings"; | ||
import { typedIncludes } from "@stackframe/stack-shared/dist/utils/arrays"; | ||
|
||
const stackSnapshotSerializerSymbol = Symbol("stackSnapshotSerializer"); | ||
|
||
const hideHeaders = [ | ||
"access-control-allow-headers", | ||
"access-control-allow-methods", | ||
"access-control-allow-origin", | ||
"access-control-expose-headers", | ||
"cache-control", | ||
"connection", | ||
"content-security-policy", | ||
"content-type", | ||
"cross-origin-opener-policy", | ||
"date", | ||
"keep-alive", | ||
"permissions-policy", | ||
"referrer-policy", | ||
"transfer-encoding", | ||
"vary", | ||
"x-content-type-options", | ||
"x-frame-options", | ||
]; | ||
|
||
const stripHeaders = ["x-stack-request-id"]; | ||
|
||
const snapshotSerializer: SnapshotSerializer = { | ||
serialize(val, config, indentation, depth, refs, printer) { | ||
return nicify(val, { | ||
currentIndent: indentation, | ||
maxDepth: config.maxDepth - depth, | ||
refs: new Map(refs.map((ref, i) => [ref, `vitestRef[${i}]`])), | ||
lineIndent: config.indent, | ||
multiline: true, | ||
path: "snapshot", | ||
overrides: (value, options) => { | ||
const stackSnapshotSerializer: null | { | ||
headersHidden?: true, | ||
} = (value as any)[stackSnapshotSerializerSymbol]; | ||
|
||
// Hide headers | ||
if (value instanceof Headers && !stackSnapshotSerializer?.headersHidden) { | ||
const originalHeaders = [...value.entries()]; | ||
const filteredHeaders = originalHeaders.filter(([key]) => !typedIncludes(hideHeaders, key.toLowerCase())); | ||
return ["replace", Object.assign(new Headers(filteredHeaders), { | ||
[stackSnapshotSerializerSymbol]: { | ||
headersHidden: true, | ||
}, | ||
getNicifiedObjectExtraLines: () => [`<several headers hidden>`], | ||
})]; | ||
} | ||
|
||
// Strip headers | ||
if (options?.parent?.value instanceof Headers) { | ||
const headerName = options.keyInParent?.toString().toLowerCase(); | ||
if (typedIncludes(stripHeaders, headerName)) { | ||
return ["result", `<stripped header '${headerName}'>`]; | ||
} | ||
} | ||
|
||
// Otherwise, use default serialization | ||
return null; | ||
}, | ||
}); | ||
}, | ||
test(val) { | ||
return true; | ||
}, | ||
}; | ||
export default snapshotSerializer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.