88namespace tests \unit \Magento \FunctionalTestFramework \DataGenerator \Handlers \SecretStorage ;
99
1010use Magento \FunctionalTestingFramework \DataGenerator \Handlers \SecretStorage \FileStorage ;
11+ use Magento \FunctionalTestingFramework \Exceptions \TestFrameworkException ;
1112use ReflectionClass ;
13+ use ReflectionException ;
1214use tests \unit \Util \MagentoTestCase ;
1315
1416class FileStorageTest extends MagentoTestCase
1517{
1618 /**
1719 * Test basic encryption/decryption functionality in FileStorage class.
20+ * @throws TestFrameworkException|ReflectionException
1821 */
1922 public function testBasicEncryptDecrypt (): void
2023 {
2124 $ testKey = 'magento/myKey ' ;
2225 $ testValue = 'myValue ' ;
23- $ creds = ["$ testKey= $ testValue " ];
26+ $ cred = ["$ testKey= $ testValue " ];
2427
2528 $ fileStorage = new FileStorage ();
2629 $ reflection = new ReflectionClass (FileStorage::class);
2730
2831 // Emulate initialize() function result with the test credentials
2932 $ reflectionMethod = $ reflection ->getMethod ('encryptCredFileContents ' );
3033 $ reflectionMethod ->setAccessible (true );
31- $ secretData = $ reflectionMethod ->invokeArgs ($ fileStorage , [$ creds ]);
34+ $ secretData = $ reflectionMethod ->invokeArgs ($ fileStorage , [$ cred ]);
3235
3336 // Set encrypted test credentials to the private 'secretData' property
3437 $ reflectionProperty = $ reflection ->getProperty ('secretData ' );
@@ -45,4 +48,32 @@ public function testBasicEncryptDecrypt(): void
4548 // assert that we are able to successfully decrypt our secret value
4649 $ this ->assertEquals ($ testValue , $ actualValue );
4750 }
51+
52+ /**
53+ * Test empty value encryption/decryption functionality in FileStorage class.
54+ * @return void
55+ * @throws TestFrameworkException|ReflectionException
56+ */
57+ public function testEmptyValueEncryptDecrypt (): void
58+ {
59+ $ this ->expectException (TestFrameworkException::class);
60+
61+ $ testKey = 'magento/myKey ' ;
62+ $ cred = ["$ testKey " ];
63+
64+ $ fileStorage = new FileStorage ();
65+ $ reflection = new ReflectionClass (FileStorage::class);
66+
67+ // Emulate initialize() function result with the test credentials
68+ $ reflectionMethod = $ reflection ->getMethod ('encryptCredFileContents ' );
69+ $ reflectionMethod ->setAccessible (true );
70+ $ secretData = $ reflectionMethod ->invokeArgs ($ fileStorage , [$ cred ]);
71+
72+ // Set encrypted test credentials to the private 'secretData' property
73+ $ reflectionProperty = $ reflection ->getProperty ('secretData ' );
74+ $ reflectionProperty ->setAccessible (true );
75+ $ reflectionProperty ->setValue ($ fileStorage , $ secretData );
76+
77+ $ fileStorage ->getEncryptedValue ($ testKey );
78+ }
4879}
0 commit comments