@@ -144,6 +144,41 @@ public function testEncryptWithExistingKeyEncryptedFieldName(): void
144144 self ::assertEquals (['id ' => 'foo ' , '!email ' => 'encrypted ' ], $ result );
145145 }
146146
147+ public function testEncryptSkipNullValueIfEncryptNullDisabled (): void
148+ {
149+ $ cipherKey = new CipherKey (
150+ 'foo ' ,
151+ 'bar ' ,
152+ 'baz ' ,
153+ );
154+
155+ $ cipherKeyStore = $ this ->createMock (CipherKeyStore::class);
156+ $ cipherKeyStore ->method ('get ' )->with ('foo ' )->willReturn ($ cipherKey );
157+ $ cipherKeyStore ->expects ($ this ->never ())->method ('store ' );
158+
159+ $ cipherKeyFactory = $ this ->createMock (CipherKeyFactory::class);
160+ $ cipherKeyFactory ->expects ($ this ->never ())->method ('__invoke ' );
161+
162+ $ cipher = $ this ->createMock (Cipher::class);
163+ $ cipher ->expects ($ this ->never ())->method ('encrypt ' );
164+
165+ $ cryptographer = new PersonalDataPayloadCryptographer (
166+ $ cipherKeyStore ,
167+ $ cipherKeyFactory ,
168+ $ cipher ,
169+ false ,
170+ false ,
171+ false ,
172+ );
173+
174+ $ result = $ cryptographer ->encrypt (
175+ $ this ->metadata (PersonalDataProfileCreated::class),
176+ ['id ' => 'foo ' , 'email ' => null ],
177+ );
178+
179+ self ::assertSame (['id ' => 'foo ' , 'email ' => null ], $ result );
180+ }
181+
147182 public function testSkipDecrypt (): void
148183 {
149184 $ cipherKeyStore = $ this ->createMock (CipherKeyStore::class);
@@ -373,6 +408,30 @@ public function testDecryptWithValidKeyAndEncryptedFieldNameAndFallbackFieldName
373408 self ::assertEquals (['id ' => 'foo ' , 'email ' => 'info@patchlevel.de ' ], $ result );
374409 }
375410
411+ public function testDecryptSkipNonStringValue (): void
412+ {
413+ $ cipherKeyStore = $ this ->createMock (CipherKeyStore::class);
414+ $ cipherKeyStore ->method ('get ' )->with ('foo ' )->willThrowException (new CipherKeyNotExists ('foo ' ));
415+
416+ $ cipherKeyFactory = $ this ->createMock (CipherKeyFactory::class);
417+ $ cipher = $ this ->createMock (Cipher::class);
418+ $ cipher ->expects ($ this ->never ())->method ('decrypt ' );
419+
420+ $ cryptographer = new PersonalDataPayloadCryptographer (
421+ $ cipherKeyStore ,
422+ $ cipherKeyFactory ,
423+ $ cipher ,
424+ );
425+
426+ $ email = new Email ('info@patchlevel.de ' );
427+ $ result = $ cryptographer ->decrypt (
428+ $ this ->metadata (PersonalDataProfileCreated::class),
429+ ['id ' => 'foo ' , 'email ' => $ email ],
430+ );
431+
432+ self ::assertSame (['id ' => 'foo ' , 'email ' => $ email ], $ result );
433+ }
434+
376435 public function testUnsupportedSubjectId (): void
377436 {
378437 $ this ->expectException (UnsupportedSubjectId::class);
0 commit comments