Skip to content

Commit

Permalink
test(e2e): Add Admin UI test for OIDC auth method (#2638)
Browse files Browse the repository at this point in the history
* test(e2e): Add managed group check in LDAP test

* test(e2e): Add oidc test

* CR: Suppress warning

* CR: Use toHaveText
  • Loading branch information
moduli authored Jan 3, 2025
1 parent ed56930 commit ca4aad0
Show file tree
Hide file tree
Showing 5 changed files with 530 additions and 11 deletions.
91 changes: 91 additions & 0 deletions e2e-tests/admin/pages/auth-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,97 @@ export class AuthMethodsPage extends BaseResourcePage {
return authMethodName;
}

/**
* Creates a new OIDC Auth Method. Assumes you have selected the desired scope.
* @param {string} issuer OIDC issuer
* @param {string} clientId OIDC client ID
* @param {string} clientSecret OIDC client secret
* @returns Name of the auth method
*/
async createOidcAuthMethod(issuer, clientId, clientSecret, boundaryAddr) {
const authMethodName = 'Auth Method ' + nanoid();
await this.page
.getByRole('navigation', { name: 'IAM' })
.getByRole('link', { name: 'Auth Methods' })
.click();
await this.page.getByRole('button', { name: 'New' }).click();
await this.page.getByRole('link', { name: 'OIDC' }).click();
await this.page.getByLabel('Name').fill(authMethodName);
await this.page.getByLabel('Description').fill('OIDC Auth Method');
await this.page.getByLabel('Issuer').fill(issuer);
await this.page.getByLabel('Client ID').fill(clientId);
await this.page.getByLabel('Client Secret').fill(clientSecret);
await this.page
.getByRole('group', { name: 'Signing Algorithms' })
.getByRole('combobox')
.selectOption('RS256');
await this.page
.getByRole('group', { name: 'Signing Algorithms' })
.getByRole('button', { name: 'Add' })
.click();

await this.page
.getByRole('group', { name: 'Claims Scopes' })
.getByRole('textbox')
.last()
.fill('groups');
await this.page
.getByRole('group', { name: 'Claims Scopes' })
.getByRole('button', { name: 'Add' })
.click();
await this.page
.getByRole('group', { name: 'Claims Scopes' })
.getByRole('textbox')
.last()
.fill('user');
await this.page
.getByRole('group', { name: 'Claims Scopes' })
.getByRole('button', { name: 'Add' })
.click();

await this.page
.getByRole('group', { name: 'Account Claim Maps' })
.getByLabel('From Claim')
.last()
.fill('username');
await this.page
.getByRole('group', { name: 'Account Claim Maps' })
.getByLabel('To Claim')
.last()
.selectOption('name');
await this.page
.getByRole('group', { name: 'Account Claim Maps' })
.getByRole('button', { name: 'Add' })
.click();
await this.page
.getByRole('group', { name: 'Account Claim Maps' })
.getByLabel('From Claim')
.last()
.fill('email');
await this.page
.getByRole('group', { name: 'Account Claim Maps' })
.getByLabel('To Claim')
.last()
.selectOption('email');
await this.page
.getByRole('group', { name: 'Account Claim Maps' })
.getByRole('button', { name: 'Add' })
.click();

await this.page.getByLabel('Maximum Age').fill('20');
await this.page.getByLabel('API URL Prefix').fill(boundaryAddr);

await this.page.getByRole('button', { name: 'Save' }).click();
await this.dismissSuccessAlert();
await expect(
this.page
.getByRole('navigation', { name: 'breadcrumbs' })
.getByText(authMethodName),
).toBeVisible();

return authMethodName;
}

/**
* Makes the first available auth method primary.
* Assumes you have created new auth method.
Expand Down
67 changes: 56 additions & 11 deletions e2e-tests/admin/tests/auth-method-ldap.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ test('Set up LDAP auth method @ce @ent @docker', async ({
).toBeVisible();

// Change state to active-public
page.getByTitle('Inactive').click();
page.getByText('Public').click();
await page.getByTitle('Inactive').click();
await page.getByText('Public').click();
await expect(
page.getByRole('alert').getByText('Success', { exact: true }),
).toBeVisible();
Expand Down Expand Up @@ -190,8 +190,13 @@ test('Set up LDAP auth method @ce @ent @docker', async ({
.click();
await page.getByRole('link', { name: ldapAuthMethodName }).click();
await page.getByRole('link', { name: 'Accounts' }).click();
await expect(
page
.getByRole('navigation', { name: 'breadcrumbs' })
.getByText('Accounts'),
).toBeVisible();

const headersCount = await page
let headersCount = await page
.getByRole('table')
.getByRole('columnheader')
.count();
Expand All @@ -211,21 +216,61 @@ test('Set up LDAP auth method @ce @ent @docker', async ({
}

expect(
await page
page
.getByRole('cell', { name: ldapAccountName })
.locator('..')
.getByRole('cell')
.nth(fullNameIndex)
.innerText(),
).toBe(ldapUserName);
.nth(fullNameIndex),
).toHaveText(ldapUserName);
expect(
await page
page
.getByRole('cell', { name: ldapAccountName })
.locator('..')
.getByRole('cell')
.nth(emailIndex)
.innerText(),
).toBe(ldapUserName + '@mail.com');
.nth(emailIndex),
).toHaveText(ldapUserName + '@mail.com');

// View the Managed Group
await page.getByRole('link', { name: 'Managed Groups' }).click();
await page.getByRole('link', { name: ldapManagedGroupName }).click();
await page.getByRole('link', { name: 'Members' }).click();
await expect(
page
.getByRole('navigation', { name: 'breadcrumbs' })
.getByText('Members'),
).toBeVisible();

headersCount = await page
.getByRole('table')
.getByRole('columnheader')
.count();
for (let i = 0; i < headersCount; i++) {
const header = await page
.getByRole('table')
.getByRole('columnheader')
.nth(i)
.innerText();
if (header == 'Full Name') {
fullNameIndex = i;
} else if (header == 'Email') {
emailIndex = i;
}
}

expect(
page
.getByRole('cell', { name: ldapAccountName })
.locator('..')
.getByRole('cell')
.nth(fullNameIndex),
).toHaveText(ldapUserName);
expect(
page
.getByRole('cell', { name: ldapAccountName })
.locator('..')
.getByRole('cell')
.nth(emailIndex),
).toHaveText(ldapUserName + '@mail.com');

// View the User account and verify attributes
await page
Expand Down
Loading

0 comments on commit ca4aad0

Please sign in to comment.