Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WFLY-18506] servlet-security quickstart enhancement CY2023Q3
Browse files Browse the repository at this point in the history
istudens committed Dec 13, 2023
1 parent c40354e commit ab763a9
Showing 5 changed files with 63 additions and 136 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
@@ -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]

96 changes: 30 additions & 66 deletions servlet-security/pom.xml
Original file line number Diff line number Diff line change
@@ -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.plugin.wildfly>4.2.0.Final</version.plugin.wildfly>
<version.pack.wildfly-datasources-galleon-pack>6.0.0.Final</version.pack.wildfly-datasources-galleon-pack>
<!-- the versions for test dependencies -->
<version.org.junit.jupiter>5.9.1</version.org.junit.jupiter>
</properties>

<repositories>
@@ -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>
@@ -150,45 +153,35 @@
<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>
@@ -197,7 +190,7 @@
<feature-pack>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-datasources-galleon-pack</artifactId>
<version>${version.wildfly-datasources-galleon-pack}</version>
<version>${version.pack.wildfly-datasources-galleon-pack}</version>
</feature-pack>
</feature-packs>
<layers>
@@ -223,30 +216,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>
@@ -257,19 +226,18 @@
<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>
<version>${version.pack.wildfly-datasources-galleon-pack}</version>
</feature-pack>
</feature-packs>
<layers>
@@ -299,20 +267,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>
Original file line number Diff line number Diff line change
@@ -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;
@@ -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");
@@ -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())
@@ -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
@@ -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 ab763a9

Please sign in to comment.