Skip to content

Instantly share code, notes, and snippets.

@ObsidianCat
Last active December 6, 2019 17:22
Show Gist options
  • Save ObsidianCat/91c95fb24be215815918353fed527b98 to your computer and use it in GitHub Desktop.
Save ObsidianCat/91c95fb24be215815918353fed527b98 to your computer and use it in GitHub Desktop.
// ./cypress/support/commands.js
Cypress.Commands.add('mockOktaLoggedState', () => {
// Set cookies
cy.setCookie('okta-oauth-nonce', 'value of this cookie copied from the browser');
cy.setCookie('okta-oauth-state', 'value of this cookie copied from the browser');
// To avoid token expiration, we create a new timestamp every time
const oneDayFromNow = Date.now() + 1000 * 60 * 60 * 24;
// Remember to replace all instances of "expiresAt":"{someTimeStampHere}",
// with "expiresAt":${oneDayFromNow}
// use backticks `` for string interpolation
localStorage.setItem(
'okta-token-storage',
`edited value of this item from the browser`
);
localStorage.setItem(
'okta-cache-storage',
`edited value of this item from the browser`
);
// In order to start intercepting requests, we need to start the server
cy.server();
// Intercept requests for Okta user profile and return our own response. We can just save a real response once and use it
cy.route('GET', 'https://dev-382196.okta.com/oauth2/default/v1/userinfo', 'fixture:okta-user-mock.json').as('okta');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment