Skip to content

Commit

Permalink
Merge pull request #152 from DivyaSreeMunagavalasa/fsintegrationtests
Browse files Browse the repository at this point in the history
File Server Integration Tests using Rest Assured
  • Loading branch information
pranavrd authored Mar 19, 2024
2 parents 1830f1a + 86bcac0 commit 57ba4e2
Show file tree
Hide file tree
Showing 13 changed files with 1,011 additions and 87 deletions.
74 changes: 40 additions & 34 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pipeline {
}
}

stage('Unit Tests and CodeCoverage Test'){
stage('Unit Tests and Code Coverage Test'){
steps{
script{
sh 'docker compose -f docker-compose.test.yml up test'
Expand All @@ -37,22 +37,22 @@ pipeline {
jacoco classPattern: 'target/classes', execPattern: 'target/jacoco.exec', sourcePattern: 'src/main/java', exclusionPattern: 'iudx/file/server/apiserver/FileServerVerticle.class,iudx/file/server/apiserver/FileServerVerticle**,iudx/file/server/authenticator/AuthenticationService.class,iudx/file/server/database/DatabaseService.class,**/JwtDataConverter.class,**/*VertxEBProxy.class,**/Constants.class,**/*VertxProxyHandler.class,**/*Verticle.class,iudx/file/server/deploy/**,iudx/file/server/databroker/DataBrokerServiceImpl.class'
}
post{
always {
recordIssues(
enabledForFailure: true,
blameDisabled: true,
forensicsDisabled: true,
qualityGates: [[threshold:0, type: 'TOTAL', unstable: false]],
tool: checkStyle(pattern: 'target/checkstyle-result.xml')
)
recordIssues(
enabledForFailure: true,
blameDisabled: true,
forensicsDisabled: true,
qualityGates: [[threshold:4, type: 'TOTAL', unstable: false]],
tool: pmdParser(pattern: 'target/pmd.xml')
)
}
always {
recordIssues(
enabledForFailure: true,
blameDisabled: true,
forensicsDisabled: true,
qualityGates: [[threshold:0, type: 'TOTAL', unstable: false]],
tool: checkStyle(pattern: 'target/checkstyle-result.xml')
)
recordIssues(
enabledForFailure: true,
blameDisabled: true,
forensicsDisabled: true,
qualityGates: [[threshold:4, type: 'TOTAL', unstable: false]],
tool: pmdParser(pattern: 'target/pmd.xml')
)
}
failure{
script{
sh 'docker compose -f docker-compose.test.yml down --remove-orphans'
Expand All @@ -67,10 +67,9 @@ pipeline {
}
}

stage('Start File server for Integration Tests'){
stage('Start File-Server for Integration Tests'){
steps{
script{
sh 'scp src/test/resources/iudx-file-server-api.Release-v5.0.0.postman_collection.json jenkins@jenkins-master:/var/lib/jenkins/iudx/fs/Newman/'
sh 'docker compose -f docker-compose.test.yml up -d integTest'
sh 'sleep 45'
}
Expand All @@ -84,24 +83,34 @@ pipeline {
}
}

stage('Integration tests & OWASP ZAP pen test'){
stage('Integration Tests and OWASP ZAP pen test'){
steps{
node('built-in') {
script{
startZap ([host: 'localhost', port: 8090, zapHome: '/var/lib/jenkins/tools/com.cloudbees.jenkins.plugins.customtools.CustomTool/OWASP_ZAP/ZAP_2.11.0'])
sh 'curl http://127.0.0.1:8090/JSON/pscan/action/disableScanners/?ids=10096'
sh 'HTTP_PROXY=\'127.0.0.1:8090\' newman run /var/lib/jenkins/iudx/fs/Newman/iudx-file-server-api.Release-v5.0.0.postman_collection.json -e /home/ubuntu/configs/fs-postman-env.json -n 2 --insecure -r htmlextra --reporter-htmlextra-export /var/lib/jenkins/iudx/fs/Newman/report/report.html --reporter-htmlextra-skipSensitiveData'
runZapAttack()
startZap ([host: '0.0.0.0', port: 8090, zapHome: '/var/lib/jenkins/tools/com.cloudbees.jenkins.plugins.customtools.CustomTool/OWASP_ZAP/ZAP_2.11.0'])
sh 'curl http://0.0.0.0:8090/JSON/pscan/action/disableScanners/?ids=10096'
}
}
script{
sh 'scp /home/ubuntu/configs/fs-config-test.json ./example-configs/config-test.json'
sh 'mvn test-compile failsafe:integration-test -DskipUnitTests=true -DintTestProxyHost=jenkins-master-priv -DintTestProxyPort=8090 -DintTestHost=jenkins-slave1 -DintTestPort=8443'
}
node('built-in') {
script{
runZapAttack()
}
}
}
post{
always{
xunit (
thresholds: [ skipped(failureThreshold: '0'), failed(failureThreshold: '0') ],
tools: [ JUnit(pattern: 'target/failsafe-reports/*.xml') ]
)
node('built-in') {
script{
archiveZap failHighAlerts: 1, failMediumAlerts: 1, failLowAlerts: 1
}
publishHTML([allowMissing: false, alwaysLinkToLastBuild: true, keepAll: true, reportDir: '/var/lib/jenkins/iudx/fs/Newman/report/', reportFiles: 'report.html', reportTitles: '', reportName: 'Integration Test Report'])
}
}
}
failure{
Expand Down Expand Up @@ -156,19 +165,16 @@ pipeline {
}
stage('Integration test on swarm deployment') {
steps {
node('built-in') {
script{
sh 'newman run /var/lib/jenkins/iudx/fs/Newman/iudx-file-server-api.Release-v5.0.0.postman_collection.json -e /home/ubuntu/configs/cd/fs-postman-env.json --insecure -r htmlextra --reporter-htmlextra-export /var/lib/jenkins/iudx/fs/Newman/report/cd-report.html --reporter-htmlextra-skipSensitiveData'
sh 'mvn test-compile failsafe:integration-test -DskipUnitTests=true -DintTestDepl=true'
}
}
}
post{
always{
node('built-in') {
script{
publishHTML([allowMissing: false, alwaysLinkToLastBuild: true, keepAll: true, reportDir: '/var/lib/jenkins/iudx/fs/Newman/report/', reportFiles: 'cd-report.html', reportTitles: '', reportName: 'Docker-Swarm Integration Test Report'])
}
}
xunit (
thresholds: [ skipped(failureThreshold: '0'), failed(failureThreshold: '0') ],
tools: [ JUnit(pattern: 'target/failsafe-reports/*.xml') ]
)
}
failure{
error "Test failure. Stopping pipeline execution!"
Expand Down
2 changes: 0 additions & 2 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ services:
- LOG_LEVEL=INFO
volumes:
- /home/ubuntu/configs/fs-config-test.json:/usr/share/app/secrets/all-verticles-configs/config-dev.json
- /home/ubuntu/configs/keystore-file.jks:/usr/share/app/secrets/keystore-file.jks
- ./docker/runTests.sh:/usr/share/app/docker/runTests.sh
- ./example-configs/:/usr/share/app/example-configs
- ./src/:/usr/share/app/src
Expand All @@ -27,7 +26,6 @@ services:
- LOG_LEVEL=INFO
volumes:
- /home/ubuntu/configs/fs-config-test.json:/usr/share/app/secrets/configs/config.json
- /home/ubuntu/configs/keystore-file.jks:/usr/share/app/secrets/keystore-file.jks
command: bash -c "exec java $$FS_JAVA_OPTS -Dvertx.logger-delegate-factory-class-name=io.vertx.core.logging.Log4j2LogDelegateFactory -jar ./fatjar.jar --host $$(hostname) -c secrets/configs/config.json"
ports:
- "8443:8443"
Expand Down
86 changes: 57 additions & 29 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,34 @@
<name>iudx-file-server</name>

<properties>
<vertx.version>4.3.2</vertx.version>
<vertx.version>4.5.4</vertx.version>
<openjdk.version>11</openjdk.version>
<hazelcast.version>4.0.2</hazelcast.version>
<micrometer.version>1.9.2</micrometer.version>
<curator.version>5.3.0</curator.version>
<micrometer.version>1.12.3</micrometer.version>
<curator.version>5.6.0</curator.version>
<!-- <maven-checkstyle-plugin.version>3.1.2</maven-checkstyle-plugin.version>-->
<junit-jupiter-api.version>5.8.2</junit-jupiter-api.version>
<junit-jupiter-params.version>5.8.2</junit-jupiter-params.version>
<junit-jupiter-engine.version>5.8.2</junit-jupiter-engine.version>
<testcontainers.version>1.17.3</testcontainers.version>
<testcontainer-elastic.version>1.17.3</testcontainer-elastic.version>
<testcontainer-postgres.version>1.17.3</testcontainer-postgres.version>
<log4j2.version>2.17.1</log4j2.version>
<disruptor.version>3.4.4</disruptor.version>
<junit-jupiter.version>1.17.3</junit-jupiter.version>
<elasticsearch-rest-client.version>8.3.3</elasticsearch-rest-client.version>
<junit-jupiter-api.version>5.10.2</junit-jupiter-api.version>
<junit-jupiter-params.version>5.10.2</junit-jupiter-params.version>
<junit-jupiter-engine.version>5.10.2</junit-jupiter-engine.version>
<testcontainers.version>1.19.6</testcontainers.version>
<testcontainer-elastic.version>1.19.6</testcontainer-elastic.version>
<testcontainer-postgres.version>1.19.6</testcontainer-postgres.version>
<log4j2.version>2.23.0</log4j2.version>
<disruptor.version>4.0.0</disruptor.version>
<junit-jupiter.version>1.19.6</junit-jupiter.version>
<elasticsearch-rest-client.version>8.12.2</elasticsearch-rest-client.version>
<!--<elasticsearch-rest-high-level-client.version>7.12.1</elasticsearch-rest-high-level-client.version>-->
<jacoco-maven-plugin.version>0.8.8</jacoco-maven-plugin.version>
<jacoco-maven-plugin.version>0.8.11</jacoco-maven-plugin.version>
<!--<checkstyle.version>10.3.1</checkstyle.version>-->
<checkstyle.version>10.5.0</checkstyle.version>
<maven-shade-plugin.version>3.3.0</maven-shade-plugin.version>
<maven-javadoc-plugin.version>3.4.0</maven-javadoc-plugin.version>
<exec-maven-plugin.version>3.0.0</exec-maven-plugin.version>
<maven-surefire-plugin.version>3.0.0-M7</maven-surefire-plugin.version>
<maven-checkstyle-plugin.version>3.1.2</maven-checkstyle-plugin.version>
<maven-compiler-plugin.version>3.10.1</maven-compiler-plugin.version>
<maven-pmd-plugin.version>3.17.0</maven-pmd-plugin.version>
<maven-surefire-report-plugin.version>3.0.0-M7</maven-surefire-report-plugin.version>
<checkstyle.version>10.13.0</checkstyle.version>
<maven-shade-plugin.version>3.5.2</maven-shade-plugin.version>
<maven-javadoc-plugin.version>3.6.3</maven-javadoc-plugin.version>
<exec-maven-plugin.version>3.2.0</exec-maven-plugin.version>
<maven-surefire-plugin.version>3.2.5</maven-surefire-plugin.version>
<maven-checkstyle-plugin.version>3.3.1</maven-checkstyle-plugin.version>
<maven-compiler-plugin.version>3.12.1</maven-compiler-plugin.version>
<maven-pmd-plugin.version>3.21.2</maven-pmd-plugin.version>
<maven-surefire-report-plugin.version>3.2.5</maven-surefire-report-plugin.version>

<exec.mainClass>iudx.file.server.deploy.Deployer</exec.mainClass>
<exec.mainClassDev>iudx.file.server.deploy.DeployerDev</exec.mainClassDev>
Expand Down Expand Up @@ -84,6 +84,11 @@
<groupId>io.vertx</groupId>
<artifactId>vertx-web-client</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>33.0.0-jre</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
Expand All @@ -110,6 +115,13 @@
<groupId>io.vertx</groupId>
<artifactId>vertx-junit5</artifactId>
</dependency>
<!-- Rest Assured -->
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>5.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-unit</artifactId>
Expand All @@ -119,15 +131,19 @@
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j2.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j2.version}</version>
</dependency>
<!-- slf4j to log4j2 bridge adapter, needed for 'io.netty' logs -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<artifactId>log4j-slf4j2-impl</artifactId>
<version>${log4j2.version}</version>
</dependency>
<!--LMAX Disruptor for enabling Asynchronous log4j2 Logging -->
<dependency>
Expand Down Expand Up @@ -190,7 +206,7 @@
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.4.3</version>
<version>42.7.2</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -211,12 +227,24 @@
<dependency>
<groupId>co.elastic.clients</groupId>
<artifactId>elasticsearch-java</artifactId>
<version>8.3.3</version>
<version>8.12.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.16.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.12.7.1</version>
<version>2.16.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-annotations -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.16.1</version>
</dependency>

<dependency>
Expand All @@ -227,13 +255,13 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<version>3.11.1</version>
<version>5.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>3.11.1</version>
<version>5.10.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public void start() throws Exception {
requestHandler.next();
});

webClientFactory = new WebClientFactory(vertx, config());
webClientFactory = new WebClientFactory(vertx);

// authService = new AuthServiceImpl(vertx, webClientFactory, config());
catalogueService = new CatalogueServiceImpl(webClientFactory, config());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static WebClient createWebClient(Vertx vertxObj, JsonObject config, boole
@Override
public void start() {

webClientFactory = new WebClientFactory(vertx, config());
webClientFactory = new WebClientFactory(vertx);
catalogueService = new CatalogueServiceImpl(webClientFactory, config());
getJwtPublicKey(vertx, config())
.onSuccess(
Expand Down
25 changes: 7 additions & 18 deletions src/main/java/iudx/file/server/common/WebClientFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import io.vertx.core.Vertx;
import io.vertx.core.json.JsonObject;
import io.vertx.core.net.JksOptions;
import io.vertx.ext.web.client.WebClient;
import io.vertx.ext.web.client.WebClientOptions;
import org.apache.logging.log4j.LogManager;
Expand All @@ -13,47 +12,37 @@ public class WebClientFactory {
private static final Logger LOGGER = LogManager.getLogger(WebClientFactory.class);

private final Vertx vertx;
private final JsonObject config;

public WebClientFactory(final Vertx vertx, final JsonObject config) {
public WebClientFactory(final Vertx vertx) {
this.vertx = vertx;
this.config = config;
}

public WebClient getWebClientFor(final ServerType serverType) {
if (serverType.equals(ServerType.FILE_SERVER)) {
return getFileServerWebClient(vertx, config);
return getFileServerWebClient(vertx);
} else if (serverType.equals(ServerType.RESOURCE_SERVER)) {
return getRsServerWebClient(vertx, config);
return getRsServerWebClient(vertx);
} else {
LOGGER.error("Unknown type passed." + serverType);
return null;
}
}

private WebClient getFileServerWebClient(final Vertx vertx, final JsonObject config) {
private WebClient getFileServerWebClient(final Vertx vertx) {
WebClientOptions options =
new WebClientOptions()
.setTrustAll(true)
.setVerifyHost(false)
.setSsl(true)
.setKeyStoreOptions(
new JksOptions()
.setPath(config.getString("file-keystore"))
.setPassword(config.getString("file-keystorePassword")));
.setSsl(true);
return WebClient.create(vertx, options);
}

private WebClient getRsServerWebClient(final Vertx vertx, final JsonObject config) {
private WebClient getRsServerWebClient(final Vertx vertx) {
WebClientOptions options =
new WebClientOptions()
.setTrustAll(true)
.setVerifyHost(false)
.setSsl(true)
.setKeyStoreOptions(
new JksOptions()
.setPath(config.getString("rs-keystore"))
.setPassword(config.getString("rs-keystorePassword")));
.setSsl(true);
return WebClient.create(vertx, options);
}
}
Loading

0 comments on commit 57ba4e2

Please sign in to comment.