{Core} Copy login credential when run test with --live and random_config_dir is enabled #26475
{Core} Copy login credential when run test with --live and random_config_dir is enabled #26475
--live and random_config_dir is enabled #26475Conversation
️✔️AzureCLI-FullTest
|
️✔️AzureCLI-BreakingChangeTest
|
|
Core |
random_config_dir when record testrandom_config_dir when recording test
| self.use_random_config_dir = True | ||
| else: | ||
| config_dir = GLOBAL_CONFIG_DIR | ||
| self.use_random_config_dir = False |
There was a problem hiding this comment.
Won't this trigger failure when executed concurrently in live mode?
There was a problem hiding this comment.
That's a valid point. I need to copy login credentials then.
random_config_dir when recording test--live and random_config_dir is enabled
| if os.path.exists(GLOBAL_CONFIG_DIR): | ||
| ensure_dir(config_dir) | ||
| import shutil | ||
| for file in ['azureProfile.json', 'msal_token_cache.bin', 'clouds.config']: |
There was a problem hiding this comment.
@jiasli Are these files requires as login credential?
There was a problem hiding this comment.
Service principal credentials are saved as service_principal_entries.bin:
If token encryption is disabled, .json is used as the file extension:
msal_token_cache.jsonservice_principal_entries.json
| except FileNotFoundError: | ||
| pass |
There was a problem hiding this comment.
I am not very familiar with the knowledge in the auth field, may I ask why do we pass for the FileNotFoundError?
There was a problem hiding this comment.
If the user is not logged in yet, these files do not exist in ~/.azure. Skip copying them.
Description
As mentioned in #26273 (comment), the login info can't be retrieved in recording mode when enable
random_config_dir,This PR copies the login credential from
~/.azureto random config dir.Related PR: #25689
Testing Guide
azdev test test_tag_update_by_patch --liveBefore:
FAILED src\azure-cli\azure\cli\command_modules\resource\tests\latest\test_resource.py::TagScenarioTest::test_tag_update_by_patch - knack.util.CLIError: Please run 'az login' to setup account.After:
Message: The client 'xxx' with object id 'xxx' does not have authorization to perform action 'Microsoft.Resources/subscriptions/resourcegroups/write' over scope '/subscriptions/axx' or the scope is invalid. If access was recently granted, please refresh your credentials.So it can read the token.
This checklist is used to make sure that common guidelines for a pull request are followed.
The PR title and description has followed the guideline in Submitting Pull Requests.
I adhere to the Command Guidelines.
I adhere to the Error Handling Guidelines.