Skip to content

Commit 899f13f

Browse files
committed
SIGA-243 Update fileName tests, formatting
1 parent feadc70 commit 899f13f

File tree

5 files changed

+105
-16
lines changed

5 files changed

+105
-16
lines changed

siga-test/src/test/java/ee/openeid/siga/test/asic/CreateAsicContainerT.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import org.json.JSONObject;
1212
import org.junit.jupiter.api.BeforeEach;
1313
import org.junit.jupiter.api.Test;
14+
import org.junit.jupiter.params.ParameterizedTest;
15+
import org.junit.jupiter.params.provider.ValueSource;
1416

1517
import java.security.InvalidKeyException;
1618
import java.security.NoSuchAlgorithmException;
@@ -123,10 +125,18 @@ void createAsicContainerEmptyFileContent() throws JSONException, NoSuchAlgorithm
123125
expectError(response, 400, INVALID_REQUEST);
124126
}
125127

128+
@ParameterizedTest(name = "Creating ASIC container not allowed if fileName contains ''{0}''")
129+
@ValueSource(strings = {"/", "`", "?", "*", "\\", "<", ">", "|", "\"", ":", "\u0017", "\u0000", "\u0007"})
130+
void tryCreatingAsicContainerWithInvalidFileName(String fileName) throws JSONException, NoSuchAlgorithmException, InvalidKeyException {
131+
Response response = postCreateContainer(flow, asicContainersDataRequest(fileName, DEFAULT_DATAFILE_CONTENT, DEFAULT_ASICE_CONTAINER_NAME));
132+
expectError(response, 400, INVALID_REQUEST, "Data file name is invalid");
133+
}
134+
126135
@Test
127-
void createAsicContainerInvalidFileName() throws JSONException, NoSuchAlgorithmException, InvalidKeyException {
128-
Response response = postCreateContainer(flow, asicContainersDataRequest("?%*", DEFAULT_DATAFILE_CONTENT, DEFAULT_ASICE_CONTAINER_NAME));
129-
expectError(response, 400, INVALID_REQUEST);
136+
void createAsicContainerWithSpecialCharsInFileName() throws JSONException, NoSuchAlgorithmException, InvalidKeyException {
137+
String fileName = "!#$%&'()+,-.0123456789;=@ ABCDEFGHIJKLMNOPQRSTUVWXYZÕÄÖÜ[]^_abcdefghijklmnopqrstuvwxyzõäöü{}~";
138+
Response response = postCreateContainer(flow, asicContainersDataRequest(fileName, DEFAULT_DATAFILE_CONTENT, DEFAULT_ASICE_CONTAINER_NAME));
139+
response.then().statusCode(200);
130140
}
131141

132142
@Test
@@ -142,13 +152,13 @@ void createAsicContainerInvalidDataFileContent() throws JSONException, NoSuchAlg
142152
}
143153

