From e406ed9a3fe0ea71bc1cff7cd3c183ba9a89aa73 Mon Sep 17 00:00:00 2001 From: Shailesh Parmar Date: Thu, 28 Nov 2024 15:35:07 +0530 Subject: [PATCH 1/2] playwright: fixed service ingestion aut --- .../ui/playwright/support/entity/ingestion/ServiceBaseClass.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openmetadata-ui/src/main/resources/ui/playwright/support/entity/ingestion/ServiceBaseClass.ts b/openmetadata-ui/src/main/resources/ui/playwright/support/entity/ingestion/ServiceBaseClass.ts index 6b0afb54bcb4..ea7dcdd11623 100644 --- a/openmetadata-ui/src/main/resources/ui/playwright/support/entity/ingestion/ServiceBaseClass.ts +++ b/openmetadata-ui/src/main/resources/ui/playwright/support/entity/ingestion/ServiceBaseClass.ts @@ -170,7 +170,7 @@ class ServiceBaseClass { // Header available once page loads await page.waitForSelector('[data-testid="data-assets-header"]'); - await page.getByTestId('loader').waitFor({ state: 'detached' }); + await page.getByTestId('loader').first().waitFor({ state: 'detached' }); await page.getByTestId('ingestions').click(); await page .getByLabel('Ingestions') From 3baa7460201d4324121923b8294a19a2ad18a691 Mon Sep 17 00:00:00 2001 From: Shailesh Parmar Date: Thu, 28 Nov 2024 17:43:38 +0530 Subject: [PATCH 2/2] updated the initial start of the playwright test --- .../ui/playwright/constant/permission.ts | 42 ++++++++++++++++ .../resources/ui/playwright/e2e/auth.setup.ts | 25 ++++++++-- .../support/access-control/PoliciesClass.ts | 2 + .../ui/playwright/utils/permission.ts | 48 ++++++++++++++++++- 4 files changed, 111 insertions(+), 6 deletions(-) diff --git a/openmetadata-ui/src/main/resources/ui/playwright/constant/permission.ts b/openmetadata-ui/src/main/resources/ui/playwright/constant/permission.ts index f8f6515de1c5..b4dccdce8030 100644 --- a/openmetadata-ui/src/main/resources/ui/playwright/constant/permission.ts +++ b/openmetadata-ui/src/main/resources/ui/playwright/constant/permission.ts @@ -62,6 +62,48 @@ export const DATA_STEWARD_RULES: PolicyRulesType[] = [ }, ]; +export const DATA_CONSUMER_RULES: PolicyRulesType[] = [ + { + name: 'DataConsumerPolicy-EditRule', + resources: ['All'], + operations: [ + 'EditDescription', + 'EditGlossaryTerms', + 'EditTags', + 'EditTier', + 'ViewAll', + ], + effect: 'allow', + }, +]; + +export const ORGANIZATION_POLICY_RULES: PolicyRulesType[] = [ + { + name: 'OrganizationPolicy-NoOwner-Rule', + description: + 'Allow any one to set the owner of an entity that has no owner set.', + effect: 'allow', + operations: ['EditOwners'], + resources: ['All'], + condition: 'noOwner()', + }, + { + name: 'OrganizationPolicy-Owner-Rule', + description: 'Allow all the operations on an entity for the owner.', + effect: 'allow', + operations: ['All'], + resources: ['All'], + condition: 'isOwner()', + }, + { + name: 'OrganizationPolicy-ViewAll-Rule', + description: 'Allow all users to discover data assets.', + effect: 'allow', + operations: ['ViewAll'], + resources: ['All'], + }, +]; + export const GLOBAL_SETTING_PERMISSIONS: Record< string, { testid: GlobalSettingOptions; isCustomProperty?: boolean } diff --git a/openmetadata-ui/src/main/resources/ui/playwright/e2e/auth.setup.ts b/openmetadata-ui/src/main/resources/ui/playwright/e2e/auth.setup.ts index 8894062b2f7e..fc6b43f36141 100644 --- a/openmetadata-ui/src/main/resources/ui/playwright/e2e/auth.setup.ts +++ b/openmetadata-ui/src/main/resources/ui/playwright/e2e/auth.setup.ts @@ -10,24 +10,39 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { test as setup } from '@playwright/test'; +import { Page, test as setup } from '@playwright/test'; import { JWT_EXPIRY_TIME_MAP } from '../constant/login'; import { AdminClass } from '../support/user/AdminClass'; import { getApiContext } from '../utils/common'; import { updateJWTTokenExpiryTime } from '../utils/login'; +import { + updateDefaultDataConsumerPolicy, + updateDefaultOrganizationPolicy, +} from '../utils/permission'; import { removeOrganizationPolicyAndRole } from '../utils/team'; const adminFile = 'playwright/.auth/admin.json'; +const initialSetup = async (page: Page) => { + const { apiContext, afterAction } = await getApiContext(page); + // Update JWT expiry time to 4 hours + await updateJWTTokenExpiryTime(apiContext, JWT_EXPIRY_TIME_MAP['4 hours']); + // Remove organization policy and role + await removeOrganizationPolicyAndRole(apiContext); + // update default Organization policy + await updateDefaultOrganizationPolicy(apiContext); + // update default Data consumer policy + await updateDefaultDataConsumerPolicy(apiContext); + + await afterAction(); +}; + setup('authenticate as admin', async ({ page }) => { const admin = new AdminClass(); // login with admin user await admin.login(page); await page.waitForURL('**/my-data'); - const { apiContext, afterAction } = await getApiContext(page); - await updateJWTTokenExpiryTime(apiContext, JWT_EXPIRY_TIME_MAP['4 hours']); - await removeOrganizationPolicyAndRole(apiContext); - await afterAction(); + await initialSetup(page); await admin.logout(page); await page.waitForURL('**/signin'); await admin.login(page); diff --git a/openmetadata-ui/src/main/resources/ui/playwright/support/access-control/PoliciesClass.ts b/openmetadata-ui/src/main/resources/ui/playwright/support/access-control/PoliciesClass.ts index 08853690bcf0..abf90b38e9d6 100644 --- a/openmetadata-ui/src/main/resources/ui/playwright/support/access-control/PoliciesClass.ts +++ b/openmetadata-ui/src/main/resources/ui/playwright/support/access-control/PoliciesClass.ts @@ -27,6 +27,8 @@ export type PolicyRulesType = { resources: string[]; operations: string[]; effect: string; + description?: string; + condition?: string; }; export class PolicyClass { diff --git a/openmetadata-ui/src/main/resources/ui/playwright/utils/permission.ts b/openmetadata-ui/src/main/resources/ui/playwright/utils/permission.ts index 26fabc27009a..e37b9ea0d801 100644 --- a/openmetadata-ui/src/main/resources/ui/playwright/utils/permission.ts +++ b/openmetadata-ui/src/main/resources/ui/playwright/utils/permission.ts @@ -10,7 +10,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { expect, Page } from '@playwright/test'; +import { APIRequestContext, expect, Page } from '@playwright/test'; +import { + DATA_CONSUMER_RULES, + ORGANIZATION_POLICY_RULES, +} from '../constant/permission'; export const checkNoPermissionPlaceholder = async ( page: Page, @@ -117,3 +121,45 @@ export const validateViewPermissions = async ( await page.waitForLoadState('domcontentloaded'); await checkNoPermissionPlaceholder(page, /Custom Properties/); }; + +export const updateDefaultDataConsumerPolicy = async ( + apiContext: APIRequestContext +) => { + const dataConsumerRoleResponse = await apiContext + .get('/api/v1/policies/name/DataConsumerPolicy') + .then((response) => response.json()); + + await apiContext.patch(`/api/v1/policies/${dataConsumerRoleResponse.id}`, { + data: [ + { + op: 'replace', + path: '/rules', + value: DATA_CONSUMER_RULES, + }, + ], + 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, + }, + ], + headers: { + 'Content-Type': 'application/json-patch+json', + }, + }); +};