8
8
namespace tests \unit \Magento \FunctionalTestFramework \DataGenerator \Handlers \SecretStorage ;
9
9
10
10
use Magento \FunctionalTestingFramework \DataGenerator \Handlers \SecretStorage \FileStorage ;
11
+ use Magento \FunctionalTestingFramework \Exceptions \TestFrameworkException ;
11
12
use ReflectionClass ;
13
+ use ReflectionException ;
12
14
use tests \unit \Util \MagentoTestCase ;
13
15
14
16
class FileStorageTest extends MagentoTestCase
15
17
{
16
18
/**
17
19
* Test basic encryption/decryption functionality in FileStorage class.
20
+ * @throws TestFrameworkException|ReflectionException
18
21
*/
19
22
public function testBasicEncryptDecrypt (): void
20
23
{
21
24
$ testKey = 'magento/myKey ' ;
22
25
$ testValue = 'myValue ' ;
23
- $ creds = ["$ testKey= $ testValue " ];
26
+ $ cred = ["$ testKey= $ testValue " ];
24
27
25
28
$ fileStorage = new FileStorage ();
26
29
$ reflection = new ReflectionClass (FileStorage::class);
27
30
28
31
// Emulate initialize() function result with the test credentials
29
32
$ reflectionMethod = $ reflection ->getMethod ('encryptCredFileContents ' );
30
33
$ reflectionMethod ->setAccessible (true );
31
- $ secretData = $ reflectionMethod ->invokeArgs ($ fileStorage , [$ creds ]);
34
+ $ secretData = $ reflectionMethod ->invokeArgs ($ fileStorage , [$ cred ]);
32
35
33
36
// Set encrypted test credentials to the private 'secretData' property
34
37
$ reflectionProperty = $ reflection ->getProperty ('secretData ' );
@@ -45,4 +48,32 @@ public function testBasicEncryptDecrypt(): void
45
48
// assert that we are able to successfully decrypt our secret value
46
49
$ this ->assertEquals ($ testValue , $ actualValue );
47
50
}
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
+ }
48
79
}
0 commit comments