From 899f13f1afbc9c447d76c236315a71696f27e3f7 Mon Sep 17 00:00:00 2001 From: Heiti Tobi Date: Mon, 18 Sep 2023 19:02:11 +0300 Subject: [PATCH] SIGA-243 Update fileName tests, formatting --- .../siga/test/asic/CreateAsicContainerT.java | 20 ++++++--- .../ManipulateDataFilesAsicContainerT.java | 12 +++++ .../siga/test/asic/UploadAsicContainerT.java | 13 ++++++ .../hashcode/CreateHashcodeContainerT.java | 32 +++++++++++--- ...ManipulateDataFilesHashcodeContainerT.java | 44 ++++++++++++++++--- 5 files changed, 105 insertions(+), 16 deletions(-) diff --git a/siga-test/src/test/java/ee/openeid/siga/test/asic/CreateAsicContainerT.java b/siga-test/src/test/java/ee/openeid/siga/test/asic/CreateAsicContainerT.java index 31ddb307..21c28a68 100644 --- a/siga-test/src/test/java/ee/openeid/siga/test/asic/CreateAsicContainerT.java +++ b/siga-test/src/test/java/ee/openeid/siga/test/asic/CreateAsicContainerT.java @@ -11,6 +11,8 @@ import org.json.JSONObject; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; @@ -123,10 +125,18 @@ void createAsicContainerEmptyFileContent() throws JSONException, NoSuchAlgorithm expectError(response, 400, INVALID_REQUEST); } + @ParameterizedTest(name = "Creating ASIC container not allowed if fileName contains ''{0}''") + @ValueSource(strings = {"/", "`", "?", "*", "\\", "<", ">", "|", "\"", ":", "\u0017", "\u0000", "\u0007"}) + void tryCreatingAsicContainerWithInvalidFileName(String fileName) throws JSONException, NoSuchAlgorithmException, InvalidKeyException { + Response response = postCreateContainer(flow, asicContainersDataRequest(fileName, DEFAULT_DATAFILE_CONTENT, DEFAULT_ASICE_CONTAINER_NAME)); + expectError(response, 400, INVALID_REQUEST, "Data file name is invalid"); + } + @Test - void createAsicContainerInvalidFileName() throws JSONException, NoSuchAlgorithmException, InvalidKeyException { - Response response = postCreateContainer(flow, asicContainersDataRequest("?%*", DEFAULT_DATAFILE_CONTENT, DEFAULT_ASICE_CONTAINER_NAME)); - expectError(response, 400, INVALID_REQUEST); + void createAsicContainerWithSpecialCharsInFileName() throws JSONException, NoSuchAlgorithmException, InvalidKeyException { + String fileName = "!#$%&'()+,-.0123456789;=@ ABCDEFGHIJKLMNOPQRSTUVWXYZÕÄÖÜ[]^_abcdefghijklmnopqrstuvwxyzõäöü{}~"; + Response response = postCreateContainer(flow, asicContainersDataRequest(fileName, DEFAULT_DATAFILE_CONTENT, DEFAULT_ASICE_CONTAINER_NAME)); + response.then().statusCode(200); } @Test @@ -142,13 +152,13 @@ void createAsicContainerInvalidDataFileContent() throws JSONException, NoSuchAlg } @Test - void createAsicContainerInvalidContainerName() throws JSONException, NoSuchAlgorithmException, InvalidKeyException{ + void createAsicContainerInvalidContainerName() throws JSONException, NoSuchAlgorithmException, InvalidKeyException { Response response = postCreateContainer(flow, asicContainersDataRequest(DEFAULT_FILENAME, DEFAULT_DATAFILE_CONTENT, "?%*")); expectError(response, 400, INVALID_REQUEST); } @Test - void createAsicContainerPathInContainerName() throws JSONException, NoSuchAlgorithmException, InvalidKeyException{ + void createAsicContainerPathInContainerName() throws JSONException, NoSuchAlgorithmException, InvalidKeyException { Response response = postCreateContainer(flow, asicContainersDataRequest(DEFAULT_FILENAME, DEFAULT_DATAFILE_CONTENT, "C://folder/test.asice")); expectError(response, 400, INVALID_REQUEST); } diff --git a/siga-test/src/test/java/ee/openeid/siga/test/asic/ManipulateDataFilesAsicContainerT.java b/siga-test/src/test/java/ee/openeid/siga/test/asic/ManipulateDataFilesAsicContainerT.java index 7e0acf6d..266b9c2c 100644 --- a/siga-test/src/test/java/ee/openeid/siga/test/asic/ManipulateDataFilesAsicContainerT.java +++ b/siga-test/src/test/java/ee/openeid/siga/test/asic/ManipulateDataFilesAsicContainerT.java @@ -10,6 +10,8 @@ import org.json.JSONObject; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import java.io.IOException; import java.security.InvalidKeyException; @@ -213,6 +215,16 @@ void uploadAsicContainerAndAddEmptyDataFile() throws JSONException, NoSuchAlgori expectError(response, 400, INVALID_REQUEST); } + @ParameterizedTest(name = "Adding datafile to ASIC container not allowed if fileName contains ''{0}''") + @ValueSource(strings = {"/", "`", "?", "*", "\\", "<", ">", "|", "\"", ":", "\u0017", "\u0000", "\u0007"}) + void uploadAsicContainerAndTryAddingDataFileWithInvalidFilename(String invalidChar) throws JSONException, NoSuchAlgorithmException, InvalidKeyException, IOException { + postUploadContainer(flow, asicContainerRequestFromFile("containerWithoutSignatures.asice")); + + Response response = addDataFile(flow, addDataFileToAsicRequest("Char=" + invalidChar + ".txt", "eWV0IGFub3RoZXIgdGVzdCBmaWxlIGNvbnRlbnQu")); + + expectError(response, 400, INVALID_REQUEST, "Data file name is invalid"); + } + @Test void createAsicContainerAndAddDataFile() throws JSONException, NoSuchAlgorithmException, InvalidKeyException, IOException { postCreateContainer(flow, asicContainersDataRequestWithDefault()); diff --git a/siga-test/src/test/java/ee/openeid/siga/test/asic/UploadAsicContainerT.java b/siga-test/src/test/java/ee/openeid/siga/test/asic/UploadAsicContainerT.java index ba2f9167..a23f24f9 100644 --- a/siga-test/src/test/java/ee/openeid/siga/test/asic/UploadAsicContainerT.java +++ b/siga-test/src/test/java/ee/openeid/siga/test/asic/UploadAsicContainerT.java @@ -9,6 +9,8 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import static ee.openeid.siga.test.helper.TestData.CONTAINERS; import static ee.openeid.siga.test.helper.TestData.CONTAINER_ID; @@ -123,6 +125,17 @@ void uploadAsicContainerEmptyContainerNameField() throws Exception { expectError(response, 400, INVALID_REQUEST); } + @ParameterizedTest(name = "Uploading ASIC container not allowed if containerName contains ''{0}''") + @ValueSource(strings = {"/", "`", "?", "*", "\\", "<", ">", "|", "\"", ":", "\u0017", "\u0000", "\u0007"}) + void tryUploadingAsicContainerWithInvalidFileName(String fileName) throws Exception { + JSONObject request = new JSONObject(); + request.put("containerName", "InvalidChar=" + fileName); + request.put("container", "RnKZobNWVy8u92sDL4S2j1BUzMT5qTgt6hm90TfAGRo="); + Response response = postUploadContainer(flow, request); + + expectError(response, 400, INVALID_REQUEST, "Container name is invalid"); + } + @Test void uploadAsiceContainerNotBase64Container() throws Exception { JSONObject request = new JSONObject(); diff --git a/siga-test/src/test/java/ee/openeid/siga/test/hashcode/CreateHashcodeContainerT.java b/siga-test/src/test/java/ee/openeid/siga/test/hashcode/CreateHashcodeContainerT.java index 1938ca64..185be4a6 100644 --- a/siga-test/src/test/java/ee/openeid/siga/test/hashcode/CreateHashcodeContainerT.java +++ b/siga-test/src/test/java/ee/openeid/siga/test/hashcode/CreateHashcodeContainerT.java @@ -10,15 +10,29 @@ import org.json.JSONObject; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.util.stream.Collectors; -import static ee.openeid.siga.test.helper.TestData.*; +import static ee.openeid.siga.test.helper.TestData.CONTAINER; +import static ee.openeid.siga.test.helper.TestData.CONTAINER_ID; +import static ee.openeid.siga.test.helper.TestData.DEFAULT_FILENAME; +import static ee.openeid.siga.test.helper.TestData.DEFAULT_FILESIZE; +import static ee.openeid.siga.test.helper.TestData.DEFAULT_SHA256_DATAFILE; +import static ee.openeid.siga.test.helper.TestData.DEFAULT_SHA512_DATAFILE; +import static ee.openeid.siga.test.helper.TestData.ERROR_CODE; +import static ee.openeid.siga.test.helper.TestData.HASHCODE_CONTAINERS; +import static ee.openeid.siga.test.helper.TestData.INVALID_REQUEST; +import static ee.openeid.siga.test.helper.TestData.MANIFEST; +import static ee.openeid.siga.test.helper.TestData.TEST_FILE_EXTENSIONS; import static ee.openeid.siga.test.utils.ContainerUtil.extractEntryFromContainer; import static ee.openeid.siga.test.utils.ContainerUtil.manifestAsXmlPath; -import static ee.openeid.siga.test.utils.RequestBuilder.*; +import static ee.openeid.siga.test.utils.RequestBuilder.hashcodeContainersDataRequest; +import static ee.openeid.siga.test.utils.RequestBuilder.hashcodeContainersDataRequestDataFile; +import static ee.openeid.siga.test.utils.RequestBuilder.hashcodeContainersDataRequestWithDefault; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -154,10 +168,18 @@ void createHashcodeContainerEmptyFileSize() throws JSONException, NoSuchAlgorith expectError(response, 400, INVALID_REQUEST); } + @ParameterizedTest(name = "Creating hashcode container not allowed if fileName contains ''{0}''") + @ValueSource(strings = {"/", "`", "?", "*", "\\", "<", ">", "|", "\"", ":", "\u0017", "\u0000", "\u0007"}) + void tryCreatingHashcodeContainerWithInvalidFileName(String fileName) throws JSONException, NoSuchAlgorithmException, InvalidKeyException { + Response response = postCreateContainer(flow, hashcodeContainersDataRequest(fileName, DEFAULT_SHA256_DATAFILE, DEFAULT_SHA512_DATAFILE, DEFAULT_FILESIZE)); + expectError(response, 400, INVALID_REQUEST, "Data file name is invalid"); + } + @Test - void createHashcodeContainerInvalidFileName() throws JSONException, NoSuchAlgorithmException, InvalidKeyException { - Response response = postCreateContainer(flow, hashcodeContainersDataRequest("?%*", DEFAULT_SHA256_DATAFILE, DEFAULT_SHA512_DATAFILE, DEFAULT_FILESIZE)); - expectError(response, 400, INVALID_REQUEST); + void createHashcodeContainerWithSpecialCharsInFileName() throws JSONException, NoSuchAlgorithmException, InvalidKeyException { + String fileName = "!#$%&'()+,-.0123456789;=@ ABCDEFGHIJKLMNOPQRSTUVWXYZÕÄÖÜ[]^_abcdefghijklmnopqrstuvwxyzõäöü{}~"; + Response response = postCreateContainer(flow, hashcodeContainersDataRequest(fileName, DEFAULT_SHA256_DATAFILE, DEFAULT_SHA512_DATAFILE, DEFAULT_FILESIZE)); + response.then().statusCode(200); } @Test diff --git a/siga-test/src/test/java/ee/openeid/siga/test/hashcode/ManipulateDataFilesHashcodeContainerT.java b/siga-test/src/test/java/ee/openeid/siga/test/hashcode/ManipulateDataFilesHashcodeContainerT.java index 5a7ecbcf..c63809bd 100644 --- a/siga-test/src/test/java/ee/openeid/siga/test/hashcode/ManipulateDataFilesHashcodeContainerT.java +++ b/siga-test/src/test/java/ee/openeid/siga/test/hashcode/ManipulateDataFilesHashcodeContainerT.java @@ -9,16 +9,38 @@ import org.json.JSONObject; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import java.io.IOException; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.util.stream.Collectors; -import static ee.openeid.siga.test.helper.TestData.*; +import static ee.openeid.siga.test.helper.TestData.CONTAINER; +import static ee.openeid.siga.test.helper.TestData.DATAFILES; +import static ee.openeid.siga.test.helper.TestData.DEFAULT_FILENAME; +import static ee.openeid.siga.test.helper.TestData.DEFAULT_FILESIZE; +import static ee.openeid.siga.test.helper.TestData.DEFAULT_SHA256_DATAFILE; +import static ee.openeid.siga.test.helper.TestData.DEFAULT_SHA512_DATAFILE; +import static ee.openeid.siga.test.helper.TestData.DUPLICATE_DATA_FILE; +import static ee.openeid.siga.test.helper.TestData.HASHCODE_CONTAINERS; +import static ee.openeid.siga.test.helper.TestData.INVALID_DATA; +import static ee.openeid.siga.test.helper.TestData.INVALID_REQUEST; +import static ee.openeid.siga.test.helper.TestData.MANIFEST; +import static ee.openeid.siga.test.helper.TestData.RESOURCE_NOT_FOUND; +import static ee.openeid.siga.test.helper.TestData.TEST_FILE_EXTENSIONS; +import static ee.openeid.siga.test.helper.TestData.UPLOADED_FILENAME; +import static ee.openeid.siga.test.helper.TestData.UPLOADED_FILESIZE; +import static ee.openeid.siga.test.helper.TestData.UPLOADED_SHA256_DATAFILE; +import static ee.openeid.siga.test.helper.TestData.UPLOADED_SHA512_DATAFILE; import static ee.openeid.siga.test.utils.ContainerUtil.extractEntryFromContainer; import static ee.openeid.siga.test.utils.ContainerUtil.manifestAsXmlPath; -import static ee.openeid.siga.test.utils.RequestBuilder.*; +import static ee.openeid.siga.test.utils.RequestBuilder.addDataFileToHashcodeRequest; +import static ee.openeid.siga.test.utils.RequestBuilder.addDataFileToHashcodeRequestDataFile; +import static ee.openeid.siga.test.utils.RequestBuilder.addDataFilesToHashcodeRequest; +import static ee.openeid.siga.test.utils.RequestBuilder.hashcodeContainerRequestFromFile; +import static ee.openeid.siga.test.utils.RequestBuilder.hashcodeContainersDataRequestWithDefault; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.MatcherAssert.assertThat; @@ -187,8 +209,18 @@ void uploadHashcodeContainerAndAddDataFileWithZeroFileSize() throws JSONExceptio expectError(response, 400, INVALID_REQUEST); } + @ParameterizedTest(name = "Adding datafile to hashcode container not allowed if fileName contains ''{0}''") + @ValueSource(strings = {"/", "`", "?", "*", "\\", "<", ">", "|", "\"", ":", "\u0017", "\u0000", "\u0007"}) + void uploadHashcontainerAndTryAddingDataFileWithInvalidFilename(String invalidChar) throws JSONException, NoSuchAlgorithmException, InvalidKeyException, IOException { + postUploadContainer(flow, hashcodeContainerRequestFromFile("hashcodeWithoutSignature.asice")); + + Response response = addDataFile(flow, addDataFileToHashcodeRequest("Char=" + invalidChar + ".txt", DEFAULT_SHA256_DATAFILE, DEFAULT_SHA512_DATAFILE, DEFAULT_FILESIZE)); + + expectError(response, 400, INVALID_REQUEST, "Data file name is invalid"); + } + @Test - void createHashcodeContainerAndAddDataFile() throws JSONException, NoSuchAlgorithmException, InvalidKeyException { + void createHashcodeContainerAndAddDataFile() throws JSONException, NoSuchAlgorithmException, InvalidKeyException { postCreateContainer(flow, hashcodeContainersDataRequestWithDefault()); addDataFile(flow, addDataFileToHashcodeRequest(DEFAULT_FILENAME, DEFAULT_SHA256_DATAFILE, DEFAULT_SHA512_DATAFILE, DEFAULT_FILESIZE)); @@ -204,7 +236,7 @@ void createHashcodeContainerAndAddDataFile() throws JSONException, NoSuchAlgorit } @Test - void createHashcodeContainerAndAddMultipleDataFile() throws JSONException, NoSuchAlgorithmException, InvalidKeyException { + void createHashcodeContainerAndAddMultipleDataFile() throws JSONException, NoSuchAlgorithmException, InvalidKeyException { postCreateContainer(flow, hashcodeContainersDataRequestWithDefault()); JSONObject dataFiles = addDataFileToHashcodeRequest("testFile1.xml", DEFAULT_SHA256_DATAFILE, DEFAULT_SHA512_DATAFILE, DEFAULT_FILESIZE); @@ -232,7 +264,7 @@ void createHashcodeContainerAndAddMultipleDataFile() throws JSONException, NoSuc } @Test - void createHashcodeContainerAndAddDuplicateDataFile() throws JSONException, NoSuchAlgorithmException, InvalidKeyException { + void createHashcodeContainerAndAddDuplicateDataFile() throws JSONException, NoSuchAlgorithmException, InvalidKeyException { postCreateContainer(flow, hashcodeContainersDataRequestWithDefault()); Response response = addDataFile(flow, addDataFileToHashcodeRequest(DEFAULT_FILENAME, DEFAULT_SHA256_DATAFILE, DEFAULT_SHA512_DATAFILE, DEFAULT_FILESIZE)); @@ -255,7 +287,7 @@ void createHashcodeContainerAndAddMultipleDataFileMimeTypeFromFileExtension() th } @Test - void createHashcodeContainerAndAddDataFileWithZeroFileSize() throws JSONException, NoSuchAlgorithmException, InvalidKeyException { + void createHashcodeContainerAndAddDataFileWithZeroFileSize() throws JSONException, NoSuchAlgorithmException, InvalidKeyException { postCreateContainer(flow, hashcodeContainersDataRequestWithDefault()); Response response = addDataFile(flow, addDataFileToHashcodeRequest("test.txt", DEFAULT_SHA256_DATAFILE, DEFAULT_SHA512_DATAFILE, 0));