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