99import org .json .JSONObject ;
1010import org .junit .jupiter .api .BeforeEach ;
1111import org .junit .jupiter .api .Test ;
12+ import org .junit .jupiter .params .ParameterizedTest ;
13+ import org .junit .jupiter .params .provider .ValueSource ;
1214
1315import java .io .IOException ;
1416import java .security .InvalidKeyException ;
1517import java .security .NoSuchAlgorithmException ;
1618import 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 ;
1937import static ee .openeid .siga .test .utils .ContainerUtil .extractEntryFromContainer ;
2038import 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 ;
2244import static org .hamcrest .CoreMatchers .equalTo ;
2345import static org .hamcrest .CoreMatchers .nullValue ;
2446import 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