-
Notifications
You must be signed in to change notification settings - Fork 3.3k
{Core} Copy login credential when run test with --live and random_config_dir is enabled
#26475
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
️✔️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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't this trigger failure when executed concurrently in live mode?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jiasli Are these files requires as login credential?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Service principal credentials are saved as service_principal_entries.bin:
| self._secret_file = os.path.join(config_dir, "service_principal_entries") |
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.