Skip to content

Commit

Permalink
[Identity] Resolve CredScan warnings (#20543)
Browse files Browse the repository at this point in the history
  • Loading branch information
mccoyp authored Sep 9, 2021
1 parent 853db90 commit 476acd5
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 33 deletions.
3 changes: 2 additions & 1 deletion eng/CredScanSuppression.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@
"eng/common/testproxy/dotnet-devcert.pfx",
"sdk/confidentialledger/azure-confidentialledger/tests/_shared/constants.py",
"sdk/keyvault/azure-keyvault-certificates/tests/ca.key",
"sdk/identity/azure-identity/tests/ec-certificate.pem",
"sdk/identity/azure-identity/tests/certificate.pfx",
"sdk/identity/azure-identity/tests/certificate-with-password.pfx",
"sdk/identity/azure-identity/tests/credscan_ignore.py",
"sdk/identity/azure-identity/tests/ec-certificate.pem",
"sdk/core/azure-servicemanagement-legacy/tests/legacy_mgmt_settings_fake.py",
"sdk/storage/azure-storage-blob/tests/fake_credentials.py",
"sdk/storage/azure-storage-file-datalake/tests/fake_credentials.py",
Expand Down
9 changes: 9 additions & 0 deletions sdk/identity/azure-identity/tests/credscan_ignore.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------

POWERSHELL_INVALID_OPERATION_EXCEPTION = """#< CLIXML
<Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"><Obj S="progress" RefId="0"><TN RefId="0"><T>System.Management.Automation.PSCustomObject</T><T>System.Object</T></TN><MS><I64 N="SourceId">1</I64><PR N="Record"><AV>Preparing modules for first use.</AV><AI>0</AI><Nil /><PI>-1</PI><PC>-1</PC><T>Completed</T><SR>-1</SR><SD> </SD></PR></MS></Obj><Obj S="progress" RefId="1"><TNRef RefId="0" /><MS><I64 N="SourceId">2</I64><PR N="Record"><AV>Preparing modules for first use.</AV><AI>0</AI><Nil /><PI>-1</PI><PC>-1</PC><T>Completed</T><SR>-1</SR><SD> </SD></PR></MS></Obj><S S="Error">Get-AzAccessToken : Run Connect-AzAccount to login._x000D__x000A_</S><S S="Error">At line:11 char:10_x000D__x000A_</S><S S="Error">+ $token = Get-AzAccessToken -ResourceUrl 'scope'_x000D__x000A_</S><S S="Error">+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~_x000D__x000A_</S><S S="Error"> + CategoryInfo : CloseError: (:) [Get-AzAccessToken], PSInvalidOperationException_x000D__x000A_</S><S S="Error"> + FullyQualifiedErrorId : Microsoft.Azure.Commands.Profile.GetAzureRmAccessTokenCommand_x000D__x000A_</S><S S="Error"> _x000D__x000A_</S></Objs>"""
POWERSHELL_NOT_LOGGED_IN_ERROR = """#< CLIXML
<Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"><S S="Error">_x001B_[91mGet-AzAccessToken: _x000D__x000A_</S><S S="Error">_x001B_[96mLine |_x000D__x000A_</S><S S="Error">_x001B_[96m 11 | _x001B_[0m $token = _x001B_[96mGet-AzAccessToken -ResourceUrl 'scope'_x001B_[0m_x000D__x000A_</S><S S="Error">_x001B_[96m | _x001B_[91m ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~_x000D__x000A_</S><S S="Error">_x001B_[91m_x001B_[96m | _x001B_[91mRun Connect-AzAccount to login._x001B_[0m_x000D__x000A_</S></Objs>"""
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ interactions:
uri: https://login.microsoftonline.com/tenant/oauth2/v2.0/devicecode
response:
body:
string: '{"user_code": "c934976f1393725db44d1d419b378baf00f383c5f3120eae059eb20bb86c08b0",
"device_code": "f942eaaebc9683c361e2038648fe4cf1ddb80d515ff47e10d48af420330eab5c",
string: '{"user_code": "redacted3c59ab",
"device_code": "redactedb9ef25",
"verification_uri": "https://microsoft.com/devicelogin", "expires_in": 900,
"interval": 5, "message": "524aa9e7bd498505c8f902c5fe65bd4679d45709259cb590e75f46c980c05aa9"}'
"interval": 5, "message": "redactedf09f37"}'
headers:
cache-control:
- no-store, no-cache
Expand Down Expand Up @@ -299,8 +299,8 @@ interactions:
body:
string: '{"token_type": "Bearer", "scope": "https://management.azure.com/user_impersonation
https://management.azure.com/.default", "expires_in": 86399, "ext_expires_in":
86399, "access_token": "27a75655adaa9cd9cd7e604a510829826acb0da287713872a9ea5658df01830f",
"refresh_token": "4c9049a37c3f1bdc3c662fb0749e887cf6c0a100f9899ef0d77029867bc9e98e",
86399, "access_token": "redactedca8839",
"refresh_token": "redacted7ef8cf",
"foci": "1", "id_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6Im5PbzNaRHJPRFhFSzFqS1doWHNsSFJfS1hFZyJ9.eyJhdWQiOiIwNGIwNzc5NS04ZGRiLTQ2MWEtYmJlZS0wMmY5ZTFiZjdiNDYiLCJpc3MiOiJodHRwczovL2xvZ2luLm1pY3Jvc29mdG9ubGluZS5jb20vNTQ4MjZiMjItMzhkNi00ZmIyLWJhZDktYjdiOTNhM2U5YzVhL3YyLjAiLCJpYXQiOjE2MTExNjQ2NTQsIm5iZiI6MTYxMTE2NDY1NCwiZXhwIjoxNjExMTY4NTU0LCJhaW8iOiJBVFFBeS84U0FBQUE4Zjl5WTlKeUFBRFQ5bEZkdlVKYU4ybk1NT3ROeGkwVlk1MWRUQUE0eFlWU3psdndwQ3NDNmdIcFRFSzB1MG1kIiwibmFtZSI6ImNobG93ZS10ZXN0Iiwib2lkIjoiYTcyOGM5MWEtNDdjOS00NTAyLWJhMDUtMzYwODQwODI2NjM2IiwicHJlZmVycmVkX3VzZXJuYW1lIjoiY2hsb3dlLXRlc3RAYXp1cmVzZGt0ZWFtLm9ubWljcm9zb2Z0LmNvbSIsInJoIjoiMC5BVGNBSW11Q1ZOWTRzay02MmJlNU9qNmNXcFYzc0FUYmpScEd1LTRDLWVHX2UwWTNBSkEuIiwic3ViIjoiSE5QcW9raHV6WUFmRlVlRkEtVm1rQ0M1Z253Mkp1b0xTSEtIZ2NDbkdHYyIsInRpZCI6IjU0ODI2YjIyLTM4ZDYtNGZiMi1iYWQ5LWI3YjkzYTNlOWM1YSIsInV0aSI6Ii10aTBqY1VrTjA2eHlxcTAzY0tFQVEiLCJ2ZXIiOiIyLjAifQ.cnsvmmnQzua0aZ96pXJOGq8hdgyUhy2DMTN2Yzjvs5TZCRd0voB0Ox_4VmjID3CFiixFOD58tn69pu5DkWEk8T3cBXMBecBRefdjEJcVuDeAQ_GnKZgVGVMjYHERcDxanukaknzs69an8nFASBJVHcLvaiRvy5UtJ4tJPpL1yM1XXwJd6EV4e2mqDt_5SgyWM_O2QPNtQF3IuozWRGrJ84ap2VN-zgkLrZRHeiE9XtNByQDfcwEXcxznx64lOXdJmUyfpxu8iiwChUzCa01PA-gM7UjTIBe_e71ALWdIj3fLmKp3HlquSDDV-eb9jTQrhtn7MtzONk6WbQTOahVMRA",
"client_info": "eyJ1aWQiOiJhNzI4YzkxYS00N2M5LTQ1MDItYmEwNS0zNjA4NDA4MjY2MzYiLCJ1dGlkIjoiNTQ4MjZiMjItMzhkNi00ZmIyLWJhZDktYjdiOTNhM2U5YzVhIn0"}'
headers:
Expand Down Expand Up @@ -579,10 +579,10 @@ interactions:
uri: https://login.microsoftonline.com/tenant/oauth2/v2.0/devicecode
response:
body:
string: '{"user_code": "37014a978b95ae6e752f54107987c3409b3cf801c3835261952f8740cb20d1c8",
"device_code": "428a20171292a6f89bedf5ef1b83a82a94f3196d1cdc914229be57fb5bdb6b1c",
string: '{"user_code": "redacted221497",
"device_code": "redacted486127",
"verification_uri": "https://microsoft.com/devicelogin", "expires_in": 900,
"interval": 5, "message": "a92bcf4b00e3e6e783399306f14035815428ee07c9e2a0c7920a27fbdb9a9b27"}'
"interval": 5, "message": "redactedb92935"}'
headers:
cache-control:
- no-store, no-cache
Expand Down Expand Up @@ -789,8 +789,8 @@ interactions:
body:
string: '{"token_type": "Bearer", "scope": "https://management.azure.com/user_impersonation
https://management.azure.com/.default", "expires_in": 86399, "ext_expires_in":
86399, "access_token": "4eae20b397129621daea0169160d06c2d3d6a26bcac8c6aed6d722f89952d41b",
"refresh_token": "5013d6d09c2f1ff82a870572f6066aecebea1137e8b1c731be5bf01ae0f67f24",
86399, "access_token": "redacteda22f90",
"refresh_token": "redacted0f5082",
"foci": "1", "id_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6Im5PbzNaRHJPRFhFSzFqS1doWHNsSFJfS1hFZyJ9.eyJhdWQiOiIwNGIwNzc5NS04ZGRiLTQ2MWEtYmJlZS0wMmY5ZTFiZjdiNDYiLCJpc3MiOiJodHRwczovL2xvZ2luLm1pY3Jvc29mdG9ubGluZS5jb20vNTQ4MjZiMjItMzhkNi00ZmIyLWJhZDktYjdiOTNhM2U5YzVhL3YyLjAiLCJpYXQiOjE2MTExNjUwODcsIm5iZiI6MTYxMTE2NTA4NywiZXhwIjoxNjExMTY4OTg3LCJhaW8iOiJBVFFBeS84U0FBQUE4L1lxaDZrd3UrRnJ3TjV2bENVQ2Z5QVlmVDR1dExpTitpeFhZS0ZsWEhZZndiSDZITW9JZEpMazlJMVZnMy9XIiwibmFtZSI6ImNobG93ZS10ZXN0Iiwib2lkIjoiYTcyOGM5MWEtNDdjOS00NTAyLWJhMDUtMzYwODQwODI2NjM2IiwicHJlZmVycmVkX3VzZXJuYW1lIjoiY2hsb3dlLXRlc3RAYXp1cmVzZGt0ZWFtLm9ubWljcm9zb2Z0LmNvbSIsInJoIjoiMC5BVGNBSW11Q1ZOWTRzay02MmJlNU9qNmNXcFYzc0FUYmpScEd1LTRDLWVHX2UwWTNBSkEuIiwic3ViIjoiSE5QcW9raHV6WUFmRlVlRkEtVm1rQ0M1Z253Mkp1b0xTSEtIZ2NDbkdHYyIsInRpZCI6IjU0ODI2YjIyLTM4ZDYtNGZiMi1iYWQ5LWI3YjkzYTNlOWM1YSIsInV0aSI6Ik9WY3ZkbXVncEV1YllWQU9va0szQVEiLCJ2ZXIiOiIyLjAifQ.b17pJRXmw9YnC97aQbdKihqjTnqYuFSGH0AxdtDk4cpt9ZviJV19dz5wVxaUORGNf6K6vnFhZRlEX89bhMLH1BpVq5lc28IQ-8zk-Q6ItIap2xVS4u2jjHHoSZLoIPtNXMXPnOz_KPuff_L46mJpKoBxpEOBUvB6Tx_k-hLyrabpNYo_swBemamDylbrDPUpyNZCIlHi_qMH60Hrtfg9JlnGUeUUi-seY4vRQcTnAB-wvsQtMWbKYsEpBgjUihoqScRZMNC9j3HuvAsWurrCIJ4vZ6WKsjg7aoqC-Z-AWnOmvVSlUTajCI1HFzhjcTYDRS_WrcKnModSLvR1I6eMrw",
"client_info": "eyJ1aWQiOiJhNzI4YzkxYS00N2M5LTQ1MDItYmEwNS0zNjA4NDA4MjY2MzYiLCJ1dGlkIjoiNTQ4MjZiMjItMzhkNi00ZmIyLWJhZDktYjdiOTNhM2U5YzVhIn0"}'
headers:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ interactions:
body:
string: '{"token_type": "Bearer", "scope": "https://management.azure.com/user_impersonation
https://management.azure.com/.default", "expires_in": 86399, "ext_expires_in":
86399, "access_token": "90bfb5b224af86355666990646b4560e01bd8e134409cf3b8957eb3439e1198d",
"refresh_token": "5cd3b6421bdc3b15ae207aa2dbd5382287ab90b682e8382d6e295dd2c9c63b95",
86399, "access_token": "redactedf2adbf",
"refresh_token": "redacted72e298",
"foci": "1", "id_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6Im5PbzNaRHJPRFhFSzFqS1doWHNsSFJfS1hFZyJ9.eyJhdWQiOiIwNGIwNzc5NS04ZGRiLTQ2MWEtYmJlZS0wMmY5ZTFiZjdiNDYiLCJpc3MiOiJodHRwczovL2xvZ2luLm1pY3Jvc29mdG9ubGluZS5jb20vNTQ4MjZiMjItMzhkNi00ZmIyLWJhZDktYjdiOTNhM2U5YzVhL3YyLjAiLCJpYXQiOjE2MTExNjM2NDAsIm5iZiI6MTYxMTE2MzY0MCwiZXhwIjoxNjExMTY3NTQwLCJhaW8iOiJBVFFBeS84U0FBQUFjSU9MUjhRbmJJd0lKb1lTYkxoakhndzMrL3BEdWJaVTdlUHB1anFjQjBvMzNzQjVXRjJWV0w4bjEwWmhkM3dWIiwibmFtZSI6ImNobG93ZS10ZXN0Iiwib2lkIjoiYTcyOGM5MWEtNDdjOS00NTAyLWJhMDUtMzYwODQwODI2NjM2IiwicHJlZmVycmVkX3VzZXJuYW1lIjoiY2hsb3dlLXRlc3RAYXp1cmVzZGt0ZWFtLm9ubWljcm9zb2Z0LmNvbSIsInJoIjoiMC5BVGNBSW11Q1ZOWTRzay02MmJlNU9qNmNXcFYzc0FUYmpScEd1LTRDLWVHX2UwWTNBSkEuIiwic3ViIjoiSE5QcW9raHV6WUFmRlVlRkEtVm1rQ0M1Z253Mkp1b0xTSEtIZ2NDbkdHYyIsInRpZCI6IjU0ODI2YjIyLTM4ZDYtNGZiMi1iYWQ5LWI3YjkzYTNlOWM1YSIsInV0aSI6IjMyLWpHQW1tNkVPckVEM2J0dl9NQVEiLCJ2ZXIiOiIyLjAifQ.Selp9Tu_RXqJjKw2Jr9tlIDEO5ZDoEQmURRZyYVHHdv7VAntq6khKkxTbcWq_UMf-XQLV9_vislkdaydPzZaM8rb-9O3DDN9Mfug8s9clxWPAUu8Cv7A8qc-eMTYF7nSjZXvcDRcAINunnUeeXjYBYYa-Cm9XrVzKiXyjb9Ue4S7c42YCdE_PUgQPQq-qr_umkWmIYLa5cOB-a017vUdGQ2DOAT3scPKCwjXb2ZlSUfeVs7bXXmvzgNGaBkCe2g2m97Fbe9JCjfmsIj89D8gkYuSup7JYV6DJzw3XAXGH1f46hEAhcHhoLoVuTTbMRKhIUV_TSQpnWSvv2CrRGEBeQ",
"client_info": "eyJ1aWQiOiJhNzI4YzkxYS00N2M5LTQ1MDItYmEwNS0zNjA4NDA4MjY2MzYiLCJ1dGlkIjoiNTQ4MjZiMjItMzhkNi00ZmIyLWJhZDktYjdiOTNhM2U5YzVhIn0"}'
headers:
Expand Down Expand Up @@ -483,8 +483,8 @@ interactions:
body:
string: '{"token_type": "Bearer", "scope": "https://management.azure.com/user_impersonation
https://management.azure.com/.default", "expires_in": 86399, "ext_expires_in":
86399, "access_token": "1cd53f96bc681d6e3c2c1e44d52166dc319ef18e0cff11cd164dcab68400703a",
"refresh_token": "543af57a4e02de41aab38056eee6672b51f7f2e4119bc09ec2f5698a94aeb569",
86399, "access_token": "redacted154205",
"refresh_token": "redacted5cc1a0",
"foci": "1", "id_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6Im5PbzNaRHJPRFhFSzFqS1doWHNsSFJfS1hFZyJ9.eyJhdWQiOiIwNGIwNzc5NS04ZGRiLTQ2MWEtYmJlZS0wMmY5ZTFiZjdiNDYiLCJpc3MiOiJodHRwczovL2xvZ2luLm1pY3Jvc29mdG9ubGluZS5jb20vNTQ4MjZiMjItMzhkNi00ZmIyLWJhZDktYjdiOTNhM2U5YzVhL3YyLjAiLCJpYXQiOjE2MTExNjQwNDUsIm5iZiI6MTYxMTE2NDA0NSwiZXhwIjoxNjExMTY3OTQ1LCJhaW8iOiJBVFFBeS84U0FBQUFLODI3b3FSMjdsMGcyRG5qM0RuR2RmeTUxcjgrZk1wYTFUb3dOK2gvMTdtdllyRHlQY0t0aTBQV0NoQ2g5TmpsIiwibmFtZSI6ImNobG93ZS10ZXN0Iiwib2lkIjoiYTcyOGM5MWEtNDdjOS00NTAyLWJhMDUtMzYwODQwODI2NjM2IiwicHJlZmVycmVkX3VzZXJuYW1lIjoiY2hsb3dlLXRlc3RAYXp1cmVzZGt0ZWFtLm9ubWljcm9zb2Z0LmNvbSIsInJoIjoiMC5BVGNBSW11Q1ZOWTRzay02MmJlNU9qNmNXcFYzc0FUYmpScEd1LTRDLWVHX2UwWTNBSkEuIiwic3ViIjoiSE5QcW9raHV6WUFmRlVlRkEtVm1rQ0M1Z253Mkp1b0xTSEtIZ2NDbkdHYyIsInRpZCI6IjU0ODI2YjIyLTM4ZDYtNGZiMi1iYWQ5LWI3YjkzYTNlOWM1YSIsInV0aSI6ImcxOTZhbTJNYlV5R0FqOE44cDdIQVEiLCJ2ZXIiOiIyLjAifQ.Uhx_g7vsHlPMQzeSbkTbeCgAVq1Yj7OWk18zJr5huT9vGX2NlFIiLJa2fUGW_thsYtSNPrmRAFCaAPD402N1-gZwFyCId0ObpmgW4m-XUXwVScGbQ4malAOIAuxX_BFQ4tLKSUzi1JWryWBvs2eBh3ZCzATGw_gJGm83TYm4Ih-QrmGULMEQP0gC0gpqvfOo2giM8via-xSh0vDTZA07ip17C5Te_IAS3AJ1ChcnJvB5uCpTLd5a-zD2fsCvK602PDtCMMZNwnbmrXVUseP_1E_3JQGRa6dfBGFq4HSdV2EvQ5s5zq_Dy3aAgpGzLQiJQgf7rzcxUd0RRHoSSLp5XQ",
"client_info": "eyJ1aWQiOiJhNzI4YzkxYS00N2M5LTQ1MDItYmEwNS0zNjA4NDA4MjY2MzYiLCJ1dGlkIjoiNTQ4MjZiMjItMzhkNi00ZmIyLWJhZDktYjdiOTNhM2U5YzVhIn0"}'
headers:
Expand Down
12 changes: 3 additions & 9 deletions sdk/identity/azure-identity/tests/test_powershell_credential.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
)
import pytest

