From 4ed95259c0ec3ec876c6d31fce50ec4cfc158f38 Mon Sep 17 00:00:00 2001 From: jonathan langlois Date: Mon, 29 Jan 2024 11:35:10 -0800 Subject: [PATCH] test: gh action test out the gh action run works --- .github/workflows/test.yaml | 69 ++++++++++++++++++++++ testing/cypress/e2e/github-bcgov-idp.cy.ts | 24 +++++--- 2 files changed, 85 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/test.yaml diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..3a4e0fa --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,69 @@ +# Workflow starts automatically on push or can be triggered manually. +# This is a desirable pattern as it allows for adhoc test runs without a code push +# name: main-e2e +# on: [workflow_dispatch, repository_dispatch] + +name: test-github +on: + workflow_dispatch: + push: + branches: + - github-idps + +jobs: + sso-request-tests: + runs-on: ubuntu-latest + # In order for Cypress to run well, it needs to be fed the needed parameters. + # The below is a mix of Cypress environment variables (All capital) and ones that are needed for this specific set of scripts (Mix of capital and lowercase) + env: + CYPRESS_users: ${{ secrets.CYPRESS_USERS }} + CYPRESS_BASE_URL: ${{ secrets.CYPRESS_BASEURL }} + CYPRESS_host: ${{ secrets.CYPRESS_HOST }} + CYPRESS_guid: ${{ secrets.CYPRESS_GUID }} + CYPRESS_ENVIRONMENT: ${{ github.base_ref }} + CYPRESS_loginproxy: ${{ secrets.CYPRESS_LOGINPROXY }} + CYPRESS_siteminder: ${{ secrets.CYPRESS_SITEMINDER }} + CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + strategy: + fail-fast: false # https://github.com/cypress-io/github-action/issues/48 + steps: + # Checkout the PR branch + - name: Checkout Target Branch + uses: actions/checkout@v3 + + # We are cache-ing our node modules to slightly speed up execution in the future. + - name: Cache node modules + id: cache-npm + uses: actions/cache@v3 + env: + cache-name: cache-node-modules + with: + # npm cache files are stored in `~/.npm` on Linux/macOS + path: ~/.npm + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-build-${{ env.cache-name }}- + ${{ runner.os }}-build- + ${{ runner.os }}- + - if: ${{ steps.cache-npm.outputs.cache-hit != 'true' }} + name: List the state of node modules + continue-on-error: true + run: npm list + + - name: Github IDP Tests + uses: cypress-io/github-action@v6.6.0 + id: github-idps + continue-on-error: false + with: + summary-title: 'Github IDP Tests' + wait-on: ${{ secrets.CYPRESS_HOST }} + wait-on-timeout: 120 + record: true + install-command: npm ci + working-directory: testing + spec: | + cypress/e2e/**/github-bcgov-idp.cy.ts + browser: chrome + # project: ./e2e + ci-build-id: ${{ github.event.number }} diff --git a/testing/cypress/e2e/github-bcgov-idp.cy.ts b/testing/cypress/e2e/github-bcgov-idp.cy.ts index 6552b62..7789e6c 100644 --- a/testing/cypress/e2e/github-bcgov-idp.cy.ts +++ b/testing/cypress/e2e/github-bcgov-idp.cy.ts @@ -20,6 +20,7 @@ describe('Github BCGov intergration', () => { req.populateCreateContent(githubBCGovIDP); it('Can create the Github BCGov integration', () => { + cy.setid('default'); cy.login(null, null, null, null); req.createRequest(); cy.logout(null); @@ -32,9 +33,11 @@ describe('Github BCGov intergration', () => { cy.wait(2000); // Wait a bit because to make sure the page is loaded + const user = Cypress.env('users').find((user) => user.type === 'githubpublic'); + // Attempt login with external account (not in the bcgovsso org) - cy.get('input#login_field').type(Cypress.env('externalGithubUsername'), { log: false }); - cy.get('input#password').type(Cypress.env('externalGithubPassword'), { log: false }); + cy.get('input#login_field').type(user.username, { log: false }); + cy.get('input#password').type(user.password, { log: false }); cy.get('input[type="submit"]').click(); cy.contains('Are you part of the GitHub BC Gov Org'); @@ -49,8 +52,10 @@ describe('Github BCGov intergration', () => { cy.get('button').contains('Login').click(); cy.wait(2000); // Wait a bit because to make sure the page is loaded - cy.get('input#login_field').type(Cypress.env('internalGithubUsername'), { log: false }); - cy.get('input#password').type(Cypress.env('internalGithubPassword'), { log: false }); + const user = Cypress.env('users').find((user) => user.type === 'githubbcgov'); + + cy.get('input#login_field').type(user.username, { log: false }); + cy.get('input#password').type(user.password, { log: false }); cy.get('input[type="submit"]').click(); cy.contains('Keycloak OIDC Playground'); @@ -73,7 +78,8 @@ describe('Github public intergration', () => { const password = Cypress.env('adminPassword'); it('Can create the Github BCGov integration', () => { - cy.login(username, password, null, null); + cy.setid('admin'); + cy.login(null, null, null, null); req.createRequest(); cy.logout(null); }); @@ -86,8 +92,10 @@ describe('Github public intergration', () => { cy.get('button').contains('Login').click(); cy.wait(2000); // Wait a bit because to make sure the page is loaded - cy.get('input#login_field').type(Cypress.env('externalGithubUsername'), { log: false }); - cy.get('input#password').type(Cypress.env('externalGithubPassword'), { log: false }); + const user = Cypress.env('users').find((user) => user.type === 'githubpublic'); + + cy.get('input#login_field').type(user.username, { log: false }); + cy.get('input#password').type(user.password, { log: false }); cy.get('input[type="submit"]').click(); cy.contains('Keycloak OIDC Playground'); @@ -95,7 +103,7 @@ describe('Github public intergration', () => { }); it('Can delete the BCGov Github integration', () => { - cy.login(username, password, null, null); + cy.login(null, null, null, null); req.deleteRequest(Cypress.env('test')); cy.logout(null); });