22
33namespace Lablnet \Tests ;
44
5- use SecurePassword \Encrypt \Adapter \{OpenSslEncryption , SodiumEncryption };
6- use SecurePassword \Encrypt \Encryption ;
75use PHPUnit \Framework \TestCase ;
6+ use SecurePassword \Encrypt \Encryption ;
7+ use SecurePassword \Encrypt \Adapter \{OpenSslEncryption , SodiumEncryption };
88
99class EncryptionTest extends TestCase
1010{
@@ -32,15 +32,13 @@ public function testEncryptAndDecryptWithOpenSsl()
3232
3333 public function testEncryptAndDecryptWithSodium ()
3434 {
35- if (extension_loaded ('sodium ' )) {
36- $ encryption = new Encryption (new SodiumEncryption ('euyq74tjfdskjFDSGq74 ' ));
37- $ encryptedString = $ encryption ->encrypt ('plain-text ' );
38- $ decryptedString = $ encryption ->decrypt ($ encryptedString );
39-
40- $ this ->assertStringEndsNotWith ('== ' , $ encryptedString );
41- $ this ->assertSame (112 , strlen ($ encryptedString ));
42- $ this ->assertSame ('plain-text ' , $ decryptedString );
43- }
35+ $ encryption = new Encryption (new SodiumEncryption ('euyq74tjfdskjFDSGq74 ' ));
36+ $ encryptedString = $ encryption ->encrypt ('plain-text ' );
37+ $ decryptedString = $ encryption ->decrypt ($ encryptedString );
38+
39+ $ this ->assertStringEndsNotWith ('== ' , $ encryptedString );
40+ $ this ->assertSame (112 , strlen ($ encryptedString ));
41+ $ this ->assertSame ('plain-text ' , $ decryptedString );
4442 }
4543
4644 public function testOpenSslEncrpytionEncryptOnEmptyStringKey ()
@@ -51,9 +49,18 @@ public function testOpenSslEncrpytionEncryptOnEmptyStringKey()
5149
5250 public function testSodiumEncrpytionEncryptOnEmptyStringKey ()
5351 {
54- if (extension_loaded ('sodium ' )) {
55- $ this ->expectException (\InvalidArgumentException::class);
56- new Encryption (new SodiumEncryption ('' ));
57- }
52+ $ this ->expectException (\InvalidArgumentException::class);
53+ new Encryption (new SodiumEncryption ('' ));
54+ }
55+
56+ public function testDecryptWithNoHash ()
57+ {
58+ $ encryption1 = new Encryption (new OpenSslEncryption ('12345678990-=====-=== ' ));
59+ $ decryptedString1 = $ encryption1 ->decrypt ("wrong-hash " );
60+ $ this ->assertFalse ($ decryptedString1 );
61+
62+ $ encryption2 = new Encryption (new SodiumEncryption ('12345678990-=====-=== ' ));
63+ $ decryptedString2 = $ encryption2 ->decrypt ("wrong-hash " );
64+ $ this ->assertFalse ($ decryptedString2 );
5865 }
5966}
0 commit comments