From 9fe62a91c7f0074329513b2b8320700ab01109ec Mon Sep 17 00:00:00 2001 From: DivyaSreeMunagavalasa Date: Thu, 11 Jan 2024 16:55:49 +0530 Subject: [PATCH 01/22] File Server Integration Tests - File upload --- .../RestAssuredConfiguration.java | 45 +++++++++++++++++++ .../integrationtests/TokenHelper.java | 20 +++++++++ .../FileDownloadIntegrationTest.java | 28 ++++++++++++ 3 files changed, 93 insertions(+) create mode 100644 src/test/java/iudx/file/server/apiserver/integrationtests/RestAssuredConfiguration.java create mode 100644 src/test/java/iudx/file/server/apiserver/integrationtests/TokenHelper.java create mode 100644 src/test/java/iudx/file/server/apiserver/integrationtests/fileDownload/FileDownloadIntegrationTest.java diff --git a/src/test/java/iudx/file/server/apiserver/integrationtests/RestAssuredConfiguration.java b/src/test/java/iudx/file/server/apiserver/integrationtests/RestAssuredConfiguration.java new file mode 100644 index 0000000..0b656cf --- /dev/null +++ b/src/test/java/iudx/file/server/apiserver/integrationtests/RestAssuredConfiguration.java @@ -0,0 +1,45 @@ +package iudx.file.server.apiserver.integrationtests; + +import io.restassured.RestAssured; +import io.vertx.core.Vertx; +import io.vertx.core.json.JsonObject; +import iudx.file.server.configuration.Configuration; +import org.junit.jupiter.api.extension.BeforeAllCallback; +import org.junit.jupiter.api.extension.ExtensionContext; + +import static io.restassured.RestAssured.*; + +/** + * JUnit5 extension to allow {@link RestAssured} configuration to be injected into all integration + * tests using {@link org.junit.jupiter.api.extension.ExtendWith}. + */ +public class RestAssuredConfiguration implements BeforeAllCallback { + + @Override + public void beforeAll(ExtensionContext context) { + Vertx vertx = Vertx.vertx(); + Configuration fileServerConfig = new Configuration(); + JsonObject config = fileServerConfig.configLoader(0, vertx); + String testHost = config.getString("ip"); + //System.out.println(testHost); + if (testHost != null) { + baseURI = "http://" + testHost; + } else { + baseURI = "http://localhost"; + } + + String testPort = config.getString("httpPort"); + //System.out.println(testPort); + + if (testPort != null) { + port = Integer.parseInt(testPort); + } else { + port = 8443; + } + basePath = "/iudx/v1"; + //System.out.println("This is the base path and port!"+ basePath + port); + + enableLoggingOfRequestAndResponseIfValidationFails(); + + } +} diff --git a/src/test/java/iudx/file/server/apiserver/integrationtests/TokenHelper.java b/src/test/java/iudx/file/server/apiserver/integrationtests/TokenHelper.java new file mode 100644 index 0000000..ae45590 --- /dev/null +++ b/src/test/java/iudx/file/server/apiserver/integrationtests/TokenHelper.java @@ -0,0 +1,20 @@ +package iudx.file.server.apiserver.integrationtests; + +public class TokenHelper { + + + public static String delegateToken = + "eyJpc3MiOiJjb3MuaXVkeC5pbyIsInR5cCI6IkpXVCIsImFsZyI6IkVTMjU2In0.eyJzdWIiOiJmZDQ3NDg2Yi0zNDk3LTQyNDgtYWMxZS0wODJlNGQzN2E2NmMiLCJpc3MiOiJjb3MuaXVkeC5pbyIsImF1ZCI6InJzLml1ZHguaW8iLCJleHAiOjE3MDIzMTM5NzksImlhdCI6MTcwMjI3MDc3OSwiaWlkIjoicmk6ODNjMmU1YzItMzU3NC00ZTExLTk1MzAtMmIxZmJkZmNlODMyIiwicm9sZSI6ImRlbGVnYXRlIiwiY29ucyI6e30sInJnIjoiOGI5NWFiODAtMmFhZi00NjM2LWE2NWUtN2YyNTYzZDBkMzcxIiwiZGlkIjoiYjJjMjdmM2YtMjUyNC00YTg0LTgxNmUtOTFmOWFiMjNmODM3IiwiZHJsIjoicHJvdmlkZXIifQ.XtK0GGAnFqZeMk13JOuvahEqn7lV-QjryM4jpItJppSkMJX0x5ibhJS_1NqETiKZ7lN6sVM99-cs5VqSSqklUQ"; +public static String openResourceToken="eyJpc3MiOiJjb3MuaXVkeC5pbyIsInR5cCI6IkpXVCIsImFsZyI6IkVTMjU2In0.eyJzdWIiOiJmZDQ3NDg2Yi0zNDk3LTQyNDgtYWMxZS0wODJlNGQzN2E2NmMiLCJpc3MiOiJjb3MuaXVkeC5pbyIsImF1ZCI6InJzLml1ZHguaW8iLCJleHAiOjE3MDQ5OTI5NTIsImlhdCI6MTcwNDk0OTc1MiwiaWlkIjoicmk6YjU4ZGExOTMtMjNkOS00M2ViLWI5OGEtYTEwM2Q0YjYxMDNjIiwicm9sZSI6ImNvbnN1bWVyIiwiY29ucyI6eyJhY2Nlc3MiOlsiYXBpIiwic3ViIiwiZmlsZSIsImFzeW5jIl19LCJyZyI6IjViNzU1NmI1LTA3NzktNGM0Ny05Y2YyLTNmMjA5Nzc5YWEyMiJ9.bjhVn1pnEbfBlFAwnEJVPTvo2LOgLRTlEftLHJMDt-JR7TvMMzDtfEXue3tnYHXlY8MDqV-SDceC-u9utglU8w"; + static String consumerTokenForOpenResource = + "eyJpc3MiOiJjb3MuaXVkeC5pbyIsInR5cCI6IkpXVCIsImFsZyI6IkVTMjU2In0.eyJzdWIiOiJmZDQ3NDg2Yi0zNDk3LTQyNDgtYWMxZS0wODJlNGQzN2E2NmMiLCJpc3MiOiJjb3MuaXVkeC5pbyIsImF1ZCI6InJzLml1ZHguaW8iLCJleHAiOjE3MDIwNTU1MTgsImlhdCI6MTcwMjAxMjMxOCwiaWlkIjoicmk6YjU4ZGExOTMtMjNkOS00M2ViLWI5OGEtYTEwM2Q0YjYxMDNjIiwicm9sZSI6ImNvbnN1bWVyIiwiY29ucyI6eyJhY2Nlc3MiOlsic3ViIiwiYXBpIiwiYXN5bmMiXX0sInJnIjoiNWI3NTU2YjUtMDc3OS00YzQ3LTljZjItM2YyMDk3NzlhYTIyIn0.KSyn7VghZM4bCMmogtWhzFtUoGDC7BpHaOYhrQ5q-3J1okYs_xj3rMyjazWo6wWOuxhZWWiz3Mv77ArMubugng"; + + static String consumerTokenForSecureResource= + "eyJpc3MiOiJjb3MuaXVkeC5pbyIsInR5cCI6IkpXVCIsImFsZyI6IkVTMjU2In0.eyJzdWIiOiJmZDQ3NDg2Yi0zNDk3LTQyNDgtYWMxZS0wODJlNGQzN2E2NmMiLCJpc3MiOiJjb3MuaXVkeC5pbyIsImF1ZCI6InJzLml1ZHguaW8iLCJleHAiOjE3MDIwNTU2MDYsImlhdCI6MTcwMjAxMjQwNiwiaWlkIjoicmk6ODNjMmU1YzItMzU3NC00ZTExLTk1MzAtMmIxZmJkZmNlODMyIiwicm9sZSI6ImNvbnN1bWVyIiwiY29ucyI6eyJhY2Nlc3MiOlsic3ViIiwiYXBpIiwiZmlsZSJdLCJsaW1pdHMiOlt7InN1YiI6IjEwMEdCIn0seyJhcGkiOjEwMDB9XX0sInJnIjoiOGI5NWFiODAtMmFhZi00NjM2LWE2NWUtN2YyNTYzZDBkMzcxIn0.UTc1Felpa8wGXBjOJQw1i3oFl8RfSCm9CgI081C-62yJIPFm9z00CMsnX4rPsJQYI1QGvA6biFFIZJ4Z941Ttw"; + + public static String adminToken= + "eyJpc3MiOiJjb3MuaXVkeC5pbyIsInR5cCI6IkpXVCIsImFsZyI6IkVTMjU2In0.eyJzdWIiOiJmZDQ3NDg2Yi0zNDk3LTQyNDgtYWMxZS0wODJlNGQzN2E2NmMiLCJpc3MiOiJjb3MuaXVkeC5pbyIsImF1ZCI6InJzLml1ZHguaW8iLCJleHAiOjE3MDIwNTU2OTksImlhdCI6MTcwMjAxMjQ5OSwiaWlkIjoicnM6cnMuaXVkeC5pbyIsInJvbGUiOiJhZG1pbiIsImNvbnMiOnt9fQ.zd-i7RxxDjKAdESNuJuCKOnxXMHk4EgC-2g9J1trbrcyQFKTlLlEUX70Xakeke2xBfKX0E6Qt5ScZKu4xOHN1Q"; + + } + + diff --git a/src/test/java/iudx/file/server/apiserver/integrationtests/fileDownload/FileDownloadIntegrationTest.java b/src/test/java/iudx/file/server/apiserver/integrationtests/fileDownload/FileDownloadIntegrationTest.java new file mode 100644 index 0000000..016fed8 --- /dev/null +++ b/src/test/java/iudx/file/server/apiserver/integrationtests/fileDownload/FileDownloadIntegrationTest.java @@ -0,0 +1,28 @@ +package iudx.file.server.apiserver.integrationtests.fileDownload; + +import iudx.file.server.apiserver.integrationtests.RestAssuredConfiguration; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import static io.restassured.RestAssured.given; +import static iudx.file.server.apiserver.integrationtests.TokenHelper.openResourceToken; +import static org.hamcrest.Matchers.equalTo; + +@ExtendWith(RestAssuredConfiguration.class) +public class FileDownloadIntegrationTest { + @Test + @DisplayName("200 (Success) DX file download - RL (Sample file )") + public void fileDownloadSuccessTest() { + String fileId="83c2e5c2-3574-4e11-9530-2b1fbdfce832/sample.txt"; + given() + .queryParam("id", fileId) + .header("token",openResourceToken) + .when() + .get("/consumer/ratings") + .then() + .statusCode(200) + .log().body(); + //.body("type", equalTo("urn:dx:cat:Success")); + } +} From 2ffb828d7e6b04687a3ea0094250c887cc061b25 Mon Sep 17 00:00:00 2001 From: DivyaSreeMunagavalasa Date: Fri, 12 Jan 2024 10:09:57 +0530 Subject: [PATCH 02/22] File Server Integration Tests - File upload --- .../FileDownloadIntegrationTest.java | 28 --- .../FileServerUploadIntegrationTest.java | 194 ++++++++++++++++++ 2 files changed, 194 insertions(+), 28 deletions(-) delete mode 100644 src/test/java/iudx/file/server/apiserver/integrationtests/fileDownload/FileDownloadIntegrationTest.java create mode 100644 src/test/java/iudx/file/server/apiserver/integrationtests/upload/FileServerUploadIntegrationTest.java diff --git a/src/test/java/iudx/file/server/apiserver/integrationtests/fileDownload/FileDownloadIntegrationTest.java b/src/test/java/iudx/file/server/apiserver/integrationtests/fileDownload/FileDownloadIntegrationTest.java deleted file mode 100644 index 016fed8..0000000 --- a/src/test/java/iudx/file/server/apiserver/integrationtests/fileDownload/FileDownloadIntegrationTest.java +++ /dev/null @@ -1,28 +0,0 @@ -package iudx.file.server.apiserver.integrationtests.fileDownload; - -import iudx.file.server.apiserver.integrationtests.RestAssuredConfiguration; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import static io.restassured.RestAssured.given; -import static iudx.file.server.apiserver.integrationtests.TokenHelper.openResourceToken; -import static org.hamcrest.Matchers.equalTo; - -@ExtendWith(RestAssuredConfiguration.class) -public class FileDownloadIntegrationTest { - @Test - @DisplayName("200 (Success) DX file download - RL (Sample file )") - public void fileDownloadSuccessTest() { - String fileId="83c2e5c2-3574-4e11-9530-2b1fbdfce832/sample.txt"; - given() - .queryParam("id", fileId) - .header("token",openResourceToken) - .when() - .get("/consumer/ratings") - .then() - .statusCode(200) - .log().body(); - //.body("type", equalTo("urn:dx:cat:Success")); - } -} diff --git a/src/test/java/iudx/file/server/apiserver/integrationtests/upload/FileServerUploadIntegrationTest.java b/src/test/java/iudx/file/server/apiserver/integrationtests/upload/FileServerUploadIntegrationTest.java new file mode 100644 index 0000000..6bc2231 --- /dev/null +++ b/src/test/java/iudx/file/server/apiserver/integrationtests/upload/FileServerUploadIntegrationTest.java @@ -0,0 +1,194 @@ +package iudx.file.server.apiserver.integrationtests.upload; + +import io.restassured.http.ContentType; +import iudx.file.server.apiserver.integrationtests.RestAssuredConfiguration; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import java.io.*; +import static org.hamcrest.Matchers.equalTo; +import static io.restassured.RestAssured.given; +import static iudx.file.server.apiserver.integrationtests.TokenHelper.delegateToken; +import static org.hamcrest.Matchers.notNullValue; + +@ExtendWith(RestAssuredConfiguration.class) +public class FileServerUploadIntegrationTest { + + private File createTempFileWithContent() { + // Create a temporary file + File tempFile; + try { + tempFile = File.createTempFile("test", ".txt"); + } catch (IOException e) { + throw new RuntimeException("Failed to create a temporary file", e); + } + + // Write content to the file + try (FileWriter writer = new FileWriter(tempFile)) { + writer.write("This is the content of the file for testing purposes."); + } catch (IOException e) { + throw new RuntimeException("Failed to write content to the temporary file", e); + } + + return tempFile; + } + // Create a temporary file and get its reference + File tempFile = createTempFileWithContent(); + String id ="83c2e5c2-3574-4e11-9530-2b1fbdfce832"; + boolean isSample=true; + String invalidToken ="abc"; + String fileDownloadURL = "https://docs.google.com/document/d/19f6oOIxHVjC3twcRHQATjrEXJsDO0rLixoFgLV7xMxk/edit?usp=sharing"; + + @Test + @DisplayName("200 (Success) DX file upload - Resource level (sample)") + public void fileUploadSuccessTest() { + + given() + .multiPart("file", tempFile, "text/plain") + .formParam("id", id) + .formParam("isSample", isSample) + .header("token", delegateToken) + .when() + .post("/upload") + .then() + .statusCode(200) + .log().body() + .contentType(ContentType.JSON) + .body("results", notNullValue()) + .body("results[0].fileId", notNullValue()); + } + @Test + @DisplayName("401 (not authorized) DX file upload - Resource level (sample)") + public void unauthorisedFileUploadTest() { + + given() + .multiPart("file", tempFile, "text/plain") + .formParam("id", id) + .formParam("isSample", isSample) + .header("token", invalidToken) + .when() + .post("/upload") + .then() + .statusCode(401) + .log().body() + .contentType(ContentType.JSON) + .body("type", equalTo("urn:dx:rs:invalidAuthorizationToken")) + .body("title", equalTo("Not authorized")) + .body("detail", equalTo("Token is invalid")); + } + @Test + @DisplayName("200 (Success) - Archive Resource Level") + public void successArchiveTest() { + // Create a temporary file and get its reference + //File tempFile = createTempFileWithContent(); + given() + .multiPart("file", tempFile, "text/plain") + .formParam("id", id) + .formParam("startTime", "2020-09-05T00:00:00Z") + .formParam("endTime", "2020-09-15T00:00:00Z") + .formParam("geometry", "point") + .formParam("coordinates", "[72.81,21.16]") + .header("token", delegateToken) + .when() + .post("/upload") + .then() + .statusCode(200) + .log().body() + .contentType(ContentType.JSON) + .body("type", equalTo("urn:dx:rs:success")) + .body("title", equalTo("Success")) + .body("results", notNullValue()) + .body("results[0].fileId", notNullValue()); + } + @Test + @DisplayName("200 (Success) - Archive Resource Level") + public void unauthorisedArchiveTest() { + // Create a temporary file and get its reference + //File tempFile = createTempFileWithContent(); + + given() + .multiPart("file", tempFile, "text/plain") + .formParam("id", id) + .formParam("startTime", "2020-09-05T00:00:00Z") + .formParam("endTime", "2020-09-15T00:00:00Z") + .formParam("geometry", "point") + .formParam("coordinates", "[72.81,21.16]") + .header("token",invalidToken) + .when() + .post("/upload") + .then() + .statusCode(401) + .log().body() + .contentType(ContentType.JSON) + .body("type", equalTo("urn:dx:rs:invalidAuthorizationToken")) + .body("title", equalTo("Not authorized")) + .body("detail", equalTo("Token is invalid")); + } + @Test + @DisplayName("400 (No id param in request) DX file upload") + public void invalidParamFileUploadTest() { + // Create a temporary file and get its reference + //File tempFile = createTempFileWithContent(); + + given() + .multiPart("file", tempFile, "text/plain") + .formParam("id1", id) + .formParam("isSample", isSample) + .header("token",delegateToken) + .when() + .post("/upload") + .then() + .statusCode(400) + .log().body() + .contentType(ContentType.JSON) + .body("type", equalTo("urn:dx:rs:invalidPayloadFormat")) + .body("title", equalTo("Bad Request")) + .body("detail", equalTo("Validation error : null or blank value for required mandatory field")); + } + @Test + @DisplayName("400 (Invalid isSample value) DX file upload") + public void invalidIsSampleFileUploadTest() { + // Create a temporary file and get its reference + //File tempFile = createTempFileWithContent(); + given() + .multiPart("file", tempFile, "text/plain") + .formParam("id", id) + .formParam("isSample", "true1") + .header("token",delegateToken) + .when() + .post("/upload") + .then() + .statusCode(400) + .log().body() + .contentType(ContentType.JSON) + .body("type", equalTo("urn:dx:rs:invalidAttributeValue")) + .body("title", equalTo("Bad Request")) + .body("detail", equalTo("Validation error : Invalid isSample field value [ true1 ]")); + } + @Test + @DisplayName("200 (Success) DX file upload - Resource level (External Storage)") + public void fileUploadExternalStorageTest() { + // Create a temporary file and get its reference + //File tempFile = createTempFileWithContent(); + given() + .multiPart("file", tempFile, "text/plain") + .formParam("id", id) + .formParam("startTime", "2020-09-05T00:00:00Z") + .formParam("endTime", "2020-09-15T00:00:00Z") + .formParam("geometry", "point") + .formParam("coordinates", "[72.81,21.16]") + .formParam("file-download-url",fileDownloadURL) + .header("token", delegateToken) + .when() + .post("/upload") + .then() + .statusCode(200) + .log().body() + .contentType(ContentType.JSON) + .body("type", equalTo("urn:dx:rs:success")) + .body("title", equalTo("Success")) + .body("results", notNullValue()) + .body("results[0].fileId", notNullValue()); + } + +} From 01657d4f66401d273488a98ddb8d9aa832a7f97c Mon Sep 17 00:00:00 2001 From: DivyaSreeMunagavalasa Date: Mon, 15 Jan 2024 19:11:44 +0530 Subject: [PATCH 03/22] Written Integration Tests for File Upload and File Download along with the automation of generating tokens --- .../RestAssuredConfiguration.java | 55 ++++++- .../integrationtests/TokenHelper.java | 20 --- .../FileServerIntegrationTests.java} | 153 ++++++++++++++++-- .../file/server/authenticator/TokenSetup.java | 145 +++++++++++++++++ .../server/authenticator/TokensForITs.java | 9 ++ 5 files changed, 341 insertions(+), 41 deletions(-) delete mode 100644 src/test/java/iudx/file/server/apiserver/integrationtests/TokenHelper.java rename src/test/java/iudx/file/server/apiserver/integrationtests/{upload/FileServerUploadIntegrationTest.java => files/FileServerIntegrationTests.java} (59%) create mode 100644 src/test/java/iudx/file/server/authenticator/TokenSetup.java create mode 100644 src/test/java/iudx/file/server/authenticator/TokensForITs.java diff --git a/src/test/java/iudx/file/server/apiserver/integrationtests/RestAssuredConfiguration.java b/src/test/java/iudx/file/server/apiserver/integrationtests/RestAssuredConfiguration.java index 0b656cf..eaf1827 100644 --- a/src/test/java/iudx/file/server/apiserver/integrationtests/RestAssuredConfiguration.java +++ b/src/test/java/iudx/file/server/apiserver/integrationtests/RestAssuredConfiguration.java @@ -3,11 +3,15 @@ import io.restassured.RestAssured; import io.vertx.core.Vertx; import io.vertx.core.json.JsonObject; +import iudx.file.server.authenticator.TokenSetup; import iudx.file.server.configuration.Configuration; import org.junit.jupiter.api.extension.BeforeAllCallback; import org.junit.jupiter.api.extension.ExtensionContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import static io.restassured.RestAssured.*; +import static iudx.file.server.authenticator.TokensForITs.*; /** * JUnit5 extension to allow {@link RestAssured} configuration to be injected into all integration @@ -15,13 +19,19 @@ */ public class RestAssuredConfiguration implements BeforeAllCallback { + private static final Logger logger = LoggerFactory.getLogger(RestAssuredConfiguration.class); + @Override public void beforeAll(ExtensionContext context) { Vertx vertx = Vertx.vertx(); Configuration fileServerConfig = new Configuration(); JsonObject config = fileServerConfig.configLoader(0, vertx); String testHost = config.getString("ip"); - //System.out.println(testHost); + // String testHost = System.getProperty("intTestHost"); + //System.out.println("testHost:"+testHost); + JsonObject config2 = fileServerConfig.configLoader(1, vertx); + String authServerHost = config2.getString("authHost"); + if (testHost != null) { baseURI = "http://" + testHost; } else { @@ -29,17 +39,54 @@ public void beforeAll(ExtensionContext context) { } String testPort = config.getString("httpPort"); - //System.out.println(testPort); - + // String testPort = System.getProperty("intTestPort"); if (testPort != null) { port = Integer.parseInt(testPort); } else { port = 8443; } + // System.out.println(testPort+","+testHost); basePath = "/iudx/v1"; - //System.out.println("This is the base path and port!"+ basePath + port); + String dxAuthBasePath = "auth/v1"; + String authEndpoint = "https://"+ authServerHost + "/" + dxAuthBasePath + "/token"; + String proxyHost = System.getProperty("intTestProxyHost"); + String proxyPort = System.getProperty("intTestProxyPort"); + + JsonObject clientCredentials = config2.getJsonObject("clientCredentials"); + String clientId = clientCredentials.getString("clientID"); + String clientSecret = clientCredentials.getString("clientSecret"); + String delegationId = clientCredentials.getString("delegationId"); + if (proxyHost != null && proxyPort != null) { + proxy(proxyHost, Integer.parseInt(proxyPort)); + } + logger.info("setting up the tokens"); + TokenSetup.setupTokens(authEndpoint, clientId, clientSecret, delegationId); + // Wait for tokens to be available before proceeding + waitForTokens(); enableLoggingOfRequestAndResponseIfValidationFails(); + } + private void waitForTokens() { + int maxAttempts = 5; + int attempt = 0; + + // Keep trying to get tokens until they are available or max attempts are reached + while ((secureResourceToken == null || adminToken == null || openResourceToken==null || delegateToken==null ) && attempt < maxAttempts) { + logger.info("Waiting for tokens to be available. Attempt: " + (attempt + 1)); + // Introduce a delay between attempts + try { + Thread.sleep(3000); // Adjust the delay as we needed + } catch (InterruptedException e) { + e.printStackTrace(); + } + attempt++; + } + if (secureResourceToken == null || adminToken == null || openResourceToken==null || delegateToken==null ) { + // Log an error or throw an exception if tokens are still not available + throw new RuntimeException("Failed to retrieve tokens after multiple attempts."); + } else { + logger.info("Tokens are now available. Proceeding with RestAssured configuration."); + } } } diff --git a/src/test/java/iudx/file/server/apiserver/integrationtests/TokenHelper.java b/src/test/java/iudx/file/server/apiserver/integrationtests/TokenHelper.java deleted file mode 100644 index ae45590..0000000 --- a/src/test/java/iudx/file/server/apiserver/integrationtests/TokenHelper.java +++ /dev/null @@ -1,20 +0,0 @@ -package iudx.file.server.apiserver.integrationtests; - -public class TokenHelper { - - - public static String delegateToken = - "eyJpc3MiOiJjb3MuaXVkeC5pbyIsInR5cCI6IkpXVCIsImFsZyI6IkVTMjU2In0.eyJzdWIiOiJmZDQ3NDg2Yi0zNDk3LTQyNDgtYWMxZS0wODJlNGQzN2E2NmMiLCJpc3MiOiJjb3MuaXVkeC5pbyIsImF1ZCI6InJzLml1ZHguaW8iLCJleHAiOjE3MDIzMTM5NzksImlhdCI6MTcwMjI3MDc3OSwiaWlkIjoicmk6ODNjMmU1YzItMzU3NC00ZTExLTk1MzAtMmIxZmJkZmNlODMyIiwicm9sZSI6ImRlbGVnYXRlIiwiY29ucyI6e30sInJnIjoiOGI5NWFiODAtMmFhZi00NjM2LWE2NWUtN2YyNTYzZDBkMzcxIiwiZGlkIjoiYjJjMjdmM2YtMjUyNC00YTg0LTgxNmUtOTFmOWFiMjNmODM3IiwiZHJsIjoicHJvdmlkZXIifQ.XtK0GGAnFqZeMk13JOuvahEqn7lV-QjryM4jpItJppSkMJX0x5ibhJS_1NqETiKZ7lN6sVM99-cs5VqSSqklUQ"; -public static String openResourceToken="eyJpc3MiOiJjb3MuaXVkeC5pbyIsInR5cCI6IkpXVCIsImFsZyI6IkVTMjU2In0.eyJzdWIiOiJmZDQ3NDg2Yi0zNDk3LTQyNDgtYWMxZS0wODJlNGQzN2E2NmMiLCJpc3MiOiJjb3MuaXVkeC5pbyIsImF1ZCI6InJzLml1ZHguaW8iLCJleHAiOjE3MDQ5OTI5NTIsImlhdCI6MTcwNDk0OTc1MiwiaWlkIjoicmk6YjU4ZGExOTMtMjNkOS00M2ViLWI5OGEtYTEwM2Q0YjYxMDNjIiwicm9sZSI6ImNvbnN1bWVyIiwiY29ucyI6eyJhY2Nlc3MiOlsiYXBpIiwic3ViIiwiZmlsZSIsImFzeW5jIl19LCJyZyI6IjViNzU1NmI1LTA3NzktNGM0Ny05Y2YyLTNmMjA5Nzc5YWEyMiJ9.bjhVn1pnEbfBlFAwnEJVPTvo2LOgLRTlEftLHJMDt-JR7TvMMzDtfEXue3tnYHXlY8MDqV-SDceC-u9utglU8w"; - static String consumerTokenForOpenResource = - "eyJpc3MiOiJjb3MuaXVkeC5pbyIsInR5cCI6IkpXVCIsImFsZyI6IkVTMjU2In0.eyJzdWIiOiJmZDQ3NDg2Yi0zNDk3LTQyNDgtYWMxZS0wODJlNGQzN2E2NmMiLCJpc3MiOiJjb3MuaXVkeC5pbyIsImF1ZCI6InJzLml1ZHguaW8iLCJleHAiOjE3MDIwNTU1MTgsImlhdCI6MTcwMjAxMjMxOCwiaWlkIjoicmk6YjU4ZGExOTMtMjNkOS00M2ViLWI5OGEtYTEwM2Q0YjYxMDNjIiwicm9sZSI6ImNvbnN1bWVyIiwiY29ucyI6eyJhY2Nlc3MiOlsic3ViIiwiYXBpIiwiYXN5bmMiXX0sInJnIjoiNWI3NTU2YjUtMDc3OS00YzQ3LTljZjItM2YyMDk3NzlhYTIyIn0.KSyn7VghZM4bCMmogtWhzFtUoGDC7BpHaOYhrQ5q-3J1okYs_xj3rMyjazWo6wWOuxhZWWiz3Mv77ArMubugng"; - - static String consumerTokenForSecureResource= - "eyJpc3MiOiJjb3MuaXVkeC5pbyIsInR5cCI6IkpXVCIsImFsZyI6IkVTMjU2In0.eyJzdWIiOiJmZDQ3NDg2Yi0zNDk3LTQyNDgtYWMxZS0wODJlNGQzN2E2NmMiLCJpc3MiOiJjb3MuaXVkeC5pbyIsImF1ZCI6InJzLml1ZHguaW8iLCJleHAiOjE3MDIwNTU2MDYsImlhdCI6MTcwMjAxMjQwNiwiaWlkIjoicmk6ODNjMmU1YzItMzU3NC00ZTExLTk1MzAtMmIxZmJkZmNlODMyIiwicm9sZSI6ImNvbnN1bWVyIiwiY29ucyI6eyJhY2Nlc3MiOlsic3ViIiwiYXBpIiwiZmlsZSJdLCJsaW1pdHMiOlt7InN1YiI6IjEwMEdCIn0seyJhcGkiOjEwMDB9XX0sInJnIjoiOGI5NWFiODAtMmFhZi00NjM2LWE2NWUtN2YyNTYzZDBkMzcxIn0.UTc1Felpa8wGXBjOJQw1i3oFl8RfSCm9CgI081C-62yJIPFm9z00CMsnX4rPsJQYI1QGvA6biFFIZJ4Z941Ttw"; - - public static String adminToken= - "eyJpc3MiOiJjb3MuaXVkeC5pbyIsInR5cCI6IkpXVCIsImFsZyI6IkVTMjU2In0.eyJzdWIiOiJmZDQ3NDg2Yi0zNDk3LTQyNDgtYWMxZS0wODJlNGQzN2E2NmMiLCJpc3MiOiJjb3MuaXVkeC5pbyIsImF1ZCI6InJzLml1ZHguaW8iLCJleHAiOjE3MDIwNTU2OTksImlhdCI6MTcwMjAxMjQ5OSwiaWlkIjoicnM6cnMuaXVkeC5pbyIsInJvbGUiOiJhZG1pbiIsImNvbnMiOnt9fQ.zd-i7RxxDjKAdESNuJuCKOnxXMHk4EgC-2g9J1trbrcyQFKTlLlEUX70Xakeke2xBfKX0E6Qt5ScZKu4xOHN1Q"; - - } - - diff --git a/src/test/java/iudx/file/server/apiserver/integrationtests/upload/FileServerUploadIntegrationTest.java b/src/test/java/iudx/file/server/apiserver/integrationtests/files/FileServerIntegrationTests.java similarity index 59% rename from src/test/java/iudx/file/server/apiserver/integrationtests/upload/FileServerUploadIntegrationTest.java rename to src/test/java/iudx/file/server/apiserver/integrationtests/files/FileServerIntegrationTests.java index 6bc2231..89d1a31 100644 --- a/src/test/java/iudx/file/server/apiserver/integrationtests/upload/FileServerUploadIntegrationTest.java +++ b/src/test/java/iudx/file/server/apiserver/integrationtests/files/FileServerIntegrationTests.java @@ -1,18 +1,22 @@ -package iudx.file.server.apiserver.integrationtests.upload; +package iudx.file.server.apiserver.integrationtests.files; import io.restassured.http.ContentType; +import io.vertx.core.json.JsonObject; import iudx.file.server.apiserver.integrationtests.RestAssuredConfiguration; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.*; import org.junit.jupiter.api.extension.ExtendWith; import java.io.*; + + +import static iudx.file.server.authenticator.TokensForITs.*; import static org.hamcrest.Matchers.equalTo; import static io.restassured.RestAssured.given; -import static iudx.file.server.apiserver.integrationtests.TokenHelper.delegateToken; + import static org.hamcrest.Matchers.notNullValue; @ExtendWith(RestAssuredConfiguration.class) -public class FileServerUploadIntegrationTest { +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) +public class FileServerIntegrationTests { private File createTempFileWithContent() { // Create a temporary file @@ -35,15 +39,24 @@ private File createTempFileWithContent() { // Create a temporary file and get its reference File tempFile = createTempFileWithContent(); String id ="83c2e5c2-3574-4e11-9530-2b1fbdfce832"; + + private static String sampleFileId; + private static String archiveFileId; + private static String externalStorageFileId; + String invalidFileId = "_abced"; + String nonExistingArchiveId ="83c2e5c2-3574-4e11-9530-2b1fbdfce832/8185010f-705d-4966-ac44-2050887c68f3_invalid.txt"; + boolean isSample=true; String invalidToken ="abc"; String fileDownloadURL = "https://docs.google.com/document/d/19f6oOIxHVjC3twcRHQATjrEXJsDO0rLixoFgLV7xMxk/edit?usp=sharing"; + //File Upload @Test + @Order(1) @DisplayName("200 (Success) DX file upload - Resource level (sample)") - public void fileUploadSuccessTest() { + public void sampleFileUploadSuccessTest() { - given() + JsonObject respJson = new JsonObject(given() .multiPart("file", tempFile, "text/plain") .formParam("id", id) .formParam("isSample", isSample) @@ -55,11 +68,16 @@ public void fileUploadSuccessTest() { .log().body() .contentType(ContentType.JSON) .body("results", notNullValue()) - .body("results[0].fileId", notNullValue()); + .body("results[0].fileId", notNullValue()) + .extract() + .asString()); + sampleFileId = respJson.getJsonArray("results").getJsonObject(0).getString("fileId"); + } @Test + @Order(2) @DisplayName("401 (not authorized) DX file upload - Resource level (sample)") - public void unauthorisedFileUploadTest() { + public void unauthorisedSampleFileUploadTest() { given() .multiPart("file", tempFile, "text/plain") @@ -77,11 +95,12 @@ public void unauthorisedFileUploadTest() { .body("detail", equalTo("Token is invalid")); } @Test + @Order(3) @DisplayName("200 (Success) - Archive Resource Level") - public void successArchiveTest() { + public void archiveFileUploadSuccessTest() { // Create a temporary file and get its reference //File tempFile = createTempFileWithContent(); - given() + JsonObject respJson = new JsonObject(given() .multiPart("file", tempFile, "text/plain") .formParam("id", id) .formParam("startTime", "2020-09-05T00:00:00Z") @@ -98,11 +117,16 @@ public void successArchiveTest() { .body("type", equalTo("urn:dx:rs:success")) .body("title", equalTo("Success")) .body("results", notNullValue()) - .body("results[0].fileId", notNullValue()); + .body("results[0].fileId", notNullValue()) + .extract() + .asString()); + archiveFileId = respJson.getJsonArray("results").getJsonObject(0).getString("fileId"); + } @Test - @DisplayName("200 (Success) - Archive Resource Level") - public void unauthorisedArchiveTest() { + @Order(4) + @DisplayName("401 (not authorized) DX file upload - Resource level (Archive)") + public void unauthorisedArchiveFileTest() { // Create a temporary file and get its reference //File tempFile = createTempFileWithContent(); @@ -125,6 +149,7 @@ public void unauthorisedArchiveTest() { .body("detail", equalTo("Token is invalid")); } @Test + @Order(5) @DisplayName("400 (No id param in request) DX file upload") public void invalidParamFileUploadTest() { // Create a temporary file and get its reference @@ -146,6 +171,7 @@ public void invalidParamFileUploadTest() { .body("detail", equalTo("Validation error : null or blank value for required mandatory field")); } @Test + @Order(6) @DisplayName("400 (Invalid isSample value) DX file upload") public void invalidIsSampleFileUploadTest() { // Create a temporary file and get its reference @@ -166,11 +192,12 @@ public void invalidIsSampleFileUploadTest() { .body("detail", equalTo("Validation error : Invalid isSample field value [ true1 ]")); } @Test + @Order(7) @DisplayName("200 (Success) DX file upload - Resource level (External Storage)") - public void fileUploadExternalStorageTest() { + public void externalStorageFileUploadSuccessTest() { // Create a temporary file and get its reference //File tempFile = createTempFileWithContent(); - given() + JsonObject respJson = new JsonObject(given() .multiPart("file", tempFile, "text/plain") .formParam("id", id) .formParam("startTime", "2020-09-05T00:00:00Z") @@ -188,7 +215,99 @@ public void fileUploadExternalStorageTest() { .body("type", equalTo("urn:dx:rs:success")) .body("title", equalTo("Success")) .body("results", notNullValue()) - .body("results[0].fileId", notNullValue()); + .body("results[0].fileId", notNullValue()) + .extract() + .asString()); + externalStorageFileId = respJson.getJsonArray("results").getJsonObject(0).getString("fileId"); } + // File Download + @Test + @Order(8) + @DisplayName("200 (Success) DX file download - RL (Sample file )") + public void sampleFileDownloadSuccessTest() { + given() + .param("file-id", sampleFileId) + .header("token", openResourceToken) + .when() + .get("/download") + .then() + .log().body() + .statusCode(200); + } + @Test + @Order(9) + @DisplayName("400 (invalid file id) DX file download") + public void invalidIdSampleFileDownloadTest() { + given() + .header("token", openResourceToken) + .param("file-id", invalidFileId) + .when() + .get("/download") + .then() + .statusCode(400) + .log().body() + .contentType(ContentType.JSON) + .body("type", equalTo("urn:dx:rs:invalidAttributeValue")) + .body("title", equalTo("Bad Request")) + .body("detail", equalTo("Validation error : invalid file id [ " + invalidFileId + " ]")); + } + @Test + @Order(10) + @DisplayName("200 (Success) DX file download -Resource level (Archive file )") + public void archiveFileDownloadSuccessTest(){ + given() + .param("file-id", archiveFileId) + .header("token", secureResourceToken) + .when() + .get("/download") + .then() + .log().body() + .statusCode(200); + } + @Test + @Order(11) + @DisplayName("401 (not authorized) DX file download - RL (Archive file )") + public void unauthorisedArchiveFileDownloadTest() { + given() + .header("token", invalidToken) + .param("file-id", archiveFileId) + .when() + .get("/download") + .then() + .statusCode(401) + .log().body() + .contentType(ContentType.JSON) + .body("type", equalTo("urn:dx:rs:invalidAuthorizationToken")) + .body("title", equalTo("Not authorized")) + .body("detail", equalTo("Token is invalid")); + } + @Test + @Order(12) + @DisplayName("404 (Not Found) DX file download -Resource level (Archive file )") + public void nonExistingArchiveFileDownloadTest() { + given() + .header("token", secureResourceToken) + .param("file-id", nonExistingArchiveId) + .when() + .get("/download") + .then() + .statusCode(404) + .log().body() + .contentType(ContentType.JSON) + .body("type", equalTo("urn:dx:rs:resourceNotFound")) + .body("title", equalTo("Not Found")) + .body("detail", equalTo("Document of given id does not exist")); + } + + + @AfterEach + public void tearDown() { + // Introduce a delay + try { + Thread.sleep(1000); // 1 second delay + } catch (InterruptedException e) { + e.printStackTrace(); + } + } } diff --git a/src/test/java/iudx/file/server/authenticator/TokenSetup.java b/src/test/java/iudx/file/server/authenticator/TokenSetup.java new file mode 100644 index 0000000..6685795 --- /dev/null +++ b/src/test/java/iudx/file/server/authenticator/TokenSetup.java @@ -0,0 +1,145 @@ +package iudx.file.server.authenticator; + +import io.vertx.core.*; +import io.vertx.core.json.JsonObject; +import io.vertx.ext.web.client.WebClient; +import io.vertx.ext.web.client.WebClientOptions; +import org.jetbrains.annotations.NotNull; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import static iudx.file.server.authenticator.TokensForITs.*; + +public class TokenSetup { + private static final Logger logger = LoggerFactory.getLogger(TokenSetup.class); + private static WebClient webClient; + + public static void setupTokens(String authEndpoint, String clientId, String clientSecret, String delegationId) { + // Fetch tokens asynchronously and wait for all completions + CompositeFuture.all( + fetchToken("openResourceToken", authEndpoint, clientId, clientSecret), + fetchToken("secureResourceToken", authEndpoint, clientId,clientSecret), + fetchToken("adminToken", authEndpoint, clientId,clientSecret), + fetchToken("delegateToken", authEndpoint, clientId,clientSecret, delegationId) + + ).onComplete(result -> { + if (result.succeeded()) { + logger.info("Tokens setup completed successfully"); + webClient.close(); + } else { + // Handle failure, e.g., log the error + logger.error("Error- {}", result.cause().getMessage()); + webClient.close(); + } + }); + } + + private static Future fetchToken(String userType, String authEndpoint, String clientID, String clientSecret) { + Promise promise = Promise.promise(); + JsonObject jsonPayload = getPayload(userType); + // Create a WebClient to make the HTTP request + webClient = WebClient.create(Vertx.vertx(), new WebClientOptions().setSsl(true)); + logger.info("Auth endpoint: {}", authEndpoint); + webClient.postAbs(authEndpoint) + .putHeader("Content-Type", "application/json") + .putHeader("clientID", clientID) + .putHeader("clientSecret", clientSecret) + .sendJson(jsonPayload) + .compose(response -> { + if (response.statusCode() == 200) { + JsonObject jsonResponse = response.bodyAsJsonObject(); + String accessToken = jsonResponse.getJsonObject("results").getString("accessToken"); + // Store the token based on user type + switch (userType) { + case "secureResourceToken": + secureResourceToken = accessToken; + break; + case "openResourceToken": + openResourceToken = accessToken; + break; + case "adminToken": + adminToken = accessToken; + } + promise.complete(accessToken); + } else { + promise.fail("Failed to get token. Status code: " + response.statusCode()); + } + return Future.succeededFuture(); + }) + .onFailure(throwable -> { + throwable.printStackTrace(); + promise.fail(throwable); + }); +// .onComplete(result -> { +// webClient.close(); +// }); + + return promise.future(); + } + + private static Future fetchToken(String userType, String authEndpoint, String clientID, String clientSecret, String delegationId) { + Promise promise = Promise.promise(); + JsonObject jsonPayload = getPayload(userType); + // Create a WebClient to make the HTTP request for fetching delegate and adaptor tokens + webClient = WebClient.create(Vertx.vertx(), new WebClientOptions().setSsl(true)); + + webClient.postAbs(authEndpoint) + .putHeader("Content-Type", "application/json") + .putHeader("clientID", clientID) + .putHeader("clientSecret", clientSecret) + .putHeader("delegationId", delegationId) + .sendJson(jsonPayload) + .compose(response -> { + if (response.statusCode() == 200) { + JsonObject jsonResponse = response.bodyAsJsonObject(); + String accessToken = jsonResponse.getJsonObject("results").getString("accessToken"); + // Store the token based on user type + if (userType.equals("delegateToken")) { + delegateToken = accessToken; + } + promise.complete(accessToken); + } else { + promise.fail("Failed to get token. Status code: " + response.statusCode()); + } + return Future.succeededFuture(); + }) + .onFailure(throwable -> { + throwable.printStackTrace(); + promise.fail(throwable); + }); +// .onComplete(result -> { +// webClient.close(); +// }); + + return promise.future(); + } + + @NotNull + private static JsonObject getPayload(String userType) { + JsonObject jsonPayload = new JsonObject(); + switch (userType) { + case "openResourceToken": + jsonPayload.put("itemId", "b58da193-23d9-43eb-b98a-a103d4b6103c"); + jsonPayload.put("itemType", "resource"); + jsonPayload.put("role", "consumer"); + break; + case "secureResourceToken": + jsonPayload.put("itemId", "83c2e5c2-3574-4e11-9530-2b1fbdfce832"); + jsonPayload.put("itemType", "resource"); + jsonPayload.put("role", "consumer"); + break; + case "adminToken": + jsonPayload.put("itemId", "rs.iudx.io"); + jsonPayload.put("itemType", "resource_server"); + jsonPayload.put("role", "admin"); + break; + case "delegateToken": + jsonPayload.put("itemId", "83c2e5c2-3574-4e11-9530-2b1fbdfce832"); + jsonPayload.put("itemType", "resource"); + jsonPayload.put("role", "delegate"); + break; + } + return jsonPayload; + } + +} diff --git a/src/test/java/iudx/file/server/authenticator/TokensForITs.java b/src/test/java/iudx/file/server/authenticator/TokensForITs.java new file mode 100644 index 0000000..5a5cb25 --- /dev/null +++ b/src/test/java/iudx/file/server/authenticator/TokensForITs.java @@ -0,0 +1,9 @@ +package iudx.file.server.authenticator; + +public class TokensForITs { + public static String secureResourceToken ; + public static String openResourceToken ; + public static String adminToken; + public static String delegateToken; + +} From 156f53a174bc7dc72cb558f22c60c994d8426568 Mon Sep 17 00:00:00 2001 From: Kranthi-Guribilli Date: Tue, 16 Jan 2024 11:59:05 +0530 Subject: [PATCH 04/22] Updating the ITs for query and delete APIs of File Server --- .../files/FileServerIntegrationTests.java | 273 +++++++++++++++++- 1 file changed, 271 insertions(+), 2 deletions(-) diff --git a/src/test/java/iudx/file/server/apiserver/integrationtests/files/FileServerIntegrationTests.java b/src/test/java/iudx/file/server/apiserver/integrationtests/files/FileServerIntegrationTests.java index 89d1a31..bc1b7b5 100644 --- a/src/test/java/iudx/file/server/apiserver/integrationtests/files/FileServerIntegrationTests.java +++ b/src/test/java/iudx/file/server/apiserver/integrationtests/files/FileServerIntegrationTests.java @@ -1,22 +1,28 @@ package iudx.file.server.apiserver.integrationtests.files; import io.restassured.http.ContentType; +import io.restassured.response.Response; import io.vertx.core.json.JsonObject; import iudx.file.server.apiserver.integrationtests.RestAssuredConfiguration; import org.junit.jupiter.api.*; import org.junit.jupiter.api.extension.ExtendWith; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.io.*; +import static org.hamcrest.Matchers.*; +import static io.restassured.RestAssured.*; import static iudx.file.server.authenticator.TokensForITs.*; import static org.hamcrest.Matchers.equalTo; -import static io.restassured.RestAssured.given; import static org.hamcrest.Matchers.notNullValue; @ExtendWith(RestAssuredConfiguration.class) @TestMethodOrder(MethodOrderer.OrderAnnotation.class) public class FileServerIntegrationTests { + private static final Logger LOGGER = LoggerFactory.getLogger(FileServerIntegrationTests.class); private File createTempFileWithContent() { // Create a temporary file @@ -39,6 +45,8 @@ private File createTempFileWithContent() { // Create a temporary file and get its reference File tempFile = createTempFileWithContent(); String id ="83c2e5c2-3574-4e11-9530-2b1fbdfce832"; + String open_rs_id = "b58da193-23d9-43eb-b98a-a103d4b6103c"; + String open_rsgrp_id = "5b7556b5-0779-4c47-9cf2-3f209779aa22"; private static String sampleFileId; private static String archiveFileId; @@ -55,7 +63,8 @@ private File createTempFileWithContent() { @Order(1) @DisplayName("200 (Success) DX file upload - Resource level (sample)") public void sampleFileUploadSuccessTest() { - + System.out.println(basePath); + System.out.println(baseURI); JsonObject respJson = new JsonObject(given() .multiPart("file", tempFile, "text/plain") .formParam("id", id) @@ -299,6 +308,266 @@ public void nonExistingArchiveFileDownloadTest() { .body("title", equalTo("Not Found")) .body("detail", equalTo("Document of given id does not exist")); } + //For query APIs + @Test + @Order(13) + @DisplayName("200 (Success) Search for Files of an open resource (using openToken)") + void GetResourceLevelSample() { + given() + .header("token", openResourceToken) + .param("id", open_rs_id) + .param("time", "2020-09-10T00:00:00Z") + .param("endTime", "2020-09-15T00:00:00Z") + .param("timerel", "between") + .when() + .get(baseURI+"/ngsi-ld/v1/temporal/entities") + .then() + .statusCode(200) + .body("type", is(200)) + .body("title", is("urn:dx:rs:success")); + } + @Test + @Order(14) + @DisplayName("200 (Success) Search for Files of an open resource group (using openToken)") + void GetResourceGroupSample() { + given() + .header("token", openResourceToken) + .param("id", open_rsgrp_id) + .param("time", "2020-09-10T00:00:00Z") + .param("endTime", "2020-09-15T00:00:00Z") + .param("timerel", "between") + .when() + .get(baseURI+"/ngsi-ld/v1/temporal/entities") + .then() + .statusCode(200) + .body("type", is(200)) + .body("title", is("urn:dx:rs:success")); + } + @Test + @Order(15) + @DisplayName("401 (Not Authorized) Search for Files") + void SearchForFilesUnAuth() { + given() + .param("id", "8b95ab80-2aaf-4636-a65e-7f2563d0d371") + .param("time", "2020-09-10T00:00:00Z") + .param("endTime", "2020-09-15T00:00:00Z") + .param("timerel", "between") + .when() + .get(baseURI+"/ngsi-ld/v1/temporal/entities") + .then() + .statusCode(401) + .body("type", is("urn:dx:rs:missingAuthorizationToken")) + .body("title", is("Not authorized")) + .body("detail", is("Token needed and not present")); + } + @Test + @Order(16) + @DisplayName("200 (Success) Search for Files using Spatial [geo(circle)]") + void SearchForFilesUsingSpatialGeoCircle(){ + Response response = given() + .header("token", secureResourceToken) + .param("id", id) + .param("georel","near;maxDistance=10000") + .param("geometry","point") + .param("coordinates", "[72.79,21.16]") + .when() + .get(baseURI+"/ngsi-ld/v1/entities") + .then() + .statusCode(200) + .body("type", is(200)) + .body("title", is("urn:dx:rs:success")) + .extract() + .response(); + LOGGER.info("response.."+response); + } + @Test + @Order(17) + @DisplayName("200 (Success) Search for Files using Spatial [geo(Polygon)]") + void SearchForFilesUsingSpatialGeoPolygon() { + given() + .header("token", secureResourceToken) + .param("id", id) + .param("georel","within") + .param("geometry", "polygon") + .param("coordinates", "[[[72.7815,21.1726],[72.7856,21.1519],[72.807,21.1527],[72.8170,21.1680],[72.800,21.1808],[72.7815,21.1726]]]") + .when() + .get(baseURI+"/ngsi-ld/v1/entities") + .then() + .statusCode(200) + .body("type", is(200)) + .body("title", is("urn:dx:rs:success")); + } + @Test + @Order(18) + @DisplayName("200 (Success) Complex Search [temporal+geo(Circle) search]") + void ComplexSearchForFilesUsingTemporalPlusGeoPolygon() { + given() + .header("token", secureResourceToken) + .param("id", id) + .param("time", "2020-09-10T00:00:00Z") + .param("endTime", "2020-09-15T00:00:00Z") + .param("timerel", "between") + .param("georel","near;maxDistance=10000") + .param("geometry", "point") + .param("coordinates", "[72.79,21.16]") + .when() + .get(baseURI+"/ngsi-ld/v1/temporal/entities") + .then() + .statusCode(200) + .body("type", is(200)) + .body("title", is("urn:dx:rs:success")); + } + @Test + @Order(19) + @DisplayName("401 (not authorized) Complex Search [temporal+geo(Circle) search]") + void ComplexSearchForFilesUsingTemporalPlusGeoPolygonUnAuth() { + given() + .param("id", id) + .param("time", "2020-09-10T00:00:00Z") + .param("endTime", "2020-09-15T00:00:00Z") + .param("timerel", "between") + .param("georel","near;maxDistance=10000") + .param("geometry", "point") + .param("coordinates", "[72.79,21.16]") + .when() + .get(baseURI+"/ngsi-ld/v1/temporal/entities") + .then() + .statusCode(401) + .body("type", is("urn:dx:rs:missingAuthorizationToken")) + .body("title", is("Not authorized")) + .body("detail", is("Token needed and not present")); + } + @Test + @Order(20) + @DisplayName("200 (Success) List metadata of an open resource (using openToken)") + void ListMetaDataOfOpenResource() { + given() + .header("token", openResourceToken) + .param("id", open_rs_id) + .when() + .get("/list") + .then() + .statusCode(200) + .body("type", is(200)) + .body("title", is("urn:dx:rs:success")); + } + @Test + @Order(21) + @DisplayName("200 (Success) List metadata of an open resource group (using openToken)") + void ListMetaDataOfOpenResourceGroup() { + given() + .header("token", openResourceToken) + .param("id", open_rsgrp_id) + .when() + .get("/list") + .then() + .statusCode(200) + .body("type", is(200)) + .body("title", is("urn:dx:rs:success")); + } + @Test + @Order(22) + @DisplayName("200 (Success) List metadata of a secure resource (using secureToken)") + void ListMetaDataOfSecureResource() { + given() + .header("token", secureResourceToken) + .param("id", id) + .when() + .get("/list") + .then() + .statusCode(200) + .body("type", is(200)) + .body("title", is("urn:dx:rs:success")); + } + @Test + @Order(23) + @DisplayName("401 (Not authorized) List metadata ") + void ListMetaDataUnAuth() { + given() + .param("id", id) + .when() + .get("/list") + .then() + .statusCode(401) + .body("type", is("urn:dx:rs:missingAuthorizationToken")) + .body("title", is("Not authorized")) + .body("detail", is("Token needed and not present")); + } + @Test + @Order(24) + @DisplayName("200 (Success) DX file delete -RL (sample file)") + void DeleteRLSampleFile() { + LOGGER.debug("rl sample..."+sampleFileId); + given() + .header("token", delegateToken) + .param("file-id", sampleFileId) + .when() + .delete("/delete") + .then() + .statusCode(200) + .body("type", is("urn:dx:rs:success")) + .body("title", is("Successful Operation")); + } + @Test + @Order(25) + @DisplayName("404 (Not Found) DX file delete - RL (sample file)") + void DeleteRLSampleFileNotFound() { + given() + .header("token", delegateToken) + .param("file-id", nonExistingArchiveId) + .when() + .delete("/delete") + .then() + .statusCode(404) + .body("type", is("urn:dx:rs:resourceNotFound")) + .body("title", is("Not Found")) + .body("detail", is("Document of given id does not exist")); + } + @Test + @Order(26) + @DisplayName("200 (Success) DX file delete - RL (Archive file)") + void DeleteRLSampleArchiveFile() { + LOGGER.debug("rl archive file id..."+archiveFileId); + given() + .header("token", delegateToken) + .param("file-id", archiveFileId) + .when() + .delete("/delete") + .then() + .statusCode(200) + .body("type", is("urn:dx:rs:success")) + .body("title", is("Successful Operation")); + } + @Test + @Order(27) + @DisplayName("404 (Not Found) DX file delete - RL (Archive file)") + void DeleteRLSampleArchiveFileNotFound() { + given() + .header("token", delegateToken) + .param("file-id", nonExistingArchiveId) + .when() + .delete("/delete") + .then() + .statusCode(404) + .body("type", is("urn:dx:rs:resourceNotFound")) + .body("title", is("Not Found")) + .body("detail", is("Document of given id does not exist")); + } + @Test + @Order(28) + @DisplayName("200 (Success) DX file delete - RL (External Storage)") + void DeleteRLSampleExternalFile() { + LOGGER.debug("rl external storage file id..."+externalStorageFileId); + given() + .header("token", delegateToken) + .param("file-id", externalStorageFileId) + .when() + .delete("/delete") + .then() + .statusCode(200) + .body("type", is("urn:dx:rs:success")) + .body("title", is("Successful Operation")); + } @AfterEach From e5946166d05346a0a019f0513adb5ee885d8efd5 Mon Sep 17 00:00:00 2001 From: DivyaSreeMunagavalasa Date: Tue, 30 Jan 2024 16:29:16 +0530 Subject: [PATCH 05/22] Updating JenkinsFile for File Server --- Jenkinsfile | 81 +++++++++++++++++++++++++++++------------------------ 1 file changed, 44 insertions(+), 37 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 2c4ec67..1bce6c5 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -25,34 +25,34 @@ 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' } xunit ( - thresholds: [ skipped(failureThreshold: '0'), failed(failureThreshold: '0') ], + thresholds: [ skipped(failureThreshold: '1'), failed(failureThreshold: '2') ], tools: [ JUnit(pattern: 'target/surefire-reports/*.xml') ] ) 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' @@ -67,11 +67,11 @@ pipeline { } } - stage('Start File server for Integration Tests'){ + stage('Start File-Server for Performance and Integration Testing'){ 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 'scp Jmeter/FileServer.jmx jenkins@jenkins-master:/var/lib/jenkins/iudx/rs/Jmeter/' + sh 'docker compose -f docker-compose.test.yml up -d perfTest' sh 'sleep 45' } } @@ -84,24 +84,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/rs-config-test.json ./configs/config-test.json' + sh 'mvn test-compile failsafe:integration-test -DskipUnitTests=true -DintTestProxyHost=jenkins-master-priv -DintTestProxyPort=8090 -DintTestHost=jenkins-slave1 -DintTestPort=8080' + } + 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{ @@ -156,19 +166,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!" @@ -187,4 +194,4 @@ Check console output at $BUILD_URL to view the results.''' } } } -} +} \ No newline at end of file From 93b3be5a000d308203dcc480971aeee4eebdaa03 Mon Sep 17 00:00:00 2001 From: DivyaSreeMunagavalasa Date: Wed, 31 Jan 2024 11:19:45 +0530 Subject: [PATCH 06/22] PR Changes --- Jenkinsfile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 1bce6c5..2ee289b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -31,7 +31,7 @@ pipeline { sh 'docker compose -f docker-compose.test.yml up test' } xunit ( - thresholds: [ skipped(failureThreshold: '1'), failed(failureThreshold: '2') ], + thresholds: [ skipped(failureThreshold: '0'), failed(failureThreshold: '0') ], tools: [ JUnit(pattern: 'target/surefire-reports/*.xml') ] ) 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' @@ -70,7 +70,6 @@ pipeline { stage('Start File-Server for Performance and Integration Testing'){ steps{ script{ - sh 'scp Jmeter/FileServer.jmx jenkins@jenkins-master:/var/lib/jenkins/iudx/rs/Jmeter/' sh 'docker compose -f docker-compose.test.yml up -d perfTest' sh 'sleep 45' } @@ -93,7 +92,7 @@ pipeline { } } script{ - sh 'scp /home/ubuntu/configs/rs-config-test.json ./configs/config-test.json' + sh 'scp /home/ubuntu/configs/fs-config-test.json ./configs/config-test.json' sh 'mvn test-compile failsafe:integration-test -DskipUnitTests=true -DintTestProxyHost=jenkins-master-priv -DintTestProxyPort=8090 -DintTestHost=jenkins-slave1 -DintTestPort=8080' } node('built-in') { From dcba9263960ae2bdc26184efafcfb5dda7a74f7b Mon Sep 17 00:00:00 2001 From: DivyaSreeMunagavalasa Date: Mon, 5 Feb 2024 21:35:00 +0530 Subject: [PATCH 07/22] Adding pom file --- pom.xml | 7 +++++++ .../RestAssuredConfiguration.java | 0 .../files/FileServerIntegrationTests.java | 0 3 files changed, 7 insertions(+) rename src/test/java/iudx/file/server/apiserver/{integrationtests => integrationTests}/RestAssuredConfiguration.java (100%) rename src/test/java/iudx/file/server/apiserver/{integrationtests => integrationTests}/files/FileServerIntegrationTests.java (100%) diff --git a/pom.xml b/pom.xml index f466bcb..b8789bb 100644 --- a/pom.xml +++ b/pom.xml @@ -110,6 +110,13 @@ io.vertx vertx-junit5 + + + io.rest-assured + rest-assured + 5.3.2 + test + io.vertx vertx-unit diff --git a/src/test/java/iudx/file/server/apiserver/integrationtests/RestAssuredConfiguration.java b/src/test/java/iudx/file/server/apiserver/integrationTests/RestAssuredConfiguration.java similarity index 100% rename from src/test/java/iudx/file/server/apiserver/integrationtests/RestAssuredConfiguration.java rename to src/test/java/iudx/file/server/apiserver/integrationTests/RestAssuredConfiguration.java diff --git a/src/test/java/iudx/file/server/apiserver/integrationtests/files/FileServerIntegrationTests.java b/src/test/java/iudx/file/server/apiserver/integrationTests/files/FileServerIntegrationTests.java similarity index 100% rename from src/test/java/iudx/file/server/apiserver/integrationtests/files/FileServerIntegrationTests.java rename to src/test/java/iudx/file/server/apiserver/integrationTests/files/FileServerIntegrationTests.java From 7601c5761ca6e97ada3ab1abe2316acdc3dea472 Mon Sep 17 00:00:00 2001 From: DivyaSreeMunagavalasa Date: Mon, 5 Feb 2024 21:38:33 +0530 Subject: [PATCH 08/22] PR Changes - Adding testOnDepl bool variable and fetching values of variables from config --- .../RestAssuredConfiguration.java | 73 +++++++++++++++---- .../files/FileServerIntegrationTests.java | 49 ++++++------- 2 files changed, 81 insertions(+), 41 deletions(-) diff --git a/src/test/java/iudx/file/server/apiserver/integrationTests/RestAssuredConfiguration.java b/src/test/java/iudx/file/server/apiserver/integrationTests/RestAssuredConfiguration.java index eaf1827..7fbf212 100644 --- a/src/test/java/iudx/file/server/apiserver/integrationTests/RestAssuredConfiguration.java +++ b/src/test/java/iudx/file/server/apiserver/integrationTests/RestAssuredConfiguration.java @@ -1,4 +1,4 @@ -package iudx.file.server.apiserver.integrationtests; +package iudx.file.server.apiserver.integrationTests; import io.restassured.RestAssured; import io.vertx.core.Vertx; @@ -20,32 +20,51 @@ public class RestAssuredConfiguration implements BeforeAllCallback { private static final Logger logger = LoggerFactory.getLogger(RestAssuredConfiguration.class); + private static String rsId; + private static String openRsId; + private static String openRsGroupId; + private static String nonExistingArchiveId; + private static String fileDownloadURL; @Override public void beforeAll(ExtensionContext context) { Vertx vertx = Vertx.vertx(); Configuration fileServerConfig = new Configuration(); JsonObject config = fileServerConfig.configLoader(0, vertx); - String testHost = config.getString("ip"); - // String testHost = System.getProperty("intTestHost"); - //System.out.println("testHost:"+testHost); + JsonObject testValues = config.getJsonObject("testValues"); + + rsId = testValues.getString("rsId"); + openRsId = testValues.getString("openRsId"); + openRsGroupId = testValues.getString("openRsGroupId"); + nonExistingArchiveId = testValues.getString("nonExistingArchiveId"); + fileDownloadURL = testValues.getString("fileDownloadURL"); + JsonObject config2 = fileServerConfig.configLoader(1, vertx); String authServerHost = config2.getString("authHost"); - if (testHost != null) { - baseURI = "http://" + testHost; + boolean testOnDepl = Boolean.parseBoolean(System.getProperty("intTestDepl")); + if (testOnDepl) { + String testHost = "file-test.iudx.io"; + baseURI = "https://" + testHost; + port = 443; } else { - baseURI = "http://localhost"; - } + String testHost = System.getProperty("intTestHost"); - String testPort = config.getString("httpPort"); - // String testPort = System.getProperty("intTestPort"); - if (testPort != null) { - port = Integer.parseInt(testPort); - } else { - port = 8443; + if (testHost != null) { + baseURI = "http://" + testHost; + } else { + baseURI = "http://localhost"; + } + + String testPort = System.getProperty("intTestPort"); + + if (testPort != null) { + port = Integer.parseInt(testPort); + } else { + port = 8081; + } } - // System.out.println(testPort+","+testHost); + basePath = "/iudx/v1"; String dxAuthBasePath = "auth/v1"; String authEndpoint = "https://"+ authServerHost + "/" + dxAuthBasePath + "/token"; @@ -66,6 +85,28 @@ public void beforeAll(ExtensionContext context) { waitForTokens(); enableLoggingOfRequestAndResponseIfValidationFails(); } + + // Getter methods for configuration values + public static String getRsId() { + return rsId; + } + + public static String getOpenRsId() { + return openRsId; + } + + public static String getOpenRsGroupId() { + return openRsGroupId; + } + + public static String getNonExistingArchiveId() { + return nonExistingArchiveId; + } + + public static String getFileDownloadURL() { + return fileDownloadURL; + } + private void waitForTokens() { int maxAttempts = 5; int attempt = 0; @@ -75,7 +116,7 @@ private void waitForTokens() { logger.info("Waiting for tokens to be available. Attempt: " + (attempt + 1)); // Introduce a delay between attempts try { - Thread.sleep(3000); // Adjust the delay as we needed + Thread.sleep(3000); // Adjust the delay as we aneeded } catch (InterruptedException e) { e.printStackTrace(); } diff --git a/src/test/java/iudx/file/server/apiserver/integrationTests/files/FileServerIntegrationTests.java b/src/test/java/iudx/file/server/apiserver/integrationTests/files/FileServerIntegrationTests.java index bc1b7b5..85b8ab4 100644 --- a/src/test/java/iudx/file/server/apiserver/integrationTests/files/FileServerIntegrationTests.java +++ b/src/test/java/iudx/file/server/apiserver/integrationTests/files/FileServerIntegrationTests.java @@ -1,9 +1,9 @@ -package iudx.file.server.apiserver.integrationtests.files; +package iudx.file.server.apiserver.integrationTests.files; import io.restassured.http.ContentType; import io.restassured.response.Response; import io.vertx.core.json.JsonObject; -import iudx.file.server.apiserver.integrationtests.RestAssuredConfiguration; +import iudx.file.server.apiserver.integrationTests.RestAssuredConfiguration; import org.junit.jupiter.api.*; import org.junit.jupiter.api.extension.ExtendWith; import org.slf4j.Logger; @@ -44,19 +44,18 @@ private File createTempFileWithContent() { } // Create a temporary file and get its reference File tempFile = createTempFileWithContent(); - String id ="83c2e5c2-3574-4e11-9530-2b1fbdfce832"; - String open_rs_id = "b58da193-23d9-43eb-b98a-a103d4b6103c"; - String open_rsgrp_id = "5b7556b5-0779-4c47-9cf2-3f209779aa22"; + private static final String rsId = RestAssuredConfiguration.getRsId(); + private static final String openRsId = RestAssuredConfiguration.getOpenRsId(); + private static final String openRsGroupId = RestAssuredConfiguration.getOpenRsGroupId(); private static String sampleFileId; private static String archiveFileId; private static String externalStorageFileId; + private static final String nonExistingArchiveId = RestAssuredConfiguration.getNonExistingArchiveId(); + private static final String fileDownloadURL = RestAssuredConfiguration.getFileDownloadURL(); String invalidFileId = "_abced"; - String nonExistingArchiveId ="83c2e5c2-3574-4e11-9530-2b1fbdfce832/8185010f-705d-4966-ac44-2050887c68f3_invalid.txt"; - boolean isSample=true; String invalidToken ="abc"; - String fileDownloadURL = "https://docs.google.com/document/d/19f6oOIxHVjC3twcRHQATjrEXJsDO0rLixoFgLV7xMxk/edit?usp=sharing"; //File Upload @Test @@ -67,7 +66,7 @@ public void sampleFileUploadSuccessTest() { System.out.println(baseURI); JsonObject respJson = new JsonObject(given() .multiPart("file", tempFile, "text/plain") - .formParam("id", id) + .formParam("id", rsId) .formParam("isSample", isSample) .header("token", delegateToken) .when() @@ -90,7 +89,7 @@ public void unauthorisedSampleFileUploadTest() { given() .multiPart("file", tempFile, "text/plain") - .formParam("id", id) + .formParam("id", rsId) .formParam("isSample", isSample) .header("token", invalidToken) .when() @@ -111,7 +110,7 @@ public void archiveFileUploadSuccessTest() { //File tempFile = createTempFileWithContent(); JsonObject respJson = new JsonObject(given() .multiPart("file", tempFile, "text/plain") - .formParam("id", id) + .formParam("id", rsId) .formParam("startTime", "2020-09-05T00:00:00Z") .formParam("endTime", "2020-09-15T00:00:00Z") .formParam("geometry", "point") @@ -141,7 +140,7 @@ public void unauthorisedArchiveFileTest() { given() .multiPart("file", tempFile, "text/plain") - .formParam("id", id) + .formParam("id", rsId) .formParam("startTime", "2020-09-05T00:00:00Z") .formParam("endTime", "2020-09-15T00:00:00Z") .formParam("geometry", "point") @@ -166,7 +165,7 @@ public void invalidParamFileUploadTest() { given() .multiPart("file", tempFile, "text/plain") - .formParam("id1", id) + .formParam("id1", rsId) .formParam("isSample", isSample) .header("token",delegateToken) .when() @@ -187,7 +186,7 @@ public void invalidIsSampleFileUploadTest() { //File tempFile = createTempFileWithContent(); given() .multiPart("file", tempFile, "text/plain") - .formParam("id", id) + .formParam("id", rsId) .formParam("isSample", "true1") .header("token",delegateToken) .when() @@ -208,7 +207,7 @@ public void externalStorageFileUploadSuccessTest() { //File tempFile = createTempFileWithContent(); JsonObject respJson = new JsonObject(given() .multiPart("file", tempFile, "text/plain") - .formParam("id", id) + .formParam("id", rsId) .formParam("startTime", "2020-09-05T00:00:00Z") .formParam("endTime", "2020-09-15T00:00:00Z") .formParam("geometry", "point") @@ -315,7 +314,7 @@ public void nonExistingArchiveFileDownloadTest() { void GetResourceLevelSample() { given() .header("token", openResourceToken) - .param("id", open_rs_id) + .param("id", openRsId) .param("time", "2020-09-10T00:00:00Z") .param("endTime", "2020-09-15T00:00:00Z") .param("timerel", "between") @@ -332,7 +331,7 @@ void GetResourceLevelSample() { void GetResourceGroupSample() { given() .header("token", openResourceToken) - .param("id", open_rsgrp_id) + .param("id", openRsGroupId) .param("time", "2020-09-10T00:00:00Z") .param("endTime", "2020-09-15T00:00:00Z") .param("timerel", "between") @@ -366,7 +365,7 @@ void SearchForFilesUnAuth() { void SearchForFilesUsingSpatialGeoCircle(){ Response response = given() .header("token", secureResourceToken) - .param("id", id) + .param("id", rsId) .param("georel","near;maxDistance=10000") .param("geometry","point") .param("coordinates", "[72.79,21.16]") @@ -386,7 +385,7 @@ void SearchForFilesUsingSpatialGeoCircle(){ void SearchForFilesUsingSpatialGeoPolygon() { given() .header("token", secureResourceToken) - .param("id", id) + .param("id", rsId) .param("georel","within") .param("geometry", "polygon") .param("coordinates", "[[[72.7815,21.1726],[72.7856,21.1519],[72.807,21.1527],[72.8170,21.1680],[72.800,21.1808],[72.7815,21.1726]]]") @@ -403,7 +402,7 @@ void SearchForFilesUsingSpatialGeoPolygon() { void ComplexSearchForFilesUsingTemporalPlusGeoPolygon() { given() .header("token", secureResourceToken) - .param("id", id) + .param("id", rsId) .param("time", "2020-09-10T00:00:00Z") .param("endTime", "2020-09-15T00:00:00Z") .param("timerel", "between") @@ -422,7 +421,7 @@ void ComplexSearchForFilesUsingTemporalPlusGeoPolygon() { @DisplayName("401 (not authorized) Complex Search [temporal+geo(Circle) search]") void ComplexSearchForFilesUsingTemporalPlusGeoPolygonUnAuth() { given() - .param("id", id) + .param("id", rsId) .param("time", "2020-09-10T00:00:00Z") .param("endTime", "2020-09-15T00:00:00Z") .param("timerel", "between") @@ -443,7 +442,7 @@ void ComplexSearchForFilesUsingTemporalPlusGeoPolygonUnAuth() { void ListMetaDataOfOpenResource() { given() .header("token", openResourceToken) - .param("id", open_rs_id) + .param("id", openRsId) .when() .get("/list") .then() @@ -457,7 +456,7 @@ void ListMetaDataOfOpenResource() { void ListMetaDataOfOpenResourceGroup() { given() .header("token", openResourceToken) - .param("id", open_rsgrp_id) + .param("id", openRsGroupId) .when() .get("/list") .then() @@ -471,7 +470,7 @@ void ListMetaDataOfOpenResourceGroup() { void ListMetaDataOfSecureResource() { given() .header("token", secureResourceToken) - .param("id", id) + .param("id", rsId) .when() .get("/list") .then() @@ -484,7 +483,7 @@ void ListMetaDataOfSecureResource() { @DisplayName("401 (Not authorized) List metadata ") void ListMetaDataUnAuth() { given() - .param("id", id) + .param("id", rsId) .when() .get("/list") .then() From 5a141ad39f62e6deec862d0587c387c84339fb2c Mon Sep 17 00:00:00 2001 From: DivyaSreeMunagavalasa Date: Fri, 23 Feb 2024 19:26:35 +0530 Subject: [PATCH 09/22] Commenting loggers --- .../files/FileServerIntegrationTests.java | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/test/java/iudx/file/server/apiserver/integrationTests/files/FileServerIntegrationTests.java b/src/test/java/iudx/file/server/apiserver/integrationTests/files/FileServerIntegrationTests.java index 85b8ab4..eef6d87 100644 --- a/src/test/java/iudx/file/server/apiserver/integrationTests/files/FileServerIntegrationTests.java +++ b/src/test/java/iudx/file/server/apiserver/integrationTests/files/FileServerIntegrationTests.java @@ -62,8 +62,6 @@ private File createTempFileWithContent() { @Order(1) @DisplayName("200 (Success) DX file upload - Resource level (sample)") public void sampleFileUploadSuccessTest() { - System.out.println(basePath); - System.out.println(baseURI); JsonObject respJson = new JsonObject(given() .multiPart("file", tempFile, "text/plain") .formParam("id", rsId) @@ -73,7 +71,7 @@ public void sampleFileUploadSuccessTest() { .post("/upload") .then() .statusCode(200) - .log().body() + //.log().body() .contentType(ContentType.JSON) .body("results", notNullValue()) .body("results[0].fileId", notNullValue()) @@ -96,7 +94,7 @@ public void unauthorisedSampleFileUploadTest() { .post("/upload") .then() .statusCode(401) - .log().body() + //.log().body() .contentType(ContentType.JSON) .body("type", equalTo("urn:dx:rs:invalidAuthorizationToken")) .body("title", equalTo("Not authorized")) @@ -120,7 +118,7 @@ public void archiveFileUploadSuccessTest() { .post("/upload") .then() .statusCode(200) - .log().body() + //.log().body() .contentType(ContentType.JSON) .body("type", equalTo("urn:dx:rs:success")) .body("title", equalTo("Success")) @@ -150,7 +148,7 @@ public void unauthorisedArchiveFileTest() { .post("/upload") .then() .statusCode(401) - .log().body() + //.log().body() .contentType(ContentType.JSON) .body("type", equalTo("urn:dx:rs:invalidAuthorizationToken")) .body("title", equalTo("Not authorized")) @@ -172,7 +170,7 @@ public void invalidParamFileUploadTest() { .post("/upload") .then() .statusCode(400) - .log().body() + //.log().body() .contentType(ContentType.JSON) .body("type", equalTo("urn:dx:rs:invalidPayloadFormat")) .body("title", equalTo("Bad Request")) @@ -193,7 +191,7 @@ public void invalidIsSampleFileUploadTest() { .post("/upload") .then() .statusCode(400) - .log().body() + //.log().body() .contentType(ContentType.JSON) .body("type", equalTo("urn:dx:rs:invalidAttributeValue")) .body("title", equalTo("Bad Request")) @@ -218,7 +216,7 @@ public void externalStorageFileUploadSuccessTest() { .post("/upload") .then() .statusCode(200) - .log().body() + //.log().body() .contentType(ContentType.JSON) .body("type", equalTo("urn:dx:rs:success")) .body("title", equalTo("Success")) @@ -240,7 +238,7 @@ public void sampleFileDownloadSuccessTest() { .when() .get("/download") .then() - .log().body() + //.log().body() .statusCode(200); } @Test @@ -254,7 +252,7 @@ public void invalidIdSampleFileDownloadTest() { .get("/download") .then() .statusCode(400) - .log().body() + //.log().body() .contentType(ContentType.JSON) .body("type", equalTo("urn:dx:rs:invalidAttributeValue")) .body("title", equalTo("Bad Request")) @@ -270,7 +268,7 @@ public void archiveFileDownloadSuccessTest(){ .when() .get("/download") .then() - .log().body() + //.log().body() .statusCode(200); } @Test @@ -284,7 +282,7 @@ public void unauthorisedArchiveFileDownloadTest() { .get("/download") .then() .statusCode(401) - .log().body() + //.log().body() .contentType(ContentType.JSON) .body("type", equalTo("urn:dx:rs:invalidAuthorizationToken")) .body("title", equalTo("Not authorized")) @@ -301,7 +299,7 @@ public void nonExistingArchiveFileDownloadTest() { .get("/download") .then() .statusCode(404) - .log().body() + //.log().body() .contentType(ContentType.JSON) .body("type", equalTo("urn:dx:rs:resourceNotFound")) .body("title", equalTo("Not Found")) From d6b51e16f1d814b6d2efc1bd0f207ba3995a4c3e Mon Sep 17 00:00:00 2001 From: DivyaSreeMunagavalasa Date: Fri, 23 Feb 2024 21:12:29 +0530 Subject: [PATCH 10/22] Update RestAssured testHost on depl by fetching from config --- .../apiserver/integrationTests/RestAssuredConfiguration.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/test/java/iudx/file/server/apiserver/integrationTests/RestAssuredConfiguration.java b/src/test/java/iudx/file/server/apiserver/integrationTests/RestAssuredConfiguration.java index 7fbf212..6edf686 100644 --- a/src/test/java/iudx/file/server/apiserver/integrationTests/RestAssuredConfiguration.java +++ b/src/test/java/iudx/file/server/apiserver/integrationTests/RestAssuredConfiguration.java @@ -44,11 +44,12 @@ public void beforeAll(ExtensionContext context) { boolean testOnDepl = Boolean.parseBoolean(System.getProperty("intTestDepl")); if (testOnDepl) { - String testHost = "file-test.iudx.io"; + String testHost = config.getString("host"); baseURI = "https://" + testHost; port = 443; } else { String testHost = System.getProperty("intTestHost"); + //String testHost = config.getString("host"); if (testHost != null) { baseURI = "http://" + testHost; @@ -61,7 +62,7 @@ public void beforeAll(ExtensionContext context) { if (testPort != null) { port = Integer.parseInt(testPort); } else { - port = 8081; + port = 8443; } } From 9788855012c81e64dac751dc65a751583e0eb11a Mon Sep 17 00:00:00 2001 From: Kranthi-Guribilli Date: Fri, 1 Mar 2024 12:51:26 +0530 Subject: [PATCH 11/22] update ITs --- .../files/FileServerIntegrationTests.java | 57 ++++++++++--------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/src/test/java/iudx/file/server/apiserver/integrationTests/files/FileServerIntegrationTests.java b/src/test/java/iudx/file/server/apiserver/integrationTests/files/FileServerIntegrationTests.java index eef6d87..9820344 100644 --- a/src/test/java/iudx/file/server/apiserver/integrationTests/files/FileServerIntegrationTests.java +++ b/src/test/java/iudx/file/server/apiserver/integrationTests/files/FileServerIntegrationTests.java @@ -1,28 +1,25 @@ package iudx.file.server.apiserver.integrationTests.files; import io.restassured.http.ContentType; -import io.restassured.response.Response; +import static io.restassured.RestAssured.*; +import io.restassured.specification.RequestSpecification; import io.vertx.core.json.JsonObject; import iudx.file.server.apiserver.integrationTests.RestAssuredConfiguration; import org.junit.jupiter.api.*; import org.junit.jupiter.api.extension.ExtendWith; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import java.io.*; import static org.hamcrest.Matchers.*; - - -import static io.restassured.RestAssured.*; import static iudx.file.server.authenticator.TokensForITs.*; import static org.hamcrest.Matchers.equalTo; - import static org.hamcrest.Matchers.notNullValue; @ExtendWith(RestAssuredConfiguration.class) @TestMethodOrder(MethodOrderer.OrderAnnotation.class) public class FileServerIntegrationTests { - private static final Logger LOGGER = LoggerFactory.getLogger(FileServerIntegrationTests.class); + private static final Logger LOGGER = LogManager.getLogger(FileServerIntegrationTests.class); private File createTempFileWithContent() { // Create a temporary file @@ -357,26 +354,30 @@ void SearchForFilesUnAuth() { .body("title", is("Not authorized")) .body("detail", is("Token needed and not present")); } - @Test - @Order(16) - @DisplayName("200 (Success) Search for Files using Spatial [geo(circle)]") - void SearchForFilesUsingSpatialGeoCircle(){ - Response response = given() - .header("token", secureResourceToken) - .param("id", rsId) - .param("georel","near;maxDistance=10000") - .param("geometry","point") - .param("coordinates", "[72.79,21.16]") - .when() - .get(baseURI+"/ngsi-ld/v1/entities") - .then() - .statusCode(200) - .body("type", is(200)) - .body("title", is("urn:dx:rs:success")) - .extract() - .response(); - LOGGER.info("response.."+response); - } +@Test +@Order(16) +@DisplayName("200 (Success) Search for Files using Spatial [geo(circle)]") +void searchForFilesUsingSpatialGeoCircle() { + String georel = "near;maxDistance=10000"; + String geometry = "point"; + String coordinates = "[72.79,21.16]"; + RequestSpecification requestSpec = given().urlEncodingEnabled(false); + given() + .header("token", secureResourceToken) + .spec(requestSpec) + .queryParam("id", rsId) + .queryParam("georel", georel) + .queryParam("geometry", geometry) + .queryParam("coordinates", coordinates) + .when() + .get(baseURI + "/ngsi-ld/v1/entities") + .then() + .statusCode(200) + .body("type", is(200)) + .body("title", is("urn:dx:rs:success")) + .extract() + .response(); +} @Test @Order(17) @DisplayName("200 (Success) Search for Files using Spatial [geo(Polygon)]") From 7d65932a86c40e823d7e927c987138b1d4e3a785 Mon Sep 17 00:00:00 2001 From: Kranthi-Guribilli Date: Fri, 1 Mar 2024 13:04:58 +0530 Subject: [PATCH 12/22] Update library versions to the latest --- pom.xml | 79 ++++++++++++------- .../file/server/mocks/FileUploadMock.java | 6 ++ 2 files changed, 56 insertions(+), 29 deletions(-) diff --git a/pom.xml b/pom.xml index b8789bb..9721a18 100644 --- a/pom.xml +++ b/pom.xml @@ -7,34 +7,34 @@ iudx-file-server - 4.3.2 + 4.5.4 11 4.0.2 - 1.9.2 - 5.3.0 + 1.12.3 + 5.6.0 - 5.8.2 - 5.8.2 - 5.8.2 - 1.17.3 - 1.17.3 - 1.17.3 - 2.17.1 - 3.4.4 - 1.17.3 - 8.3.3 + 5.10.2 + 5.10.2 + 5.10.2 + 1.19.6 + 1.19.6 + 1.19.6 + 2.23.0 + 4.0.0 + 1.19.6 + 8.12.2 - 0.8.8 + 0.8.11 - 10.5.0 - 3.3.0 - 3.4.0 - 3.0.0 - 3.0.0-M7 - 3.1.2 - 3.10.1 - 3.17.0 - 3.0.0-M7 + 10.13.0 + 3.5.2 + 3.6.3 + 3.2.0 + 3.2.5 + 3.3.1 + 3.12.1 + 3.21.2 + 3.2.5 iudx.file.server.deploy.Deployer iudx.file.server.deploy.DeployerDev @@ -84,6 +84,11 @@ io.vertx vertx-web-client + + com.google.guava + guava + 33.0.0-jre + org.apache.maven.plugins maven-checkstyle-plugin @@ -114,7 +119,7 @@ io.rest-assured rest-assured - 5.3.2 + 5.4.0 test @@ -126,15 +131,19 @@ org.apache.logging.log4j log4j-core + ${log4j2.version} + compile org.apache.logging.log4j log4j-api + ${log4j2.version} org.apache.logging.log4j log4j-slf4j-impl + ${log4j2.version} @@ -197,7 +206,7 @@ org.postgresql postgresql - 42.4.3 + 42.7.1 test @@ -218,12 +227,24 @@ co.elastic.clients elasticsearch-java - 8.3.3 + 8.12.2 + + + + com.fasterxml.jackson.core + jackson-core + 2.17.0-rc1 com.fasterxml.jackson.core jackson-databind - 2.12.7.1 + 2.17.0-rc1 + + + + com.fasterxml.jackson.core + jackson-annotations + 2.17.0-rc1 @@ -234,13 +255,13 @@ org.mockito mockito-inline - 3.11.1 + 5.2.0 test org.mockito mockito-junit-jupiter - 3.11.1 + 5.10.0 test diff --git a/src/test/java/iudx/file/server/mocks/FileUploadMock.java b/src/test/java/iudx/file/server/mocks/FileUploadMock.java index d5cb057..4141795 100644 --- a/src/test/java/iudx/file/server/mocks/FileUploadMock.java +++ b/src/test/java/iudx/file/server/mocks/FileUploadMock.java @@ -1,5 +1,6 @@ package iudx.file.server.mocks; +import io.vertx.core.Future; import io.vertx.ext.web.FileUpload; public class FileUploadMock implements FileUpload{ @@ -43,4 +44,9 @@ public String charSet() { public boolean cancel() { return false; } + + @Override + public Future delete() { + return Future.succeededFuture(); + } } From 657e26a8433052286b5d31ffa3a201a0363fcbd6 Mon Sep 17 00:00:00 2001 From: Kranthi-Guribilli Date: Tue, 5 Mar 2024 15:16:01 +0530 Subject: [PATCH 13/22] update jackson versions --- pom.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 9721a18..672d809 100644 --- a/pom.xml +++ b/pom.xml @@ -206,7 +206,7 @@ org.postgresql postgresql - 42.7.1 + 42.7.2 test @@ -233,18 +233,18 @@ com.fasterxml.jackson.core jackson-core - 2.17.0-rc1 + 2.16.1 com.fasterxml.jackson.core jackson-databind - 2.17.0-rc1 + 2.16.1 com.fasterxml.jackson.core jackson-annotations - 2.17.0-rc1 + 2.16.1 From c5ac5089defd47d3da4a00e9541765cff9cdf685 Mon Sep 17 00:00:00 2001 From: Kranthi-Guribilli Date: Thu, 7 Mar 2024 10:25:10 +0530 Subject: [PATCH 14/22] log4j-slf4j-impl artifactID is moved to log4j-slf4j2-impl --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 672d809..f82d7d9 100644 --- a/pom.xml +++ b/pom.xml @@ -142,7 +142,7 @@ org.apache.logging.log4j - log4j-slf4j-impl + log4j-slf4j2-impl ${log4j2.version} From 4b65f11bfebbc73093e1f9478968152b2ee6e3a8 Mon Sep 17 00:00:00 2001 From: pranavrd Date: Wed, 13 Mar 2024 18:26:07 +0530 Subject: [PATCH 15/22] renamed integration test to have IT in name --- .../{FileServerIntegrationTests.java => FileServerIT.java} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename src/test/java/iudx/file/server/apiserver/integrationTests/files/{FileServerIntegrationTests.java => FileServerIT.java} (99%) diff --git a/src/test/java/iudx/file/server/apiserver/integrationTests/files/FileServerIntegrationTests.java b/src/test/java/iudx/file/server/apiserver/integrationTests/files/FileServerIT.java similarity index 99% rename from src/test/java/iudx/file/server/apiserver/integrationTests/files/FileServerIntegrationTests.java rename to src/test/java/iudx/file/server/apiserver/integrationTests/files/FileServerIT.java index 9820344..cfe38b2 100644 --- a/src/test/java/iudx/file/server/apiserver/integrationTests/files/FileServerIntegrationTests.java +++ b/src/test/java/iudx/file/server/apiserver/integrationTests/files/FileServerIT.java @@ -18,8 +18,8 @@ @ExtendWith(RestAssuredConfiguration.class) @TestMethodOrder(MethodOrderer.OrderAnnotation.class) -public class FileServerIntegrationTests { - private static final Logger LOGGER = LogManager.getLogger(FileServerIntegrationTests.class); +public class FileServerIT { + private static final Logger LOGGER = LogManager.getLogger(FileServerIT.class); private File createTempFileWithContent() { // Create a temporary file From f1f3ae2694d5da8414b14790db3120bf7dd8e45e Mon Sep 17 00:00:00 2001 From: pranavrd Date: Thu, 14 Mar 2024 13:24:06 +0530 Subject: [PATCH 16/22] fix: pipeline port --- Jenkinsfile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index c1121d6..bcdda26 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -67,10 +67,10 @@ pipeline { } } - stage('Start File-Server for Performance and Integration Testing'){ + stage('Start File-Server for Integration Tests'){ steps{ script{ - sh 'docker compose -f docker-compose.test.yml up -d perfTest' + sh 'docker compose -f docker-compose.test.yml up -d integTest' sh 'sleep 45' } } @@ -93,7 +93,7 @@ pipeline { } script{ sh 'scp /home/ubuntu/configs/fs-config-test.json ./configs/config-test.json' - sh 'mvn test-compile failsafe:integration-test -DskipUnitTests=true -DintTestProxyHost=jenkins-master-priv -DintTestProxyPort=8090 -DintTestHost=jenkins-slave1 -DintTestPort=8080' + sh 'mvn test-compile failsafe:integration-test -DskipUnitTests=true -DintTestProxyHost=jenkins-master-priv -DintTestProxyPort=8090 -DintTestHost=jenkins-slave1 -DintTestPort=8443' } node('built-in') { script{ @@ -193,4 +193,4 @@ Check console output at $BUILD_URL to view the results.''' } } } -} \ No newline at end of file +} From bf7daabd283d645a9f40ed0cad108d3c93716913 Mon Sep 17 00:00:00 2001 From: Pranav Doshetty <34604452+pranavrd@users.noreply.github.com> Date: Thu, 14 Mar 2024 14:38:51 +0530 Subject: [PATCH 17/22] Update Jenkinsfile Co-authored-by: karun-singh <66350877+karun-singh@users.noreply.github.com> --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index bcdda26..442afe1 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -92,7 +92,7 @@ pipeline { } } script{ - sh 'scp /home/ubuntu/configs/fs-config-test.json ./configs/config-test.json' + sh 'mkdir configs; scp /home/ubuntu/configs/fs-config-test.json ./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') { From 1b0fff1d66b4c9e9275126fb7111a938df6aa971 Mon Sep 17 00:00:00 2001 From: pranavrd Date: Thu, 14 Mar 2024 15:03:58 +0530 Subject: [PATCH 18/22] update path for config test --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 442afe1..17a37c2 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -92,7 +92,7 @@ pipeline { } } script{ - sh 'mkdir configs; scp /home/ubuntu/configs/fs-config-test.json ./configs/config-test.json' + sh 'mkdir example-configs; 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') { From b79e888e4127d4bf6c289798c63382b2fc0cdd8d Mon Sep 17 00:00:00 2001 From: pranavrd Date: Thu, 14 Mar 2024 15:16:50 +0530 Subject: [PATCH 19/22] update path for config test --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 17a37c2..08efef0 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -92,7 +92,7 @@ pipeline { } } script{ - sh 'mkdir example-configs; scp /home/ubuntu/configs/fs-config-test.json ./example-configs/config-test.json' + 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') { From ffbadd560ffc78a10994e2f58c35ad93ec8d0a05 Mon Sep 17 00:00:00 2001 From: pranavrd Date: Tue, 19 Mar 2024 14:08:05 +0530 Subject: [PATCH 20/22] fix: file upload dir --- Jenkinsfile | 1 + .../RestAssuredConfiguration.java | 214 ++-- .../integrationTests/files/FileServerIT.java | 1131 +++++++++-------- 3 files changed, 686 insertions(+), 660 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 08efef0..b09eed4 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -93,6 +93,7 @@ pipeline { } script{ sh 'scp /home/ubuntu/configs/fs-config-test.json ./example-configs/config-test.json' + sh 'cp /home/ubuntu/configs/file_upload_test.txt .' sh 'mvn test-compile failsafe:integration-test -DskipUnitTests=true -DintTestProxyHost=jenkins-master-priv -DintTestProxyPort=8090 -DintTestHost=jenkins-slave1 -DintTestPort=8443' } node('built-in') { diff --git a/src/test/java/iudx/file/server/apiserver/integrationTests/RestAssuredConfiguration.java b/src/test/java/iudx/file/server/apiserver/integrationTests/RestAssuredConfiguration.java index 6edf686..4065b2e 100644 --- a/src/test/java/iudx/file/server/apiserver/integrationTests/RestAssuredConfiguration.java +++ b/src/test/java/iudx/file/server/apiserver/integrationTests/RestAssuredConfiguration.java @@ -19,116 +19,118 @@ */ public class RestAssuredConfiguration implements BeforeAllCallback { - private static final Logger logger = LoggerFactory.getLogger(RestAssuredConfiguration.class); - private static String rsId; - private static String openRsId; - private static String openRsGroupId; - private static String nonExistingArchiveId; - private static String fileDownloadURL; - - @Override - public void beforeAll(ExtensionContext context) { - Vertx vertx = Vertx.vertx(); - Configuration fileServerConfig = new Configuration(); - JsonObject config = fileServerConfig.configLoader(0, vertx); - JsonObject testValues = config.getJsonObject("testValues"); - - rsId = testValues.getString("rsId"); - openRsId = testValues.getString("openRsId"); - openRsGroupId = testValues.getString("openRsGroupId"); - nonExistingArchiveId = testValues.getString("nonExistingArchiveId"); - fileDownloadURL = testValues.getString("fileDownloadURL"); - - JsonObject config2 = fileServerConfig.configLoader(1, vertx); - String authServerHost = config2.getString("authHost"); - - boolean testOnDepl = Boolean.parseBoolean(System.getProperty("intTestDepl")); - if (testOnDepl) { - String testHost = config.getString("host"); - baseURI = "https://" + testHost; - port = 443; - } else { - String testHost = System.getProperty("intTestHost"); - //String testHost = config.getString("host"); - - if (testHost != null) { - baseURI = "http://" + testHost; - } else { - baseURI = "http://localhost"; - } - - String testPort = System.getProperty("intTestPort"); - - if (testPort != null) { - port = Integer.parseInt(testPort); - } else { - port = 8443; - } - } - - basePath = "/iudx/v1"; - String dxAuthBasePath = "auth/v1"; - String authEndpoint = "https://"+ authServerHost + "/" + dxAuthBasePath + "/token"; - String proxyHost = System.getProperty("intTestProxyHost"); - String proxyPort = System.getProperty("intTestProxyPort"); - - JsonObject clientCredentials = config2.getJsonObject("clientCredentials"); - String clientId = clientCredentials.getString("clientID"); - String clientSecret = clientCredentials.getString("clientSecret"); - String delegationId = clientCredentials.getString("delegationId"); - if (proxyHost != null && proxyPort != null) { - proxy(proxyHost, Integer.parseInt(proxyPort)); - } - logger.info("setting up the tokens"); - TokenSetup.setupTokens(authEndpoint, clientId, clientSecret, delegationId); - - // Wait for tokens to be available before proceeding - waitForTokens(); - enableLoggingOfRequestAndResponseIfValidationFails(); + private static final Logger logger = LoggerFactory.getLogger(RestAssuredConfiguration.class); + private static String rsId; + private static String openRsId; + private static String openRsGroupId; + private static String nonExistingArchiveId; + private static String fileDownloadURL; + + // Getter methods for configuration values + public static String getRsId() { + return rsId; + } + + public static String getOpenRsId() { + return openRsId; + } + + public static String getOpenRsGroupId() { + return openRsGroupId; + } + + public static String getNonExistingArchiveId() { + return nonExistingArchiveId; + } + + public static String getFileDownloadURL() { + return fileDownloadURL; + } + + @Override + public void beforeAll(ExtensionContext context) { + Vertx vertx = Vertx.vertx(); + Configuration fileServerConfig = new Configuration(); + JsonObject config = fileServerConfig.configLoader(0, vertx); + JsonObject testValues = config.getJsonObject("testValues"); + Boolean isSsl = config.getBoolean("ssl"); + + logger.debug(config.encodePrettily()); + rsId = testValues.getString("rsId"); + openRsId = testValues.getString("openRsId"); + openRsGroupId = testValues.getString("openRsGroupId"); + nonExistingArchiveId = testValues.getString("nonExistingArchiveId"); + fileDownloadURL = testValues.getString("fileDownloadURL"); + + JsonObject config2 = fileServerConfig.configLoader(1, vertx); + String authServerHost = config2.getString("authHost"); + + boolean testOnDepl = Boolean.parseBoolean(System.getProperty("intTestDepl")); + if (testOnDepl) { + String testHost = config.getString("host"); + baseURI = "https://" + testHost; + port = 443; + } else { + String testHost = System.getProperty("intTestHost"); + //String testHost = config.getString("host"); + String httpProtocol = isSsl ? "https://" : "http://"; + if (testHost != null) { + baseURI = httpProtocol + testHost; + } else { + baseURI = httpProtocol + "localhost"; + } + + String testPort = System.getProperty("intTestPort"); + + if (testPort != null) { + port = Integer.parseInt(testPort); + } else { + port = 8443; + } } - // Getter methods for configuration values - public static String getRsId() { - return rsId; + basePath = "/iudx/v1"; + String dxAuthBasePath = "auth/v1"; + String authEndpoint = "https://" + authServerHost + "/" + dxAuthBasePath + "/token"; + String proxyHost = System.getProperty("intTestProxyHost"); + String proxyPort = System.getProperty("intTestProxyPort"); + + JsonObject clientCredentials = config2.getJsonObject("clientCredentials"); + String clientId = clientCredentials.getString("clientID"); + String clientSecret = clientCredentials.getString("clientSecret"); + String delegationId = clientCredentials.getString("delegationId"); + if (proxyHost != null && proxyPort != null) { + proxy(proxyHost, Integer.parseInt(proxyPort)); } - - public static String getOpenRsId() { - return openRsId; - } - - public static String getOpenRsGroupId() { - return openRsGroupId; - } - - public static String getNonExistingArchiveId() { - return nonExistingArchiveId; - } - - public static String getFileDownloadURL() { - return fileDownloadURL; + logger.info("setting up the tokens"); + TokenSetup.setupTokens(authEndpoint, clientId, clientSecret, delegationId); + + // Wait for tokens to be available before proceeding + waitForTokens(); + enableLoggingOfRequestAndResponseIfValidationFails(); + } + + private void waitForTokens() { + int maxAttempts = 5; + int attempt = 0; + + // Keep trying to get tokens until they are available or max attempts are reached + while ((secureResourceToken == null || adminToken == null || openResourceToken == null || delegateToken == null) && attempt < maxAttempts) { + logger.info("Waiting for tokens to be available. Attempt: " + (attempt + 1)); + // Introduce a delay between attempts + try { + Thread.sleep(3000); // Adjust the delay as we aneeded + } catch (InterruptedException e) { + e.printStackTrace(); + } + attempt++; } - private void waitForTokens() { - int maxAttempts = 5; - int attempt = 0; - - // Keep trying to get tokens until they are available or max attempts are reached - while ((secureResourceToken == null || adminToken == null || openResourceToken==null || delegateToken==null ) && attempt < maxAttempts) { - logger.info("Waiting for tokens to be available. Attempt: " + (attempt + 1)); - // Introduce a delay between attempts - try { - Thread.sleep(3000); // Adjust the delay as we aneeded - } catch (InterruptedException e) { - e.printStackTrace(); - } - attempt++; - } - - if (secureResourceToken == null || adminToken == null || openResourceToken==null || delegateToken==null ) { - // Log an error or throw an exception if tokens are still not available - throw new RuntimeException("Failed to retrieve tokens after multiple attempts."); - } else { - logger.info("Tokens are now available. Proceeding with RestAssured configuration."); - } + if (secureResourceToken == null || adminToken == null || openResourceToken == null || delegateToken == null) { + // Log an error or throw an exception if tokens are still not available + throw new RuntimeException("Failed to retrieve tokens after multiple attempts."); + } else { + logger.info("Tokens are now available. Proceeding with RestAssured configuration."); } + } } diff --git a/src/test/java/iudx/file/server/apiserver/integrationTests/files/FileServerIT.java b/src/test/java/iudx/file/server/apiserver/integrationTests/files/FileServerIT.java index cfe38b2..32c42be 100644 --- a/src/test/java/iudx/file/server/apiserver/integrationTests/files/FileServerIT.java +++ b/src/test/java/iudx/file/server/apiserver/integrationTests/files/FileServerIT.java @@ -1,580 +1,603 @@ package iudx.file.server.apiserver.integrationTests.files; import io.restassured.http.ContentType; -import static io.restassured.RestAssured.*; import io.restassured.specification.RequestSpecification; import io.vertx.core.json.JsonObject; import iudx.file.server.apiserver.integrationTests.RestAssuredConfiguration; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.junit.jupiter.api.*; import org.junit.jupiter.api.extension.ExtendWith; -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.LogManager; -import java.io.*; -import static org.hamcrest.Matchers.*; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; + +import static io.restassured.RestAssured.baseURI; +import static io.restassured.RestAssured.given; import static iudx.file.server.authenticator.TokensForITs.*; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.Matchers.*; @ExtendWith(RestAssuredConfiguration.class) @TestMethodOrder(MethodOrderer.OrderAnnotation.class) public class FileServerIT { - private static final Logger LOGGER = LogManager.getLogger(FileServerIT.class); - - private File createTempFileWithContent() { - // Create a temporary file - File tempFile; - try { - tempFile = File.createTempFile("test", ".txt"); - } catch (IOException e) { - throw new RuntimeException("Failed to create a temporary file", e); - } - - // Write content to the file - try (FileWriter writer = new FileWriter(tempFile)) { - writer.write("This is the content of the file for testing purposes."); - } catch (IOException e) { - throw new RuntimeException("Failed to write content to the temporary file", e); - } - - return tempFile; + private static final Logger LOGGER = LogManager.getLogger(FileServerIT.class); + private static final String rsId = RestAssuredConfiguration.getRsId(); + private static final String openRsId = RestAssuredConfiguration.getOpenRsId(); + private static final String openRsGroupId = RestAssuredConfiguration.getOpenRsGroupId(); + private static final String nonExistingArchiveId = RestAssuredConfiguration.getNonExistingArchiveId(); + private static final String fileDownloadURL = RestAssuredConfiguration.getFileDownloadURL(); + private static String sampleFileId; + private static String archiveFileId; + private static String externalStorageFileId; + // Create a temporary file and get its reference + File tempFile = createTempFileWithContent(); + String invalidFileId = "_abced"; + boolean isSample = true; + String invalidToken = "abc"; + + private File createTempFileWithContent() { + // Create a temporary file + tempFile = new File("./file_upload_test.txt"); + + // Write content to the file + try (FileWriter writer = new FileWriter(tempFile)) { + writer.write("This is the content of the file for testing purposes."); + } catch (IOException e) { + throw new RuntimeException("Failed to write content to the temporary file", e); } + + return tempFile; + } + + //File Upload + @Test + @Order(1) + @DisplayName("200 (Success) DX file upload - Resource level (sample)") + public void sampleFileUploadSuccessTest() { + JsonObject respJson = new JsonObject( + given().relaxedHTTPSValidation() + .multiPart("file", tempFile, "text/plain") + .formParam("id", rsId) + .formParam("isSample", isSample) + .header("token", delegateToken) + .when() + .post("/upload") + .then() + .statusCode(200) + //.log().body() + .contentType(ContentType.JSON) + .body("results", notNullValue()) + .body("results[0].fileId", notNullValue()) + .extract() + .asString()); + sampleFileId = respJson.getJsonArray("results").getJsonObject(0).getString("fileId"); + + } + + @Test + @Order(2) + @DisplayName("401 (not authorized) DX file upload - Resource level (sample)") + public void unauthorisedSampleFileUploadTest() { + + given().relaxedHTTPSValidation() + .multiPart("file", tempFile, "text/plain") + .formParam("id", rsId) + .formParam("isSample", isSample) + .header("token", invalidToken) + .when() + .post("/upload") + .then() + .statusCode(401) + //.log().body() + .contentType(ContentType.JSON) + .body("type", equalTo("urn:dx:rs:invalidAuthorizationToken")) + .body("title", equalTo("Not authorized")) + .body("detail", equalTo("Token is invalid")); + } + + @Test + @Order(3) + @DisplayName("200 (Success) - Archive Resource Level") + public void archiveFileUploadSuccessTest() { // Create a temporary file and get its reference - File tempFile = createTempFileWithContent(); - - private static final String rsId = RestAssuredConfiguration.getRsId(); - private static final String openRsId = RestAssuredConfiguration.getOpenRsId(); - private static final String openRsGroupId = RestAssuredConfiguration.getOpenRsGroupId(); - private static String sampleFileId; - private static String archiveFileId; - private static String externalStorageFileId; - private static final String nonExistingArchiveId = RestAssuredConfiguration.getNonExistingArchiveId(); - private static final String fileDownloadURL = RestAssuredConfiguration.getFileDownloadURL(); - String invalidFileId = "_abced"; - boolean isSample=true; - String invalidToken ="abc"; - - //File Upload - @Test - @Order(1) - @DisplayName("200 (Success) DX file upload - Resource level (sample)") - public void sampleFileUploadSuccessTest() { - JsonObject respJson = new JsonObject(given() - .multiPart("file", tempFile, "text/plain") - .formParam("id", rsId) - .formParam("isSample", isSample) - .header("token", delegateToken) - .when() - .post("/upload") - .then() - .statusCode(200) - //.log().body() - .contentType(ContentType.JSON) - .body("results", notNullValue()) - .body("results[0].fileId", notNullValue()) - .extract() - .asString()); - sampleFileId = respJson.getJsonArray("results").getJsonObject(0).getString("fileId"); + //File tempFile = createTempFileWithContent(); + JsonObject respJson = new JsonObject(given().relaxedHTTPSValidation() + .multiPart("file", tempFile, "text/plain") + .formParam("id", rsId) + .formParam("startTime", "2020-09-05T00:00:00Z") + .formParam("endTime", "2020-09-15T00:00:00Z") + .formParam("geometry", "point") + .formParam("coordinates", "[72.81,21.16]") + .header("token", delegateToken) + .when() + .post("/upload") + .then() + .statusCode(200) + //.log().body() + .contentType(ContentType.JSON) + .body("type", equalTo("urn:dx:rs:success")) + .body("title", equalTo("Success")) + .body("results", notNullValue()) + .body("results[0].fileId", notNullValue()) + .extract() + .asString()); + archiveFileId = respJson.getJsonArray("results").getJsonObject(0).getString("fileId"); - } - @Test - @Order(2) - @DisplayName("401 (not authorized) DX file upload - Resource level (sample)") - public void unauthorisedSampleFileUploadTest() { - - given() - .multiPart("file", tempFile, "text/plain") - .formParam("id", rsId) - .formParam("isSample", isSample) - .header("token", invalidToken) - .when() - .post("/upload") - .then() - .statusCode(401) - //.log().body() - .contentType(ContentType.JSON) - .body("type", equalTo("urn:dx:rs:invalidAuthorizationToken")) - .body("title", equalTo("Not authorized")) - .body("detail", equalTo("Token is invalid")); - } - @Test - @Order(3) - @DisplayName("200 (Success) - Archive Resource Level") - public void archiveFileUploadSuccessTest() { - // Create a temporary file and get its reference - //File tempFile = createTempFileWithContent(); - JsonObject respJson = new JsonObject(given() - .multiPart("file", tempFile, "text/plain") - .formParam("id", rsId) - .formParam("startTime", "2020-09-05T00:00:00Z") - .formParam("endTime", "2020-09-15T00:00:00Z") - .formParam("geometry", "point") - .formParam("coordinates", "[72.81,21.16]") - .header("token", delegateToken) - .when() - .post("/upload") - .then() - .statusCode(200) - //.log().body() - .contentType(ContentType.JSON) - .body("type", equalTo("urn:dx:rs:success")) - .body("title", equalTo("Success")) - .body("results", notNullValue()) - .body("results[0].fileId", notNullValue()) - .extract() - .asString()); - archiveFileId = respJson.getJsonArray("results").getJsonObject(0).getString("fileId"); + } - } - @Test - @Order(4) - @DisplayName("401 (not authorized) DX file upload - Resource level (Archive)") - public void unauthorisedArchiveFileTest() { - // Create a temporary file and get its reference - //File tempFile = createTempFileWithContent(); - - given() - .multiPart("file", tempFile, "text/plain") - .formParam("id", rsId) - .formParam("startTime", "2020-09-05T00:00:00Z") - .formParam("endTime", "2020-09-15T00:00:00Z") - .formParam("geometry", "point") - .formParam("coordinates", "[72.81,21.16]") - .header("token",invalidToken) - .when() - .post("/upload") - .then() - .statusCode(401) - //.log().body() - .contentType(ContentType.JSON) - .body("type", equalTo("urn:dx:rs:invalidAuthorizationToken")) - .body("title", equalTo("Not authorized")) - .body("detail", equalTo("Token is invalid")); - } - @Test - @Order(5) - @DisplayName("400 (No id param in request) DX file upload") - public void invalidParamFileUploadTest() { - // Create a temporary file and get its reference - //File tempFile = createTempFileWithContent(); - - given() - .multiPart("file", tempFile, "text/plain") - .formParam("id1", rsId) - .formParam("isSample", isSample) - .header("token",delegateToken) - .when() - .post("/upload") - .then() - .statusCode(400) - //.log().body() - .contentType(ContentType.JSON) - .body("type", equalTo("urn:dx:rs:invalidPayloadFormat")) - .body("title", equalTo("Bad Request")) - .body("detail", equalTo("Validation error : null or blank value for required mandatory field")); - } - @Test - @Order(6) - @DisplayName("400 (Invalid isSample value) DX file upload") - public void invalidIsSampleFileUploadTest() { - // Create a temporary file and get its reference - //File tempFile = createTempFileWithContent(); - given() - .multiPart("file", tempFile, "text/plain") - .formParam("id", rsId) - .formParam("isSample", "true1") - .header("token",delegateToken) - .when() - .post("/upload") - .then() - .statusCode(400) - //.log().body() - .contentType(ContentType.JSON) - .body("type", equalTo("urn:dx:rs:invalidAttributeValue")) - .body("title", equalTo("Bad Request")) - .body("detail", equalTo("Validation error : Invalid isSample field value [ true1 ]")); - } - @Test - @Order(7) - @DisplayName("200 (Success) DX file upload - Resource level (External Storage)") - public void externalStorageFileUploadSuccessTest() { - // Create a temporary file and get its reference - //File tempFile = createTempFileWithContent(); - JsonObject respJson = new JsonObject(given() - .multiPart("file", tempFile, "text/plain") - .formParam("id", rsId) - .formParam("startTime", "2020-09-05T00:00:00Z") - .formParam("endTime", "2020-09-15T00:00:00Z") - .formParam("geometry", "point") - .formParam("coordinates", "[72.81,21.16]") - .formParam("file-download-url",fileDownloadURL) - .header("token", delegateToken) - .when() - .post("/upload") - .then() - .statusCode(200) - //.log().body() - .contentType(ContentType.JSON) - .body("type", equalTo("urn:dx:rs:success")) - .body("title", equalTo("Success")) - .body("results", notNullValue()) - .body("results[0].fileId", notNullValue()) - .extract() - .asString()); - externalStorageFileId = respJson.getJsonArray("results").getJsonObject(0).getString("fileId"); - } + @Test + @Order(4) + @DisplayName("401 (not authorized) DX file upload - Resource level (Archive)") + public void unauthorisedArchiveFileTest() { + // Create a temporary file and get its reference + //File tempFile = createTempFileWithContent(); - // File Download - @Test - @Order(8) - @DisplayName("200 (Success) DX file download - RL (Sample file )") - public void sampleFileDownloadSuccessTest() { - given() - .param("file-id", sampleFileId) - .header("token", openResourceToken) - .when() - .get("/download") - .then() - //.log().body() - .statusCode(200); - } - @Test - @Order(9) - @DisplayName("400 (invalid file id) DX file download") - public void invalidIdSampleFileDownloadTest() { - given() - .header("token", openResourceToken) - .param("file-id", invalidFileId) - .when() - .get("/download") - .then() - .statusCode(400) - //.log().body() - .contentType(ContentType.JSON) - .body("type", equalTo("urn:dx:rs:invalidAttributeValue")) - .body("title", equalTo("Bad Request")) - .body("detail", equalTo("Validation error : invalid file id [ " + invalidFileId + " ]")); - } - @Test - @Order(10) - @DisplayName("200 (Success) DX file download -Resource level (Archive file )") - public void archiveFileDownloadSuccessTest(){ - given() - .param("file-id", archiveFileId) - .header("token", secureResourceToken) - .when() - .get("/download") - .then() - //.log().body() - .statusCode(200); - } - @Test - @Order(11) - @DisplayName("401 (not authorized) DX file download - RL (Archive file )") - public void unauthorisedArchiveFileDownloadTest() { - given() - .header("token", invalidToken) - .param("file-id", archiveFileId) - .when() - .get("/download") - .then() - .statusCode(401) - //.log().body() - .contentType(ContentType.JSON) - .body("type", equalTo("urn:dx:rs:invalidAuthorizationToken")) - .body("title", equalTo("Not authorized")) - .body("detail", equalTo("Token is invalid")); - } - @Test - @Order(12) - @DisplayName("404 (Not Found) DX file download -Resource level (Archive file )") - public void nonExistingArchiveFileDownloadTest() { - given() - .header("token", secureResourceToken) - .param("file-id", nonExistingArchiveId) - .when() - .get("/download") - .then() - .statusCode(404) - //.log().body() - .contentType(ContentType.JSON) - .body("type", equalTo("urn:dx:rs:resourceNotFound")) - .body("title", equalTo("Not Found")) - .body("detail", equalTo("Document of given id does not exist")); - } - //For query APIs - @Test - @Order(13) - @DisplayName("200 (Success) Search for Files of an open resource (using openToken)") - void GetResourceLevelSample() { - given() - .header("token", openResourceToken) - .param("id", openRsId) - .param("time", "2020-09-10T00:00:00Z") - .param("endTime", "2020-09-15T00:00:00Z") - .param("timerel", "between") - .when() - .get(baseURI+"/ngsi-ld/v1/temporal/entities") - .then() - .statusCode(200) - .body("type", is(200)) - .body("title", is("urn:dx:rs:success")); - } - @Test - @Order(14) - @DisplayName("200 (Success) Search for Files of an open resource group (using openToken)") - void GetResourceGroupSample() { - given() - .header("token", openResourceToken) - .param("id", openRsGroupId) - .param("time", "2020-09-10T00:00:00Z") - .param("endTime", "2020-09-15T00:00:00Z") - .param("timerel", "between") - .when() - .get(baseURI+"/ngsi-ld/v1/temporal/entities") - .then() - .statusCode(200) - .body("type", is(200)) - .body("title", is("urn:dx:rs:success")); - } - @Test - @Order(15) - @DisplayName("401 (Not Authorized) Search for Files") - void SearchForFilesUnAuth() { - given() - .param("id", "8b95ab80-2aaf-4636-a65e-7f2563d0d371") - .param("time", "2020-09-10T00:00:00Z") - .param("endTime", "2020-09-15T00:00:00Z") - .param("timerel", "between") - .when() - .get(baseURI+"/ngsi-ld/v1/temporal/entities") - .then() - .statusCode(401) - .body("type", is("urn:dx:rs:missingAuthorizationToken")) - .body("title", is("Not authorized")) - .body("detail", is("Token needed and not present")); - } -@Test -@Order(16) -@DisplayName("200 (Success) Search for Files using Spatial [geo(circle)]") -void searchForFilesUsingSpatialGeoCircle() { + given().relaxedHTTPSValidation() + .multiPart("file", tempFile, "text/plain") + .formParam("id", rsId) + .formParam("startTime", "2020-09-05T00:00:00Z") + .formParam("endTime", "2020-09-15T00:00:00Z") + .formParam("geometry", "point") + .formParam("coordinates", "[72.81,21.16]") + .header("token", invalidToken) + .when() + .post("/upload") + .then() + .statusCode(401) + //.log().body() + .contentType(ContentType.JSON) + .body("type", equalTo("urn:dx:rs:invalidAuthorizationToken")) + .body("title", equalTo("Not authorized")) + .body("detail", equalTo("Token is invalid")); + } + + @Test + @Order(5) + @DisplayName("400 (No id param in request) DX file upload") + public void invalidParamFileUploadTest() { + // Create a temporary file and get its reference + //File tempFile = createTempFileWithContent(); + + given().relaxedHTTPSValidation() + .multiPart("file", tempFile, "text/plain") + .formParam("id1", rsId) + .formParam("isSample", isSample) + .header("token", delegateToken) + .when() + .post("/upload") + .then() + .statusCode(400) + //.log().body() + .contentType(ContentType.JSON) + .body("type", equalTo("urn:dx:rs:invalidPayloadFormat")) + .body("title", equalTo("Bad Request")) + .body("detail", equalTo("Validation error : null or blank value for required mandatory field")); + } + + @Test + @Order(6) + @DisplayName("400 (Invalid isSample value) DX file upload") + public void invalidIsSampleFileUploadTest() { + // Create a temporary file and get its reference + //File tempFile = createTempFileWithContent(); + given().relaxedHTTPSValidation() + .multiPart("file", tempFile, "text/plain") + .formParam("id", rsId) + .formParam("isSample", "true1") + .header("token", delegateToken) + .when() + .post("/upload") + .then() + .statusCode(400) + //.log().body() + .contentType(ContentType.JSON) + .body("type", equalTo("urn:dx:rs:invalidAttributeValue")) + .body("title", equalTo("Bad Request")) + .body("detail", equalTo("Validation error : Invalid isSample field value [ true1 ]")); + } + + @Test + @Order(7) + @DisplayName("200 (Success) DX file upload - Resource level (External Storage)") + public void externalStorageFileUploadSuccessTest() { + // Create a temporary file and get its reference + //File tempFile = createTempFileWithContent(); + JsonObject respJson = new JsonObject(given().relaxedHTTPSValidation() + .multiPart("file", tempFile, "text/plain") + .formParam("id", rsId) + .formParam("startTime", "2020-09-05T00:00:00Z") + .formParam("endTime", "2020-09-15T00:00:00Z") + .formParam("geometry", "point") + .formParam("coordinates", "[72.81,21.16]") + .formParam("file-download-url", fileDownloadURL) + .header("token", delegateToken) + .when() + .post("/upload") + .then() + .statusCode(200) + //.log().body() + .contentType(ContentType.JSON) + .body("type", equalTo("urn:dx:rs:success")) + .body("title", equalTo("Success")) + .body("results", notNullValue()) + .body("results[0].fileId", notNullValue()) + .extract() + .asString()); + externalStorageFileId = respJson.getJsonArray("results").getJsonObject(0).getString("fileId"); + } + + // File Download + @Test + @Order(8) + @DisplayName("200 (Success) DX file download - RL (Sample file )") + public void sampleFileDownloadSuccessTest() { + given().relaxedHTTPSValidation() + .param("file-id", sampleFileId) + .header("token", openResourceToken) + .when() + .get("/download") + .then() + //.log().body() + .statusCode(200); + } + + @Test + @Order(9) + @DisplayName("400 (invalid file id) DX file download") + public void invalidIdSampleFileDownloadTest() { + given().relaxedHTTPSValidation() + .header("token", openResourceToken) + .param("file-id", invalidFileId) + .when() + .get("/download") + .then() + .statusCode(400) + //.log().body() + .contentType(ContentType.JSON) + .body("type", equalTo("urn:dx:rs:invalidAttributeValue")) + .body("title", equalTo("Bad Request")) + .body("detail", equalTo("Validation error : invalid file id [ " + invalidFileId + " ]")); + } + + @Test + @Order(10) + @DisplayName("200 (Success) DX file download -Resource level (Archive file )") + public void archiveFileDownloadSuccessTest() { + given().relaxedHTTPSValidation() + .param("file-id", archiveFileId) + .header("token", secureResourceToken) + .when() + .get("/download") + .then() + //.log().body() + .statusCode(200); + } + + @Test + @Order(11) + @DisplayName("401 (not authorized) DX file download - RL (Archive file )") + public void unauthorisedArchiveFileDownloadTest() { + given().relaxedHTTPSValidation() + .header("token", invalidToken) + .param("file-id", archiveFileId) + .when() + .get("/download") + .then() + .statusCode(401) + //.log().body() + .contentType(ContentType.JSON) + .body("type", equalTo("urn:dx:rs:invalidAuthorizationToken")) + .body("title", equalTo("Not authorized")) + .body("detail", equalTo("Token is invalid")); + } + + @Test + @Order(12) + @DisplayName("404 (Not Found) DX file download -Resource level (Archive file )") + public void nonExistingArchiveFileDownloadTest() { + given().relaxedHTTPSValidation() + .header("token", secureResourceToken) + .param("file-id", nonExistingArchiveId) + .when() + .get("/download") + .then() + .statusCode(404) + //.log().body() + .contentType(ContentType.JSON) + .body("type", equalTo("urn:dx:rs:resourceNotFound")) + .body("title", equalTo("Not Found")) + .body("detail", equalTo("Document of given id does not exist")); + } + + //For query APIs + @Test + @Order(13) + @DisplayName("200 (Success) Search for Files of an open resource (using openToken)") + void GetResourceLevelSample() { + given().relaxedHTTPSValidation() + .header("token", openResourceToken) + .param("id", openRsId) + .param("time", "2020-09-10T00:00:00Z") + .param("endTime", "2020-09-15T00:00:00Z") + .param("timerel", "between") + .when() + .get(baseURI + "/ngsi-ld/v1/temporal/entities") + .then() + .statusCode(200) + .body("type", is(200)) + .body("title", is("urn:dx:rs:success")); + } + + @Test + @Order(14) + @DisplayName("200 (Success) Search for Files of an open resource group (using openToken)") + void GetResourceGroupSample() { + given().relaxedHTTPSValidation() + .header("token", openResourceToken) + .param("id", openRsGroupId) + .param("time", "2020-09-10T00:00:00Z") + .param("endTime", "2020-09-15T00:00:00Z") + .param("timerel", "between") + .when() + .get(baseURI + "/ngsi-ld/v1/temporal/entities") + .then() + .statusCode(200) + .body("type", is(200)) + .body("title", is("urn:dx:rs:success")); + } + + @Test + @Order(15) + @DisplayName("401 (Not Authorized) Search for Files") + void SearchForFilesUnAuth() { + given().relaxedHTTPSValidation() + .param("id", "8b95ab80-2aaf-4636-a65e-7f2563d0d371") + .param("time", "2020-09-10T00:00:00Z") + .param("endTime", "2020-09-15T00:00:00Z") + .param("timerel", "between") + .when() + .get(baseURI + "/ngsi-ld/v1/temporal/entities") + .then() + .statusCode(401) + .body("type", is("urn:dx:rs:missingAuthorizationToken")) + .body("title", is("Not authorized")) + .body("detail", is("Token needed and not present")); + } + + @Test + @Order(16) + @DisplayName("200 (Success) Search for Files using Spatial [geo(circle)]") + void searchForFilesUsingSpatialGeoCircle() { String georel = "near;maxDistance=10000"; String geometry = "point"; String coordinates = "[72.79,21.16]"; - RequestSpecification requestSpec = given().urlEncodingEnabled(false); - given() - .header("token", secureResourceToken) - .spec(requestSpec) - .queryParam("id", rsId) - .queryParam("georel", georel) - .queryParam("geometry", geometry) - .queryParam("coordinates", coordinates) - .when() - .get(baseURI + "/ngsi-ld/v1/entities") - .then() - .statusCode(200) - .body("type", is(200)) - .body("title", is("urn:dx:rs:success")) - .extract() - .response(); -} - @Test - @Order(17) - @DisplayName("200 (Success) Search for Files using Spatial [geo(Polygon)]") - void SearchForFilesUsingSpatialGeoPolygon() { - given() - .header("token", secureResourceToken) - .param("id", rsId) - .param("georel","within") - .param("geometry", "polygon") - .param("coordinates", "[[[72.7815,21.1726],[72.7856,21.1519],[72.807,21.1527],[72.8170,21.1680],[72.800,21.1808],[72.7815,21.1726]]]") - .when() - .get(baseURI+"/ngsi-ld/v1/entities") - .then() - .statusCode(200) - .body("type", is(200)) - .body("title", is("urn:dx:rs:success")); - } - @Test - @Order(18) - @DisplayName("200 (Success) Complex Search [temporal+geo(Circle) search]") - void ComplexSearchForFilesUsingTemporalPlusGeoPolygon() { - given() - .header("token", secureResourceToken) - .param("id", rsId) - .param("time", "2020-09-10T00:00:00Z") - .param("endTime", "2020-09-15T00:00:00Z") - .param("timerel", "between") - .param("georel","near;maxDistance=10000") - .param("geometry", "point") - .param("coordinates", "[72.79,21.16]") - .when() - .get(baseURI+"/ngsi-ld/v1/temporal/entities") - .then() - .statusCode(200) - .body("type", is(200)) - .body("title", is("urn:dx:rs:success")); - } - @Test - @Order(19) - @DisplayName("401 (not authorized) Complex Search [temporal+geo(Circle) search]") - void ComplexSearchForFilesUsingTemporalPlusGeoPolygonUnAuth() { - given() - .param("id", rsId) - .param("time", "2020-09-10T00:00:00Z") - .param("endTime", "2020-09-15T00:00:00Z") - .param("timerel", "between") - .param("georel","near;maxDistance=10000") - .param("geometry", "point") - .param("coordinates", "[72.79,21.16]") - .when() - .get(baseURI+"/ngsi-ld/v1/temporal/entities") - .then() - .statusCode(401) - .body("type", is("urn:dx:rs:missingAuthorizationToken")) - .body("title", is("Not authorized")) - .body("detail", is("Token needed and not present")); - } - @Test - @Order(20) - @DisplayName("200 (Success) List metadata of an open resource (using openToken)") - void ListMetaDataOfOpenResource() { - given() - .header("token", openResourceToken) - .param("id", openRsId) - .when() - .get("/list") - .then() - .statusCode(200) - .body("type", is(200)) - .body("title", is("urn:dx:rs:success")); - } - @Test - @Order(21) - @DisplayName("200 (Success) List metadata of an open resource group (using openToken)") - void ListMetaDataOfOpenResourceGroup() { - given() - .header("token", openResourceToken) - .param("id", openRsGroupId) - .when() - .get("/list") - .then() - .statusCode(200) - .body("type", is(200)) - .body("title", is("urn:dx:rs:success")); - } - @Test - @Order(22) - @DisplayName("200 (Success) List metadata of a secure resource (using secureToken)") - void ListMetaDataOfSecureResource() { - given() - .header("token", secureResourceToken) - .param("id", rsId) - .when() - .get("/list") - .then() - .statusCode(200) - .body("type", is(200)) - .body("title", is("urn:dx:rs:success")); - } - @Test - @Order(23) - @DisplayName("401 (Not authorized) List metadata ") - void ListMetaDataUnAuth() { - given() - .param("id", rsId) - .when() - .get("/list") - .then() - .statusCode(401) - .body("type", is("urn:dx:rs:missingAuthorizationToken")) - .body("title", is("Not authorized")) - .body("detail", is("Token needed and not present")); - } - @Test - @Order(24) - @DisplayName("200 (Success) DX file delete -RL (sample file)") - void DeleteRLSampleFile() { - LOGGER.debug("rl sample..."+sampleFileId); - given() - .header("token", delegateToken) - .param("file-id", sampleFileId) - .when() - .delete("/delete") - .then() - .statusCode(200) - .body("type", is("urn:dx:rs:success")) - .body("title", is("Successful Operation")); - } - @Test - @Order(25) - @DisplayName("404 (Not Found) DX file delete - RL (sample file)") - void DeleteRLSampleFileNotFound() { - given() - .header("token", delegateToken) - .param("file-id", nonExistingArchiveId) - .when() - .delete("/delete") - .then() - .statusCode(404) - .body("type", is("urn:dx:rs:resourceNotFound")) - .body("title", is("Not Found")) - .body("detail", is("Document of given id does not exist")); - } - @Test - @Order(26) - @DisplayName("200 (Success) DX file delete - RL (Archive file)") - void DeleteRLSampleArchiveFile() { - LOGGER.debug("rl archive file id..."+archiveFileId); - given() - .header("token", delegateToken) - .param("file-id", archiveFileId) - .when() - .delete("/delete") - .then() - .statusCode(200) - .body("type", is("urn:dx:rs:success")) - .body("title", is("Successful Operation")); - } - @Test - @Order(27) - @DisplayName("404 (Not Found) DX file delete - RL (Archive file)") - void DeleteRLSampleArchiveFileNotFound() { - given() - .header("token", delegateToken) - .param("file-id", nonExistingArchiveId) - .when() - .delete("/delete") - .then() - .statusCode(404) - .body("type", is("urn:dx:rs:resourceNotFound")) - .body("title", is("Not Found")) - .body("detail", is("Document of given id does not exist")); - } - @Test - @Order(28) - @DisplayName("200 (Success) DX file delete - RL (External Storage)") - void DeleteRLSampleExternalFile() { - LOGGER.debug("rl external storage file id..."+externalStorageFileId); - given() - .header("token", delegateToken) - .param("file-id", externalStorageFileId) - .when() - .delete("/delete") - .then() - .statusCode(200) - .body("type", is("urn:dx:rs:success")) - .body("title", is("Successful Operation")); - } + RequestSpecification requestSpec = given().relaxedHTTPSValidation().urlEncodingEnabled(false); + given().relaxedHTTPSValidation() + .header("token", secureResourceToken) + .spec(requestSpec) + .queryParam("id", rsId) + .queryParam("georel", georel) + .queryParam("geometry", geometry) + .queryParam("coordinates", coordinates) + .when() + .get(baseURI + "/ngsi-ld/v1/entities") + .then() + .statusCode(200) + .body("type", is(200)) + .body("title", is("urn:dx:rs:success")) + .extract() + .response(); + } + + @Test + @Order(17) + @DisplayName("200 (Success) Search for Files using Spatial [geo(Polygon)]") + void SearchForFilesUsingSpatialGeoPolygon() { + given().relaxedHTTPSValidation() + .header("token", secureResourceToken) + .param("id", rsId) + .param("georel", "within") + .param("geometry", "polygon") + .param("coordinates", "[[[72.7815,21.1726],[72.7856,21.1519],[72.807,21.1527],[72.8170,21.1680],[72.800,21.1808],[72.7815,21.1726]]]") + .when() + .get(baseURI + "/ngsi-ld/v1/entities") + .then() + .statusCode(200) + .body("type", is(200)) + .body("title", is("urn:dx:rs:success")); + } + + @Test + @Order(18) + @DisplayName("200 (Success) Complex Search [temporal+geo(Circle) search]") + void ComplexSearchForFilesUsingTemporalPlusGeoPolygon() { + given().relaxedHTTPSValidation() + .header("token", secureResourceToken) + .param("id", rsId) + .param("time", "2020-09-10T00:00:00Z") + .param("endTime", "2020-09-15T00:00:00Z") + .param("timerel", "between") + .param("georel", "near;maxDistance=10000") + .param("geometry", "point") + .param("coordinates", "[72.79,21.16]") + .when() + .get(baseURI + "/ngsi-ld/v1/temporal/entities") + .then() + .statusCode(200) + .body("type", is(200)) + .body("title", is("urn:dx:rs:success")); + } + + @Test + @Order(19) + @DisplayName("401 (not authorized) Complex Search [temporal+geo(Circle) search]") + void ComplexSearchForFilesUsingTemporalPlusGeoPolygonUnAuth() { + given().relaxedHTTPSValidation() + .param("id", rsId) + .param("time", "2020-09-10T00:00:00Z") + .param("endTime", "2020-09-15T00:00:00Z") + .param("timerel", "between") + .param("georel", "near;maxDistance=10000") + .param("geometry", "point") + .param("coordinates", "[72.79,21.16]") + .when() + .get(baseURI + "/ngsi-ld/v1/temporal/entities") + .then() + .statusCode(401) + .body("type", is("urn:dx:rs:missingAuthorizationToken")) + .body("title", is("Not authorized")) + .body("detail", is("Token needed and not present")); + } + + @Test + @Order(20) + @DisplayName("200 (Success) List metadata of an open resource (using openToken)") + void ListMetaDataOfOpenResource() { + given().relaxedHTTPSValidation() + .header("token", openResourceToken) + .param("id", openRsId) + .when() + .get("/list") + .then() + .statusCode(200) + .body("type", is(200)) + .body("title", is("urn:dx:rs:success")); + } + + @Test + @Order(21) + @DisplayName("200 (Success) List metadata of an open resource group (using openToken)") + void ListMetaDataOfOpenResourceGroup() { + given().relaxedHTTPSValidation() + .header("token", openResourceToken) + .param("id", openRsGroupId) + .when() + .get("/list") + .then() + .statusCode(200) + .body("type", is(200)) + .body("title", is("urn:dx:rs:success")); + } + + @Test + @Order(22) + @DisplayName("200 (Success) List metadata of a secure resource (using secureToken)") + void ListMetaDataOfSecureResource() { + given().relaxedHTTPSValidation() + .header("token", secureResourceToken) + .param("id", rsId) + .when() + .get("/list") + .then() + .statusCode(200) + .body("type", is(200)) + .body("title", is("urn:dx:rs:success")); + } + + @Test + @Order(23) + @DisplayName("401 (Not authorized) List metadata ") + void ListMetaDataUnAuth() { + given().relaxedHTTPSValidation() + .param("id", rsId) + .when() + .get("/list") + .then() + .statusCode(401) + .body("type", is("urn:dx:rs:missingAuthorizationToken")) + .body("title", is("Not authorized")) + .body("detail", is("Token needed and not present")); + } + + @Test + @Order(24) + @DisplayName("200 (Success) DX file delete -RL (sample file)") + void DeleteRLSampleFile() { + LOGGER.debug("rl sample..." + sampleFileId); + given().relaxedHTTPSValidation() + .header("token", delegateToken) + .param("file-id", sampleFileId) + .when() + .delete("/delete") + .then() + .statusCode(200) + .body("type", is("urn:dx:rs:success")) + .body("title", is("Successful Operation")); + } + + @Test + @Order(25) + @DisplayName("404 (Not Found) DX file delete - RL (sample file)") + void DeleteRLSampleFileNotFound() { + given().relaxedHTTPSValidation() + .header("token", delegateToken) + .param("file-id", nonExistingArchiveId) + .when() + .delete("/delete") + .then() + .statusCode(404) + .body("type", is("urn:dx:rs:resourceNotFound")) + .body("title", is("Not Found")) + .body("detail", is("Document of given id does not exist")); + } + + @Test + @Order(26) + @DisplayName("200 (Success) DX file delete - RL (Archive file)") + void DeleteRLSampleArchiveFile() { + LOGGER.debug("rl archive file id..." + archiveFileId); + given().relaxedHTTPSValidation() + .header("token", delegateToken) + .param("file-id", archiveFileId) + .when() + .delete("/delete") + .then() + .statusCode(200) + .body("type", is("urn:dx:rs:success")) + .body("title", is("Successful Operation")); + } + + @Test + @Order(27) + @DisplayName("404 (Not Found) DX file delete - RL (Archive file)") + void DeleteRLSampleArchiveFileNotFound() { + given().relaxedHTTPSValidation() + .header("token", delegateToken) + .param("file-id", nonExistingArchiveId) + .when() + .delete("/delete") + .then() + .statusCode(404) + .body("type", is("urn:dx:rs:resourceNotFound")) + .body("title", is("Not Found")) + .body("detail", is("Document of given id does not exist")); + } + + @Test + @Order(28) + @DisplayName("200 (Success) DX file delete - RL (External Storage)") + void DeleteRLSampleExternalFile() { + LOGGER.debug("rl external storage file id..." + externalStorageFileId); + given().relaxedHTTPSValidation() + .header("token", delegateToken) + .param("file-id", externalStorageFileId) + .when() + .delete("/delete") + .then() + .statusCode(200) + .body("type", is("urn:dx:rs:success")) + .body("title", is("Successful Operation")); + } - @AfterEach - public void tearDown() { - // Introduce a delay - try { - Thread.sleep(1000); // 1 second delay - } catch (InterruptedException e) { - e.printStackTrace(); - } + @AfterEach + public void tearDown() { + // Introduce a delay + try { + Thread.sleep(1000); // 1 second delay + } catch (InterruptedException e) { + e.printStackTrace(); } + } } From a2da4eac329c99c7a9d4391e30b258fb5389698b Mon Sep 17 00:00:00 2001 From: pranavrd Date: Tue, 19 Mar 2024 14:35:10 +0530 Subject: [PATCH 21/22] fix: removed keystore dependency --- Jenkinsfile | 1 - docker-compose.test.yml | 2 -- .../iudx/file/server/common/WebClientFactory.java | 12 ++---------- .../integrationTests/files/FileServerIT.java | 6 +++++- 4 files changed, 7 insertions(+), 14 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index b09eed4..08efef0 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -93,7 +93,6 @@ pipeline { } script{ sh 'scp /home/ubuntu/configs/fs-config-test.json ./example-configs/config-test.json' - sh 'cp /home/ubuntu/configs/file_upload_test.txt .' sh 'mvn test-compile failsafe:integration-test -DskipUnitTests=true -DintTestProxyHost=jenkins-master-priv -DintTestProxyPort=8090 -DintTestHost=jenkins-slave1 -DintTestPort=8443' } node('built-in') { diff --git a/docker-compose.test.yml b/docker-compose.test.yml index 8f226a2..d33d098 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -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 @@ -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" diff --git a/src/main/java/iudx/file/server/common/WebClientFactory.java b/src/main/java/iudx/file/server/common/WebClientFactory.java index 2ddc22d..3090b53 100644 --- a/src/main/java/iudx/file/server/common/WebClientFactory.java +++ b/src/main/java/iudx/file/server/common/WebClientFactory.java @@ -36,11 +36,7 @@ private WebClient getFileServerWebClient(final Vertx vertx, final JsonObject con 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); } @@ -49,11 +45,7 @@ private WebClient getRsServerWebClient(final Vertx vertx, final JsonObject confi 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); } } diff --git a/src/test/java/iudx/file/server/apiserver/integrationTests/files/FileServerIT.java b/src/test/java/iudx/file/server/apiserver/integrationTests/files/FileServerIT.java index 32c42be..7d6a955 100644 --- a/src/test/java/iudx/file/server/apiserver/integrationTests/files/FileServerIT.java +++ b/src/test/java/iudx/file/server/apiserver/integrationTests/files/FileServerIT.java @@ -38,7 +38,11 @@ public class FileServerIT { private File createTempFileWithContent() { // Create a temporary file - tempFile = new File("./file_upload_test.txt"); + try { + tempFile = File.createTempFile("test", ".txt"); + } catch (IOException e) { + throw new RuntimeException("Failed to create a temporary file", e); + } // Write content to the file try (FileWriter writer = new FileWriter(tempFile)) { From 86bcac000e5555709db0db7f02d33ea32ffa182a Mon Sep 17 00:00:00 2001 From: pranavrd Date: Tue, 19 Mar 2024 14:42:16 +0530 Subject: [PATCH 22/22] fix: pmd issues --- .../file/server/apiserver/FileServerVerticle.java | 2 +- .../authenticator/AuthenticationVerticle.java | 2 +- .../iudx/file/server/common/WebClientFactory.java | 13 +++++-------- .../server/authenticator/JwtAuthServiceTest.java | 2 +- .../file/server/common/WebClientFactoryTest.java | 2 +- 5 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/main/java/iudx/file/server/apiserver/FileServerVerticle.java b/src/main/java/iudx/file/server/apiserver/FileServerVerticle.java index 4facde9..59db35e 100644 --- a/src/main/java/iudx/file/server/apiserver/FileServerVerticle.java +++ b/src/main/java/iudx/file/server/apiserver/FileServerVerticle.java @@ -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()); diff --git a/src/main/java/iudx/file/server/authenticator/AuthenticationVerticle.java b/src/main/java/iudx/file/server/authenticator/AuthenticationVerticle.java index 90b622c..ac135a6 100644 --- a/src/main/java/iudx/file/server/authenticator/AuthenticationVerticle.java +++ b/src/main/java/iudx/file/server/authenticator/AuthenticationVerticle.java @@ -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( diff --git a/src/main/java/iudx/file/server/common/WebClientFactory.java b/src/main/java/iudx/file/server/common/WebClientFactory.java index 3090b53..7df4ce9 100644 --- a/src/main/java/iudx/file/server/common/WebClientFactory.java +++ b/src/main/java/iudx/file/server/common/WebClientFactory.java @@ -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; @@ -13,25 +12,23 @@ 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) @@ -40,7 +37,7 @@ private WebClient getFileServerWebClient(final Vertx vertx, final JsonObject con 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) diff --git a/src/test/java/iudx/file/server/authenticator/JwtAuthServiceTest.java b/src/test/java/iudx/file/server/authenticator/JwtAuthServiceTest.java index 6620737..4350fec 100644 --- a/src/test/java/iudx/file/server/authenticator/JwtAuthServiceTest.java +++ b/src/test/java/iudx/file/server/authenticator/JwtAuthServiceTest.java @@ -112,7 +112,7 @@ static void init(Vertx vertx, VertxTestContext testContext) { // test JWTAuth jwtAuth = JWTAuth.create(vertx, jwtAuthOptions); - webClientFactory = new WebClientFactory(vertx, authConfig); + webClientFactory = new WebClientFactory(vertx); // catalogueService = new CatalogueServiceImpl(vertx, webClientFactory, authConfig); catalogueServiceMock = mock(CatalogueServiceImpl.class); cacheServiceMock = mock(CacheService.class); diff --git a/src/test/java/iudx/file/server/common/WebClientFactoryTest.java b/src/test/java/iudx/file/server/common/WebClientFactoryTest.java index db7a50d..bbec8c4 100644 --- a/src/test/java/iudx/file/server/common/WebClientFactoryTest.java +++ b/src/test/java/iudx/file/server/common/WebClientFactoryTest.java @@ -26,7 +26,7 @@ public void setup(Vertx vertx) { config = new JsonObject(); config.put("catalogueHost", "abcdefg"); config.put("cataloguePort", 123); - webClientFactory = new WebClientFactory(vertx, config); + webClientFactory = new WebClientFactory(vertx); } @DisplayName("Test getWebClientFor method for Unknown serverType")