Skip to content

Commit

Permalink
Bumped Keycloak version to 13.0.1 (#3)
Browse files Browse the repository at this point in the history
* simplified tests

* simplified tests

* Cucumber tests!

* tests polish

* bumped Keycloak version to 13.0.1

* renamed job
  • Loading branch information
kilmajster authored Jun 4, 2021
1 parent a7dae7e commit a2d3bbe
Show file tree
Hide file tree
Showing 13 changed files with 157 additions and 191 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/automation-tests.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI with 🐋 & Selenide
name: automation tests

on:
push:
Expand All @@ -24,5 +24,5 @@ jobs:
- name: Build test docker container
run: docker-compose build

- name: Run Selenide tests
run: mvn -B -ntp test -P automation-tests -D headless=true
- name: Run automation tests
run: mvn -B -ntp test -P automation-tests -D selenide.headless=true
3 changes: 1 addition & 2 deletions .github/workflows/release-github-tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
mvn \
--no-transfer-progress \
--batch-mode \
-Dgpg.passphrase=${{ secrets.OSSRH_GPG_SECRET_KEY_PASSWORD }} \
-D gpg.passphrase=${{ secrets.OSSRH_GPG_SECRET_KEY_PASSWORD }} \
-P ossrh \
clean deploy
env:
Expand All @@ -56,7 +56,6 @@ jobs:

- name: Build docker init container
run: |
echo "Building docker image = kilmajster/keycloak-username-password-attribute-authenticator:$TAG" && \
docker build \
--build-arg VERSION="$TAG" \
-f src/main/docker/initContainer.Dockerfile \
Expand Down
30 changes: 22 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,16 @@
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>

<keycloak.version>13.0.0</keycloak.version>
<keycloak.version>13.0.1</keycloak.version>

<!-- test dependencies versions -->
<assertj.version>3.19.0</assertj.version>
<cucumber.version>6.10.4</cucumber.version>
<junit.version>4.13.2</junit.version>
<selenium-chrome-driver.version>3.141.59</selenium-chrome-driver.version>
<selenide.version>5.21.0</selenide.version>
<testcontainers.version>1.15.3</testcontainers.version>
<testcontainers-keycloak.version>1.7.0</testcontainers-keycloak.version>
<selenide.version>5.21.0</selenide.version>
<selenium-chrome-driver.version>3.141.59</selenium-chrome-driver.version>

<!-- plugins versions -->
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
Expand All @@ -96,23 +97,24 @@
<dependencies>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-server-spi</artifactId>
<artifactId>keycloak-services</artifactId>
<version>${keycloak.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-server-spi-private</artifactId>
<artifactId>keycloak-server-spi</artifactId>
<version>${keycloak.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-services</artifactId>
<artifactId>keycloak-server-spi-private</artifactId>
<version>${keycloak.version}</version>
<scope>provided</scope>
</dependency>


<!-- test dependencies -->
<dependency>
<groupId>junit</groupId>
Expand Down Expand Up @@ -154,6 +156,19 @@
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>${selenium-chrome-driver.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

Expand Down Expand Up @@ -184,7 +199,7 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<includes>**/*AT</includes>
<includes>**/CucumberConfig.java</includes>
</configuration>
</plugin>
</plugins>
Expand Down Expand Up @@ -237,7 +252,6 @@
<artifactId>maven-gpg-plugin</artifactId>
<version>${maven-gpg-plugin.version}</version>
<configuration>
<!-- Prevent gpg from using pinentry programs -->
<gpgArguments>
<arg>--pinentry-mode</arg>
<arg>loopback</arg>
Expand Down
10 changes: 10 additions & 0 deletions src/test/java/io.github.kilmajster.keycloak/CucumberConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.github.kilmajster.keycloak;

import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
@CucumberOptions(features = "src/test/resources/cucumber")
public class CucumberConfig {
}
93 changes: 93 additions & 0 deletions src/test/java/io.github.kilmajster.keycloak/KeycloakSteps.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package io.github.kilmajster.keycloak;

import com.codeborne.selenide.SelenideElement;
import dasniko.testcontainers.keycloak.KeycloakContainer;
import io.cucumber.java.en.And;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import org.junit.Before;
import org.openqa.selenium.By;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.containers.output.Slf4jLogConsumer;

import static com.codeborne.selenide.Condition.text;
import static com.codeborne.selenide.Selenide.$;
import static com.codeborne.selenide.Selenide.open;
import static io.github.kilmajster.keycloak.TestConstants.*;
import static org.assertj.core.api.Assertions.assertThat;

public final class KeycloakSteps {

private static final Logger log = LoggerFactory.getLogger(KeycloakSteps.class);

private final KeycloakContainer keycloak = new KeycloakContainer(KEYCLOAK_DEV_DOCKER_IMAGE)
.withRealmImportFile("dev-realm.json")
.withLogConsumer(new Slf4jLogConsumer(log));

@Given("keycloak is running with default setup")
public void keycloak_is_running_with_default_setup() {
if (!keycloak.isRunning()) {
log.info("Starting keycloak container...");
keycloak.start();
}
}

@Given("keycloak is running with LOGIN_FORM_ATTRIBUTE_LABEL = {string}")
public void keycloak_is_running_with_login_form_attribute_label_env(final String envLoginFormAttributeLabel) {
keycloak.addEnv("LOGIN_FORM_ATTRIBUTE_LABEL", envLoginFormAttributeLabel);
if (!keycloak.isRunning()) {
log.info("Starting keycloak container with LOGIN_FORM_ATTRIBUTE_LABEL = " + envLoginFormAttributeLabel);
keycloak.start();
}
}

@When("user goes to the account console page")
public void go_to_keycloak_account_page() {
final String keycloakUrl = TestConstants.KEYCLOAK_LOCAL_URL_PREFIX + keycloak.getFirstMappedPort();
open(keycloakUrl + "/auth/realms/dev-realm/account");
}

@Then("user should be not logged in")
public void user_should_be_not_logged_in() {
final String loggedInUser = $(By.id("landingLoggedInUser")).val();
assertThat(loggedInUser).isNullOrEmpty();
}

@When("user clicks a sign in button")
public static void click_sign_in_button() {
log.info("click_sign_in_button()");

$(By.id("landingSignInButton")).click();
}

@Then("login form with attribute input labeled as {string} should be shown")
public static void verify_login_form_is_displayed_with_user_attribute_label(final String label) {
log.info("verify_login_form_is_displayed_with_user_attribute_label( label = " + label + " )");

assertThat($(By.id("kc-form-login")).isDisplayed()).isTrue();
userAttributeFormLabel().shouldHave(text(label));
}

@When("user log into account console with a valid credentials and user attribute equal {string}")
public static void log_into_account_console(final String attribute) {
log.info("log_into_account_console()");

$(By.id("username")).val(TEST_USERNAME);
$(By.id("password")).val(TEST_PASSWORD);
$(By.id("login_form_user_attribute")).val(attribute);
$(By.id("kc-login")).click();
}

@Then("user should be logged into account console")
public static void verify_that_user_is_logged_in() {
log.info("verify_that_user_is_logged_in()");

$(By.id("landingLoggedInUser")).shouldHave(text("test"));
}

private static SelenideElement userAttributeFormLabel() {
return $(By.xpath("//input[@id='login_form_user_attribute']/preceding-sibling::label"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.github.kilmajster.keycloak;

public interface TestConstants {
String KEYCLOAK_DEV_DOCKER_IMAGE = "kilmajster/keycloak-with-authenticator:test";
String KEYCLOAK_LOCAL_URL_PREFIX = "http://localhost:";

String TEST_USERNAME = "test";
String TEST_PASSWORD = "test";
}

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit a2d3bbe

Please sign in to comment.