From c30fe30a00f8a0bfac7c681fc8d4a694d14504a8 Mon Sep 17 00:00:00 2001 From: Jan Richter Date: Wed, 6 Dec 2023 12:03:49 +0100 Subject: [PATCH] fix(e2e): get access token from an existing source --- integration-tests/cypress.config.ts | 1 + integration-tests/utils/APIHelper.ts | 28 ++++++++++++++-------------- pr_check.sh | 1 + 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/integration-tests/cypress.config.ts b/integration-tests/cypress.config.ts index 2d9bffd2b..d3204bf2b 100644 --- a/integration-tests/cypress.config.ts +++ b/integration-tests/cypress.config.ts @@ -147,6 +147,7 @@ export default defineConfig({ resolution: 'high', REMOVE_APP_ON_FAIL: false, SNYK_TOKEN: '', + SSO_URL: 'https://sso.redhat.com/auth/', }; for (const key in defaultValues) { diff --git a/integration-tests/utils/APIHelper.ts b/integration-tests/utils/APIHelper.ts index a35dbf099..5f6478355 100644 --- a/integration-tests/utils/APIHelper.ts +++ b/integration-tests/utils/APIHelper.ts @@ -7,22 +7,22 @@ export class APIHelper { 'X-GitHub-Api-Version': '2022-11-28', }; - static requestHACAPI(options: object) { - return cy - .getCookie('cs_jwt') - .should('exist') - .its('value') - .then((token) => { - options.headers = { - authorization: `Bearer ${token}`, - accept: 'application/json', - }; - return cy.request(options); - }); + static requestHACAPI(options: Partial) { + const oidcUser = JSON.parse( + localStorage.getItem(`oidc.user:${Cypress.env('SSO_URL')}:cloud-services`), + ); + const token = oidcUser.access_token as string; + + options.headers = { + authorization: `Bearer ${token}`, + accept: 'application/json', + }; + + return cy.request(options); } static githubRequest(method: Cypress.HttpMethod, url: string, body?: Cypress.RequestBody) { - const options = { + const options: Partial = { method, url, headers: this.githubHeaders, @@ -42,7 +42,7 @@ export class APIHelper { headers?: object, ) { expect(retryNum).to.be.lessThan(maxRetryNum); - const options = { + const options: Partial = { url, timeout: 30000, failOnStatusCode: false, diff --git a/pr_check.sh b/pr_check.sh index 2e5ebc501..def59c321 100755 --- a/pr_check.sh +++ b/pr_check.sh @@ -72,6 +72,7 @@ COMMON_SETUP="-v $WORKSPACE/artifacts:/tmp/artifacts:Z \ -e CYPRESS_USERNAME=`echo ${B64_USER} | base64 -d` \ -e CYPRESS_PASSWORD=`echo ${B64_PASS} | base64 -d` \ -e CYPRESS_GH_PR_TITLE=${PR_TITLE} \ + -e CYPRESS_SSO_URL=${HAC_KC_SSO_URL} \ -e GH_COMMENTBODY=${GH_COMMENTBODY}" TEST_IMAGE="quay.io/hacdev/hac-tests:next"