mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-10-25 15:55:15 +00:00
Chore(UI): Refactor auth setup to avoid unnecessary logout and login operation (#23064)
* Refactor auth setup to avoid unnecessary logout and login operation * Revert initial setup refactoring * Remove the auth.teardown and logout code from auth.setup * Cleanup logic --------- Co-authored-by: Shailesh Parmar <shailesh.parmar.webdev@gmail.com>
This commit is contained in:
parent
92682f6992
commit
83ba3633ae
@ -64,11 +64,6 @@ export default defineConfig({
|
|||||||
{
|
{
|
||||||
name: 'setup',
|
name: 'setup',
|
||||||
testMatch: '**/*.setup.ts',
|
testMatch: '**/*.setup.ts',
|
||||||
teardown: 'restore-policies',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'restore-policies',
|
|
||||||
testMatch: '**/auth.teardown.ts',
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'chromium',
|
name: 'chromium',
|
||||||
|
|||||||
@ -10,7 +10,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
import { Page, test as setup } from '@playwright/test';
|
import { test as setup } from '@playwright/test';
|
||||||
import {
|
import {
|
||||||
EDIT_DESCRIPTION_RULE,
|
EDIT_DESCRIPTION_RULE,
|
||||||
EDIT_GLOSSARY_TERM_RULE,
|
EDIT_GLOSSARY_TERM_RULE,
|
||||||
@ -71,20 +71,41 @@ const ownerUser = new UserClass({
|
|||||||
|
|
||||||
setup('authenticate all users', async ({ browser }) => {
|
setup('authenticate all users', async ({ browser }) => {
|
||||||
setup.setTimeout(120 * 1000);
|
setup.setTimeout(120 * 1000);
|
||||||
|
// Create separate pages for each user
|
||||||
let adminPage: Page;
|
const [
|
||||||
let dataConsumerPage: Page;
|
adminPage,
|
||||||
let dataStewardPage: Page;
|
dataConsumerPage,
|
||||||
let editDescriptionPage: Page;
|
dataStewardPage,
|
||||||
let editTagsPage: Page;
|
editDescriptionPage,
|
||||||
let editGlossaryTermPage: Page;
|
editTagsPage,
|
||||||
let ownerPage: Page;
|
editGlossaryTermPage,
|
||||||
|
ownerPage,
|
||||||
|
] = await Promise.all([
|
||||||
|
browser.newPage(),
|
||||||
|
browser.newPage(),
|
||||||
|
browser.newPage(),
|
||||||
|
browser.newPage(),
|
||||||
|
browser.newPage(),
|
||||||
|
browser.newPage(),
|
||||||
|
browser.newPage(),
|
||||||
|
]);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Create admin page and context
|
// Create admin page and context
|
||||||
adminPage = await browser.newPage();
|
|
||||||
const admin = new AdminClass();
|
const admin = new AdminClass();
|
||||||
|
|
||||||
await loginAsAdmin(adminPage, admin);
|
await loginAsAdmin(adminPage, admin);
|
||||||
|
|
||||||
|
// Create a new page to login with admin user after token expiry is set to 4 hours
|
||||||
|
// This is done to avoid logging out the user to get the new token
|
||||||
|
const newAdminPage = await browser.newPage();
|
||||||
|
await admin.login(newAdminPage);
|
||||||
|
|
||||||
|
// Close the leftside bar to run tests smoothly
|
||||||
|
await newAdminPage.getByTestId('sidebar-toggle').click();
|
||||||
|
|
||||||
|
await newAdminPage.waitForURL('**/my-data');
|
||||||
|
|
||||||
const { apiContext, afterAction } = await getApiContext(adminPage);
|
const { apiContext, afterAction } = await getApiContext(adminPage);
|
||||||
|
|
||||||
// Create all users, Using allSettled to avoid failing the setup if one of the users fails to create
|
// Create all users, Using allSettled to avoid failing the setup if one of the users fails to create
|
||||||
@ -120,24 +141,7 @@ setup('authenticate all users', async ({ browser }) => {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
// Save admin state
|
// Save admin state
|
||||||
await adminPage.context().storageState({ path: adminFile });
|
await newAdminPage.context().storageState({ path: adminFile });
|
||||||
|
|
||||||
// Create separate pages for each user
|
|
||||||
const [
|
|
||||||
dataConsumerPage,
|
|
||||||
dataStewardPage,
|
|
||||||
editDescriptionPage,
|
|
||||||
editTagsPage,
|
|
||||||
editGlossaryTermPage,
|
|
||||||
ownerPage,
|
|
||||||
] = await Promise.all([
|
|
||||||
browser.newPage(),
|
|
||||||
browser.newPage(),
|
|
||||||
browser.newPage(),
|
|
||||||
browser.newPage(),
|
|
||||||
browser.newPage(),
|
|
||||||
browser.newPage(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
// Save states for each user sequentially to avoid file operation conflicts
|
// Save states for each user sequentially to avoid file operation conflicts
|
||||||
await dataConsumer.login(dataConsumerPage);
|
await dataConsumer.login(dataConsumerPage);
|
||||||
|
|||||||
@ -1,22 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2025 Collate.
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
import { test as teardown } from '@playwright/test';
|
|
||||||
import { AdminClass } from '../support/user/AdminClass';
|
|
||||||
import { resetPolicyChanges } from '../utils/authTeardown';
|
|
||||||
|
|
||||||
teardown('restore the organization roles and policies', async ({ page }) => {
|
|
||||||
const admin = new AdminClass();
|
|
||||||
|
|
||||||
// Reset the default organization roles and policies
|
|
||||||
await resetPolicyChanges(page, admin);
|
|
||||||
});
|
|
||||||
@ -1,91 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2025 Collate.
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
import { APIRequestContext, Page } from '@playwright/test';
|
|
||||||
import {
|
|
||||||
ORGANIZATION_POLICY_RULES,
|
|
||||||
VIEW_ALL_RULE,
|
|
||||||
} from '../constant/permission';
|
|
||||||
import { AdminClass } from '../support/user/AdminClass';
|
|
||||||
import { enableDisableAutoPilotApplication } from './applications';
|
|
||||||
import { getApiContext } from './common';
|
|
||||||
|
|
||||||
export const restoreOrganizationDefaultRole = async (
|
|
||||||
apiContext: APIRequestContext
|
|
||||||
) => {
|
|
||||||
const organizationTeamResponse = await apiContext
|
|
||||||
.get(`/api/v1/teams/name/Organization`)
|
|
||||||
.then((res) => res.json());
|
|
||||||
|
|
||||||
const dataConsumerRoleResponse = await apiContext
|
|
||||||
.get('/api/v1/roles/name/DataConsumer')
|
|
||||||
.then((res) => res.json());
|
|
||||||
|
|
||||||
await apiContext.patch(`/api/v1/teams/${organizationTeamResponse.id}`, {
|
|
||||||
data: [
|
|
||||||
{
|
|
||||||
op: 'replace',
|
|
||||||
path: '/defaultRoles',
|
|
||||||
value: [
|
|
||||||
{
|
|
||||||
id: dataConsumerRoleResponse.id,
|
|
||||||
type: 'role',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json-patch+json',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
export const updateDefaultOrganizationPolicy = async (
|
|
||||||
apiContext: APIRequestContext
|
|
||||||
) => {
|
|
||||||
const orgPolicyResponse = await apiContext
|
|
||||||
.get('/api/v1/policies/name/OrganizationPolicy')
|
|
||||||
.then((response) => response.json());
|
|
||||||
|
|
||||||
await apiContext.patch(`/api/v1/policies/${orgPolicyResponse.id}`, {
|
|
||||||
data: [
|
|
||||||
{
|
|
||||||
op: 'replace',
|
|
||||||
path: '/rules',
|
|
||||||
value: [...ORGANIZATION_POLICY_RULES, ...VIEW_ALL_RULE],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json-patch+json',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const restoreRolesAndPolicies = async (page: Page) => {
|
|
||||||
const { apiContext, afterAction } = await getApiContext(page);
|
|
||||||
// Remove organization policy and role
|
|
||||||
await restoreOrganizationDefaultRole(apiContext);
|
|
||||||
// update default Organization policy
|
|
||||||
await updateDefaultOrganizationPolicy(apiContext);
|
|
||||||
// enable the AutoPilot application
|
|
||||||
await enableDisableAutoPilotApplication(apiContext);
|
|
||||||
|
|
||||||
await afterAction();
|
|
||||||
};
|
|
||||||
|
|
||||||
export const resetPolicyChanges = async (page: Page, admin: AdminClass) => {
|
|
||||||
await admin.login(page);
|
|
||||||
await page.waitForURL('**/my-data');
|
|
||||||
await restoreRolesAndPolicies(page);
|
|
||||||
await admin.logout(page);
|
|
||||||
await page.waitForURL('**/signin');
|
|
||||||
};
|
|
||||||
@ -44,13 +44,7 @@ const initialSetup = async (page: Page) => {
|
|||||||
export const loginAsAdmin = async (page: Page, admin: AdminClass) => {
|
export const loginAsAdmin = async (page: Page, admin: AdminClass) => {
|
||||||
await admin.login(page);
|
await admin.login(page);
|
||||||
await page.waitForURL('**/my-data');
|
await page.waitForURL('**/my-data');
|
||||||
|
|
||||||
|
// Setup policy and increase the token expiry time
|
||||||
await initialSetup(page);
|
await initialSetup(page);
|
||||||
await admin.logout(page);
|
|
||||||
await page.waitForURL('**/signin');
|
|
||||||
await admin.login(page);
|
|
||||||
|
|
||||||
// Close the leftside bar to run tests smoothly
|
|
||||||
await page.getByTestId('sidebar-toggle').click();
|
|
||||||
|
|
||||||
await page.waitForURL('**/my-data');
|
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user