Skip to content

Commit

Permalink
Merge pull request Fredx87#11 from Fredx87/develop
Browse files Browse the repository at this point in the history
chore: merge develop into master
  • Loading branch information
Fredx87 authored Feb 28, 2020
2 parents 40dadb2 + c7f2d57 commit 54a0a70
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 6 deletions.
39 changes: 39 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
@@ -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"
}
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# cypress-keycloak-commands
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-2-orange.svg?style=flat-square)](#contributors-)
<!-- ALL-CONTRIBUTORS-BADGE:END -->

Cypress commands for login with [Keycloak](https://www.keycloak.org/).

Expand Down Expand Up @@ -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)):

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
<table>
<tr>
<td align="center"><a href="https://github.com/Fredx87"><img src="https://avatars2.githubusercontent.com/u/13420283?v=4" width="100px;" alt=""/><br /><sub><b>Gianluca Frediani</b></sub></a><br /><a href="#infra-Fredx87" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="#tool-Fredx87" title="Tools">🔧</a> <a href="https://github.com/Fredx87/cypress-keycloak-commands/commits?author=Fredx87" title="Tests">⚠️</a> <a href="https://github.com/Fredx87/cypress-keycloak-commands/commits?author=Fredx87" title="Documentation">📖</a> <a href="#ideas-Fredx87" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/Fredx87/cypress-keycloak-commands/commits?author=Fredx87" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/groie"><img src="https://avatars3.githubusercontent.com/u/5516998?v=4" width="100px;" alt=""/><br /><sub><b>Ilkka Harmanen</b></sub></a><br /><a href="https://github.com/Fredx87/cypress-keycloak-commands/commits?author=groie" title="Code">💻</a></td>
</tr>
</table>

<!-- markdownlint-enable -->
<!-- prettier-ignore-end -->
<!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
18 changes: 14 additions & 4 deletions cypress/integration/fake-login.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@
/// <reference types="../../" />

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();
Expand All @@ -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)");
});
});
5 changes: 4 additions & 1 deletion src/kc-fake-login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down

0 comments on commit 54a0a70

Please sign in to comment.