9
9
import org .json .JSONObject ;
10
10
import org .junit .jupiter .api .BeforeEach ;
11
11
import org .junit .jupiter .api .Test ;
12
+ import org .junit .jupiter .params .ParameterizedTest ;
13
+ import org .junit .jupiter .params .provider .ValueSource ;
12
14
13
15
import java .io .IOException ;
14
16
import java .security .InvalidKeyException ;
15
17
import java .security .NoSuchAlgorithmException ;
16
18
import java .util .stream .Collectors ;
17
19
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 ;
19
37
import static ee .openeid .siga .test .utils .ContainerUtil .extractEntryFromContainer ;
20
38
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 ;
22
44
import static org .hamcrest .CoreMatchers .equalTo ;
23
45
import static org .hamcrest .CoreMatchers .nullValue ;
24
46
import static org .hamcrest .MatcherAssert .assertThat ;
@@ -187,8 +209,18 @@ void uploadHashcodeContainerAndAddDataFileWithZeroFileSize() throws JSONExceptio
187
209
expectError (response , 400 , INVALID_REQUEST );
188
210
}
189
211
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
+
190
222
@ Test
191
- void createHashcodeContainerAndAddDataFile () throws JSONException , NoSuchAlgorithmException , InvalidKeyException {
223
+ void createHashcodeContainerAndAddDataFile () throws JSONException , NoSuchAlgorithmException , InvalidKeyException {
192
224
postCreateContainer (flow , hashcodeContainersDataRequestWithDefault ());
193
225
194
226
addDataFile (flow , addDataFileToHashcodeRequest (DEFAULT_FILENAME , DEFAULT_SHA256_DATAFILE , DEFAULT_SHA512_DATAFILE , DEFAULT_FILESIZE ));
@@ -204,7 +236,7 @@ void createHashcodeContainerAndAddDataFile() throws JSONException, NoSuchAlgorit
204
236
}
205
237
206
238
@ Test
207
- void createHashcodeContainerAndAddMultipleDataFile () throws JSONException , NoSuchAlgorithmException , InvalidKeyException {
239
+ void createHashcodeContainerAndAddMultipleDataFile () throws JSONException , NoSuchAlgorithmException , InvalidKeyException {
208
240
postCreateContainer (flow , hashcodeContainersDataRequestWithDefault ());
209
241
210
242
JSONObject dataFiles = addDataFileToHashcodeRequest ("testFile1.xml" , DEFAULT_SHA256_DATAFILE , DEFAULT_SHA512_DATAFILE , DEFAULT_FILESIZE );
@@ -232,7 +264,7 @@ void createHashcodeContainerAndAddMultipleDataFile() throws JSONException, NoSuc
232
264
}
233
265
234
266
@ Test
235
- void createHashcodeContainerAndAddDuplicateDataFile () throws JSONException , NoSuchAlgorithmException , InvalidKeyException {
267
+ void createHashcodeContainerAndAddDuplicateDataFile () throws JSONException , NoSuchAlgorithmException , InvalidKeyException {
236
268
postCreateContainer (flow , hashcodeContainersDataRequestWithDefault ());
237
269
238
270
Response response = addDataFile (flow , addDataFileToHashcodeRequest (DEFAULT_FILENAME , DEFAULT_SHA256_DATAFILE , DEFAULT_SHA512_DATAFILE , DEFAULT_FILESIZE ));
@@ -255,7 +287,7 @@ void createHashcodeContainerAndAddMultipleDataFileMimeTypeFromFileExtension() th
255
287
}
256
288
257
289
@ Test
258
- void createHashcodeContainerAndAddDataFileWithZeroFileSize () throws JSONException , NoSuchAlgorithmException , InvalidKeyException {
290
+ void createHashcodeContainerAndAddDataFileWithZeroFileSize () throws JSONException , NoSuchAlgorithmException , InvalidKeyException {
259
291
postCreateContainer (flow , hashcodeContainersDataRequestWithDefault ());
260
292
261
293
Response response = addDataFile (flow , addDataFileToHashcodeRequest ("test.txt" , DEFAULT_SHA256_DATAFILE , DEFAULT_SHA512_DATAFILE , 0 ));
0 commit comments