88
99class FieldLevelEncryptionConfigBuilderTest extends TestCase {
1010
11+ public function testBuild_Nominal () {
12+ $ config = FieldLevelEncryptionConfigBuilder::aFieldLevelEncryptionConfig ()
13+ ->withEncryptionPath ('$.payload ' , '$.encryptedPayload ' )
14+ ->withEncryptionCertificate (TestUtils::getTestEncryptionCertificate ())
15+ ->withEncryptionCertificateFingerprint ('97A2FFE9F0D48960EF31E87FCD7A55BF7843FB4A9EEEF01BDB6032AD6FEF146B ' )
16+ ->withEncryptionKeyFingerprint ('F806B26BC4870E26986C70B6590AF87BAF4C2B56BB50622C51B12212DAFF2810 ' )
17+ ->withEncryptionCertificateFingerprintFieldName ('publicCertificateFingerprint ' )
18+ ->withEncryptionCertificateFingerprintHeaderName ('x-public-certificate-fingerprint ' )
19+ ->withEncryptionKeyFingerprintFieldName ('publicKeyFingerprint ' )
20+ ->withEncryptionKeyFingerprintHeaderName ('x-public-key-fingerprint ' )
21+ ->withDecryptionPath ('$.encryptedPayload ' , '$.payload ' )
22+ ->withDecryptionKey (TestUtils::getTestDecryptionKey ())
23+ ->withOaepPaddingDigestAlgorithm ('SHA-512 ' )
24+ ->withOaepPaddingDigestAlgorithmFieldName ('oaepPaddingDigestAlgorithm ' )
25+ ->withOaepPaddingDigestAlgorithmHeaderName ('x-oaep-padding-digest-algorithm ' )
26+ ->withEncryptedValueFieldName ('encryptedValue ' )
27+ ->withEncryptedKeyFieldName ('encryptedKey ' )
28+ ->withEncryptedKeyHeaderName ('x-encrypted-key ' )
29+ ->withIvFieldName ('iv ' )
30+ ->withIvHeaderName ('x-iv ' )
31+ ->withFieldValueEncoding (FieldValueEncoding::BASE64 )
32+ ->build ();
33+ $ this ->assertNotEmpty ($ config );
34+ $ this ->assertEquals (1 , sizeof ($ config ->encryptionPaths ));
35+ $ this ->assertNotEmpty ($ config ->encryptionCertificate );
36+ $ this ->assertEquals ('97A2FFE9F0D48960EF31E87FCD7A55BF7843FB4A9EEEF01BDB6032AD6FEF146B ' , $ config ->encryptionCertificateFingerprint );
37+ $ this ->assertEquals ('F806B26BC4870E26986C70B6590AF87BAF4C2B56BB50622C51B12212DAFF2810 ' , $ config ->encryptionKeyFingerprint );
38+ $ this ->assertEquals ('publicCertificateFingerprint ' , $ config ->encryptionCertificateFingerprintFieldName );
39+ $ this ->assertEquals ('x-public-certificate-fingerprint ' , $ config ->encryptionCertificateFingerprintHeaderName );
40+ $ this ->assertEquals ('publicKeyFingerprint ' , $ config ->encryptionKeyFingerprintFieldName );
41+ $ this ->assertEquals ('x-public-key-fingerprint ' , $ config ->encryptionKeyFingerprintHeaderName );
42+ $ this ->assertEquals (1 , sizeof ($ config ->decryptionPaths ));
43+ $ this ->assertNotEmpty ($ config ->decryptionKey );
44+ $ this ->assertEquals ('SHA-512 ' , $ config ->oaepPaddingDigestAlgorithm );
45+ $ this ->assertEquals ('encryptedValue ' , $ config ->encryptedValueFieldName );
46+ $ this ->assertEquals ('encryptedKey ' , $ config ->encryptedKeyFieldName );
47+ $ this ->assertEquals ('x-encrypted-key ' , $ config ->encryptedKeyHeaderName );
48+ $ this ->assertEquals ('iv ' , $ config ->ivFieldName );
49+ $ this ->assertEquals ('x-iv ' , $ config ->ivHeaderName );
50+ $ this ->assertEquals ('oaepPaddingDigestAlgorithm ' , $ config ->oaepPaddingDigestAlgorithmFieldName );
51+ $ this ->assertEquals ('x-oaep-padding-digest-algorithm ' , $ config ->oaepPaddingDigestAlgorithmHeaderName );
52+ $ this ->assertEquals (FieldValueEncoding::BASE64 , $ config ->fieldValueEncoding );
53+ }
54+
55+ public function testBuild_ShouldComputeCertificateAndKeyFingerprints_WhenFingerprintsNotSet () {
56+ $ config = TestUtils::getTestFieldLevelEncryptionConfigBuilder ()
57+ ->withEncryptionCertificateFingerprint (null )
58+ ->withEncryptionKeyFingerprint (null )
59+ ->withEncryptionCertificate (TestUtils::getTestEncryptionCertificate ())
60+ ->withDecryptionKey (TestUtils::getTestDecryptionKey ())
61+ ->build ();
62+ $ this ->assertEquals ('761b003c1eade3a5490e5000d37887baa5e6ec0e226c07706e599451fc032a79 ' , $ config ->encryptionKeyFingerprint );
63+ $ this ->assertEquals ('80810fc13a8319fcf0e2ec322c82a4c304b782cc3ce671176343cfe8160c2279 ' , $ config ->encryptionCertificateFingerprint );
64+ }
65+
1166 public function testBuild_ShouldThrowInvalidArgumentException_WhenNotDefiniteDecryptionPath () {
1267 $ this ->expectException (\InvalidArgumentException::class);
1368 $ this ->expectExceptionMessage ('JSON paths for decryption must point to a single item! ' );
@@ -140,48 +195,4 @@ public function testBuild_ShouldThrowInvalidArgumentException_WhenEncryptedKeyAn
140195 ->withFieldValueEncoding (FieldValueEncoding::HEX )
141196 ->build ();
142197 }
143-
144- public function testBuild_Nominal () {
145- $ config = FieldLevelEncryptionConfigBuilder::aFieldLevelEncryptionConfig ()
146- ->withEncryptionPath ('$.payload ' , '$.encryptedPayload ' )
147- ->withEncryptionCertificate (TestUtils::getTestEncryptionCertificate ())
148- ->withEncryptionCertificateFingerprint ('97A2FFE9F0D48960EF31E87FCD7A55BF7843FB4A9EEEF01BDB6032AD6FEF146B ' )
149- ->withEncryptionKeyFingerprint ('F806B26BC4870E26986C70B6590AF87BAF4C2B56BB50622C51B12212DAFF2810 ' )
150- ->withEncryptionCertificateFingerprintFieldName ('publicCertificateFingerprint ' )
151- ->withEncryptionCertificateFingerprintHeaderName ('x-public-certificate-fingerprint ' )
152- ->withEncryptionKeyFingerprintFieldName ('publicKeyFingerprint ' )
153- ->withEncryptionKeyFingerprintHeaderName ('x-public-key-fingerprint ' )
154- ->withDecryptionPath ('$.encryptedPayload ' , '$.payload ' )
155- ->withDecryptionKey (TestUtils::getTestDecryptionKey ())
156- ->withOaepPaddingDigestAlgorithm ('SHA-512 ' )
157- ->withOaepPaddingDigestAlgorithmFieldName ('oaepPaddingDigestAlgorithm ' )
158- ->withOaepPaddingDigestAlgorithmHeaderName ('x-oaep-padding-digest-algorithm ' )
159- ->withEncryptedValueFieldName ('encryptedValue ' )
160- ->withEncryptedKeyFieldName ('encryptedKey ' )
161- ->withEncryptedKeyHeaderName ('x-encrypted-key ' )
162- ->withIvFieldName ('iv ' )
163- ->withIvHeaderName ('x-iv ' )
164- ->withFieldValueEncoding (FieldValueEncoding::BASE64 )
165- ->build ();
166- $ this ->assertNotEmpty ($ config );
167- $ this ->assertEquals (1 , sizeof ($ config ->encryptionPaths ));
168- $ this ->assertNotEmpty ($ config ->encryptionCertificate );
169- $ this ->assertEquals ('97A2FFE9F0D48960EF31E87FCD7A55BF7843FB4A9EEEF01BDB6032AD6FEF146B ' , $ config ->encryptionCertificateFingerprint );
170- $ this ->assertEquals ('F806B26BC4870E26986C70B6590AF87BAF4C2B56BB50622C51B12212DAFF2810 ' , $ config ->encryptionKeyFingerprint );
171- $ this ->assertEquals ('publicCertificateFingerprint ' , $ config ->encryptionCertificateFingerprintFieldName );
172- $ this ->assertEquals ('x-public-certificate-fingerprint ' , $ config ->encryptionCertificateFingerprintHeaderName );
173- $ this ->assertEquals ('publicKeyFingerprint ' , $ config ->encryptionKeyFingerprintFieldName );
174- $ this ->assertEquals ('x-public-key-fingerprint ' , $ config ->encryptionKeyFingerprintHeaderName );
175- $ this ->assertEquals (1 , sizeof ($ config ->decryptionPaths ));
176- $ this ->assertNotEmpty ($ config ->decryptionKey );
177- $ this ->assertEquals ('SHA-512 ' , $ config ->oaepPaddingDigestAlgorithm );
178- $ this ->assertEquals ('encryptedValue ' , $ config ->encryptedValueFieldName );
179- $ this ->assertEquals ('encryptedKey ' , $ config ->encryptedKeyFieldName );
180- $ this ->assertEquals ('x-encrypted-key ' , $ config ->encryptedKeyHeaderName );
181- $ this ->assertEquals ('iv ' , $ config ->ivFieldName );
182- $ this ->assertEquals ('x-iv ' , $ config ->ivHeaderName );
183- $ this ->assertEquals ('oaepPaddingDigestAlgorithm ' , $ config ->oaepPaddingDigestAlgorithmFieldName );
184- $ this ->assertEquals ('x-oaep-padding-digest-algorithm ' , $ config ->oaepPaddingDigestAlgorithmHeaderName );
185- $ this ->assertEquals (FieldValueEncoding::BASE64 , $ config ->fieldValueEncoding );
186- }
187198}
0 commit comments