Return cached admin token before decrypting credentials#927
Open
lbajsarowicz wants to merge 1 commit into
Open
Return cached admin token before decrypting credentials#927lbajsarowicz wants to merge 1 commit into
lbajsarowicz wants to merge 1 commit into
Conversation
WebApiAuth::getAdminToken() decrypted the admin password via CredentialStore before checking the per-login token cache. Because a new executor authorizes on construction for every createData/deleteData/magentoCLI operation, this ran a needless decrypt on every fixture call even when the token was already cached. The cache key depends only on $login, which is known before decryption, so the cache check can safely run first. Adds a unit test asserting the cache hit path never invokes CredentialStore. Ref magento#925
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
WebApiAuth::getAdminToken()caches the admin bearer token per login inself::$adminAuthTokens(with a ~4h freshness check inhasExistingToken()). However,the method decrypts the admin password via
CredentialStorebefore it checks thatcache:
A new executor authorizes on construction for every
createData/deleteData/magentoCLIoperation, so this runs a credential decrypt on every fixture call even whenthe token is already cached and no decrypt is needed.
Fixed Issues
Part of #925
Fix
$loginis fully determined ($username ?? getenv(...)) before any decryption, and thecache key depends only on
$login. Move the cache check ahead of the decrypt so a cachehit short-circuits before touching
CredentialStore:The cache-miss path (decrypt, empty-credential validation, error messages, HTTP auth,
token storage) is byte-for-byte unchanged; only the position of the cache-check block
moves.
Security impact
CredentialStore.never more. What is decrypted, how it is stored, and the auth request payload are all
unchanged. No secret values are logged or added to any error context by this change.
boundary or to what is transmitted.
Manual testing scenarios
createData/deleteDatasteps sharing one admin login andconfirm fixtures still create/delete correctly (token reuse path).
credentials, still throws the existing
FastFailException.Unit test
Adds
WebApiAuthTestasserting the cache-hit path returns the cached token withoutinvoking
CredentialStoredecryption (mock configured withexpects($this->never())).Contribution checklist
develop