Skip to content

Commit

Permalink
SIGA-243 Update fileName tests, formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
heititobi committed Sep 20, 2023
1 parent feadc70 commit 899f13f
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand All @@ -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);
Expand Down Expand Up @@ -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));
Expand All @@ -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));
Expand Down

0 comments on commit 899f13f

Please sign in to comment.