Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fix tests
Signed-off-by: Paul Van Eck <[email protected]>
  • Loading branch information
pvaneck committed Feb 12, 2024
commit e947456905a7b42c9e62d477b709dbdb36917c58
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ def test_get_token(stderr):
command = args[0][-1]
assert command.startswith("pwsh -NoProfile -NonInteractive -EncodedCommand ")

encoded_script = command.split()[-1]
match = re.search(r"-EncodedCommand\s+(\S+)", command)
assert match, "couldn't find encoded script in command line"
encoded_script = match.groups()[0]
decoded_script = base64.b64decode(encoded_script).decode("utf-16-le")
assert "TenantId" not in decoded_script
assert "Get-AzAccessToken -ResourceUrl '{}'".format(scope) in decoded_script
Expand Down Expand Up @@ -295,7 +297,9 @@ def test_multitenant_authentication():

def fake_Popen(command, **_):
assert command[-1].startswith("pwsh -NoProfile -NonInteractive -EncodedCommand ")
encoded_script = command[-1].split()[-1]
match = re.search(r"-EncodedCommand\s+(\S+)", command[-1])
assert match, "couldn't find encoded script in command line"
encoded_script = match.groups()[0]
decoded_script = base64.b64decode(encoded_script).decode("utf-16-le")
match = re.search(r"Get-AzAccessToken -ResourceUrl '(\S+)'(?: -TenantId (\S+))?", decoded_script)
tenant = match.groups()[1]
Expand Down Expand Up @@ -325,7 +329,9 @@ def test_multitenant_authentication_not_allowed():

def fake_Popen(command, **_):
assert command[-1].startswith("pwsh -NoProfile -NonInteractive -EncodedCommand ")
encoded_script = command[-1].split()[-1]
match = re.search(r"-EncodedCommand\s+(\S+)", command[-1])
assert match, "couldn't find encoded script in command line"
encoded_script = match.groups()[0]
decoded_script = base64.b64decode(encoded_script).decode("utf-16-le")
match = re.search(r"Get-AzAccessToken -ResourceUrl '(\S+)'(?: -TenantId (\S+))?", decoded_script)
tenant = match.groups()[1]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ async def test_get_token(stderr):
command = args[-1]
assert command.startswith("pwsh -NoProfile -NonInteractive -EncodedCommand ")

encoded_script = command.split()[-1]
match = re.search(r"-EncodedCommand\s+(\S+)", command)
assert match, "couldn't find encoded script in command line"
encoded_script = match.groups()[0]
decoded_script = base64.b64decode(encoded_script).decode("utf-16-le")
assert "TenantId" not in decoded_script
assert "Get-AzAccessToken -ResourceUrl '{}'".format(scope) in decoded_script
Expand Down Expand Up @@ -277,11 +279,10 @@ async def mock_exec(*args, **kwargs):
communicate = Mock(return_value=get_completed_future((stdout.encode(), stderr.encode())))
return Mock(communicate=communicate, returncode=return_code)

with patch(AzurePowerShellCredential.__module__ + ".sys.platform", "win32"):
credential = AzurePowerShellCredential()
with pytest.raises(CredentialUnavailableError, match=AZ_ACCOUNT_NOT_INSTALLED):
with patch(CREATE_SUBPROCESS_EXEC, mock_exec):
await credential.get_token("scope")
credential = AzurePowerShellCredential()
with pytest.raises(CredentialUnavailableError, match=AZ_ACCOUNT_NOT_INSTALLED):
with patch(CREATE_SUBPROCESS_EXEC, mock_exec):
await credential.get_token("scope")

assert calls == 2

Expand All @@ -294,7 +295,9 @@ async def test_multitenant_authentication():
async def fake_exec(*args, **_):
command = args[2]
assert command.startswith("pwsh -NoProfile -NonInteractive -EncodedCommand ")
encoded_script = command.split()[-1]
match = re.search(r"-EncodedCommand\s+(\S+)", command)
assert match, "couldn't find encoded script in command line"
encoded_script = match.groups()[0]
decoded_script = base64.b64decode(encoded_script).decode("utf-16-le")
match = re.search(r"Get-AzAccessToken -ResourceUrl '(\S+)'(?: -TenantId (\S+))?", decoded_script)
tenant = match[2]
Expand Down Expand Up @@ -325,7 +328,9 @@ async def test_multitenant_authentication_not_allowed():
async def fake_exec(*args, **_):
command = args[2]
assert command.startswith("pwsh -NoProfile -NonInteractive -EncodedCommand ")
encoded_script = command.split()[-1]
match = re.search(r"-EncodedCommand\s+(\S+)", command)
assert match, "couldn't find encoded script in command line"
encoded_script = match.groups()[0]
decoded_script = base64.b64decode(encoded_script).decode("utf-16-le")
match = re.search(r"Get-AzAccessToken -ResourceUrl '(\S+)'(?: -TenantId (\S+))?", decoded_script)
tenant = match[2]
Expand Down