Comments (3)
from cypress-keycloak-commands.
@jdtully I can attach the file with an updated code
// https://github.com/Fredx87/cypress-keycloak-commands/blob/develop/src/kc-fake-login.ts
// the cypress-keycloak-commands library is still using cy.sever() and cy.route()
// which commands are deprecated in cypress 12 version. it fails with cypress 12.
// this file hold the same logic with using cy.intercept() instead of using the above commands
// This file should be deleted once the library starts supporting the latest version of cypress
// reported issue: https://github.com/Fredx87/cypress-keycloak-commands/issues/57
import { createUUID, decodeToken } from "cypress-keycloak-commands/dist/utils";
export default Cypress.Commands.add("kcFakeLogin", (user: string, visitUrl = "") => {
Cypress.log({ name: "Discover Fake Login" });
return cy.fixture(`users/${user}`).then((userData: UserData) => {
if (!userData.fakeLogin) {
throw new Error(
"To use kcFakeLogin command you should define fakeLogin data in fixture"
);
}
const authBaseUrl = Cypress.env("auth_base_url");
const realm = Cypress.env("auth_realm");
const {
account,
access_token,
refresh_token,
id_token
} = userData.fakeLogin;
const state = createUUID();
const { nonce } = decodeToken(access_token);
const token = {
access_token,
expires_in: 300,
refresh_expires_in: 1800,
refresh_token,
token_type: "bearer",
id_token,
"not-before-policy": 0,
session_state: createUUID(),
scope: "openid"
};
const localStorageObj = {
state,
nonce,
expires: Date() + 3600
};
const localStorageKey = `kc-callback-${state}`;
window.localStorage.setItem(
localStorageKey,
JSON.stringify(localStorageObj)
);
// the below 2 lines are updated to work with cypress 12
cy.intercept({method: 'post', url: authBaseUrl + "/realms/" + realm + "/protocol/openid-connect/token"}, token)
cy.intercept({method: 'get', url: authBaseUrl + "/realms/" + realm + "/account"}, account);
// in case visitUrl is an url with a hash, a second hash should not be added to the url
const joiningCharacter = visitUrl.indexOf("#") === -1 ? "#" : "&";
const url = `${
Cypress.config().baseUrl
}/${visitUrl}${joiningCharacter}state=${state}&session_state=${createUUID()}&code=${createUUID()}`;
cy.visit(url);
});
});
from cypress-keycloak-commands.
from cypress-keycloak-commands.
Related Issues (20)
- Add support for client-secret beside client-id HOT 11
- Token request not stubbed when running tests on production environment
- error: kcLogin: no location in response headers HOT 2
- kcFakeLogin stuck on redirecting HOT 2
- kcLogin: Blocked a frame with origin "http://localhost:3000" from accessing a cross-origin frame. HOT 7
- Documentation typos should be fixed
- Is the static user fixture a requirement? HOT 8
- Cannot authenticate - No cookies being set HOT 1
- Chrome 87, Cookies and kcLogin HOT 2
- PKCE support HOT 4
- Error: self signed certificate in certificate chain
- Cross-Domain still an issue
- kcLogin no longer working since Chrome 94? HOT 8
- How do I get otp_secret and otp_credential_id?
- mock session-iframe instead of changing the frontend for runtime HOT 2
- Cannot read properties of undefined (reading 'replace')
- cy.kcFakeLogin is not a function HOT 2
- Cannot read properties of undefined (reading 'action') HOT 4
- Give the possibility to do not add a file for the user but specify it in the env variables HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cypress-keycloak-commands.