Skip to content

Commit

Permalink
Merge pull request #814 from istudens/WFLY-18506
Browse files Browse the repository at this point in the history
[WFLY-18506] servlet-security quickstart enhancement CY2023Q3
  • Loading branch information
emmartins authored Dec 14, 2023
2 parents 543ee74 + f88a02d commit 817760c
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 140 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/quickstart_servlet-security_ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: WildFly servlet-security Quickstart CI

on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
paths:
- 'servlet-security/**'
- '.github/workflows/quickstart_ci.yml'
jobs:
call-quickstart_ci:
uses: ./.github/workflows/quickstart_ci.yml
with:
QUICKSTART_PATH: servlet-security
TEST_PROVISIONED_SERVER: true
4 changes: 2 additions & 2 deletions servlet-security/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ Now close the browser. Open a new browser and log in with username `guest` and p
Forbidden
----

// Testing with Arquillian
include::../shared-doc/run-arquillian-integration-tests-with-server-distribution.adoc[leveloffset=+2]
// Server Distribution Testing
include::../shared-doc/run-integration-tests-with-server-distribution.adoc[leveloffset=+2]
// Undeploy the Quickstart
include::../shared-doc/undeploy-the-quickstart.adoc[leveloffset=+2]

Expand Down
100 changes: 30 additions & 70 deletions servlet-security/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,15 @@
</licenses>

<properties>
<!-- The versions for BOMs, Dependencies and Plugins -->
<version.server.bom>30.0.0.Final</version.server.bom>
<!-- the version for the Server -->
<version.server>30.0.0.Final</version.server>
<version.wildfly.maven.plugin>4.2.0.Final</version.wildfly.maven.plugin>
<version.cloud.fp>5.0.0.Final</version.cloud.fp>
<version.wildfly-datasources-galleon-pack>6.0.0.Final</version.wildfly-datasources-galleon-pack>
<!-- the versions for BOMs, Packs and Plugins -->
<version.bom.ee>${version.server}</version.bom.ee>
<version.pack.cloud>5.0.0.Final</version.pack.cloud>
<version.pack.datasources>6.0.0.Final</version.pack.datasources>
<version.plugin.wildfly>4.2.0.Final</version.plugin.wildfly>
<!-- the versions for test dependencies -->
<version.org.junit.jupiter>5.9.1</version.org.junit.jupiter>
</properties>

<repositories>
Expand Down Expand Up @@ -113,7 +116,7 @@
<dependency>
<groupId>org.wildfly.bom</groupId>
<artifactId>wildfly-ee-with-tools</artifactId>
<version>${version.server.bom}</version>
<version>${version.bom.ee}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down Expand Up @@ -150,54 +153,42 @@
<scope>provided</scope>
</dependency>

<!-- Needed for running tests (you may also use TestNG) -->
<!-- Import test dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>

<!-- Optional, but highly recommended -->
<!-- Arquillian allows you to test enterprise code such as EJBs and Transactional(JTA)
JPA from JUnit/TestNG -->
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jboss.arquillian.protocol</groupId>
<artifactId>arquillian-protocol-servlet-jakarta</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${version.org.junit.jupiter}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>${version.plugin.wildfly}</version>
</plugin>
</plugins>
</pluginManagement>
</build>

