mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-08-06 09:28:34 +00:00
fix: avoid initial webui password error
This commit is contained in:
parent
fca1f2ad02
commit
9713fe2a3b
@ -411,7 +411,7 @@ export default function App() {
|
|||||||
if (cancelled) return;
|
if (cancelled) return;
|
||||||
const msg = (e as Error).message;
|
const msg = (e as Error).message;
|
||||||
if (msg.includes("HTTP 401") || msg.includes("HTTP 403")) {
|
if (msg.includes("HTTP 401") || msg.includes("HTTP 403")) {
|
||||||
setState({ status: "auth", failed: true });
|
setState({ status: "auth", failed: !!secret });
|
||||||
} else {
|
} else {
|
||||||
setState({ status: "error", message: msg });
|
setState({ status: "error", message: msg });
|
||||||
}
|
}
|
||||||
@ -433,7 +433,7 @@ export default function App() {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
const msg = (e as Error).message;
|
const msg = (e as Error).message;
|
||||||
if (msg.includes("HTTP 401") || msg.includes("HTTP 403")) {
|
if (msg.includes("HTTP 401") || msg.includes("HTTP 403")) {
|
||||||
setState({ status: "auth", failed: true });
|
setState({ status: "auth", failed: !!bootstrapSecretRef.current });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, tokenRefreshDelayMs(state.tokenExpiresAt));
|
}, tokenRefreshDelayMs(state.tokenExpiresAt));
|
||||||
|
|||||||
@ -256,6 +256,34 @@ describe("App layout", () => {
|
|||||||
vi.useRealTimers();
|
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 () => {
|
it("keeps sidebar layout out of the main thread width contract", async () => {
|
||||||
const { container } = render(<App />);
|
const { container } = render(<App />);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user