@@ -45,4 +45,37 @@ public function testBasicEncryptDecrypt(): void
4545 // assert that we are able to successfully decrypt our secret value
4646 $ this ->assertEquals ($ testValue , $ actualValue );
4747 }
48+
49+ /**
50+ * Test empty value encryption/decryption functionality in FileStorage class.
51+ */
52+ public function testEmptyValueEncryptDecrypt (): void
53+ {
54+ $ testKey = 'magento/myKey ' ;
55+ $ testValue = '' ;
56+ $ creds = ["$ testKey " ];
57+
58+ $ fileStorage = new FileStorage ();
59+ $ reflection = new ReflectionClass (FileStorage::class);
60+
61+ // Emulate initialize() function result with the test credentials
62+ $ reflectionMethod = $ reflection ->getMethod ('encryptCredFileContents ' );
63+ $ reflectionMethod ->setAccessible (true );
64+ $ secretData = $ reflectionMethod ->invokeArgs ($ fileStorage , [$ creds ]);
65+
66+ // Set encrypted test credentials to the private 'secretData' property
67+ $ reflectionProperty = $ reflection ->getProperty ('secretData ' );
68+ $ reflectionProperty ->setAccessible (true );
69+ $ reflectionProperty ->setValue ($ fileStorage , $ secretData );
70+
71+ $ encryptedCred = $ fileStorage ->getEncryptedValue ($ testKey );
72+
73+ // assert the value we've gotten is in fact not identical to our test value
74+ $ this ->assertNotEquals ($ testValue , $ encryptedCred );
75+
76+ $ actualValue = $ fileStorage ->getDecryptedValue ($ encryptedCred );
77+
78+ // assert that we are able to successfully decrypt our secret value
79+ $ this ->assertEquals ($ testValue , $ actualValue );
80+ }
4881}
0 commit comments