11<?php
22namespace Mastercard \Developer \Utils ;
33
4+ use InvalidArgumentException ;
5+ use Mastercard \Developer \Encryption \EncryptionException ;
46use Mastercard \Developer \Encryption \FieldLevelEncryptionConfigBuilder ;
57use Mastercard \Developer \Encryption \FieldValueEncoding ;
68use Mastercard \Developer \Test \TestUtils ;
@@ -63,8 +65,17 @@ public function testBuild_ShouldComputeCertificateAndKeyFingerprints_WhenFingerp
6365 $ this ->assertEquals ('80810fc13a8319fcf0e2ec322c82a4c304b782cc3ce671176343cfe8160c2279 ' , $ config ->getEncryptionCertificateFingerprint ());
6466 }
6567
68+ public function testBuild_ShouldThrowEncryptionException_WhenFingerprintCanNotBeCalculated () {
69+ $ this ->expectException (EncryptionException::class);
70+ $ this ->expectExceptionMessage ('Failed to compute encryption certificate fingerprint! ' );
71+ TestUtils::getTestFieldLevelEncryptionConfigBuilder ()
72+ ->withEncryptionCertificateFingerprint (null )
73+ ->withEncryptionCertificate ('not a certificate ' )
74+ ->build ();
75+ }
76+
6677 public function testBuild_ShouldThrowInvalidArgumentException_WhenNotDefiniteDecryptionPath () {
67- $ this ->expectException (\ InvalidArgumentException::class);
78+ $ this ->expectException (InvalidArgumentException::class);
6879 $ this ->expectExceptionMessage ('JSON paths for decryption must point to a single item! ' );
6980 FieldLevelEncryptionConfigBuilder::aFieldLevelEncryptionConfig ()
7081 ->withDecryptionPath ('$.encryptedPayloads[*] ' , '$.payload ' )
@@ -73,7 +84,7 @@ public function testBuild_ShouldThrowInvalidArgumentException_WhenNotDefiniteDec
7384 }
7485
7586 public function testBuild_ShouldThrowInvalidArgumentException_WhenMissingDecryptionKey () {
76- $ this ->expectException (\ InvalidArgumentException::class);
87+ $ this ->expectException (InvalidArgumentException::class);
7788 $ this ->expectExceptionMessage ('Can \'t decrypt without decryption key! ' );
7889 FieldLevelEncryptionConfigBuilder::aFieldLevelEncryptionConfig ()
7990 ->withDecryptionPath ('$.encryptedPayload ' , '$.payload ' )
@@ -86,7 +97,7 @@ public function testBuild_ShouldThrowInvalidArgumentException_WhenMissingDecrypt
8697 }
8798
8899 public function testBuild_ShouldThrowInvalidArgumentException_WhenNotDefiniteEncryptionPath () {
89- $ this ->expectException (\ InvalidArgumentException::class);
100+ $ this ->expectException (InvalidArgumentException::class);
90101 $ this ->expectExceptionMessage ('JSON paths for encryption must point to a single item! ' );
91102 FieldLevelEncryptionConfigBuilder::aFieldLevelEncryptionConfig ()
92103 ->withEncryptionPath ('$.payloads[*] ' , '$.encryptedPayload ' )
@@ -95,7 +106,7 @@ public function testBuild_ShouldThrowInvalidArgumentException_WhenNotDefiniteEnc
95106 }
96107
97108 public function testBuild_ShouldThrowInvalidArgumentException_WhenMissingEncryptionCertificate () {
98- $ this ->expectException (\ InvalidArgumentException::class);
109+ $ this ->expectException (InvalidArgumentException::class);
99110 $ this ->expectExceptionMessage ('Can \'t encrypt without encryption key! ' );
100111 FieldLevelEncryptionConfigBuilder::aFieldLevelEncryptionConfig ()
101112 ->withEncryptionPath ('$.payload ' , '$.encryptedPayload ' )
@@ -108,7 +119,7 @@ public function testBuild_ShouldThrowInvalidArgumentException_WhenMissingEncrypt
108119 }
109120
110121 public function testBuild_ShouldThrowInvalidArgumentException_WhenMissingOaepPaddingDigestAlgorithm () {
111- $ this ->expectException (\ InvalidArgumentException::class);
122+ $ this ->expectException (InvalidArgumentException::class);
112123 $ this ->expectExceptionMessage ('The digest algorithm for OAEP cannot be empty! ' );
113124 FieldLevelEncryptionConfigBuilder::aFieldLevelEncryptionConfig ()
114125 ->withEncryptedValueFieldName ('encryptedValue ' )
@@ -119,15 +130,15 @@ public function testBuild_ShouldThrowInvalidArgumentException_WhenMissingOaepPad
119130 }
120131
121132 public function testBuild_ShouldThrowInvalidArgumentException_WhenUnsupportedOaepPaddingDigestAlgorithm () {
122- $ this ->expectException (\ InvalidArgumentException::class);
133+ $ this ->expectException (InvalidArgumentException::class);
123134 $ this ->expectExceptionMessage ('Unsupported OAEP digest algorithm: SHA-720! ' );
124135 FieldLevelEncryptionConfigBuilder::aFieldLevelEncryptionConfig ()
125136 ->withOaepPaddingDigestAlgorithm ('SHA-720 ' )
126137 ->build ();
127138 }
128139
129140 public function testBuild_ShouldThrowInvalidArgumentException_WhenMissingEncryptedValueFieldName () {
130- $ this ->expectException (\ InvalidArgumentException::class);
141+ $ this ->expectException (InvalidArgumentException::class);
131142 $ this ->expectExceptionMessage ('Encrypted value field name cannot be empty! ' );
132143 FieldLevelEncryptionConfigBuilder::aFieldLevelEncryptionConfig ()
133144 ->withOaepPaddingDigestAlgorithm ('SHA-512 ' )
@@ -138,7 +149,7 @@ public function testBuild_ShouldThrowInvalidArgumentException_WhenMissingEncrypt
138149 }
139150
140151 public function testBuild_ShouldThrowInvalidArgumentException_WhenMissingBothEncryptedKeyFieldNameAndHeaderName () {
141- $ this ->expectException (\ InvalidArgumentException::class);
152+ $ this ->expectException (InvalidArgumentException::class);
142153 $ this ->expectExceptionMessage ('At least one of encrypted key field name or encrypted key header name must be set! ' );
143154 FieldLevelEncryptionConfigBuilder::aFieldLevelEncryptionConfig ()
144155 ->withOaepPaddingDigestAlgorithm ('SHA-512 ' )
@@ -149,7 +160,7 @@ public function testBuild_ShouldThrowInvalidArgumentException_WhenMissingBothEnc
149160 }
150161
151162 public function testBuild_ShouldThrowInvalidArgumentException_WhenMissingBothIvFieldNameAndHeaderName () {
152- $ this ->expectException (\ InvalidArgumentException::class);
163+ $ this ->expectException (InvalidArgumentException::class);
153164 $ this ->expectExceptionMessage ('At least one of IV field name or IV header name must be set! ' );
154165 FieldLevelEncryptionConfigBuilder::aFieldLevelEncryptionConfig ()
155166 ->withOaepPaddingDigestAlgorithm ('SHA-512 ' )
@@ -160,7 +171,7 @@ public function testBuild_ShouldThrowInvalidArgumentException_WhenMissingBothIvF
160171 }
161172
162173 public function testBuild_ShouldThrowInvalidArgumentException_WhenMissingFieldValueEncoding () {
163- $ this ->expectException (\ InvalidArgumentException::class);
174+ $ this ->expectException (InvalidArgumentException::class);
164175 $ this ->expectExceptionMessage ('Value encoding for fields and headers cannot be empty! ' );
165176 FieldLevelEncryptionConfigBuilder::aFieldLevelEncryptionConfig ()
166177 ->withOaepPaddingDigestAlgorithm ('SHA-512 ' )
@@ -171,7 +182,7 @@ public function testBuild_ShouldThrowInvalidArgumentException_WhenMissingFieldVa
171182 }
172183
173184 public function testBuild_ShouldThrowInvalidArgumentException_WhenEncryptedKeyAndIvHeaderNamesNotBothSetOrUnset () {
174- $ this ->expectException (\ InvalidArgumentException::class);
185+ $ this ->expectException (InvalidArgumentException::class);
175186 $ this ->expectExceptionMessage ('IV header name and encrypted key header name must be both set or both unset! ' );
176187 FieldLevelEncryptionConfigBuilder::aFieldLevelEncryptionConfig ()
177188 ->withOaepPaddingDigestAlgorithm ('SHA-512 ' )
@@ -184,7 +195,7 @@ public function testBuild_ShouldThrowInvalidArgumentException_WhenEncryptedKeyAn
184195 }
185196
186197 public function testBuild_ShouldThrowInvalidArgumentException_WhenEncryptedKeyAndIvFieldNamesNotBothSetOrUnset () {
187- $ this ->expectException (\ InvalidArgumentException::class);
198+ $ this ->expectException (InvalidArgumentException::class);
188199 $ this ->expectExceptionMessage ('IV field name and encrypted key field name must be both set or both unset! ' );
189200 FieldLevelEncryptionConfigBuilder::aFieldLevelEncryptionConfig ()
190201 ->withOaepPaddingDigestAlgorithm ('SHA-512 ' )
@@ -195,4 +206,4 @@ public function testBuild_ShouldThrowInvalidArgumentException_WhenEncryptedKeyAn
195206 ->withFieldValueEncoding (FieldValueEncoding::HEX )
196207 ->build ();
197208 }
198- }
209+ }
0 commit comments