|
6 | 6 |
|
7 | 7 | namespace Magento\FunctionalTestingFramework\DataTransport\Auth; |
8 | 8 |
|
| 9 | +use Magento\FunctionalTestingFramework\DataGenerator\Handlers\CredentialStore; |
9 | 10 | use Magento\FunctionalTestingFramework\Exceptions\FastFailException; |
10 | 11 | use Magento\FunctionalTestingFramework\Util\MftfGlobals; |
11 | 12 | use Magento\FunctionalTestingFramework\DataTransport\Protocol\CurlInterface; |
@@ -53,18 +54,26 @@ class WebApiAuth |
53 | 54 | * @throws FastFailException |
54 | 55 | * |
55 | 56 | * @SuppressWarnings(PHPMD.CyclomaticComplexity) |
| 57 | + * @SuppressWarnings(PHPMD.NPathComplexity) |
56 | 58 | */ |
57 | 59 | public static function getAdminToken($username = null, $password = null) |
58 | 60 | { |
59 | 61 | $login = $username ?? getenv('MAGENTO_ADMIN_USERNAME'); |
60 | | - $password = $password ?? getenv('MAGENTO_ADMIN_PASSWORD'); |
| 62 | + try { |
| 63 | + $encryptedSecret = CredentialStore::getInstance()->getSecret('magento/MAGENTO_ADMIN_PASSWORD'); |
| 64 | + $secret = CredentialStore::getInstance()->decryptSecretValue($encryptedSecret); |
| 65 | + $password = $password ?? $secret; |
| 66 | + } catch (TestFrameworkException $e) { |
| 67 | + $message = "Password not found in credentials file"; |
| 68 | + throw new FastFailException($message . $e->getMessage(), $e->getContext()); |
| 69 | + } |
61 | 70 | if (!$login || !$password) { |
62 | 71 | $message = 'Cannot retrieve API token without credentials. Please fill out .env.'; |
63 | 72 | $context = [ |
64 | 73 | 'MAGENTO_BASE_URL' => getenv('MAGENTO_BASE_URL'), |
65 | 74 | 'MAGENTO_BACKEND_BASE_URL' => getenv('MAGENTO_BACKEND_BASE_URL'), |
66 | 75 | 'MAGENTO_ADMIN_USERNAME' => getenv('MAGENTO_ADMIN_USERNAME'), |
67 | | - 'MAGENTO_ADMIN_PASSWORD' => getenv('MAGENTO_ADMIN_PASSWORD'), |
| 76 | + 'MAGENTO_ADMIN_PASSWORD' => $secret, |
68 | 77 | ]; |
69 | 78 | throw new FastFailException($message, $context); |
70 | 79 | } |
|
0 commit comments