diff --git a/.all-contributorsrc b/.all-contributorsrc new file mode 100644 index 0000000..698f850 --- /dev/null +++ b/.all-contributorsrc @@ -0,0 +1,39 @@ +{ + "files": [ + "README.md" + ], + "imageSize": 100, + "commit": false, + "contributors": [ + { + "login": "Fredx87", + "name": "Gianluca Frediani", + "avatar_url": "https://avatars2.githubusercontent.com/u/13420283?v=4", + "profile": "https://github.com/Fredx87", + "contributions": [ + "infra", + "tool", + "test", + "doc", + "ideas", + "code" + ] + }, + { + "login": "groie", + "name": "Ilkka Harmanen", + "avatar_url": "https://avatars3.githubusercontent.com/u/5516998?v=4", + "profile": "https://github.com/groie", + "contributions": [ + "code" + ] + } + ], + "contributorsPerLine": 7, + "projectName": "cypress-keycloak-commands", + "projectOwner": "Fredx87", + "repoType": "github", + "repoHost": "https://github.com", + "skipCi": true, + "commitConvention": "none" +} diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 97b10a4..9b13707 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -8,7 +8,7 @@ jobs: strategy: matrix: - keycloak: ["4.8.3.Final", "5.0.0", "6.0.1", "7.0.1", "8.0.1"] + keycloak: ["4.8.3.Final", "5.0.0", "6.0.1", "7.0.1", "8.0.1", "9.0.0"] steps: - uses: actions/checkout@v1 diff --git a/README.md b/README.md index 963c756..7729215 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,7 @@ # cypress-keycloak-commands + +[![All Contributors](https://img.shields.io/badge/all_contributors-2-orange.svg?style=flat-square)](#contributors-) + Cypress commands for login with [Keycloak](https://www.keycloak.org/). @@ -163,3 +166,23 @@ Other solutions that have inspired this library: ## License MIT + +## Contributors ✨ + +Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)): + + + + + + + + + +

Gianluca Frediani

🚇 🔧 ⚠️ 📖 🤔 💻

Ilkka Harmanen

💻
+ + + + + +This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome! \ No newline at end of file diff --git a/cypress/integration/fake-login.spec.ts b/cypress/integration/fake-login.spec.ts index 3bfb697..8c71a79 100644 --- a/cypress/integration/fake-login.spec.ts +++ b/cypress/integration/fake-login.spec.ts @@ -2,15 +2,13 @@ /// describe("Keycloak Fake Login", () => { - beforeEach(() => { - cy.kcFakeLogin("user"); - }); - it("should show user as authenticated", () => { + cy.kcFakeLogin("user"); cy.get("#output").should("contain.text", "Init Success (Authenticated)"); }); it("should get user data equal to fixture data", () => { + cy.kcFakeLogin("user"); cy.get("#output").should("contain.text", "Init Success (Authenticated)"); cy.findByText("Get Profile").click(); @@ -22,4 +20,16 @@ describe("Keycloak Fake Login", () => { }); }); }); + + it("should go to the specified path with hash and show user as authenticated", () => { + cy.kcFakeLogin("user", "#/foobar"); + cy.url().should("be.equal", `${Cypress.config("baseUrl")}/#/foobar`); + cy.get("#output").should("contain.text", "Init Success (Authenticated)"); + }); + + it("should go to the specified path without hash and show user as authenticated", () => { + cy.kcFakeLogin("user", "index.html"); + cy.url().should("be.equal", `${Cypress.config("baseUrl")}/index.html`); + cy.get("#output").should("contain.text", "Init Success (Authenticated)"); + }); }); diff --git a/src/kc-fake-login.ts b/src/kc-fake-login.ts index b98f207..0ca7254 100644 --- a/src/kc-fake-login.ts +++ b/src/kc-fake-login.ts @@ -57,9 +57,12 @@ Cypress.Commands.add("kcFakeLogin", (user: string, visitUrl = "") => { cy.route(`${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}#state=${state}&session_state=${createUUID()}&code=${createUUID()}`; + }/${visitUrl}${joiningCharacter}state=${state}&session_state=${createUUID()}&code=${createUUID()}`; cy.visit(url); });