from credscan_ignore import POWERSHELL_INVALID_OPERATION_EXCEPTION, POWERSHELL_NOT_LOGGED_IN_ERROR


POPEN = AzurePowerShellCredential.__module__ + ".subprocess.Popen"

Expand Down Expand Up @@ -145,15 +147,7 @@ def test_powershell_not_installed_sh():
AzurePowerShellCredential().get_token("scope")


@pytest.mark.parametrize(
"stderr",
(
"""#< CLIXML
<Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"><Obj S="progress" RefId="0"><TN RefId="0"><T>System.Management.Automation.PSCustomObject</T><T>System.Object</T></TN><MS><I64 N="SourceId">1</I64><PR N="Record"><AV>Preparing modules for first use.</AV><AI>0</AI><Nil /><PI>-1</PI><PC>-1</PC><T>Completed</T><SR>-1</SR><SD> </SD></PR></MS></Obj><Obj S="progress" RefId="1"><TNRef RefId="0" /><MS><I64 N="SourceId">2</I64><PR N="Record"><AV>Preparing modules for first use.</AV><AI>0</AI><Nil /><PI>-1</PI><PC>-1</PC><T>Completed</T><SR>-1</SR><SD> </SD></PR></MS></Obj><S S="Error">Get-AzAccessToken : Run Connect-AzAccount to login._x000D__x000A_</S><S S="Error">At line:11 char:10_x000D__x000A_</S><S S="Error">+ $token = Get-AzAccessToken -ResourceUrl 'scope'_x000D__x000A_</S><S S="Error">+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~_x000D__x000A_</S><S S="Error"> + CategoryInfo : CloseError: (:) [Get-AzAccessToken], PSInvalidOperationException_x000D__x000A_</S><S S="Error"> + FullyQualifiedErrorId : Microsoft.Azure.Commands.Profile.GetAzureRmAccessTokenCommand_x000D__x000A_</S><S S="Error"> _x000D__x000A_</S></Objs>""",
"""#< CLIXML
<Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"><S S="Error">_x001B_[91mGet-AzAccessToken: _x000D__x000A_</S><S S="Error">_x001B_[96mLine |_x000D__x000A_</S><S S="Error">_x001B_[96m 11 | _x001B_[0m $token = _x001B_[96mGet-AzAccessToken -ResourceUrl 'scope'_x001B_[0m_x000D__x000A_</S><S S="Error">_x001B_[96m | _x001B_[91m ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~_x000D__x000A_</S><S S="Error">_x001B_[91m_x001B_[96m | _x001B_[91mRun Connect-AzAccount to login._x001B_[0m_x000D__x000A_</S></Objs>""",
),
)
@pytest.mark.parametrize("stderr", (POWERSHELL_INVALID_OPERATION_EXCEPTION, POWERSHELL_NOT_LOGGED_IN_ERROR))
def test_not_logged_in(stderr):
"""The credential should raise CredentialUnavailableError when a user isn't logged in to Azure PowerShell"""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
)
import pytest