144154
@Test
145-
void createAsicContainerInvalidContainerName() throws JSONException, NoSuchAlgorithmException, InvalidKeyException{
155+
void createAsicContainerInvalidContainerName() throws JSONException, NoSuchAlgorithmException, InvalidKeyException {
146156
Response response = postCreateContainer(flow, asicContainersDataRequest(DEFAULT_FILENAME, DEFAULT_DATAFILE_CONTENT, "?%*"));
147157
expectError(response, 400, INVALID_REQUEST);
148158
}
149159

150160
@Test
151-
void createAsicContainerPathInContainerName() throws JSONException, NoSuchAlgorithmException, InvalidKeyException{
161+
void createAsicContainerPathInContainerName() throws JSONException, NoSuchAlgorithmException, InvalidKeyException {
152162
Response response = postCreateContainer(flow, asicContainersDataRequest(DEFAULT_FILENAME, DEFAULT_DATAFILE_CONTENT, "C://folder/test.asice"));
153163
expectError(response, 400, INVALID_REQUEST);
154164
}

siga-test/src/test/java/ee/openeid/siga/test/asic/ManipulateDataFilesAsicContainerT.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import org.json.JSONObject;
1111
import org.junit.jupiter.api.BeforeEach;
1212
import org.junit.jupiter.api.Test;
13+
import org.junit.jupiter.params.ParameterizedTest;
14+
import org.junit.jupiter.params.provider.ValueSource;
1315

1416
import java.io.IOException;
1517
import java.security.InvalidKeyException;
@@ -213,6 +215,16 @@ void uploadAsicContainerAndAddEmptyDataFile() throws JSONException, NoSuchAlgori
213215
expectError(response, 400, INVALID_REQUEST);
214216
}
215217

218+
@ParameterizedTest(name = "Adding datafile to ASIC container not allowed if fileName contains ''{0}''")
219+
@ValueSource(strings = {"/", "`", "?", "*", "\\", "<", ">", "|", "\"", ":", "\u0017", "\u0000", "\u0007"})
220+
void uploadAsicContainerAndTryAddingDataFileWithInvalidFilename(String invalidChar) throws JSONException, NoSuchAlgorithmException, InvalidKeyException, IOException {
221+
postUploadContainer(flow, asicContainerRequestFromFile("containerWithoutSignatures.asice"));
222+
223+
Response response = addDataFile(flow, addDataFileToAsicRequest("Char=" + invalidChar + ".txt", "eWV0IGFub3RoZXIgdGVzdCBmaWxlIGNvbnRlbnQu"));
224+
225+
expectError(response, 400, INVALID_REQUEST, "Data file name is invalid");
226+
}
227+
216228
@Test
217229
void createAsicContainerAndAddDataFile() throws JSONException, NoSuchAlgorithmException, InvalidKeyException, IOException {
218230
postCreateContainer(flow, asicContainersDataRequestWithDefault());

siga-test/src/test/java/ee/openeid/siga/test/asic/UploadAsicContainerT.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import org.junit.jupiter.api.BeforeEach;
1010
import org.junit.jupiter.api.Disabled;
1111
import org.junit.jupiter.api.Test;
12+
import org.junit.jupiter.params.ParameterizedTest;
13+
import org.junit.jupiter.params.provider.ValueSource;
1214

1315
import static ee.openeid.siga.test.helper.TestData.CONTAINERS;
1416
import static ee.openeid.siga.test.helper.TestData.CONTAINER_ID;
@@ -123,6 +125,17 @@ void uploadAsicContainerEmptyContainerNameField() throws Exception {
123125
expectError(response, 400, INVALID_REQUEST);
124126
}
125127

128+
@ParameterizedTest(name = "Uploading ASIC container not allowed if containerName contains ''{0}''")
129+
@ValueSource(strings = {"/", "`", "?", "*", "\\", "<", ">", "|", "\"", ":", "\u0017", "\u0000", "\u0007"})
130+
void tryUploadingAsicContainerWithInvalidFileName(String fileName) throws Exception {
131+
JSONObject request = new JSONObject();
132+
request.put("containerName", "InvalidChar=" + fileName);
133+
request.put("container", "RnKZobNWVy8u92sDL4S2j1BUzMT5qTgt6hm90TfAGRo=");
134+
Response response = postUploadContainer(flow, request);
135+
136+
expectError(response, 400, INVALID_REQUEST, "Container name is invalid");
137+
}
138+
126139
@Test
127140
void uploadAsiceContainerNotBase64Container() throws Exception {
128141
JSONObject request = new JSONObject();

siga-test/src/test/java/ee/openeid/siga/test/hashcode/CreateHashcodeContainerT.java

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,29 @@
1010
import org.json.JSONObject;
1111
import org.junit.jupiter.api.BeforeEach;
1212
import org.junit.jupiter.api.Test;
13+
import org.junit.jupiter.params.ParameterizedTest;
14+
import org.junit.jupiter.params.provider.ValueSource;
1315

1416
import java.security.InvalidKeyException;
1517
import java.security.NoSuchAlgorithmException;
1618
import java.util.stream.Collectors;
1719

18-
import static ee.openeid.siga.test.helper.TestData.*;
20+
import static ee.openeid.siga.test.helper.TestData.CONTAINER;
21+
import static ee.openeid.siga.test.helper.TestData.CONTAINER_ID;
22+
import static ee.openeid.siga.test.helper.TestData.DEFAULT_FILENAME;
23+
import static ee.openeid.siga.test.helper.TestData.DEFAULT_FILESIZE;
24+
import static ee.openeid.siga.test.helper.TestData.DEFAULT_SHA256_DATAFILE;
25+
import static ee.openeid.siga.test.helper.TestData.DEFAULT_SHA512_DATAFILE;
26+
import static ee.openeid.siga.test.helper.TestData.ERROR_CODE;
27+
import static ee.openeid.siga.test.helper.TestData.HASHCODE_CONTAINERS;
28+
import static ee.openeid.siga.test.helper.TestData.INVALID_REQUEST;
29+
import static ee.openeid.siga.test.helper.TestData.MANIFEST;
30+
import static ee.openeid.siga.test.helper.TestData.TEST_FILE_EXTENSIONS;
1931
import static ee.openeid.siga.test.utils.ContainerUtil.extractEntryFromContainer;
2032
import static ee.openeid.siga.test.utils.ContainerUtil.manifestAsXmlPath;
21-
import static ee.openeid.siga.test.utils.RequestBuilder.*;
33+
import static ee.openeid.siga.test.utils.RequestBuilder.hashcodeContainersDataRequest;
34+
import static ee.openeid.siga.test.utils.RequestBuilder.hashcodeContainersDataRequestDataFile;
35+
import static ee.openeid.siga.test.utils.RequestBuilder.hashcodeContainersDataRequestWithDefault;
2236
import static org.hamcrest.CoreMatchers.equalTo;
2337
import static org.hamcrest.MatcherAssert.assertThat;
2438
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -154,10 +168,18 @@ void createHashcodeContainerEmptyFileSize() throws JSONException, NoSuchAlgorith
154168
expectError(response, 400, INVALID_REQUEST);
155169
}
156170

171+
@ParameterizedTest(name = "Creating hashcode container not allowed if fileName contains ''{0}''")
172+
@ValueSource(strings = {"/", "`", "?", "*", "\\", "<", ">", "|", "\"", ":", "\u0017", "\u0000", "\u0007"})
173+
void tryCreatingHashcodeContainerWithInvalidFileName(String fileName) throws JSONException, NoSuchAlgorithmException, InvalidKeyException {
174+
Response response = postCreateContainer(flow, hashcodeContainersDataRequest(fileName, DEFAULT_SHA256_DATAFILE, DEFAULT_SHA512_DATAFILE, DEFAULT_FILESIZE));
175+
expectError(response, 400, INVALID_REQUEST, "Data file name is invalid");
176+
}
177+
157178
@Test
158-
void createHashcodeContainerInvalidFileName() throws JSONException, NoSuchAlgorithmException, InvalidKeyException {
159-
Response response = postCreateContainer(flow, hashcodeContainersDataRequest("?%*", DEFAULT_SHA256_DATAFILE, DEFAULT_SHA512_DATAFILE, DEFAULT_FILESIZE));
160-
expectError(response, 400, INVALID_REQUEST);
179+
void createHashcodeContainerWithSpecialCharsInFileName() throws JSONException, NoSuchAlgorithmException, InvalidKeyException {
180+
String fileName = "!#$%&'()+,-.0123456789;=@ ABCDEFGHIJKLMNOPQRSTUVWXYZÕÄÖÜ[]^_abcdefghijklmnopqrstuvwxyzõäöü{}~";
181+
Response response = postCreateContainer(flow, hashcodeContainersDataRequest(fileName, DEFAULT_SHA256_DATAFILE, DEFAULT_SHA512_DATAFILE, DEFAULT_FILESIZE));
182+
response.then().statusCode(200);
161183
}
162184

163185
@Test

siga-test/src/test/java/ee/openeid/siga/test/hashcode/ManipulateDataFilesHashcodeContainerT.java

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,38 @@
99
import org.json.JSONObject;
1010
import org.junit.jupiter.api.BeforeEach;
1111
import org.junit.jupiter.api.Test;
12+
import org.junit.jupiter.params.ParameterizedTest;
13+
import org.junit.jupiter.params.provider.ValueSource;
1214

1315
import java.io.IOException;
1416
import java.security.InvalidKeyException;
1517
import java.security.NoSuchAlgorithmException;
1618
import java.util.stream.Collectors;
1719

18-
import static ee.openeid.siga.test.helper.TestData.*;
20+
import static ee.openeid.siga.test.helper.TestData.CONTAINER;
21+
import static ee.openeid.siga.test.helper.TestData.DATAFILES;
22+
import static ee.openeid.siga.test.helper.TestData.DEFAULT_FILENAME;
23+
import static ee.openeid.siga.test.helper.TestData.DEFAULT_FILESIZE;
24+
import static ee.openeid.siga.test.helper.TestData.DEFAULT_SHA256_DATAFILE;
25+
import static ee.openeid.siga.test.helper.TestData.DEFAULT_SHA512_DATAFILE;
26+
import static ee.openeid.siga.test.helper.TestData.DUPLICATE_DATA_FILE;
27+
import static ee.openeid.siga.test.helper.TestData.HASHCODE_CONTAINERS;
28+
import static ee.openeid.siga.test.helper.TestData.INVALID_DATA;
29+
import static ee.openeid.siga.test.helper.TestData.INVALID_REQUEST;
30+
import static ee.openeid.siga.test.helper.TestData.MANIFEST;
31+
import static ee.openeid.siga.test.helper.TestData.RESOURCE_NOT_FOUND;
32+
import static ee.openeid.siga.test.helper.TestData.TEST_FILE_EXTENSIONS;
33+
import static ee.openeid.siga.test.helper.TestData.UPLOADED_FILENAME;
34+
import static ee.openeid.siga.test.helper.TestData.UPLOADED_FILESIZE;
35+
import static ee.openeid.siga.test.helper.TestData.UPLOADED_SHA256_DATAFILE;
36+
import static ee.openeid.siga.test.helper.TestData.UPLOADED_SHA512_DATAFILE;
1937
import static ee.openeid.siga.test.utils.ContainerUtil.extractEntryFromContainer;
2038
import static ee.openeid.siga.test.utils.ContainerUtil.manifestAsXmlPath;
21-
import static ee.openeid.siga.test.utils.RequestBuilder.*;
39+
import static ee.openeid.siga.test.utils.RequestBuilder.addDataFileToHashcodeRequest;
40+
import static ee.openeid.siga.test.utils.RequestBuilder.addDataFileToHashcodeRequestDataFile;
41+
import static ee.openeid.siga.test.utils.RequestBuilder.addDataFilesToHashcodeRequest;
42+
import static ee.openeid.siga.test.utils.RequestBuilder.hashcodeContainerRequestFromFile;
43+
import static ee.openeid.siga.test.utils.RequestBuilder.hashcodeContainersDataRequestWithDefault;
2244
import static org.hamcrest.CoreMatchers.equalTo;
2345
import static org.hamcrest.CoreMatchers.nullValue;
2446
import static org.hamcrest.MatcherAssert.assertThat;
@@ -187,8 +209,18 @@ void uploadHashcodeContainerAndAddDataFileWithZeroFileSize() throws JSONExceptio
187209
expectError(response, 400, INVALID_REQUEST);
188210
}
189211

212+
@ParameterizedTest(name = "Adding datafile to hashcode container not allowed if fileName contains ''{0}''")
213+
@ValueSource(strings = {"/", "`", "?", "*", "\\", "<", ">", "|", "\"", ":", "\u0017", "\u0000", "\u0007"})
214+
void uploadHashcontainerAndTryAddingDataFileWithInvalidFilename(String invalidChar) throws JSONException, NoSuchAlgorithmException, InvalidKeyException, IOException {
215+
postUploadContainer(flow, hashcodeContainerRequestFromFile("hashcodeWithoutSignature.asice"));
216+
217+
Response response = addDataFile(flow, addDataFileToHashcodeRequest("Char=" + invalidChar + ".txt", DEFAULT_SHA256_DATAFILE, DEFAULT_SHA512_DATAFILE, DEFAULT_FILESIZE));
218+
219+
expectError(response, 400, INVALID_REQUEST, "Data file name is invalid");
220+
}
221+
190222
@Test
191-
void createHashcodeContainerAndAddDataFile() throws JSONException, NoSuchAlgorithmException, InvalidKeyException {
223+
void createHashcodeContainerAndAddDataFile() throws JSONException, NoSuchAlgorithmException, InvalidKeyException {
192224
postCreateContainer(flow, hashcodeContainersDataRequestWithDefault());
193225

194226
addDataFile(flow, addDataFileToHashcodeRequest(DEFAULT_FILENAME, DEFAULT_SHA256_DATAFILE, DEFAULT_SHA512_DATAFILE, DEFAULT_FILESIZE));
@@ -204,7 +236,7 @@ void createHashcodeContainerAndAddDataFile() throws JSONException, NoSuchAlgorit
204236
}
205237

206238
@Test
207-
void createHashcodeContainerAndAddMultipleDataFile() throws JSONException, NoSuchAlgorithmException, InvalidKeyException {
239+
void createHashcodeContainerAndAddMultipleDataFile() throws JSONException, NoSuchAlgorithmException, InvalidKeyException {
208240
postCreateContainer(flow, hashcodeContainersDataRequestWithDefault());
209241

210242
JSONObject dataFiles = addDataFileToHashcodeRequest("testFile1.xml", DEFAULT_SHA256_DATAFILE, DEFAULT_SHA512_DATAFILE, DEFAULT_FILESIZE);
@@ -232,7 +264,7 @@ void createHashcodeContainerAndAddMultipleDataFile() throws JSONException, NoSuc
232264
}
233265

234266
@Test
235-
void createHashcodeContainerAndAddDuplicateDataFile() throws JSONException, NoSuchAlgorithmException, InvalidKeyException {
267+
void createHashcodeContainerAndAddDuplicateDataFile() throws JSONException, NoSuchAlgorithmException, InvalidKeyException {
236268
postCreateContainer(flow, hashcodeContainersDataRequestWithDefault());
237269

238270
Response response = addDataFile(flow, addDataFileToHashcodeRequest(DEFAULT_FILENAME, DEFAULT_SHA256_DATAFILE, DEFAULT_SHA512_DATAFILE, DEFAULT_FILESIZE));
@@ -255,7 +287,7 @@ void createHashcodeContainerAndAddMultipleDataFileMimeTypeFromFileExtension() th
255287
}
256288

257289
@Test
258-
void createHashcodeContainerAndAddDataFileWithZeroFileSize() throws JSONException, NoSuchAlgorithmException, InvalidKeyException {
290+
void createHashcodeContainerAndAddDataFileWithZeroFileSize() throws JSONException, NoSuchAlgorithmException, InvalidKeyException {
259291
postCreateContainer(flow, hashcodeContainersDataRequestWithDefault());
260292

261293
Response response = addDataFile(flow, addDataFileToHashcodeRequest("test.txt", DEFAULT_SHA256_DATAFILE, DEFAULT_SHA512_DATAFILE, 0));

0 commit comments

Comments
 (0)