Skip to content

Commit

Permalink
PMM-7 added auth method
Browse files Browse the repository at this point in the history
  • Loading branch information
Vadym Yarosh committed Aug 21, 2023
1 parent b77dc22 commit bfc7511
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 76 deletions.
2 changes: 1 addition & 1 deletion playwright-tests/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
// { "blankLine": "any", "prev": ["const", "let", "var"], "next": ["const", "let", "var"] }
],
"object-curly-newline": ["warn", {
"ObjectExpression": { "multiline": true, "minProperties": 1},
"ObjectExpression": { "multiline": true, "minProperties": 3},
"ObjectPattern": { "multiline": true },
"ImportDeclaration": { "multiline": true, "minProperties": 4 },
"ExportDeclaration": { "multiline": true, "minProperties": 4 }
Expand Down
1 change: 1 addition & 0 deletions playwright-tests/helpers/grafana-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const grafanaHelper = {
const authToken = await this.getToken(username, password);
await page.setExtraHTTPHeaders({ Authorization: `Basic ${authToken}` });
await page.reload();
return page;
},

async unAuthorize(page: Page) {
Expand Down
4 changes: 0 additions & 4 deletions playwright-tests/helpers/test-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,5 @@ export const test = base.extend<PagesCollection>({
usersConfigurationPage: async ({ page }, use) => {
await use(new UsersConfigurationPage(page));
},

// authenticateSession: async ({ page: Page }) => {
// await grafanaHelper.authorize(page);
// },
});
export { expect } from '@playwright/test';
9 changes: 9 additions & 0 deletions playwright-tests/pages/common.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { LeftNavigationMenu } from '@components/left-navigation-menu';
import { Toast } from '@components/toast';
import OptionsMenu from '@components/options-menu';
import { expect } from '@helpers/test-helper';
import grafanaHelper from "@helpers/grafana-helper";

export class CommonPage {
toast = new Toast(this.page);
Expand All @@ -29,6 +30,14 @@ export class CommonPage {

constructor(public readonly page: Page) {}

/**
* Authenticates current page at grafana level
*/
authenticateSession = async () => {
await grafanaHelper.authorize(this.page);
return this;
};

/**
* To open Page with specified path by entering url into the address field.
* Including all required checks
Expand Down
132 changes: 61 additions & 71 deletions playwright-tests/tests/portal/connectPmm.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,64 +22,57 @@ test.describe('Spec file for connecting PMM to the portal', async () => {
await apiHelper.confirmTour(page);
});

test(
'PMM-T809 PMM-T398 Verify Percona Platform elements on PMM Settings'
+ ' Page @portal @pre-pmm-portal-upgrade',
async ({ page, perconaPlatformPage }) => {
test.skip(pmmVersion < 27, 'This test is for PMM version 2.27.0 and higher');

await test.step('1. Open Percona Platform tab in PMM Settings', async () => {
await grafanaHelper.authorize(page);
await perconaPlatformPage.open();
});

await test.step('2. Verify all required element are displayed.', async () => {
await expect(perconaPlatformPage.elements.pmmServerIdHeader)
.toHaveText(perconaPlatformPage.labels.pmmServerId, { ignoreCase: true });
await expect(perconaPlatformPage.elements.pmmServerNameHeader).toHaveText(perconaPlatformPage.labels.pmmServerName);
await expect(perconaPlatformPage.elements.accessTokenHeader).toHaveText(perconaPlatformPage.labels.accessToken);
if (pmmVersion >= 35) {
await expect(perconaPlatformPage.buttons.createPerconaAccount).toHaveAttribute('href', perconaPlatformPage.links.portalLogin);
await expect(perconaPlatformPage.buttons.connect).toHaveText(perconaPlatformPage.labels.validateConnection);
} else {
await expect(perconaPlatformPage.buttons.connect).toHaveText(perconaPlatformPage.labels.connect);
}

if (pmmVersion >= 35) {
await expect(perconaPlatformPage.buttons.getToken35).toHaveAttribute('href', perconaPlatformPage.links.portalProfile);
} else if (pmmVersion > 29 && pmmVersion < 35) {
await expect(perconaPlatformPage.buttons.getToken).toHaveAttribute('href', perconaPlatformPage.links.portalProfile);
} else {
await expect(perconaPlatformPage.buttons.getToken).toHaveAttribute('href', perconaPlatformPage.links.platformProfile);
}
});

await test.step('3. Verify that pmm server name and access token are required.', async () => {
await perconaPlatformPage.fields.pmmServerName.focus();
await perconaPlatformPage.fields.accessToken.focus();
await perconaPlatformPage.buttons.connect.click({
force: true,
});
await expect(perconaPlatformPage.elements.pmmServerNameError).toHaveText(perconaPlatformPage.labels.requiredField);
await expect(perconaPlatformPage.elements.accessTokenError).toHaveText(perconaPlatformPage.labels.requiredField);
});

await test.step('4. Verify user can connect to the portal only when server name and access token are valid.', async () => {
await perconaPlatformPage.fields.pmmServerName.type('Some Name');
await perconaPlatformPage.fields.accessToken.type('Some Token');
await expect(perconaPlatformPage.buttons.connect).toBeEnabled();
});
},
);
test('PMM-T809 PMM-T398 Verify Percona Platform elements on PMM Settings'
+ ' Page @portal @pre-pmm-portal-upgrade', async ({ perconaPlatformPage }) => {
test.skip(pmmVersion < 27, 'This test is for PMM version 2.27.0 and higher');

await test.step('1. Open Percona Platform tab in PMM Settings', async () => {
await perconaPlatformPage.authenticateSession();
await perconaPlatformPage.open();
});

await test.step('2. Verify all required element are displayed.', async () => {
await expect(perconaPlatformPage.elements.pmmServerIdHeader)
.toHaveText(perconaPlatformPage.labels.pmmServerId, { ignoreCase: true });
await expect(perconaPlatformPage.elements.pmmServerNameHeader).toHaveText(perconaPlatformPage.labels.pmmServerName);
await expect(perconaPlatformPage.elements.accessTokenHeader).toHaveText(perconaPlatformPage.labels.accessToken);
if (pmmVersion >= 35) {
await expect(perconaPlatformPage.buttons.createPerconaAccount).toHaveAttribute('href', perconaPlatformPage.links.portalLogin);
await expect(perconaPlatformPage.buttons.connect).toHaveText(perconaPlatformPage.labels.validateConnection);
} else {
await expect(perconaPlatformPage.buttons.connect).toHaveText(perconaPlatformPage.labels.connect);
}
if (pmmVersion >= 35) {
await expect(perconaPlatformPage.buttons.getToken35).toHaveAttribute('href', perconaPlatformPage.links.portalProfile);
} else if (pmmVersion > 29 && pmmVersion < 35) {
await expect(perconaPlatformPage.buttons.getToken).toHaveAttribute('href', perconaPlatformPage.links.portalProfile);
} else {
await expect(perconaPlatformPage.buttons.getToken).toHaveAttribute('href', perconaPlatformPage.links.platformProfile);
}
});

await test.step('3. Verify that pmm server name and access token are required.', async () => {
await perconaPlatformPage.fields.pmmServerName.focus();
await perconaPlatformPage.fields.accessToken.focus();
await perconaPlatformPage.buttons.connect.click({ force: true });
await expect(perconaPlatformPage.elements.pmmServerNameError).toHaveText(perconaPlatformPage.labels.requiredField);
await expect(perconaPlatformPage.elements.accessTokenError).toHaveText(perconaPlatformPage.labels.requiredField);
});

await test.step('4. Verify user can connect to the portal only when server name and access token are valid.', async () => {
await perconaPlatformPage.fields.pmmServerName.type('Some Name');
await perconaPlatformPage.fields.accessToken.type('Some Token');
await expect(perconaPlatformPage.buttons.connect).toBeEnabled();
});
});

test(
'PMM-T1224 Verify user is notified about using old PMM version while trying to connect to Portal'
+ ' @portal @pre-pmm-portal-upgrade @post-pmm-portal-upgrade',
async ({ page, perconaPlatformPage }) => {
async ({ perconaPlatformPage }) => {
test.skip(pmmVersion > 26, 'This test is for PMM version 2.26.0 and lower');

await grafanaHelper.authorize(page);
await page.goto(perconaPlatformPage.PAGE_PATH);
await perconaPlatformPage.authenticateSession();
await perconaPlatformPage.open();
await perconaPlatformPage.fields.pmmServerName.type(`Test Server ${Date.now()}`);
await perconaPlatformPage.fields.email.type(firstAdmin.email);
await perconaPlatformPage.fields.password.type(firstAdmin.password);
Expand All @@ -91,21 +84,18 @@ test.describe('Spec file for connecting PMM to the portal', async () => {
test(
'PMM-T1097 Verify PMM server is connected to Portal'
+ ' @not-ui-pipeline @portal @pre-pmm-portal-upgrade',
async ({ page, perconaPlatformPage }) => {
async ({ perconaPlatformPage }) => {
test.skip(pmmVersion < 27, 'This test is for PMM version 2.27.0 and higher');

await test.step('1. Open Percona Platform tab in PMM Settings', async () => {
await grafanaHelper.authorize(page);
await page.goto(perconaPlatformPage.PAGE_PATH);
await perconaPlatformPage.perconaPlatformContainer.waitFor({
state: 'visible',
});
await perconaPlatformPage.authenticateSession();
await perconaPlatformPage.open();
await perconaPlatformPage.perconaPlatformContainer.waitFor({ state: 'visible' });
});

await test.step('2. Connect PMM to the Portal', async () => {
const adminToken = await portalApi.getUserAccessToken(firstAdmin.email, firstAdmin.password);

// pmm address is not set automatically in older pmms.
// pmm address is not set automatically in older PMMs.
await perconaPlatformPage.connectToPortal(adminToken, `Test Server ${Date.now()}`, true);
});
},
Expand All @@ -115,38 +105,38 @@ test.describe('Spec file for connecting PMM to the portal', async () => {
'PMM-T1098 Verify All org users can login in connected PMM server'
+ ' @not-ui-pipeline @portal @pre-pmm-portal-upgrade @post-pmm-portal-upgrade',
async ({
page, loginPage, homeDashboardPage, baseURL, context,
loginPage, homeDashboardPage, baseURL, context,
}) => {
test.skip(pmmVersion < 27, 'This test is for PMM version 2.27.0 and higher');

await test.step('1. Login as admin user that created the org.', async () => {
await loginPage.open();
await loginPage.oktaLogin(firstAdmin.email, firstAdmin.password);
await homeDashboardPage.pmmUpgrade.containers.upgradeContainer.waitFor({
state: 'visible', timeout: Duration.OneMinute,
});
await expect(page).toHaveURL(`${baseURL}/${loginPage.landingUrl}`);
await homeDashboardPage.pmmUpgrade.containers.upgradeContainer
.waitFor({ state: 'visible', timeout: Duration.OneMinute });
await expect(loginPage.page).toHaveURL(`${baseURL}/${loginPage.landingUrl}`);
await context.clearCookies();
await page.reload();
await loginPage.page.reload();
});

await test.step('1. Login as admin user that was invited to the org.', async () => {
await loginPage.oktaLogin(secondAdmin.email, secondAdmin.password);
await homeDashboardPage.pmmUpgrade.containers.upgradeContainer.waitFor({
state: 'visible', timeout: Duration.OneMinute,
});
await expect(page).toHaveURL(`${baseURL}/${loginPage.landingUrl}`);
await expect(loginPage.page).toHaveURL(`${baseURL}/${loginPage.landingUrl}`);
await context.clearCookies();
await page.reload();
await loginPage.page.reload();
});

await test.step('1. Login as technical user that was invited to the org.', async () => {
await loginPage.oktaLogin(technicalUser.email, technicalUser.password);
await homeDashboardPage.pmmUpgrade.containers.upgradeContainer.waitFor({
state: 'visible', timeout: Duration.OneMinute,
});
await expect(page).toHaveURL(`${baseURL}/${loginPage.landingUrl}`);
await expect(loginPage.page).toHaveURL(`${baseURL}/${loginPage.landingUrl}`);
await context.clearCookies();
await page.reload();
await loginPage.page.reload();
});
},
);
Expand Down

0 comments on commit bfc7511

Please sign in to comment.