Skip to content

Commit a1e6d52

Browse files
authored
chore(e2e): add tests to 'sessionDuration' auth config (#2612)
Signed-off-by: Jessica He <[email protected]>
1 parent 01fb56c commit a1e6d52

File tree

4 files changed

+244
-56
lines changed

4 files changed

+244
-56
lines changed

e2e-tests/playwright/e2e/authProviders/github-provider.spec.ts

+82-12
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@ import { HelmActions } from "../../utils/helm";
2020
import { RhdhAuthUiHack } from "../../support/api/rhdh-auth-hack";
2121

2222
let page: Page;
23+
const githubFlags = [
24+
"--set upstream.backstage.appConfig.signInPage=github",
25+
"--set upstream.backstage.appConfig.auth.environment=production",
26+
"--set upstream.backstage.appConfig.catalog.providers.microsoftGraphOrg=null",
27+
"--set upstream.backstage.appConfig.catalog.providers.keycloakOrg=null",
28+
"--set upstream.backstage.appConfig.auth.providers.microsoft=null",
29+
"--set upstream.backstage.appConfig.auth.providers.oidc=null",
30+
"--set global.dynamic.plugins[1].disabled=false",
31+
"--set global.dynamic.plugins[3].disabled=false",
32+
"--set upstream.backstage.appConfig.permission.enabled=true",
33+
"--set upstream.postgresql.primary.persistence.enabled=false",
34+
];
2335

2436
test.describe("Standard authentication providers: Github Provider", () => {
2537
test.use({ baseURL: constants.AUTH_PROVIDERS_BASE_URL });
@@ -43,18 +55,40 @@ test.describe("Standard authentication providers: Github Provider", () => {
4355

4456
LOGGER.info(`Base Url is ${process.env.BASE_URL}`);
4557
LOGGER.info(
46-
`Starting scenario: Standard authentication providers: Basic authentication: attemp #${testInfo.retry}`,
58+
`Starting scenario: Standard authentication providers: Basic authentication: attempt #${testInfo.retry}`,
4759
);
4860

4961
await ghHelper.setupGithubEnvironment();
5062
});
5163

5264
test("Setup Github authentication provider and wait for first sync", async () => {
53-
test.setTimeout(300 * 1000);
65+
test.setTimeout(600 * 1000);
5466
LOGGER.info(
5567
"Execute testcase: Setup Github authentication provider and wait for first sync",
5668
);
5769

70+
await HelmActions.upgradeHelmChartWithWait(
71+
constants.AUTH_PROVIDERS_RELEASE,
72+
constants.AUTH_PROVIDERS_CHART,
73+
constants.AUTH_PROVIDERS_NAMESPACE,
74+
constants.AUTH_PROVIDERS_VALUES_FILE,
75+
constants.CHART_VERSION,
76+
constants.QUAY_REPO,
77+
constants.TAG_NAME,
78+
githubFlags,
79+
);
80+
81+
await waitForNextSync("github", syncTime);
82+
});
83+
84+
test("Set sessionDuration and confirm in auth cookie duration has been set", async () => {
85+
LOGGER.info(`Executing testcase: ${test.info().title}`);
86+
87+
test.setTimeout(600 * 1000);
88+
if (test.info().retry > 0) {
89+
await waitForNextSync("github", syncTime);
90+
}
91+
5892
await HelmActions.upgradeHelmChartWithWait(
5993
constants.AUTH_PROVIDERS_RELEASE,
6094
constants.AUTH_PROVIDERS_CHART,
@@ -64,20 +98,56 @@ test.describe("Standard authentication providers: Github Provider", () => {
6498
constants.QUAY_REPO,
6599
constants.TAG_NAME,
66100
[
67-
"--set upstream.backstage.appConfig.signInPage=github",
68-
"--set upstream.backstage.appConfig.auth.environment=production",
69-
"--set upstream.backstage.appConfig.catalog.providers.microsoftGraphOrg=null",
70-
"--set upstream.backstage.appConfig.catalog.providers.keycloakOrg=null",
71-
"--set upstream.backstage.appConfig.auth.providers.microsoft=null",
72-
"--set upstream.backstage.appConfig.auth.providers.oidc=null",
73-
"--set global.dynamic.plugins[1].disabled=false",
74-
"--set global.dynamic.plugins[3].disabled=false",
75-
"--set upstream.backstage.appConfig.permission.enabled=true",
76-
"--set upstream.postgresql.primary.persistence.enabled=false",
101+
...githubFlags,
102+
"--set upstream.backstage.appConfig.auth.providers.github.production.sessionDuration=3days",
77103
],
78104
);
79105

80106
await waitForNextSync("github", syncTime);
107+
108+
await page.goto("/");
109+
await uiHelper.verifyHeading("Select a sign-in method");
110+
const singInMethods = await page
111+
.locator("div[class^='MuiCardHeader-root']")
112+
.allInnerTexts();
113+
expect(singInMethods).not.toContain("Guest");
114+
115+
await common.githubLogin(
116+
constants.GH_USERS["admin"].name,
117+
constants.GH_USER_PASSWORD,
118+
constants.AUTH_PROVIDERS_GH_ADMIN_2FA,
119+
);
120+
121+
await expect(async () => {
122+
expect(
123+
await common.CheckUserIsIngestedInCatalog(
124+
[constants.GH_USERS["user_1"].displayName],
125+
constants.STATIC_API_TOKEN,
126+
),
127+
).toBe(true);
128+
}).toPass({
129+
intervals: [1_000, 2_000, 5_000],
130+
timeout: 90 * 1000,
131+
});
132+
133+
await page.reload();
134+
135+
const cookies = await context.cookies();
136+
const authCookie = cookies.find(
137+
(cookie) => cookie.name === "github-refresh-token",
138+
);
139+
140+
const threeDays = 3 * 24 * 60 * 60 * 1000; // expected duration of 3 days in ms
141+
const tolerance = 3 * 60 * 1000; // allow for 3 minutes tolerance
142+
143+
const actualDuration = authCookie.expires * 1000 - Date.now();
144+
145+
expect(actualDuration).toBeGreaterThan(threeDays - tolerance);
146+
expect(actualDuration).toBeLessThan(threeDays + tolerance);
147+
148+
await uiHelper.goToSettingsPage();
149+
await common.signOut();
150+
await context.clearCookies();
81151
});
82152

83153
test("Github with default resolver: user should login and entity is in the catalog", async () => {

e2e-tests/playwright/e2e/authProviders/microsoft-provider.spec.ts

+88-30
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,35 @@ import { HelmActions } from "../../utils/helm";
2222
import { RhdhAuthUiHack } from "../../support/api/rhdh-auth-hack";
2323

2424
let page: Page;
25+
const oauthFlags = [
26+
"--set upstream.backstage.appConfig.auth.providers.github=null",
27+
"--set upstream.backstage.appConfig.signInPage=microsoft",
28+
"--set upstream.backstage.appConfig.auth.environment=production",
29+
"--set upstream.backstage.appConfig.catalog.providers.githubOrg=null",
30+
"--set upstream.backstage.appConfig.catalog.providers.keycloakOrg=null",
31+
"--set global.dynamic.plugins[2].disabled=false",
32+
"--set global.dynamic.plugins[3].disabled=false",
33+
"--set upstream.backstage.appConfig.permission.enabled=true",
34+
];
35+
36+
const oidcFlags = [
37+
"--set upstream.backstage.appConfig.auth.providers.github=null",
38+
"--set upstream.backstage.appConfig.signInPage=oidc",
39+
"--set upstream.backstage.appConfig.auth.environment=production",
40+
"--set upstream.backstage.appConfig.catalog.providers.githubOrg=null",
41+
"--set upstream.backstage.appConfig.catalog.providers.keycloakOrg=null",
42+
"--set global.dynamic.plugins[2].disabled=false",
43+
"--set global.dynamic.plugins[3].disabled=false",
44+
"--set upstream.backstage.appConfig.permission.enabled=true",
45+
"--set upstream.backstage.appConfig.auth.providers.oidc.production.metadataUrl=https://login.microsoftonline.com/${AUTH_PROVIDERS_AZURE_TENANT_ID}/.well-known/openid-configuration",
46+
"--set upstream.backstage.appConfig.auth.providers.oidc.production.tenantId=${AUTH_PROVIDERS_AZURE_TENANT_ID}",
47+
"--set upstream.backstage.appConfig.auth.providers.oidc.production.clientId=${AUTH_PROVIDERS_AZURE_CLIENT_ID}",
48+
"--set upstream.backstage.appConfig.auth.providers.oidc.production.clientSecret=${AUTH_PROVIDERS_AZURE_CLIENT_SECRET}",
49+
"--set upstream.backstage.appConfig.auth.providers.oidc.production.prompt=auto",
50+
"--set upstream.backstage.appConfig.auth.providers.oidc.production.callbackUrl=${BASE_URL}/api/auth/oidc/handler/frame",
51+
"--set upstream.backstage.appConfig.auth.providers.oidc.production.signIn.resolvers[0].resolver=emailMatchingUserEntityProfileEmail",
52+
"--set upstream.backstage.appConfig.auth.providers.oidc.production.signIn.resolvers[0].dangerouslyAllowSignInWithoutUserInCatalog=true",
53+
];
2554

2655
test.describe("Standard authentication providers: Micorsoft Azure EntraID", () => {
2756
test.use({ baseURL: constants.AUTH_PROVIDERS_BASE_URL });
@@ -36,7 +65,7 @@ test.describe("Standard authentication providers: Micorsoft Azure EntraID", () =
3665
test.beforeAll(async ({ browser }, testInfo) => {
3766
test.setTimeout(120 * 1000);
3867
LOGGER.info(
39-
`Staring scenario: Standard authentication providers: Micorsoft Azure EntraID: attemp #${testInfo.retry}`,
68+
`Staring scenario: Standard authentication providers: Microsoft Azure EntraID: attempt #${testInfo.retry}`,
4069
);
4170

4271
const browserSetup = await setupBrowser(browser, testInfo);
@@ -66,35 +95,6 @@ test.describe("Standard authentication providers: Micorsoft Azure EntraID", () =
6695
test("Setup RHDH with Microsoft EntraID ingestion and eventually wait for the first sync", async () => {
6796
test.setTimeout(600 * 1000);
6897
const oidcFlow = false;
69-
const oauthFlags = [
70-
"--set upstream.backstage.appConfig.auth.providers.github=null",
71-
"--set upstream.backstage.appConfig.signInPage=microsoft",
72-
"--set upstream.backstage.appConfig.auth.environment=production",
73-
"--set upstream.backstage.appConfig.catalog.providers.githubOrg=null",
74-
"--set upstream.backstage.appConfig.catalog.providers.keycloakOrg=null",
75-
"--set global.dynamic.plugins[2].disabled=false",
76-
"--set global.dynamic.plugins[3].disabled=false",
77-
"--set upstream.backstage.appConfig.permission.enabled=true",
78-
];
79-
80-
const oidcFlags = [
81-
"--set upstream.backstage.appConfig.auth.providers.github=null",
82-
"--set upstream.backstage.appConfig.signInPage=oidc",
83-
"--set upstream.backstage.appConfig.auth.environment=production",
84-
"--set upstream.backstage.appConfig.catalog.providers.githubOrg=null",
85-
"--set upstream.backstage.appConfig.catalog.providers.keycloakOrg=null",
86-
"--set global.dynamic.plugins[2].disabled=false",
87-
"--set global.dynamic.plugins[3].disabled=false",
88-
"--set upstream.backstage.appConfig.permission.enabled=true",
89-
"--set upstream.backstage.appConfig.auth.providers.oidc.production.metadataUrl=https://login.microsoftonline.com/${AUTH_PROVIDERS_AZURE_TENANT_ID}/.well-known/openid-configuration",
90-
"--set upstream.backstage.appConfig.auth.providers.oidc.production.tenantId=${AUTH_PROVIDERS_AZURE_TENANT_ID}",
91-
"--set upstream.backstage.appConfig.auth.providers.oidc.production.clientId=${AUTH_PROVIDERS_AZURE_CLIENT_ID}",
92-
"--set upstream.backstage.appConfig.auth.providers.oidc.production.clientSecret=${AUTH_PROVIDERS_AZURE_CLIENT_SECRET}",
93-
"--set upstream.backstage.appConfig.auth.providers.oidc.production.prompt=auto",
94-
"--set upstream.backstage.appConfig.auth.providers.oidc.production.callbackUrl=${BASE_URL}/api/auth/oidc/handler/frame",
95-
"--set upstream.backstage.appConfig.auth.providers.oidc.production.signIn.resolvers[0].resolver=emailMatchingUserEntityProfileEmail",
96-
"--set upstream.backstage.appConfig.auth.providers.oidc.production.signIn.resolvers[0].dangerouslyAllowSignInWithoutUserInCatalog=true",
97-
];
9898
// setup RHSSO provider with user ingestion
9999
await HelmActions.upgradeHelmChartWithWait(
100100
constants.AUTH_PROVIDERS_RELEASE,
@@ -110,6 +110,64 @@ test.describe("Standard authentication providers: Micorsoft Azure EntraID", () =
110110
await waitForNextSync("microsoft", syncTime);
111111
});
112112

113+
test("Set sessionDuration and confirm in auth cookie duration has been set", async () => {
114+
LOGGER.info(`Executing testcase: ${test.info().title}`);
115+
116+
test.setTimeout(600 * 1000);
117+
118+
await HelmActions.upgradeHelmChartWithWait(
119+
constants.AUTH_PROVIDERS_RELEASE,
120+
constants.AUTH_PROVIDERS_CHART,
121+
constants.AUTH_PROVIDERS_NAMESPACE,
122+
constants.AUTH_PROVIDERS_VALUES_FILE,
123+
constants.CHART_VERSION,
124+
constants.QUAY_REPO,
125+
constants.TAG_NAME,
126+
[
127+
...oauthFlags,
128+
"--set upstream.backstage.appConfig.auth.providers.microsoft.production.sessionDuration=3days",
129+
],
130+
);
131+
132+
await waitForNextSync("microsoft", syncTime);
133+
134+
await common.MicrosoftAzureLogin(
135+
constants.MSGRAPH_USERS["user_1"].userPrincipalName,
136+
constants.RHSSO76_DEFAULT_PASSWORD,
137+
);
138+
139+
await expect(async () => {
140+
expect(
141+
await common.CheckUserIsIngestedInCatalog(
142+
[constants.MSGRAPH_USERS["user_1"].displayName],
143+
constants.STATIC_API_TOKEN,
144+
),
145+
).toBe(true);
146+
}).toPass({
147+
intervals: [1_000, 2_000, 5_000],
148+
timeout: 90 * 1000,
149+
});
150+
151+
await page.reload();
152+
153+
const cookies = await context.cookies();
154+
const authCookie = cookies.find(
155+
(cookie) => cookie.name === "microsoft-refresh-token",
156+
);
157+
158+
const threeDays = 3 * 24 * 60 * 60 * 1000; // expected duration of 3 days in ms
159+
const tolerance = 3 * 60 * 1000; // allow for 3 minutes tolerance
160+
161+
const actualDuration = authCookie.expires * 1000 - Date.now();
162+
163+
expect(actualDuration).toBeGreaterThan(threeDays - tolerance);
164+
expect(actualDuration).toBeLessThan(threeDays + tolerance);
165+
166+
await uiHelper.goToSettingsPage();
167+
await common.signOut();
168+
await context.clearCookies();
169+
});
170+
113171
test("Microsoft EntraID with default resolver: user_1 should login and entity is in the catalog", async () => {
114172
// resolvers from upstream are not available in rhdh
115173
// testing only default settings

0 commit comments

Comments
 (0)