Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions e2e-tests/playwright/e2e/auth-providers/oidc.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@

test("Ensure Guest login is disabled when setting environment to production", async () => {
await uiHelper.goToPageUrl("/", "Select a sign-in method");
const singInMethods = await page

Check warning on line 390 in e2e-tests/playwright/e2e/auth-providers/oidc.spec.ts

View workflow job for this annotation

GitHub Actions / TSC, ESLint and Prettier

Usage of raw locator detected. Use methods like .getByRole() or .getByText() instead of raw locators
.locator("div[class^='MuiCardHeader-root']")
.allInnerTexts();
expect(singInMethods).not.toContain("Guest");
Expand Down Expand Up @@ -444,6 +444,73 @@
await context.clearCookies();
});

test(`Enable autologout and user is logged out after inactivity`, async () => {
deployment.setAppConfigProperty("auth.autologout.enabled", "true");
deployment.setAppConfigProperty(
"auth.autologout.idleTimeoutMinutes",
"0.5", // minimum allowed value is 0.5 minutes
);
deployment.setAppConfigProperty(
"auth.autologout.promptBeforeIdleSeconds",
"3",
);
await deployment.updateAllConfigs();
await deployment.restartLocalDeployment();
await page.waitForTimeout(3000);
await deployment.waitForDeploymentReady();
await deployment.waitForSynced();

const login = await common.keycloakLogin(
"zeus",
process.env.DEFAULT_USER_PASSWORD,
);
expect(login).toBe("Login successful");

await uiHelper.verifyTextVisible(
"Logging out due to inactivity",
false,
60000,
);
await page.waitForTimeout(5000);

await page.reload();

const cookies = await context.cookies();
const authCookie = cookies.find(
(cookie) => cookie.name === "oidc-refresh-token",
);
expect(authCookie).toBeUndefined();
});

test(`Enable autologout and user stays logged in after clicking "Don't log me out"`, async () => {
deployment.setAppConfigProperty("auth.autologout.enabled", "true");
deployment.setAppConfigProperty(
"auth.autologout.idleTimeoutMinutes",
"0.5", // minimum allowed value is 0.5 minutes
);
deployment.setAppConfigProperty(
"auth.autologout.promptBeforeIdleSeconds",
"5",
);
await deployment.updateAllConfigs();
await deployment.restartLocalDeployment();
await page.waitForTimeout(3000);
await deployment.waitForDeploymentReady();
await deployment.waitForSynced();

const login = await common.keycloakLogin(
"zeus",
process.env.DEFAULT_USER_PASSWORD,
);
expect(login).toBe("Login successful");

await uiHelper.clickButtonByText("Don't log me out", { timeout: 60000 });

await uiHelper.goToPageUrl("/settings", "Settings");
await uiHelper.verifyHeading("Zeus Giove");
await common.signOut();
});

test.afterAll(async () => {
console.log("[TEST] Starting cleanup...");
await deployment.killRunningProcess();
Expand Down
11 changes: 10 additions & 1 deletion packages/app/src/components/AppBase/AppBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { useContext } from 'react';
import { Route } from 'react-router-dom';

import { FlatRoutes } from '@backstage/core-app-api';
import { AlertDisplay, OAuthRequestDialog } from '@backstage/core-components';
import {
AlertDisplay,
AutoLogout,
OAuthRequestDialog,
} from '@backstage/core-components';
import { ApiExplorerPage } from '@backstage/plugin-api-docs';
import {
CatalogEntityPage,
Expand Down Expand Up @@ -152,6 +156,11 @@ const AppBase = () => {
</Root>
</ApplicationProvider>
</AppRouter>
<AutoLogout
enabled={false}
idleTimeoutMinutes={60}
useWorkerTimers={false}
/>
</AppProvider>
);
};
Expand Down
Loading