1313import java .security .InvalidKeyException ;
1414
1515import static com .mastercard .developer .encryption .FieldLevelEncryptionConfig .FieldValueEncoding ;
16- import static com .mastercard .developer .test .TestUtils .getFieldLevelEncryptionConfigBuilder ;
16+ import static com .mastercard .developer .test .TestUtils .getTestFieldLevelEncryptionConfigBuilder ;
1717import static com .mastercard .developer .utils .EncryptionUtils .loadDecryptionKey ;
1818import static org .hamcrest .core .Is .isA ;
1919import static org .junit .Assert .*;
@@ -28,7 +28,7 @@ public void testEncryptPayload_Nominal() throws Exception {
2828
2929 // GIVEN
3030 String payload = "{\" data\" : {}, \" encryptedData\" : {}}" ;
31- FieldLevelEncryptionConfig config = getFieldLevelEncryptionConfigBuilder ()
31+ FieldLevelEncryptionConfig config = getTestFieldLevelEncryptionConfigBuilder ()
3232 .withEncryptionPath ("data" , "encryptedData" )
3333 .withOaepPaddingDigestAlgorithm ("SHA-256" )
3434 .build ();
@@ -55,7 +55,7 @@ public void testEncryptPayload_ShouldSupportBase64FieldValueEncoding() throws Ex
5555
5656 // GIVEN
5757 String payload = "{\" data\" : {}, \" encryptedData\" : {}}" ;
58- FieldLevelEncryptionConfig config = getFieldLevelEncryptionConfigBuilder ()
58+ FieldLevelEncryptionConfig config = getTestFieldLevelEncryptionConfigBuilder ()
5959 .withEncryptionPath ("data" , "encryptedData" )
6060 .withOaepPaddingDigestAlgorithm ("SHA-256" )
6161 .withFieldValueEncoding (FieldValueEncoding .BASE64 )
@@ -84,7 +84,7 @@ public void testEncryptPayload_ShouldEncryptPrimitiveTypes() throws Exception {
8484
8585 // GIVEN
8686 String payload = "{\" data\" : \" string\" , \" encryptedData\" : {}}" ;
87- FieldLevelEncryptionConfig config = getFieldLevelEncryptionConfigBuilder ()
87+ FieldLevelEncryptionConfig config = getTestFieldLevelEncryptionConfigBuilder ()
8888 .withEncryptionPath ("data" , "encryptedData" )
8989 .withOaepPaddingDigestAlgorithm ("SHA-256" )
9090 .build ();
@@ -104,7 +104,7 @@ public void testEncryptPayload_ShouldDoNothing_WhenInPathDoesNotExistInPayload()
104104
105105 // GIVEN
106106 String payload = "{\" data\" : {}, \" encryptedData\" : {}}" ;
107- FieldLevelEncryptionConfig config = getFieldLevelEncryptionConfigBuilder ()
107+ FieldLevelEncryptionConfig config = getTestFieldLevelEncryptionConfigBuilder ()
108108 .withEncryptionPath ("objectNotInPayload" , "encryptedData" )
109109 .build ();
110110
@@ -120,7 +120,7 @@ public void testEncryptPayload_ShouldCreateEncryptionFields_WhenOutPathParentExi
120120
121121 // GIVEN
122122 String payload = "{\" data\" : {}, \" encryptedDataParent\" : {}}" ;
123- FieldLevelEncryptionConfig config = getFieldLevelEncryptionConfigBuilder ()
123+ FieldLevelEncryptionConfig config = getTestFieldLevelEncryptionConfigBuilder ()
124124 .withEncryptionPath ("data" , "encryptedDataParent.encryptedData" )
125125 .build ();
126126
@@ -138,7 +138,7 @@ public void testEncryptPayload_ShouldThrowIllegalArgumentException_WhenOutPathPa
138138
139139 // GIVEN
140140 String payload = "{\" data\" : {}}" ;
141- FieldLevelEncryptionConfig config = getFieldLevelEncryptionConfigBuilder ()
141+ FieldLevelEncryptionConfig config = getTestFieldLevelEncryptionConfigBuilder ()
142142 .withEncryptionPath ("data" , "parentNotInPayload.encryptedData" )
143143 .build ();
144144
@@ -155,7 +155,7 @@ public void testEncryptPayload_ShouldThrowIllegalArgumentException_WhenOutPathIs
155155
156156 // GIVEN
157157 String payload = "{\" data\" : {}, \" encryptedData\" : \" string\" }" ;
158- FieldLevelEncryptionConfig config = getFieldLevelEncryptionConfigBuilder ()
158+ FieldLevelEncryptionConfig config = getTestFieldLevelEncryptionConfigBuilder ()
159159 .withEncryptionPath ("data" , "encryptedData" )
160160 .withOaepPaddingDigestAlgorithm ("SHA-256" )
161161 .build ();
@@ -173,7 +173,7 @@ public void testEncryptPayload_ShouldComputeCertificateAndKeyFingerprints_WhenFi
173173
174174 // GIVEN
175175 String payload = "{\" data\" : {}, \" encryptedData\" : {}}" ;
176- FieldLevelEncryptionConfig config = getFieldLevelEncryptionConfigBuilder ()
176+ FieldLevelEncryptionConfig config = getTestFieldLevelEncryptionConfigBuilder ()
177177 .withEncryptionPath ("data" , "encryptedData" )
178178 .withEncryptionCertificateFingerprint (null )
179179 .withEncryptionKeyFingerprint (null )
@@ -194,7 +194,7 @@ public void testEncryptPayload_ShouldNotSetCertificateAndKeyFingerprints_WhenFie
194194
195195 // GIVEN
196196 String payload = "{\" data\" : {}, \" encryptedData\" : {}}" ;
197- FieldLevelEncryptionConfig config = getFieldLevelEncryptionConfigBuilder ()
197+ FieldLevelEncryptionConfig config = getTestFieldLevelEncryptionConfigBuilder ()
198198 .withEncryptionPath ("data" , "encryptedData" )
199199 .withEncryptionCertificateFingerprintFieldName (null )
200200 .withEncryptionKeyFingerprintFieldName (null )
@@ -215,7 +215,7 @@ public void testEncryptPayload_ShouldSupportMultipleEncryptions() throws Excepti
215215
216216 // GIVEN
217217 String payload = "{\" data1\" : {}, \" data2\" : {}, \" encryptedData1\" : {}, \" encryptedData2\" : {}}" ;
218- FieldLevelEncryptionConfig config = getFieldLevelEncryptionConfigBuilder ()
218+ FieldLevelEncryptionConfig config = getTestFieldLevelEncryptionConfigBuilder ()
219219 .withEncryptionPath ("data1" , "encryptedData1" )
220220 .withEncryptionPath ("data2" , "encryptedData2" )
221221 .build ();
@@ -241,7 +241,7 @@ public void testEncryptPayload_ShouldSupportBasicExistingJsonPaths() throws Exce
241241 " \" data2\" : {}, \" encryptedData2\" : {}," +
242242 " \" data3\" : {}, \" encryptedData3\" : {}," +
243243 " \" data4\" : { \" object\" : {} }, \" encryptedData4\" : { \" object\" : {} }}" ;
244- FieldLevelEncryptionConfig config = getFieldLevelEncryptionConfigBuilder ()
244+ FieldLevelEncryptionConfig config = getTestFieldLevelEncryptionConfigBuilder ()
245245 .withEncryptionPath ("$.data1" , "$.encryptedData1" )
246246 .withEncryptionPath ("data2" , "encryptedData2" )
247247 .withEncryptionPath ("$['data3']" , "$['encryptedData3']" )
@@ -269,7 +269,7 @@ public void testEncryptPayload_ShouldSupportBasicNotExistingJsonPaths() throws E
269269 // GIVEN
270270 String payload = "{\" data1\" : {}, \" data2\" : {}, \" data3\" : {}, " +
271271 " \" data4\" : { \" object\" : {} }, \" encryptedData4\" : {}}" ;
272- FieldLevelEncryptionConfig config = getFieldLevelEncryptionConfigBuilder ()
272+ FieldLevelEncryptionConfig config = getTestFieldLevelEncryptionConfigBuilder ()
273273 .withEncryptionPath ("$.data1" , "$.encryptedData1" )
274274 .withEncryptionPath ("data2" , "encryptedData2" )
275275 .withEncryptionPath ("$['data3']" , "$['encryptedData3']" )
@@ -302,7 +302,7 @@ public void testEncryptPayload_ShouldMergeJsonObjects_WhenOutPathAlreadyContainD
302302 " \" iv\" : \" previousIvValue\" " +
303303 " }" +
304304 "}" ;
305- FieldLevelEncryptionConfig config = getFieldLevelEncryptionConfigBuilder ()
305+ FieldLevelEncryptionConfig config = getTestFieldLevelEncryptionConfigBuilder ()
306306 .withEncryptionPath ("data" , "encryptedData" )
307307 .withOaepPaddingDigestAlgorithm ("SHA-256" )
308308 .build ();
@@ -327,7 +327,7 @@ public void testEncryptPayload_ShouldOverwriteInputObject_WhenOutPathSameAsInPat
327327 " \" encryptedData\" : {}" +
328328 " } " +
329329 "}" ;
330- FieldLevelEncryptionConfig config = getFieldLevelEncryptionConfigBuilder ()
330+ FieldLevelEncryptionConfig config = getTestFieldLevelEncryptionConfigBuilder ()
331331 .withEncryptionPath ("data.encryptedData" , "data" )
332332 .withEncryptedValueFieldName ("encryptedData" )
333333 .withOaepPaddingDigestAlgorithm ("SHA-256" )
@@ -348,7 +348,7 @@ public void testEncryptPayload_ShouldNotAddOaepPaddingDigestAlgorithm_WhenOaepPa
348348
349349 // GIVEN
350350 String payload = "{\" data\" : {}, \" encryptedData\" : {}}" ;
351- FieldLevelEncryptionConfig config = getFieldLevelEncryptionConfigBuilder ()
351+ FieldLevelEncryptionConfig config = getTestFieldLevelEncryptionConfigBuilder ()
352352 .withEncryptionPath ("data" , "encryptedData" )
353353 .withOaepPaddingDigestAlgorithm ("SHA-256" )
354354 .withOaepPaddingDigestAlgorithmFieldName (null )
@@ -369,7 +369,7 @@ public void testEncryptPayload_ShouldThrowEncryptionException_WhenInvalidCertifi
369369
370370 // GIVEN
371371 String payload = "{\" data\" : {}, \" encryptedData\" : {}}" ;
372- FieldLevelEncryptionConfig config = getFieldLevelEncryptionConfigBuilder ()
372+ FieldLevelEncryptionConfig config = getTestFieldLevelEncryptionConfigBuilder ()
373373 .withEncryptionPath ("data" , "encryptedData" )
374374 .withEncryptionCertificate (new X509CertImpl ())
375375 .withOaepPaddingDigestAlgorithm ("SHA-256" )
@@ -398,7 +398,7 @@ public void testDecryptPayload_Nominal() throws Exception {
398398 " \" oaepHashingAlgorithm\" : \" SHA256\" " +
399399 " }" +
400400 "}" ;
401- FieldLevelEncryptionConfig config = getFieldLevelEncryptionConfigBuilder ()
401+ FieldLevelEncryptionConfig config = getTestFieldLevelEncryptionConfigBuilder ()
402402 .withDecryptionPath ("encryptedData" , "data" )
403403 .withOaepPaddingDigestAlgorithm ("SHA-256" )
404404 .build ();
@@ -424,7 +424,7 @@ public void testDecryptPayload_ShouldDecryptPrimitiveTypes() throws Exception {
424424 " \" oaepHashingAlgorithm\" : \" SHA256\" " +
425425 " }" +
426426 "}" ;
427- FieldLevelEncryptionConfig config = getFieldLevelEncryptionConfigBuilder ()
427+ FieldLevelEncryptionConfig config = getTestFieldLevelEncryptionConfigBuilder ()
428428 .withDecryptionPath ("encryptedData" , "data" )
429429 .withOaepPaddingDigestAlgorithm ("SHA-256" )
430430 .build ();
@@ -452,7 +452,7 @@ public void testDecryptPayload_ShouldSupportBase64FieldValueDecoding() throws Ex
452452 " \" oaepHashingAlgorithm\" : \" SHA256\" " +
453453 " }" +
454454 "}" ;
455- FieldLevelEncryptionConfig config = getFieldLevelEncryptionConfigBuilder ()
455+ FieldLevelEncryptionConfig config = getTestFieldLevelEncryptionConfigBuilder ()
456456 .withDecryptionPath ("encryptedData" , "data" )
457457 .withOaepPaddingDigestAlgorithm ("SHA-256" )
458458 .withFieldValueEncoding (FieldValueEncoding .BASE64 )
@@ -472,7 +472,7 @@ public void testDecryptPayload_ShouldDoNothing_WhenInPathDoesNotExistInPayload()
472472
473473 // GIVEN
474474 String encryptedPayload = "{\" data\" : {}}" ;
475- FieldLevelEncryptionConfig config = getFieldLevelEncryptionConfigBuilder ()
475+ FieldLevelEncryptionConfig config = getTestFieldLevelEncryptionConfigBuilder ()
476476 .withDecryptionPath ("objectNotInPayload" , "data" )
477477 .build ();
478478
@@ -496,7 +496,7 @@ public void testDecryptPayload_ShouldCreateDataFields_WhenOutPathParentExistsInP
496496 " }, " +
497497 " \" dataParent\" : {}" +
498498 "}" ;
499- FieldLevelEncryptionConfig config = getFieldLevelEncryptionConfigBuilder ()
499+ FieldLevelEncryptionConfig config = getTestFieldLevelEncryptionConfigBuilder ()
500500 .withDecryptionPath ("encryptedData" , "dataParent.data" )
501501 .withOaepPaddingDigestAlgorithm ("SHA-256" )
502502 .build ();
@@ -522,7 +522,7 @@ public void testDecryptPayload_ShouldThrowIllegalArgumentException_WhenOutPathPa
522522 " \" oaepHashingAlgorithm\" : \" SHA256\" " +
523523 " }" +
524524 "}" ;
525- FieldLevelEncryptionConfig config = getFieldLevelEncryptionConfigBuilder ()
525+ FieldLevelEncryptionConfig config = getTestFieldLevelEncryptionConfigBuilder ()
526526 .withDecryptionPath ("encryptedData" , "parentNotInPayload.data" )
527527 .build ();
528528
@@ -547,7 +547,7 @@ public void testDecryptPayload_ShouldThrowIllegalArgumentException_WhenOutPathIs
547547 " }, " +
548548 " \" data\" : \" string\" " +
549549 "}" ;
550- FieldLevelEncryptionConfig config = getFieldLevelEncryptionConfigBuilder ()
550+ FieldLevelEncryptionConfig config = getTestFieldLevelEncryptionConfigBuilder ()
551551 .withDecryptionPath ("encryptedData" , "data" )
552552 .build ();
553553
@@ -564,7 +564,7 @@ public void testDecryptPayload_ShouldThrowIllegalArgumentException_WhenInPathIsP
564564
565565 // GIVEN
566566 String encryptedPayload = "{ \" encryptedData\" : \" string\" }" ;
567- FieldLevelEncryptionConfig config = getFieldLevelEncryptionConfigBuilder ()
567+ FieldLevelEncryptionConfig config = getTestFieldLevelEncryptionConfigBuilder ()
568568 .withDecryptionPath ("encryptedData" , "data" )
569569 .build ();
570570
@@ -587,7 +587,7 @@ public void testDecryptPayload_ShouldUseOaepDigestAlgorithmFromConfig_WhenOaepDi
587587 " \" encryptedValue\" : \" 2867e67545b2f3d0708500a1cea649e3\" " +
588588 " }" +
589589 "}" ;
590- FieldLevelEncryptionConfig config = getFieldLevelEncryptionConfigBuilder ()
590+ FieldLevelEncryptionConfig config = getTestFieldLevelEncryptionConfigBuilder ()
591591 .withDecryptionPath ("encryptedData" , "data" )
592592 .build ();
593593
@@ -616,7 +616,7 @@ public void testDecryptPayload_ShouldSupportMultipleDecryptions() throws Excepti
616616 " \" encryptedValue\" : \" 1ea73031bc0cf9c67b61bc1684d78f2b\" " +
617617 " }" +
618618 "}" ;
619- FieldLevelEncryptionConfig config = getFieldLevelEncryptionConfigBuilder ()
619+ FieldLevelEncryptionConfig config = getTestFieldLevelEncryptionConfigBuilder ()
620620 .withDecryptionPath ("encryptedData1" , "data1" )
621621 .withDecryptionPath ("encryptedData2" , "data2" )
622622 .build ();
@@ -649,7 +649,7 @@ public void testDecryptPayload_ShouldMergeJsonObjects_WhenOutPathAlreadyContainD
649649 " }" +
650650 "}" ;
651651
652- FieldLevelEncryptionConfig config = getFieldLevelEncryptionConfigBuilder ()
652+ FieldLevelEncryptionConfig config = getTestFieldLevelEncryptionConfigBuilder ()
653653 .withDecryptionPath ("encryptedData" , "data" )
654654 .build ();
655655
@@ -675,7 +675,7 @@ public void testDecryptPayload_ShouldKeepInputObject_WhenContainsAdditionalField
675675 " \" field\" : \" fieldValue\" " +
676676 " }" +
677677 "}" ;
678- FieldLevelEncryptionConfig config = getFieldLevelEncryptionConfigBuilder ()
678+ FieldLevelEncryptionConfig config = getTestFieldLevelEncryptionConfigBuilder ()
679679 .withDecryptionPath ("encryptedData" , "data" )
680680 .withOaepPaddingDigestAlgorithm ("SHA-256" )
681681 .build ();
@@ -700,7 +700,7 @@ public void testDecryptPayload_ShouldOverwriteInputObject_WhenOutPathSameAsInPat
700700 " \" oaepHashingAlgorithm\" : \" SHA256\" " +
701701 " } " +
702702 "}" ;
703- FieldLevelEncryptionConfig config = getFieldLevelEncryptionConfigBuilder ()
703+ FieldLevelEncryptionConfig config = getTestFieldLevelEncryptionConfigBuilder ()
704704 .withDecryptionPath ("encryptedData" , "encryptedData" )
705705 .withOaepPaddingDigestAlgorithm ("SHA-256" )
706706 .build ();
@@ -725,7 +725,7 @@ public void testDecryptPayload_ShouldThrowEncryptionException_WhenWrongDecryptio
725725 " \" encryptedValue\" : \" 2867e67545b2f3d0708500a1cea649e3\" " +
726726 " }" +
727727 "}" ;
728- FieldLevelEncryptionConfig config = getFieldLevelEncryptionConfigBuilder ()
728+ FieldLevelEncryptionConfig config = getTestFieldLevelEncryptionConfigBuilder ()
729729 .withDecryptionPath ("encryptedData" , "data" )
730730 .withOaepPaddingDigestAlgorithm ("SHA-256" )
731731 .withDecryptionKey (loadDecryptionKey ("./src/test/resources/test_key_container.p12" , "mykeyalias" , "Password1" ))
0 commit comments