Skip to content
This repository was archived by the owner on Nov 23, 2026. It is now read-only.

[tests-only][full-ci] Add e2e tests for access token renewal flows (iframe and refresh_token) - #11296

Merged
saw-jan merged 12 commits into
masterfrom
add-tests-for-refreshing-token
Aug 12, 2024
Merged

saw-jan merged 12 commits into
masterfrom
add-tests-for-refreshing-token

Conversation

@amrita-shrestha

@amrita-shrestha amrita-shrestha commented Jul 30, 2024 •

Copy link
Copy Markdown
Contributor

Description

This PR adds tests coverage for access token refresh flow. Currently, we have two flows in web

  • oCIS / oidc with refresh token (i.e. offline_access in requested scopes) works (WEB_OIDC_SCOPE="openid profile email offline_access" IDP_ACCESS_TOKEN_EXPIRATION=30)

  • oCIS / oidc without refresh token (i.e. token renewal via iframe) works (IDP_ACCESS_TOKEN_EXPIRATION=10)

    • iframe visible for a short period of time so it's hard to detect the iframe using the playwright locator/framelocator
    • added an assertion to check that the iframe appeared
      Untitled design (1)
  • use webUI steps only for oidc journey so that we don't have to update access token at certain interval and after hook

Related Issue

Motivation and Context

How Has This Been Tested?

  • test environment:
  • test case 1:
  • test case 2:
  • ...

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Technical debt
  • Tests
  • Documentation
  • Maintenance (e.g. dependency updates or tooling)

Open tasks:

  • ...

@amrita-shrestha amrita-shrestha self-assigned this Jul 30, 2024
@amrita-shrestha
amrita-shrestha force-pushed the add-tests-for-refreshing-token branch 9 times, most recently from cf9493b to 0a94876 Compare August 2, 2024 09:50
@saw-jan saw-jan self-assigned this Aug 7, 2024
@saw-jan
saw-jan force-pushed the add-tests-for-refreshing-token branch 2 times, most recently from d775a7a to 943a4f3 Compare August 8, 2024 04:14
Comment thread .drone.star Resolved
@saw-jan saw-jan changed the title [tests-only][full-ci]Add tests for access token refresh flow [tests-only][full-ci] Add tests for access token renewal flows (ifram and refresh_token) Aug 8, 2024
@saw-jan saw-jan changed the title [tests-only][full-ci] Add tests for access token renewal flows (ifram and refresh_token) [tests-only][full-ci] Add e2e tests for access token renewal flows (iframe and refresh_token) Aug 8, 2024
@saw-jan
saw-jan force-pushed the add-tests-for-refreshing-token branch from 7490c3d to ea50eb1 Compare August 8, 2024 06:45

@saw-jan saw-jan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kulmann @dschmidt
Please, have a look if the requirements are met. we have tried to implement the test scenario for token renewal via iframe and refresh_token.

Comment on lines +79 to +94
async waitForTokenRenewalViaRefreshToken(): Promise<void> {
await Promise.all([
this.#page.waitForResponse(
(resp) => !resp.url().includes('/oidc-silent-redirect.html'),
// timeout after 50 seconds
{ timeout: (config.timeout - 10) * 1000 }
),
this.#page.waitForResponse(
(resp) =>
resp.url().includes('/token') &&
resp.status() === 200 &&
resp.request().method() === 'POST' &&
resp.request().postDataJSON().grant_type === 'refresh_token' &&
resp.request().postDataJSON().hasOwnProperty('refresh_token') &&
resp.request().postDataJSON().refresh_token &&
resp.request().postDataJSON().hasOwnProperty('scope') &&
resp.request().postDataJSON().scope.includes('offline_access'),
// timeout after 50 seconds
{ timeout: (config.timeout - 10) * 1000 }
)
])
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we added this function to check that the token renewal was done using the refresh_token.

Comment on lines +128 to +142
await Promise.all([
this.#page.waitForResponse(
(resp) =>
resp.url().includes('/oidc-silent-redirect.html') &&
resp.status() === 200 &&
resp.request().method() === 'GET',
// timeout after 50 seconds
{ timeout: (config.timeout - 10) * 1000 }
),
this.#page.waitForResponse(
(resp) =>
resp.url().endsWith('/token') &&
resp.status() === 200 &&
resp.request().method() === 'POST' &&
resp.request().postDataJSON().grant_type === 'authorization_code' &&
resp.request().postDataJSON().hasOwnProperty('code') &&
resp.request().postDataJSON().code,
// timeout after 50 seconds
{ timeout: (config.timeout - 10) * 1000 }
),
waitForIframe
])
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and to check that token renewal was done via iframe

@saw-jan
saw-jan marked this pull request as ready for review August 8, 2024 06:50
@saw-jan
saw-jan requested review from a user, dschmidt, ishabaral, kulmann and v-scharf August 8, 2024 06:51
@saw-jan
saw-jan force-pushed the add-tests-for-refreshing-token branch from ea50eb1 to 197a88e Compare August 8, 2024 11:27

@dschmidt dschmidt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great! Thanks a lot, I wouldn't have wanted to write this code :)

Comment thread tests/e2e/cucumber/steps/ui/session.ts Resolved
@saw-jan
saw-jan force-pushed the add-tests-for-refreshing-token branch 2 times, most recently from f4b504a to d607d05 Compare August 12, 2024 08:28
@saw-jan
saw-jan force-pushed the add-tests-for-refreshing-token branch from d607d05 to 7981baa Compare August 12, 2024 08:29
@sonarqubecloud

Copy link
Copy Markdown

@saw-jan
saw-jan merged commit d37119c into master Aug 12, 2024
@saw-jan
saw-jan deleted the add-tests-for-refreshing-token branch August 12, 2024 08:46
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add tests for all auth and access token refresh flows

3 participants