Skip to content

Commit

Permalink
github auth test
Browse files Browse the repository at this point in the history
  • Loading branch information
Yonas Berhe authored and Yonas Berhe committed Nov 27, 2024
1 parent 907875f commit 8bd355f
Show file tree
Hide file tree
Showing 20 changed files with 1,111 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ require('dotenv').config();
*/

const testDirs = [
'cypress/e2e/tests/priority/**/*.spec.ts',
'cypress/e2e/tests/components/**/*.spec.ts',
'cypress/e2e/tests/setup/**/*.spec.ts',
'cypress/e2e/tests/pages/**/*.spec.ts',
'cypress/e2e/tests/navigation/**/*.spec.ts',
'cypress/e2e/tests/global-ui/**/*.spec.ts',
'cypress/e2e/tests/features/**/*.spec.ts',
'cypress/e2e/tests/extensions/**/*.spec.ts'
// 'cypress/e2e/tests/priority/**/*.spec.ts',
// 'cypress/e2e/tests/components/**/*.spec.ts',
// 'cypress/e2e/tests/setup/**/*.spec.ts',
'cypress/e2e/tests/pages/users-and-auth/*.spec.ts',
// 'cypress/e2e/tests/navigation/**/*.spec.ts',
// 'cypress/e2e/tests/global-ui/**/*.spec.ts',
// 'cypress/e2e/tests/features/**/*.spec.ts',
// 'cypress/e2e/tests/extensions/**/*.spec.ts'
];
const skipSetup = process.env.TEST_SKIP?.includes('setup');
const baseUrl = (process.env.TEST_BASE_URL || 'https://localhost:8005').replace(/\/$/, '');
Expand Down Expand Up @@ -67,7 +67,7 @@ export default defineConfig({
trashAssetsBeforeRuns: true,
chromeWebSecurity: false,
retries: {
runMode: 2,
runMode: 0,
openMode: 0
},
env: {
Expand All @@ -86,7 +86,16 @@ export default defineConfig({
azureClientId: process.env.AZURE_CLIENT_ID,
azureClientSecret: process.env.AZURE_CLIENT_SECRET,
customNodeIp: process.env.CUSTOM_NODE_IP,
customNodeKey: process.env.CUSTOM_NODE_KEY
customNodeKey: process.env.CUSTOM_NODE_KEY,
githubUser1: process.env.GITHUB_USER1,
githubPassword1: process.env.GITHUB_PASSWORD1,
githubUser2: process.env.GITHUB_USER2,
githubPassword2: process.env.GITHUB_PASSWORD2,
googleClientId: process.env.GOOGLE_CLIENT_ID,
googleClientSecret: process.env.GOOGLE_CLIENT_SECRET,
googleRefreshToken: process.env.GOOGLE_REFRESH_TOKEN,
githubClientId: process.env.GITHUB_CLIENT_ID,
githubClientSecret: process.env.GITHUB_CLIENT_SECRET
},
// Jenkins reporters configuration jUnit and HTML
reporter: 'cypress-multi-reporters',
Expand All @@ -106,9 +115,10 @@ export default defineConfig({
require('@cypress/grep/src/plugin')(config);
on('task', { removeDirectory });
},
fixturesFolder: 'cypress/e2e/blueprints',
experimentalSessionAndOrigin: true,
specPattern: testDirs,
fixturesFolder: 'cypress/e2e/blueprints',
experimentalSessionAndOrigin: true,
experimentalModifyObstructiveThirdPartyCode: true,
specPattern: testDirs,
baseUrl
},
video: false,
Expand Down
11 changes: 10 additions & 1 deletion cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,16 @@ export default defineConfig({
azureClientId: process.env.AZURE_CLIENT_ID,
azureClientSecret: process.env.AZURE_CLIENT_SECRET,
customNodeIp: process.env.CUSTOM_NODE_IP,
customNodeKey: process.env.CUSTOM_NODE_KEY
customNodeKey: process.env.CUSTOM_NODE_KEY,
githubUser1: process.env.GITHUB_USER1,
githubPassword1: process.env.GITHUB_PASSWORD1,
githubUser2: process.env.GITHUB_USER2,
githubPassword2: process.env.GITHUB_PASSWORD2,
googleClientId: process.env.GOOGLE_CLIENT_ID,
googleClientSecret: process.env.GOOGLE_CLIENT_SECRET,
googleRefreshToken: process.env.GOOGLE_REFRESH_TOKEN,
githubClientId: process.env.GITHUB_CLIENT_ID,
githubClientSecret: process.env.GITHUB_CLIENT_SECRET
},
e2e: {
fixturesFolder: 'cypress/e2e/blueprints',
Expand Down
80 changes: 80 additions & 0 deletions cypress/e2e/po/edit/auth/github.po.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import PagePo from '@/cypress/e2e/po/pages/page.po';
import RadioGroupInputPo from '@/cypress/e2e/po/components/radio-group-input.po';
import LabeledInputPo from '@/cypress/e2e/po/components/labeled-input.po';
import AsyncButtonPo from '@/cypress/e2e/po/components/async-button.po';
import ProductNavPo from '@/cypress/e2e/po/side-bars/product-side-nav.po';
import BurgerMenuPo from '@/cypress/e2e/po/side-bars/burger-side-menu.po';
import BannersPo from '@/cypress/e2e/po/components/banners.po';
import LabeledSelectPo from '@/cypress/e2e/po/components/labeled-select.po';

export default class GitHubPo extends PagePo {
private static createPath(clusterId: string) {
return `/c/${ clusterId }/auth/config/github?mode=edit`;
}

static goTo(clusterId: string): Cypress.Chainable<Cypress.AUTWindow> {
return super.goTo(GitHubPo.createPath(clusterId));
}

constructor(clusterId: string) {
super(GitHubPo.createPath(clusterId));
}

static navTo() {
const sideNav = new ProductNavPo();

BurgerMenuPo.burgerMenuNavToMenubyLabel('Users & Authentication');
sideNav.navToSideMenuEntryByLabel('Auth Provider');
}

githubAppLink() {
return this.self().get('ul.step-list [href="https://github.com/settings/developers"]').then((el) => {
expect(el).to.have.attr('target');
})
.invoke('removeAttr', 'target');
}

authConfigRadioBtn(): RadioGroupInputPo {
return new RadioGroupInputPo('[data-testid="access-mode-options"]');
}

selectLoginCofigOption(index: number): Cypress.Chainable {
return this.authConfigRadioBtn().set(index);
}

bannerContent(element:string) {
return new BannersPo('[data-testid="banner-content"]', this.self()).bannerElement(element);
}

clientId() {
return new LabeledInputPo('[data-testid="input-github-clientId"]');
}

clientSecret() {
return new LabeledInputPo('[data-testid="input-github-clientSecret"]');
}

disable() {
return this.bannerContent('button').contains('Disable').click();
}

usersAndGroupsArrayListItem(index: number) {
return this.self().find(`[data-testid="array-list-box${ index }"]`);
}

addMemberSearch() {
return new LabeledSelectPo('.labeled-select.select-principal', this.self());
}

cancelButton(): AsyncButtonPo {
return new AsyncButtonPo('[data-testid="form-cancel"]', this.self());
}

saveButton(): AsyncButtonPo {
return new AsyncButtonPo('[data-testid="form-save"]', this.self());
}

save() {
return new AsyncButtonPo('[data-testid="form-save"]').click();
}
}
14 changes: 4 additions & 10 deletions cypress/e2e/po/pages/login-page.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,12 @@ export class LoginPagePo extends PagePo {
}

switchToLocal(): Cypress.Chainable {
const useLocal = this.useLocal();

// TODO: We should have control over this instead of using a condition, as we want deterministic tests
return useLocal ? useLocal.click() : cy;
return cy.getId('login-useLocal');
}

useLocal() {
return this.self().then(($page) => {
const elements = $page.find('[data-testid="login-useLocal"]');

return elements?.[0];
});
useAuthProvider(text: string) {
return this.self().find('button.btn').contains(text);
// return cy.getId('login-userAuthProvider').contains(text);
}

submitButton(): AsyncButtonPo {
Expand Down
9 changes: 9 additions & 0 deletions cypress/e2e/po/pages/users-and-auth/authProvider.po.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import PagePo from '@/cypress/e2e/po/pages/page.po';
import ProductNavPo from '@/cypress/e2e/po/side-bars/product-side-nav.po';
import BurgerMenuPo from '@/cypress/e2e/po/side-bars/burger-side-menu.po';
import GenericPrompt from '@/cypress/e2e/po/prompts/genericPrompt.po';

export default class AuthProviderPo extends PagePo {
private static createPath(clusterId: string, id?: string ) {
Expand Down Expand Up @@ -29,4 +30,12 @@ export default class AuthProviderPo extends PagePo {
selectAzureAd() {
return this.self().find('[data-testid="select-icon-grid-AzureAD"]').click();
}

selectGit() {
return this.self().find('[data-testid="select-icon-grid-GitHub"]').click();
}

disableAuthProviderModal(): GenericPrompt {
return new GenericPrompt('.prompt-restore');
}
}
6 changes: 5 additions & 1 deletion cypress/e2e/po/side-bars/user-menu.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export default class UserMenuPo extends ComponentPo {
return this.self().getId(`user-menu-dropdown`);
}

userImage() {
return this.self().getId('nav_header_showUserMenu');
}

/**
* Open the user menu
*
Expand Down Expand Up @@ -92,7 +96,7 @@ export default class UserMenuPo extends ComponentPo {
* @returns
*/
getMenuItems(): Cypress.Chainable {
return this.userMenu().find('li').should('be.visible').and('have.length', 4);
return this.userMenu().find('li');
}

/**
Expand Down
42 changes: 42 additions & 0 deletions cypress/e2e/po/third-party-apps/github.po.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* eslint-disable cypress/no-unnecessary-waiting */
export default class GitHubThirdPartyPo {
usernameField(text: string) {
return cy.get('#login_field').should('be.visible').clear().type(text, { force: true, delay: 100 });
}

passwordField(text: string) {
return cy.get('#password').should('be.visible').clear().type(text, { force: true, delay: 100 });
}

signInButton() {
return cy.get('input').contains('Sign in');
}

appNameField(text: string) {
return cy.get('#oauth_application_name').type(text);
}

oauthApplicationUrl(text: string) {
return cy.get('#oauth_application_url').type(text);
}

oauthApplicationCallbackUrl(text: string) {
return cy.get('#oauth_application_callback_url').type(text);
}

registerAppButton() {
return cy.get('button.btn').contains('Register application');
}

generateClientSecret() {
return cy.get('input.btn').contains('Generate a new client secret');
}

newOauthToken() {
return cy.get('#new-oauth-token');
}

authorizeButton(options: any) {
return cy.get('button[name="authorize"][value="1"]', options).should('be.enabled').click();
}
}
25 changes: 25 additions & 0 deletions cypress/e2e/tests/pages/users-and-auth/email-test.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

describe('Email Code Extraction', () => {
it('should extract code from the Gmail email body', () => {
const emailSearchQuery = 'subject:[GitHub] Please verify your device';

// Call the fetchGmailMessages custom command to get the email messages
cy.fetchGmailMessage(emailSearchQuery).then((resp: Cypress.Response<any>) => {
const emailBody = resp.body.payload.body.data;

// Decode the base64 content (Gmail API returns email body in base64url encoding)
const decodedBody = Cypress.Buffer.from(emailBody, 'base64').toString('utf-8');

// Regex to extract the 6-digit code
const match = decodedBody.match(/(\d{6})/);

if (match) {
const code = match[1]; // Extracted code

cy.log('Extracted Code:', code);
} else {
cy.log('No code found');
}
});
});
});
Loading

0 comments on commit 8bd355f

Please sign in to comment.