fix: avoid initial webui password error

This commit is contained in:
chengyongru
2026-06-22 13:04:05 +08:00
committed by Xubin Ren
parent fca1f2ad02
commit 9713fe2a3b
2 changed files with 30 additions and 2 deletions
+2 -2
View File
@@ -411,7 +411,7 @@ export default function App() {
if (cancelled) return;
const msg = (e as Error).message;
if (msg.includes("HTTP 401") || msg.includes("HTTP 403")) {
setState({ status: "auth", failed: true });
setState({ status: "auth", failed: !!secret });
} else {
setState({ status: "error", message: msg });
}
@@ -433,7 +433,7 @@ export default function App() {
} catch (e) {
const msg = (e as Error).message;
if (msg.includes("HTTP 401") || msg.includes("HTTP 403")) {
setState({ status: "auth", failed: true });
setState({ status: "auth", failed: !!bootstrapSecretRef.current });
}
}
}, tokenRefreshDelayMs(state.tokenExpiresAt));
+28
View File
@@ -256,6 +256,34 @@ describe("App layout", () => {
vi.useRealTimers();
});
it("shows the auth form without an invalid-password error on first load", async () => {
vi.mocked(fetchBootstrap).mockRejectedValueOnce(
new Error("bootstrap failed: HTTP 401"),
);
render(<App />);
expect(await screen.findByText("Authentication required")).toBeInTheDocument();
expect(screen.queryByText("Invalid password. Try again.")).not.toBeInTheDocument();
expect(connectSpy).not.toHaveBeenCalled();
});
it("shows an invalid-password error after a submitted password is rejected", async () => {
vi.mocked(fetchBootstrap).mockRejectedValue(
new Error("bootstrap failed: HTTP 401"),
);
render(<App />);
const password = await screen.findByPlaceholderText("Password");
fireEvent.change(password, { target: { value: "wrong-password" } });
fireEvent.click(screen.getByRole("button", { name: "Connect" }));
expect(await screen.findByText("Invalid password. Try again.")).toBeInTheDocument();
expect(fetchBootstrap).toHaveBeenLastCalledWith("", "wrong-password");
expect(connectSpy).not.toHaveBeenCalled();
});
it("keeps sidebar layout out of the main thread width contract", async () => {
const { container } = render(<App />);