-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fakeLogin is not working with cypress 12 #57
Comments
do you have a working set? Care to share?
…On Fri, Feb 3, 2023 at 10:18 AM Suresh Babu ***@***.***> wrote:
*cypress-keycloak-commands* library is still using cy.sever() and cy.route()
. These commands are deprecated in Cypress 12 version. the test cases fail
with cypress 12.
the below code in file
<https://github.com/Fredx87/cypress-keycloak-commands/blob/develop/src/kc-fake-login.ts>
cy.server();
cy.route(
"post",
`${authBaseUrl}/realms/${realm}/protocol/openid-connect/token`,
token
);
cy.route(`${authBaseUrl}/realms/${realm}/account`, account);
should be replaced with below in order to work:
// 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);
—
Reply to this email directly, view it on GitHub
<#57>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ALVKJ2XEWG6HG2L2AUZ22NTWVUOUBANCNFSM6AAAAAAUQMEADM>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
--
Jeffrey Tully
|
@jdtully I can attach the file with an updated code
|
I don't think the OP has looked at in in a couple years and this is
really upsetting my project. logins and logouts don't work for me
anymore either
…On Mon, Feb 6, 2023 at 6:22 AM Suresh Babu ***@***.***> wrote:
@jdtully <https://github.com/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: #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);
});
});
—
Reply to this email directly, view it on GitHub
<#57 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ALVKJ2XEEYRLULJCCK7EFDTWWDNF7ANCNFSM6AAAAAAUQMEADM>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
--
Jeffrey Tully
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
cypress-keycloak-commands library is still using
cy.sever()
andcy.route()
. These commands are deprecated in Cypress 12 version. the test cases fail with cypress 12.the below code in file
should be replaced with the below in order to work:
Source: https://docs.cypress.io/guides/references/migration-guide
The text was updated successfully, but these errors were encountered: