Skip to content

Commit 7729d62

Browse files
authored
fix: hide default credentials warning when basic auth disabled (#3111)
## Summary - The sidebar's `DefaultCredentialsWarning` was still shown even when basic auth was disabled via `ARCHESTRA_AUTH_DISABLE_BASIC_AUTH`. The sign-in page already had the correct `!isBasicAuthDisabled` guard but the sidebar (`SidebarWarnings`) was missing it. - Added `!config.disableBasicAuth` check to `showDefaultCredsWarning` in `SidebarWarnings`
1 parent 4ba0e0c commit 7729d62

File tree

3 files changed

+68
-4
lines changed

3 files changed

+68
-4
lines changed

platform/frontend/src/app/auth/[path]/auth-page-with-invitation-check.test.tsx

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,21 @@ vi.mock("@/lib/backend-connectivity", () => ({
2222
}));
2323

2424
// Mock config
25+
const mockConfig = {
26+
disableBasicAuth: false,
27+
enterpriseLicenseActivated: false,
28+
};
29+
2530
vi.mock("@/lib/config", () => ({
26-
default: {
27-
disableBasicAuth: false,
28-
enterpriseLicenseActivated: false,
29-
},
31+
default: new Proxy(
32+
{},
33+
{
34+
get: (_target, prop) =>
35+
prop in mockConfig
36+
? mockConfig[prop as keyof typeof mockConfig]
37+
: undefined,
38+
},
39+
),
3040
}));
3141

3242
// Mock AuthViewWithErrorHandling
@@ -68,6 +78,8 @@ const mockRetry = vi.fn();
6878
describe("AuthPageWithInvitationCheck", () => {
6979
beforeEach(() => {
7080
vi.clearAllMocks();
81+
mockConfig.disableBasicAuth = false;
82+
mockConfig.enterpriseLicenseActivated = false;
7183
vi.mocked(useRouter).mockReturnValue({
7284
push: mockRouterPush,
7385
} as unknown as ReturnType<typeof useRouter>);
@@ -128,6 +140,23 @@ describe("AuthPageWithInvitationCheck", () => {
128140
).not.toBeInTheDocument();
129141
});
130142

143+
it("should not show default credentials warning when basic auth is disabled", () => {
144+
mockConfig.disableBasicAuth = true;
145+
vi.mocked(useSearchParams).mockReturnValue({
146+
get: vi.fn().mockReturnValue(null),
147+
} as unknown as ReturnType<typeof useSearchParams>);
148+
vi.mocked(useInvitationCheck).mockReturnValue({
149+
data: undefined,
150+
isLoading: false,
151+
} as ReturnType<typeof useInvitationCheck>);
152+
153+
render(<AuthPageWithInvitationCheck path="sign-in" />);
154+
155+
expect(
156+
screen.queryByTestId("default-credentials-warning"),
157+
).not.toBeInTheDocument();
158+
});
159+
131160
it("should show welcome back message for existing users with invitation", () => {
132161
vi.mocked(useSearchParams).mockReturnValue({
133162
get: vi.fn((key: string) => (key === "invitationId" ? "inv123" : null)),

platform/frontend/src/components/sidebar-warnings.test.tsx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,22 @@ vi.mock("@/lib/config.query", () => ({
2121
useFeatures: (...args: unknown[]) => mockUseFeatures(...args),
2222
}));
2323

24+
const mockConfig = {
25+
disableBasicAuth: false,
26+
};
27+
28+
vi.mock("@/lib/config", () => ({
29+
default: new Proxy(
30+
{},
31+
{
32+
get: (_target, prop) =>
33+
prop in mockConfig
34+
? mockConfig[prop as keyof typeof mockConfig]
35+
: undefined,
36+
},
37+
),
38+
}));
39+
2440
vi.mock("@shared", () => ({
2541
DEFAULT_ADMIN_EMAIL: "admin@example.com",
2642
DEFAULT_ADMIN_PASSWORD: "admin",
@@ -40,6 +56,7 @@ import { SidebarWarnings } from "./sidebar-warnings";
4056
describe("SidebarWarnings", () => {
4157
beforeEach(() => {
4258
vi.clearAllMocks();
59+
mockConfig.disableBasicAuth = false;
4360

4461
// Default: no session, no warnings
4562
mockUseSession.mockReturnValue({ data: null });
@@ -150,6 +167,22 @@ describe("SidebarWarnings", () => {
150167
expect(container.firstChild).toBeNull();
151168
});
152169

170+
it("does not show when basic auth is disabled", () => {
171+
mockConfig.disableBasicAuth = true;
172+
mockUseSession.mockReturnValue({
173+
data: { user: { email: "admin@example.com" } },
174+
});
175+
mockUseDefaultCredentialsEnabled.mockReturnValue({
176+
data: true,
177+
isLoading: false,
178+
});
179+
180+
const { container } = render(<SidebarWarnings />);
181+
expect(
182+
screen.queryByTestId("default-credentials-warning"),
183+
).not.toBeInTheDocument();
184+
});
185+
153186
it("does not show when credentials are not default", () => {
154187
mockUseSession.mockReturnValue({
155188
data: { user: { email: "admin@example.com" } },

platform/frontend/src/components/sidebar-warnings.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Link from "next/link";
66
import { DefaultCredentialsWarning } from "@/components/default-credentials-warning";
77
import { useDefaultCredentialsEnabled } from "@/lib/auth.query";
88
import { authClient } from "@/lib/clients/auth/auth-client";
9+
import config from "@/lib/config";
910
import { useFeatures } from "@/lib/config.query";
1011

1112
export function SidebarWarnings() {
@@ -21,6 +22,7 @@ export function SidebarWarnings() {
2122
const showSecurityEngineWarning =
2223
!!session && !isLoadingFeatures && features !== undefined && isPermissive;
2324
const showDefaultCredsWarning =
25+
!config.disableBasicAuth &&
2426
!isLoadingCreds &&
2527
defaultCredentialsEnabled !== undefined &&
2628
defaultCredentialsEnabled &&

0 commit comments

Comments
 (0)