Overview
Keycloak Steps adds step definitions to Webship-js 2.0.x for the markup the platform itself renders, regardless of theme or distribution, so scenarios read as plain sentences instead of CSS selectors. It is a plugin for Webship-js: it ships one file of step definitions you drop into an existing test project, and it composes with the built-in steps rather than duplicating them.
Install
npm install --save-dev @webship-js/keycloak-steps
Then add its step file to cucumber.js beside the Webship-js steps:
require: [
'node_modules/webship-js/tests/step-definitions/**/*.js',
'node_modules/@webship-js/keycloak-steps/tests/step-definitions/*.js',
'tests/step-definitions/**/*.js',
]
Test users
The steps that log in use accounts that already exist on the site, by the handle a feature names (Given I am a logged in user with the "admin" user). The site build creates them; a feature never creates or deletes an account. They are listed in cucumber.js under worldParameters. These are the test accounts of the pack's own test site: put the accounts of your site in your project, and keep real passwords in environment variables.
{
"worldParameters": {
"users": {
"administrator": {
"username": "administrator",
"email": "administrator@example.com",
"password": "dD.123123ddd"
},
"editor": {
"username": "editor",
"email": "editor@example.com",
"password": "dD.123123ddd"
},
"user": {
"username": "user",
"email": "user@example.com",
"password": "dD.123123ddd"
},
"otpuser": {
"username": "otpuser",
"email": "otpuser@example.com",
"password": "dD.123123ddd",
"otpSecret": "O5SWE43INFYHIZLTORXXI4DTMVRXEZLU"
}
}
}
}
Steps
- Given I am a logged in user with the "user" user
- When I log in as "user" with the login form
- When I log in with the username "user" and the password "Wrong-password-1"
- Given I am not logged in
- Given I am on the login page
- When I go to the login page
- When I submit the login form as "otpuser"
- Then the login should be refused with "Invalid username or password."
- When I log out
- Then I should be logged in
- Then I should not be logged in
- Then I should be on the login page
- Then the sign-in should be remembered
- When I restart the login
- When I start a sign-in for the client "webship-app" with the redirect "https://wrong.example.org/"
- Then the signing-in page should list the authenticator "Test phone"
- Then the device activity should show the current session with "Webship test app"
- When I sign out of the account console
- Then I should be back in the app
- When I close the browser and open it again
- Then I should be asked for a one-time code
- When I enter the one-time code of "otpuser"
- When I enter the one-time code "123456"
- Then the one-time code should be refused with "Invalid authenticator code."
- Then I should be asked to set up a one-time code
- When I set up a one-time code named "Test laptop"
- When I ask for a password reset link for "user"
- Then I should see the status message "You should receive an email shortly with further instructions."
- Then I should be asked to update my password
- When I choose a new password
- When I choose the new password "Webship-New-Pass-1" confirmed as "Webship-Other-Pass-2"
- Then I should be asked to verify my email
- When I try to register with:
- Then the "Username" field should have the error "Username already exists."
- Then the "Username" field should have no error
- Then an email with the subject "Reset password" should be sent to "user"
- Then no email should be sent to "nobody@example.com"
- Then the email with the subject "Reset password" to "user" should contain "This link and code will expire within 5 minutes."
- When I open the "Link to reset credentials" link of the email to "user"
- Then I should be asked to grant access to "Webship partner app"
- Then the consent screen should ask for "Email address"
- When I grant access
- Then I should see the error page "Invalid parameter: redirect_uri"
- When I go back to the application
- When I go to the account console
- When I open "Signing in" in the account console
- Then I should be on the "Signing in" page of the account console
- Then the personal info should show "user@example.com" as "Email"
- When I set my "First name" to "Webship tester" in the personal info
- When I save my personal info
- Then I should see the success notification "Your account has been updated."
- When I start setting up an authenticator in the account console
- When I delete the authenticator "Second phone" in the account console
- Then the applications should list "Webship partner app" as "Third-party"
- Then "Webship partner app" should have access to "Email address"
- When I remove the access of "Webship partner app" in the account console
- When I go to the admin console
- Then I should not be allowed into the admin console
- Then the admin console should show the realm "Webship test sign-in"
- When I open "Users" in the admin console
- When I search the users for "user"
- Then the user list should show "user"
- When I open the user "user" in the admin console
- When I open the "Credentials" tab
- When I reset the password of "user" in the admin console
- Then the user's details should show "editor@example.com" as "Email"
- Then the user should have the role "editor"
- Then the realm should have the client "webship-app"
- Given the account "user" must update its password
- Given "user" has not granted access to "Webship partner app"
Every assertion step reads both polarities from one definition: should see and should not see are the same step. Source and issues: github.com/webship/keycloak-steps.