from credscan_ignore import POWERSHELL_INVALID_OPERATION_EXCEPTION, POWERSHELL_NOT_LOGGED_IN_ERROR
from helpers_async import get_completed_future
from test_powershell_credential import PREPARING_MODULES

Expand Down Expand Up @@ -133,15 +134,7 @@ async def test_powershell_not_installed_sh():
await AzurePowerShellCredential().get_token("scope")


@pytest.mark.parametrize(
"stderr",
(
"""#< CLIXML
<Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"><Obj S="progress" RefId="0"><TN RefId="0"><T>System.Management.Automation.PSCustomObject</T><T>System.Object</T></TN><MS><I64 N="SourceId">1</I64><PR N="Record"><AV>Preparing modules for first use.</AV><AI>0</AI><Nil /><PI>-1</PI><PC>-1</PC><T>Completed</T><SR>-1</SR><SD> </SD></PR></MS></Obj><Obj S="progress" RefId="1"><TNRef RefId="0" /><MS><I64 N="SourceId">2</I64><PR N="Record"><AV>Preparing modules for first use.</AV><AI>0</AI><Nil /><PI>-1</PI><PC>-1</PC><T>Completed</T><SR>-1</SR><SD> </SD></PR></MS></Obj><S S="Error">Get-AzAccessToken : Run Connect-AzAccount to login._x000D__x000A_</S><S S="Error">At line:11 char:10_x000D__x000A_</S><S S="Error">+ $token = Get-AzAccessToken -ResourceUrl 'scope'_x000D__x000A_</S><S S="Error">+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~_x000D__x000A_</S><S S="Error"> + CategoryInfo : CloseError: (:) [Get-AzAccessToken], PSInvalidOperationException_x000D__x000A_</S><S S="Error"> + FullyQualifiedErrorId : Microsoft.Azure.Commands.Profile.GetAzureRmAccessTokenCommand_x000D__x000A_</S><S S="Error"> _x000D__x000A_</S></Objs>""",
"""#< CLIXML
<Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"><S S="Error">_x001B_[91mGet-AzAccessToken: _x000D__x000A_</S><S S="Error">_x001B_[96mLine |_x000D__x000A_</S><S S="Error">_x001B_[96m 11 | _x001B_[0m $token = _x001B_[96mGet-AzAccessToken -ResourceUrl 'scope'_x001B_[0m_x000D__x000A_</S><S S="Error">_x001B_[96m | _x001B_[91m ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~_x000D__x000A_</S><S S="Error">_x001B_[91m_x001B_[96m | _x001B_[91mRun Connect-AzAccount to login._x001B_[0m_x000D__x000A_</S></Objs>""",
),
)
@pytest.mark.parametrize("stderr", (POWERSHELL_INVALID_OPERATION_EXCEPTION, POWERSHELL_NOT_LOGGED_IN_ERROR))
async def test_not_logged_in(stderr):
"""The credential should raise CredentialUnavailableError when a user isn't logged in to Azure PowerShell"""

Expand Down

0 comments on commit 476acd5

Please sign in to comment.