mirror of
https://github.com/stack-auth/stack.git
synced 2026-06-13 21:01:21 +08:00
tests
This commit is contained in:
parent
41d8a4c807
commit
e2cb2ab2e8
@ -2,123 +2,123 @@ import { it } from "../../../../../helpers";
|
||||
import { Project, niceBackendFetch } from "../../../../backend-helpers";
|
||||
|
||||
|
||||
// it("client and server should not have access to config overrides", async ({ expect }) => {
|
||||
// await Project.createAndSwitch();
|
||||
it("client and server should not have access to config overrides", async ({ expect }) => {
|
||||
await Project.createAndSwitch();
|
||||
|
||||
// // Test client access
|
||||
// const clientResponse = await niceBackendFetch("/api/v1/internal/config-overrides", {
|
||||
// accessType: "client"
|
||||
// });
|
||||
// expect(clientResponse.status).toBe(401);
|
||||
// Test client access
|
||||
const clientResponse = await niceBackendFetch("/api/v1/internal/config-overrides", {
|
||||
accessType: "client"
|
||||
});
|
||||
expect(clientResponse.status).toBe(401);
|
||||
|
||||
// // Test server access
|
||||
// const serverResponse = await niceBackendFetch("/api/v1/internal/config-overrides", {
|
||||
// accessType: "server"
|
||||
// });
|
||||
// expect(serverResponse.status).toBe(401);
|
||||
// });
|
||||
// Test server access
|
||||
const serverResponse = await niceBackendFetch("/api/v1/internal/config-overrides", {
|
||||
accessType: "server"
|
||||
});
|
||||
expect(serverResponse.status).toBe(401);
|
||||
});
|
||||
|
||||
// it("gets config", async ({ expect }) => {
|
||||
// const { adminAccessToken } = await Project.createAndSwitch({
|
||||
// config: {
|
||||
// magic_link_enabled: true,
|
||||
// }
|
||||
// });
|
||||
it("gets config", async ({ expect }) => {
|
||||
const { adminAccessToken } = await Project.createAndSwitch({
|
||||
config: {
|
||||
magic_link_enabled: true,
|
||||
}
|
||||
});
|
||||
|
||||
// const response = await niceBackendFetch("/api/v1/internal/config-overrides", {
|
||||
// method: "GET",
|
||||
// accessType: "admin",
|
||||
// headers: {
|
||||
// 'x-stack-admin-access-token': adminAccessToken,
|
||||
// },
|
||||
// });
|
||||
const response = await niceBackendFetch("/api/v1/internal/config-overrides", {
|
||||
method: "GET",
|
||||
accessType: "admin",
|
||||
headers: {
|
||||
'x-stack-admin-access-token': adminAccessToken,
|
||||
},
|
||||
});
|
||||
|
||||
// expect(response.status).toBe(200);
|
||||
// const parsedConfig = JSON.parse(response.body.config);
|
||||
// expect(pick(parsedConfig, ["auth", "domains", 'users', 'teams'])).toMatchInlineSnapshot(`
|
||||
// {
|
||||
// "auth": {
|
||||
// "allowSignUp": true,
|
||||
// "oauth": {
|
||||
// "accountMergeStrategy": "link_method",
|
||||
// "providers": {},
|
||||
// },
|
||||
// "otp": { "allowSignIn": true },
|
||||
// "passkey": { "allowSignIn": false },
|
||||
// "password": { "allowSignIn": true },
|
||||
// },
|
||||
// "domains": {
|
||||
// "allowLocalhost": true,
|
||||
// "trustedDomains": {},
|
||||
// },
|
||||
// "teams": {
|
||||
// "allowClientTeamCreation": false,
|
||||
// "createPersonalTeamOnSignUp": false,
|
||||
// },
|
||||
// "users": { "allowClientUserDeletion": false },
|
||||
// }
|
||||
// `);
|
||||
// });
|
||||
expect(response.status).toBe(200);
|
||||
const parsedConfig = JSON.parse(response.body.config);
|
||||
expect(pick(parsedConfig, ["auth", "domains", 'users', 'teams'])).toMatchInlineSnapshot(`
|
||||
{
|
||||
"auth": {
|
||||
"allowSignUp": true,
|
||||
"oauth": {
|
||||
"accountMergeStrategy": "link_method",
|
||||
"providers": {},
|
||||
},
|
||||
"otp": { "allowSignIn": true },
|
||||
"passkey": { "allowSignIn": false },
|
||||
"password": { "allowSignIn": true },
|
||||
},
|
||||
"domains": {
|
||||
"allowLocalhost": true,
|
||||
"trustedDomains": {},
|
||||
},
|
||||
"teams": {
|
||||
"allowClientTeamCreation": false,
|
||||
"createPersonalTeamOnSignUp": false,
|
||||
},
|
||||
"users": { "allowClientUserDeletion": false },
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
// it("updates basic config", async ({ expect }) => {
|
||||
// const { adminAccessToken } = await Project.createAndSwitch({
|
||||
// config: {
|
||||
// magic_link_enabled: true,
|
||||
// }
|
||||
// });
|
||||
it("updates basic config", async ({ expect }) => {
|
||||
const { adminAccessToken } = await Project.createAndSwitch({
|
||||
config: {
|
||||
magic_link_enabled: true,
|
||||
}
|
||||
});
|
||||
|
||||
// // Get initial config
|
||||
// const initialResponse = await niceBackendFetch("/api/v1/internal/config-overrides", {
|
||||
// method: "GET",
|
||||
// accessType: "admin",
|
||||
// headers: {
|
||||
// 'x-stack-admin-access-token': adminAccessToken,
|
||||
// },
|
||||
// });
|
||||
// Get initial config
|
||||
const initialResponse = await niceBackendFetch("/api/v1/internal/config-overrides", {
|
||||
method: "GET",
|
||||
accessType: "admin",
|
||||
headers: {
|
||||
'x-stack-admin-access-token': adminAccessToken,
|
||||
},
|
||||
});
|
||||
|
||||
// expect(initialResponse.status).toBe(200);
|
||||
// const initialConfig = JSON.parse(initialResponse.body.config);
|
||||
expect(initialResponse.status).toBe(200);
|
||||
const initialConfig = JSON.parse(initialResponse.body.config);
|
||||
|
||||
// expect(initialConfig.users.allowClientUserDeletion).toBe(false);
|
||||
// expect(initialConfig.teams.allowClientTeamCreation).toBe(false);
|
||||
// expect(initialConfig.teams.createPersonalTeamOnSignUp).toBe(false);
|
||||
expect(initialConfig.users.allowClientUserDeletion).toBe(false);
|
||||
expect(initialConfig.teams.allowClientTeamCreation).toBe(false);
|
||||
expect(initialConfig.teams.createPersonalTeamOnSignUp).toBe(false);
|
||||
|
||||
// const updateResponse = await niceBackendFetch("/api/v1/internal/config-overrides", {
|
||||
// method: "PATCH",
|
||||
// accessType: "admin",
|
||||
// headers: {
|
||||
// 'x-stack-admin-access-token': adminAccessToken,
|
||||
// },
|
||||
// body: {
|
||||
// config: JSON.stringify({
|
||||
// 'users.allowClientUserDeletion': true,
|
||||
// 'teams.allowClientTeamCreation': true,
|
||||
// 'teams.createPersonalTeamOnSignUp': true,
|
||||
// }),
|
||||
// },
|
||||
// });
|
||||
const updateResponse = await niceBackendFetch("/api/v1/internal/config-overrides", {
|
||||
method: "PATCH",
|
||||
accessType: "admin",
|
||||
headers: {
|
||||
'x-stack-admin-access-token': adminAccessToken,
|
||||
},
|
||||
body: {
|
||||
config: JSON.stringify({
|
||||
'users.allowClientUserDeletion': true,
|
||||
'teams.allowClientTeamCreation': true,
|
||||
'teams.createPersonalTeamOnSignUp': true,
|
||||
}),
|
||||
},
|
||||
});
|
||||
|
||||
// expect(updateResponse.status).toBe(200);
|
||||
// const returnedConfig = JSON.parse(updateResponse.body.config);
|
||||
// expect(returnedConfig.users.allowClientUserDeletion).toBe(true);
|
||||
// expect(returnedConfig.teams.allowClientTeamCreation).toBe(true);
|
||||
// expect(returnedConfig.teams.createPersonalTeamOnSignUp).toBe(true);
|
||||
expect(updateResponse.status).toBe(200);
|
||||
const returnedConfig = JSON.parse(updateResponse.body.config);
|
||||
expect(returnedConfig.users.allowClientUserDeletion).toBe(true);
|
||||
expect(returnedConfig.teams.allowClientTeamCreation).toBe(true);
|
||||
expect(returnedConfig.teams.createPersonalTeamOnSignUp).toBe(true);
|
||||
|
||||
// // Verify the changes are persisted by making another GET request
|
||||
// const verifyResponse = await niceBackendFetch("/api/v1/internal/config-overrides", {
|
||||
// method: "GET",
|
||||
// accessType: "admin",
|
||||
// headers: {
|
||||
// 'x-stack-admin-access-token': adminAccessToken,
|
||||
// },
|
||||
// });
|
||||
// Verify the changes are persisted by making another GET request
|
||||
const verifyResponse = await niceBackendFetch("/api/v1/internal/config-overrides", {
|
||||
method: "GET",
|
||||
accessType: "admin",
|
||||
headers: {
|
||||
'x-stack-admin-access-token': adminAccessToken,
|
||||
},
|
||||
});
|
||||
|
||||
// expect(verifyResponse.status).toBe(200);
|
||||
// const persistedConfig = JSON.parse(verifyResponse.body.config);
|
||||
// expect(persistedConfig.users.allowClientUserDeletion).toBe(true);
|
||||
// expect(persistedConfig.teams.allowClientTeamCreation).toBe(true);
|
||||
// expect(persistedConfig.teams.createPersonalTeamOnSignUp).toBe(true);
|
||||
// });
|
||||
expect(verifyResponse.status).toBe(200);
|
||||
const persistedConfig = JSON.parse(verifyResponse.body.config);
|
||||
expect(persistedConfig.users.allowClientUserDeletion).toBe(true);
|
||||
expect(persistedConfig.teams.allowClientTeamCreation).toBe(true);
|
||||
expect(persistedConfig.teams.createPersonalTeamOnSignUp).toBe(true);
|
||||
});
|
||||
|
||||
it("adds, updates, and removes oauth config", async ({ expect }) => {
|
||||
const { adminAccessToken } = await Project.createAndSwitch({
|
||||
|
||||
Loading…
Reference in New Issue
Block a user