Skip to content

Commit

Permalink
chore: Update to Keycloak 24
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-frak committed Apr 14, 2024
1 parent 9de0f68 commit 201cb4d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 24 deletions.
2 changes: 1 addition & 1 deletion docker/.env
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
COMPOSE_PROJECT_NAME=keycloak_migration_demo
KEYCLOAK_IMAGE=quay.io/keycloak/keycloak:23.0.7
KEYCLOAK_IMAGE=quay.io/keycloak/keycloak:24.0.2
MAVEN_IMAGE=maven:3.9.2-eclipse-temurin-17
OPENJDK_IMAGE=openjdk:17-jdk-slim

Expand Down
58 changes: 37 additions & 21 deletions docker/e2e/cypress/e2e/migrating_users.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ const LEGACY_USER_EMAIL = '[email protected]';
const LEGACY_USER_FIRST_NAME = 'Lucy';
const LEGACY_USER_LAST_NAME = 'Brennan';

const USER_DETAILS_EMAIL_ID = '#email';
const ADMIN_PERSONAL_INFO_EMAIL_ID = '#email';
const ADMIN_PERSONAL_INFO_FIRST_NAME_ID = '#firstName';
const ADMIN_PERSONAL_INFO_LAST_NAME_ID = '#lastName';
const ACCOUNT_INFORMATION_EMAIL_ID = '#email';
const ACCOUNT_INFORMATION_FIRST_NAME_ID = '#firstName';
const ACCOUNT_INFORMATION_LAST_NAME_ID = '#lastName';
const ACCOUNT_DROPDOWN_SELECTOR = '[data-testid="options"]';
const RESET_PASSWORD_EMAIL_ID = '#username';
const RESET_PASSWORD_NEW_PASSWORD_ID = '#password-new';
const RESET_PASSWORD_CONFIRM_NEW_PASSWORD_ID = '#password-confirm';
describe('user migration plugin', () => {

before(() => {
Expand All @@ -48,15 +59,19 @@ describe('user migration plugin', () => {
}

function signOutViaUI() {
cy.get('#pf-dropdown-toggle-id-6').click()
cy.get('#user-dropdown').click()
cy.get('#sign-out').get('a').contains('Sign out').click({force: true});
}

function configureLoginSettings() {
cy.visit('/admin/master/console/#/master/realm-settings/login');
cy.get('#kc-forgot-pw-switch')
.check({force: true});
cy.get('.pf-c-alert__title').should('contain', "Forgot password changed successfully");

cy.get('#kc-forgot-pw-switch').then(($checkbox) => {
if (!$checkbox.prop('checked')) {
cy.wrap($checkbox).check({ force: true });
cy.get('.pf-c-alert__title').should('contain', "Forgot password changed successfully");
}
});
}

function configureMigrationPlugin() {
Expand Down Expand Up @@ -103,28 +118,28 @@ describe('user migration plugin', () => {
cy.get('*[placeholder="Search user"').clear().type('*');
cy.get('.pf-c-input-group').get('.pf-c-button.pf-m-control').click();
cy.get('table').get('td[data-label="Username"]').get('a').contains(ADMIN_USERNAME).click();
cy.get('#kc-email').clear();
cy.get('#kc-email').clear().type(ADMIN_EMAIL);
cy.get('*[data-testid="firstName-input"]').clear().type(ADMIN_USERNAME);
cy.get('*[data-testid="lastName-input"]').clear().type(ADMIN_USERNAME);
cy.get(USER_DETAILS_EMAIL_ID).clear();
cy.get(USER_DETAILS_EMAIL_ID).clear().type(ADMIN_EMAIL);
cy.get('*[data-testid="firstName"]').clear().type(ADMIN_USERNAME);
cy.get('*[data-testid="lastName"]').clear().type(ADMIN_USERNAME);
cy.get('.pf-c-form__actions').get('button[type="submit"]').contains('Save').click({force: true});

}

function configureAdminPersonalInfo() {
cy.intercept('GET', '/realms/master/account/')
cy.intercept('GET', '/realms/master/account/**')
.as("accountDetails");
cy.visit('/realms/master/account/#/personal-info');
cy.visit('/realms/master/account');
cy.wait('@accountDetails');

// Wait a while, otherwise Keycloak overrides the inputs randomly
cy.wait(2000);
cy.get('#email-address').clear();
cy.get(ADMIN_PERSONAL_INFO_EMAIL_ID).clear();
// Wait for email to be cleared
cy.wait(2000);
cy.get('#email-address').clear().type(ADMIN_EMAIL);
cy.get('#first-name').clear().type(ADMIN_USERNAME);
cy.get('#last-name').clear().type(ADMIN_USERNAME);
cy.get(ADMIN_PERSONAL_INFO_EMAIL_ID).clear().type(ADMIN_EMAIL);
cy.get(ADMIN_PERSONAL_INFO_FIRST_NAME_ID).clear().type(ADMIN_USERNAME);
cy.get(ADMIN_PERSONAL_INFO_LAST_NAME_ID).clear().type(ADMIN_USERNAME);

cy.get('button').contains('Save').click();

Expand Down Expand Up @@ -238,14 +253,15 @@ describe('user migration plugin', () => {
}

function updateAccountInformation() {
cy.get('#email').should('have.value', LEGACY_USER_EMAIL);
cy.get('#firstName').should('have.value', LEGACY_USER_FIRST_NAME);
cy.get('#lastName').should('have.value', LEGACY_USER_LAST_NAME);
cy.get(ACCOUNT_INFORMATION_EMAIL_ID).should('have.value', LEGACY_USER_EMAIL);
cy.get(ACCOUNT_INFORMATION_FIRST_NAME_ID).should('have.value', LEGACY_USER_FIRST_NAME);
cy.get(ACCOUNT_INFORMATION_LAST_NAME_ID).should('have.value', LEGACY_USER_LAST_NAME);
cy.get("input").contains("Submit").click();
}

function assertIsLoggedInAsLegacyUser() {
cy.get('#landingLoggedInUser').should('contain', LEGACY_USER_FIRST_NAME + ' ' + LEGACY_USER_LAST_NAME);
cy.get(ACCOUNT_DROPDOWN_SELECTOR)
.should('contain', LEGACY_USER_FIRST_NAME + ' ' + LEGACY_USER_LAST_NAME);
}

it('should reset password after inputting wrong credentials', () => {
Expand Down Expand Up @@ -275,7 +291,7 @@ describe('user migration plugin', () => {
.as('resetCredentials');
cy.get("a").contains("Forgot Password?").click();
cy.wait('@resetCredentials');
cy.get('#username').clear().type(LEGACY_USER_EMAIL);
cy.get(RESET_PASSWORD_EMAIL_ID).clear().type(LEGACY_USER_EMAIL);
cy.get('input[type=submit]').click();
cy.get('body').should('contain.text',
'You should receive an email shortly with further instructions.');
Expand All @@ -298,8 +314,8 @@ describe('user migration plugin', () => {
}

function inputNewPassword() {
cy.get('#password-new').type(LEGACY_USER_PASSWORD);
cy.get('#password-confirm').type(LEGACY_USER_PASSWORD);
cy.get(RESET_PASSWORD_NEW_PASSWORD_ID).type(LEGACY_USER_PASSWORD);
cy.get(RESET_PASSWORD_CONFIRM_NEW_PASSWORD_ID).type(LEGACY_USER_PASSWORD);
cy.get('input[type=submit]').click();
}

Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

<groupId>com.danielfrak.code.keycloak.providers</groupId>
<artifactId>keycloak-rest-provider</artifactId>
<version>3.0.1-SNAPSHOT</version>
<version>4.0.0-SNAPSHOT</version>
<properties>
<java.version>17</java.version>
<keycloak.version>23.0.7</keycloak.version>
<keycloak.version>24.0.2</keycloak.version>
<mockito.version>5.11.0</mockito.version>

<maven.compiler.target>${java.version}</maven.compiler.target>
Expand Down

0 comments on commit 201cb4d

Please sign in to comment.