fix(auth): keep logout and project recovery on access denial
This commit is contained in:
@@ -120,6 +120,7 @@ describe("RefineContext access authentication", () => {
|
||||
ok: false,
|
||||
status: 403,
|
||||
headers: new Headers(),
|
||||
json: async () => ({ detail: "User authorization pending" }),
|
||||
} as Response);
|
||||
|
||||
render(
|
||||
@@ -131,6 +132,10 @@ describe("RefineContext access authentication", () => {
|
||||
expect(
|
||||
await screen.findByText("账号尚未获得访问权限"),
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByRole("button", { name: "退出登录" }),
|
||||
).toBeInTheDocument();
|
||||
expect(screen.getByText("Test User")).toBeInTheDocument();
|
||||
expect(screen.queryByText("应用内容")).not.toBeInTheDocument();
|
||||
expect(useAuthStore.getState()).toMatchObject({
|
||||
sessionExpired: false,
|
||||
@@ -138,6 +143,27 @@ describe("RefineContext access authentication", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps project recovery available when the selected project is denied", async () => {
|
||||
global.fetch = jest.fn().mockResolvedValue({
|
||||
ok: false,
|
||||
status: 403,
|
||||
headers: new Headers(),
|
||||
json: async () => ({ detail: "No access to project" }),
|
||||
} as Response);
|
||||
|
||||
render(
|
||||
<App>
|
||||
<div>应用内容</div>
|
||||
</App>,
|
||||
);
|
||||
|
||||
expect(await screen.findByText("无权访问当前项目")).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByRole("button", { name: "切换项目" }),
|
||||
).toBeInTheDocument();
|
||||
expect(screen.queryByText("应用内容")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("prioritizes an unauthenticated session over route permissions", async () => {
|
||||
mockSessionState = { data: null, status: "unauthenticated" };
|
||||
|
||||
|
||||
Reference in New Issue
Block a user