@@ -77,7 +77,7 @@ public function testEncryptWithMissingKey(): void
7777
7878 $ result = $ cryptographer ->encrypt ($ this ->metadata (PersonalDataProfileCreated::class), ['id ' => 'foo ' , 'email ' => 'info@patchlevel.de ' ]);
7979
80- self ::assertEquals (['id ' => 'foo ' , 'email ' => 'encrypted ' ], $ result );
80+ self ::assertEquals (['id ' => 'foo ' , '! email ' => 'encrypted ' ], $ result );
8181 }
8282
8383 public function testEncryptWithExistingKey (): void
@@ -109,7 +109,7 @@ public function testEncryptWithExistingKey(): void
109109
110110 $ result = $ cryptographer ->encrypt ($ this ->metadata (PersonalDataProfileCreated::class), ['id ' => 'foo ' , 'email ' => 'info@patchlevel.de ' ]);
111111
112- self ::assertEquals (['id ' => 'foo ' , 'email ' => 'encrypted ' ], $ result );
112+ self ::assertEquals (['id ' => 'foo ' , '! email ' => 'encrypted ' ], $ result );
113113 }
114114
115115 public function testSkipDecrypt (): void
@@ -148,9 +148,10 @@ public function testDecryptWithMissingKey(): void
148148 $ cipherKeyStore ->reveal (),
149149 $ cipherKeyFactory ->reveal (),
150150 $ cipher ->reveal (),
151+ false ,
151152 );
152153
153- $ result = $ cryptographer ->decrypt ($ this ->metadata (PersonalDataProfileCreated::class), ['id ' => 'foo ' , 'email ' => 'encrypted ' ]);
154+ $ result = $ cryptographer ->decrypt ($ this ->metadata (PersonalDataProfileCreated::class), ['id ' => 'foo ' , '! email ' => 'encrypted ' ]);
154155
155156 self ::assertEquals (['id ' => 'foo ' , 'email ' => new Email ('unknown ' )], $ result );
156157 }
@@ -180,9 +181,10 @@ public function testDecryptWithInvalidKey(): void
180181 $ cipherKeyStore ->reveal (),
181182 $ cipherKeyFactory ->reveal (),
182183 $ cipher ->reveal (),
184+ false ,
183185 );
184186
185- $ result = $ cryptographer ->decrypt ($ this ->metadata (PersonalDataProfileCreated::class), ['id ' => 'foo ' , 'email ' => 'encrypted ' ]);
187+ $ result = $ cryptographer ->decrypt ($ this ->metadata (PersonalDataProfileCreated::class), ['id ' => 'foo ' , '! email ' => 'encrypted ' ]);
186188
187189 self ::assertEquals (['id ' => 'foo ' , 'email ' => new Email ('unknown ' )], $ result );
188190 }
@@ -202,6 +204,68 @@ public function testDecryptWithExistingKey(): void
202204 $ cipherKeyFactory = $ this ->prophesize (CipherKeyFactory::class);
203205 $ cipherKeyFactory ->__invoke ()->shouldNotBeCalled ();
204206
207+ $ cipher = $ this ->prophesize (Cipher::class);
208+ $ cipher
209+ ->decrypt ($ cipherKey , 'encrypted ' )
210+ ->willReturn ('info@patchlevel.de ' )
211+ ->shouldBeCalledOnce ();
212+
213+ $ cryptographer = new PersonalDataPayloadCryptographer (
214+ $ cipherKeyStore ->reveal (),
215+ $ cipherKeyFactory ->reveal (),
216+ $ cipher ->reveal (),
217+ false ,
218+ );
219+
220+ $ result = $ cryptographer ->decrypt ($ this ->metadata (PersonalDataProfileCreated::class), ['id ' => 'foo ' , '!email ' => 'encrypted ' ]);
221+
222+ self ::assertEquals (['id ' => 'foo ' , 'email ' => 'info@patchlevel.de ' ], $ result );
223+ }
224+
225+ public function testDecryptWithoutPrefixField (): void
226+ {
227+ $ cipherKey = new CipherKey (
228+ 'foo ' ,
229+ 'bar ' ,
230+ 'baz ' ,
231+ );
232+
233+ $ cipherKeyStore = $ this ->prophesize (CipherKeyStore::class);
234+ $ cipherKeyStore ->get ('foo ' )->willReturn ($ cipherKey );
235+ $ cipherKeyStore ->store ('foo ' , Argument::type (CipherKey::class))->shouldNotBeCalled ();
236+
237+ $ cipherKeyFactory = $ this ->prophesize (CipherKeyFactory::class);
238+ $ cipherKeyFactory ->__invoke ()->shouldNotBeCalled ();
239+
240+ $ cipher = $ this ->prophesize (Cipher::class);
241+
242+ $ cryptographer = new PersonalDataPayloadCryptographer (
243+ $ cipherKeyStore ->reveal (),
244+ $ cipherKeyFactory ->reveal (),
245+ $ cipher ->reveal (),
246+ false ,
247+ );
248+
249+ $ result = $ cryptographer ->decrypt ($ this ->metadata (PersonalDataProfileCreated::class), ['id ' => 'foo ' , 'email ' => 'info@patchlevel.de ' ]);
250+
251+ self ::assertEquals (['id ' => 'foo ' , 'email ' => 'info@patchlevel.de ' ], $ result );
252+ }
253+
254+ public function testDecryptWithFallbackWithoutPrefix (): void
255+ {
256+ $ cipherKey = new CipherKey (
257+ 'foo ' ,
258+ 'bar ' ,
259+ 'baz ' ,
260+ );
261+
262+ $ cipherKeyStore = $ this ->prophesize (CipherKeyStore::class);
263+ $ cipherKeyStore ->get ('foo ' )->willReturn ($ cipherKey );
264+ $ cipherKeyStore ->store ('foo ' , Argument::type (CipherKey::class))->shouldNotBeCalled ();
265+
266+ $ cipherKeyFactory = $ this ->prophesize (CipherKeyFactory::class);
267+ $ cipherKeyFactory ->__invoke ()->shouldNotBeCalled ();
268+
205269 $ cipher = $ this ->prophesize (Cipher::class);
206270 $ cipher
207271 ->decrypt ($ cipherKey , 'encrypted ' )
0 commit comments