<profiles>
<profile>
<id>provisioned-server</id>
<dependencies>
<dependency>
<groupId>org.wildfly.arquillian</groupId>
<artifactId>wildfly-arquillian-container-managed</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>${version.wildfly.maven.plugin}</version>
<configuration>
<feature-packs>
<feature-pack>
<location>org.wildfly:wildfly-galleon-pack:${version.server}</location>
</feature-pack>
<feature-pack>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-datasources-galleon-pack</artifactId>
<version>${version.wildfly-datasources-galleon-pack}</version>
<location>org.wildfly:wildfly-datasources-galleon-pack:${version.pack.datasources}</location>
</feature-pack>
</feature-packs>
<layers>
Expand All @@ -223,30 +214,6 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${version.failsafe.plugin}</version>
<configuration>
<environmentVariables>
<JBOSS_HOME>${project.build.directory}/server</JBOSS_HOME>
</environmentVariables>
<includes>
<include>**/ProvisionedManagedSecureIT</include>
</includes>
<excludes>
<exclude>**/RemoteSecureIT</exclude>
</excludes>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
Expand All @@ -257,19 +224,16 @@
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>${version.wildfly.maven.plugin}</version>
<configuration>
<feature-packs>
<feature-pack>
<location>org.wildfly:wildfly-galleon-pack:${version.server}</location>
</feature-pack>
<feature-pack>
<location>org.wildfly.cloud:wildfly-cloud-galleon-pack:${version.cloud.fp}</location>
<location>org.wildfly.cloud:wildfly-cloud-galleon-pack:${version.pack.cloud}</location>
</feature-pack>
<feature-pack>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-datasources-galleon-pack</artifactId>
<version>${version.wildfly-datasources-galleon-pack}</version>
<location>org.wildfly:wildfly-datasources-galleon-pack:${version.pack.datasources}</location>
</feature-pack>
</feature-packs>
<layers>
Expand Down Expand Up @@ -299,20 +263,16 @@
</build>
</profile>
<profile>
<id>arq-remote</id>
<id>integration-testing</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${version.failsafe.plugin}</version>
<configuration>
<includes>
<include>**/RemoteSecureIT</include>
<include>**/*IT</include>
</includes>
<excludes>
<exclude>**/ProvisionedManagedSecureIT</exclude>
</excludes>
</configuration>
<executions>
<execution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
*/
package org.jboss.as.quickstarts.servlet_security;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.net.Authenticator;
import java.net.PasswordAuthentication;
Expand All @@ -28,20 +31,23 @@
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import org.junit.Assert;
import org.junit.Test;

/**
*
* @author Emmanuel Hugonnet (c) 2022 Red Hat, Inc.
* @author istudens
*/
public class BasicRuntimeIT {

public class RemoteSecureIT {
protected static final String DEFAULT_SERVER_HOST = "http://localhost:8080/servlet-security";

protected URI getHTTPEndpoint() {
String host = getServerHost();
String host = System.getenv("SERVER_HOST");
if (host == null) {
host = System.getProperty("server.host");
}
if (host == null) {
host = "http://localhost:8080/servlet-security";
host = DEFAULT_SERVER_HOST;
}
try {
return new URI(host + "/SecuredServlet");
Expand All @@ -50,14 +56,6 @@ protected URI getHTTPEndpoint() {
}
}

protected static String getServerHost() {
String host = System.getenv("SERVER_HOST");
if (host == null) {
host = System.getProperty("server.host");
}
return host;
}

@Test
public void testConnectOk() throws IOException, InterruptedException {
HttpRequest request = HttpRequest.newBuilder(getHTTPEndpoint())
Expand All @@ -70,12 +68,12 @@ protected PasswordAuthentication getPasswordAuthentication() {
}
}).build();
HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString());
Assert.assertEquals(200, response.statusCode());
Assertions.assertEquals(200, response.statusCode());
String[] lines = response.body().toString().split(System.lineSeparator());
Assert.assertEquals("<h1>Successfully called Secured Servlet </h1>", lines[1].trim());
Assert.assertEquals("<p>Principal : quickstartUser</p>", lines[2].trim());
Assert.assertEquals("<p>Remote User : quickstartUser</p>", lines[3].trim());
Assert.assertEquals("<p>Authentication Type : BASIC</p>", lines[4].trim());
Assertions.assertEquals("<h1>Successfully called Secured Servlet </h1>", lines[1].trim());
Assertions.assertEquals("<p>Principal : quickstartUser</p>", lines[2].trim());
Assertions.assertEquals("<p>Remote User : quickstartUser</p>", lines[3].trim());
Assertions.assertEquals("<p>Authentication Type : BASIC</p>", lines[4].trim());
}

@Test
Expand All @@ -90,6 +88,6 @@ protected PasswordAuthentication getPasswordAuthentication() {
}
}).build();
HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString());
Assert.assertEquals(403, response.statusCode());
Assertions.assertEquals(403, response.statusCode());
}
}

This file was deleted.

0 comments on commit 817760c

Please sign in to comment.