Skip to content

Commit f454077

Browse files
Sync Az.Accounts-5.0.1 OOB to Main (#27846)
Co-authored-by: azure-powershell-bot <[email protected]>
1 parent 77db2d5 commit f454077

File tree

14 files changed

+221
-110
lines changed

14 files changed

+221
-110
lines changed

src/Accounts/Accounts.Test/AccessTokenCmdletTest.cs

Lines changed: 119 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
using Microsoft.Azure.Commands.Common.Authentication;
1616
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
17-
using Microsoft.Azure.Commands.Common.Authentication.Abstractions.Interfaces;
1817
using Microsoft.Azure.Commands.Common.Authentication.Models;
1918
using Microsoft.Azure.Commands.Profile;
2019
using Microsoft.Azure.Commands.Profile.Models;
@@ -40,18 +39,14 @@ namespace Microsoft.Azure.Commands.ResourceManager.Common.Test
4039
{
4140
public class AccessTokenCmdletTests
4241
{
43-
private GetAzureRmAccessTokenCommand cmdlet;
4442
private Mock<IAuthenticationFactory> factoryMock = new Mock<IAuthenticationFactory>();
4543
private MockCommandRuntime mockedCommandRuntime;
4644
private IAuthenticationFactory previousFactory = null;
4745

4846
private string tenantId = Guid.NewGuid().ToString();
4947

50-
public AccessTokenCmdletTests(ITestOutputHelper output)
48+
private GetAzureRmAccessTokenCommand CreateCommand()
5149
{
52-
TestExecutionHelpers.SetUpSessionAndProfile();
53-
XunitTracingInterceptor.AddToContext(new XunitTracingInterceptor(output));
54-
AzureSession.Instance.RegisterComponent<AuthenticationTelemetry>(AuthenticationTelemetry.Name, () => new AuthenticationTelemetry());
5550
var defaultContext = new AzureContext(
5651
new AzureSubscription()
5752
{
@@ -70,29 +65,40 @@ public AccessTokenCmdletTests(ITestOutputHelper output)
7065
});
7166

7267
mockedCommandRuntime = new MockCommandRuntime();
73-
cmdlet = new GetAzureRmAccessTokenCommand()
68+
var cmdlet = new GetAzureRmAccessTokenCommand()
7469
{
7570
CommandRuntime = mockedCommandRuntime,
7671
DefaultProfile = new AzureRmProfile()
7772
};
7873
cmdlet.DefaultProfile.DefaultContext = defaultContext;
74+
return cmdlet;
75+
}
76+
77+
public AccessTokenCmdletTests(ITestOutputHelper output)
78+
{
79+
TestExecutionHelpers.SetUpSessionAndProfile();
80+
XunitTracingInterceptor.AddToContext(new XunitTracingInterceptor(output));
81+
AzureSession.Instance.RegisterComponent<AuthenticationTelemetry>(AuthenticationTelemetry.Name, () => new AuthenticationTelemetry());
82+
7983
}
8084

8185
[Fact]
8286
[Trait(Category.AcceptanceType, Category.CheckIn)]
8387
public void TestGetAccessTokenAsPlainText()
8488
{
8589
// Setup
90+
var cmdlet = CreateCommand();
8691
cmdlet.TenantId = tenantId;
8792
var fakeToken = "eyfaketoken.eyfaketoken";
8893
Environment.SetEnvironmentVariable(Constants.AzPsOutputPlainTextAccessToken, bool.TrueString);
8994

90-
var expected = new PSAccessToken {
95+
var expected = new PSAccessToken
96+
{
9197
UserId = "[email protected]",
9298
TenantId = cmdlet.TenantId,
9399
Token = fakeToken
94100
};
95-
101+
96102
factoryMock.Setup(t => t.Authenticate(
97103
It.IsAny<IAzureAccount>(),
98104
It.IsAny<IAzureEnvironment>(),
@@ -132,6 +138,110 @@ public void TestGetAccessTokenAsPlainText()
132138
public void TestGetAccessTokenAsSecureString()
133139
{
134140
// Setup
141+
var cmdlet = CreateCommand();
142+
cmdlet.TenantId = tenantId;
143+
var fakeToken = "eyfaketoken.eyfaketoken";
144+
145+
var expected = new PSSecureAccessToken();
146+
expected.UserId = "[email protected]";
147+
expected.TenantId = cmdlet.TenantId;
148+
expected.Token = fakeToken.ConvertToSecureString();
149+
150+
151+
factoryMock.Setup(t => t.Authenticate(
152+
It.IsAny<IAzureAccount>(),
153+
It.IsAny<IAzureEnvironment>(),
154+
It.IsAny<string>(),
155+
It.IsAny<SecureString>(),
156+
It.IsAny<string>(),
157+
It.IsAny<Action<string>>(),
158+
It.IsAny<IDictionary<string, object>>())).Returns(new MockAccessToken
159+
{
160+
UserId = expected.UserId,
161+
LoginType = LoginType.OrgId,
162+
AccessToken = fakeToken,
163+
TenantId = expected.TenantId
164+
});
165+
previousFactory = AzureSession.Instance.AuthenticationFactory;
166+
AzureSession.Instance.AuthenticationFactory = factoryMock.Object;
167+
168+
// Act
169+
cmdlet.InvokeBeginProcessing();
170+
cmdlet.ExecuteCmdlet();
171+
cmdlet.InvokeEndProcessing();
172+
173+
//Verify
174+
Assert.Single(mockedCommandRuntime.OutputPipeline);
175+
var outputPipeline = mockedCommandRuntime.OutputPipeline;
176+
Assert.Equal(expected.TenantId, ((PSSecureAccessToken)outputPipeline.First()).TenantId);
177+
Assert.Equal(expected.UserId, ((PSSecureAccessToken)outputPipeline.First()).UserId);
178+
Assert.Equal("Bearer", ((PSSecureAccessToken)outputPipeline.First()).Type);
179+
var expectedToken = expected.Token.ConvertToString();
180+
var actualToken = ((PSSecureAccessToken)outputPipeline.First()).Token.ConvertToString();
181+
Assert.Equal(expectedToken, actualToken);
182+
183+
AzureSession.Instance.AuthenticationFactory = previousFactory;
184+
}
185+
186+
[Fact]
187+
[Trait(Category.AcceptanceType, Category.CheckIn)]
188+
public void TestGetAccessTokenAsSecureStringWhenHasEnvVarAndAsSecureString()
189+
{
190+
// Setup
191+
var cmdlet = CreateCommand();
192+
cmdlet.TenantId = tenantId;
193+
cmdlet.AsSecureString = true;
194+
var fakeToken = "eyfaketoken.eyfaketoken";
195+
Environment.SetEnvironmentVariable(Constants.AzPsOutputPlainTextAccessToken, bool.TrueString);
196+
197+
var expected = new PSSecureAccessToken();
198+
expected.UserId = "[email protected]";
199+
expected.TenantId = cmdlet.TenantId;
200+
expected.Token = fakeToken.ConvertToSecureString();
201+
202+
203+
factoryMock.Setup(t => t.Authenticate(
204+
It.IsAny<IAzureAccount>(),
205+
It.IsAny<IAzureEnvironment>(),
206+
It.IsAny<string>(),
207+
It.IsAny<SecureString>(),
208+
It.IsAny<string>(),
209+
It.IsAny<Action<string>>(),
210+
It.IsAny<IDictionary<string, object>>())).Returns(new MockAccessToken
211+
{
212+
UserId = expected.UserId,
213+
LoginType = LoginType.OrgId,
214+
AccessToken = fakeToken,
215+
TenantId = expected.TenantId
216+
});
217+
previousFactory = AzureSession.Instance.AuthenticationFactory;
218+
AzureSession.Instance.AuthenticationFactory = factoryMock.Object;
219+
220+
// Act
221+
cmdlet.InvokeBeginProcessing();
222+
cmdlet.ExecuteCmdlet();
223+
cmdlet.InvokeEndProcessing();
224+
225+
//Verify
226+
Assert.Single(mockedCommandRuntime.OutputPipeline);
227+
var outputPipeline = mockedCommandRuntime.OutputPipeline;
228+
Assert.Equal(expected.TenantId, ((PSSecureAccessToken)outputPipeline.First()).TenantId);
229+
Assert.Equal(expected.UserId, ((PSSecureAccessToken)outputPipeline.First()).UserId);
230+
Assert.Equal("Bearer", ((PSSecureAccessToken)outputPipeline.First()).Type);
231+
var expectedToken = expected.Token.ConvertToString();
232+
var actualToken = ((PSSecureAccessToken)outputPipeline.First()).Token.ConvertToString();
233+
Assert.Equal(expectedToken, actualToken);
234+
235+
Environment.SetEnvironmentVariable(Constants.AzPsOutputPlainTextAccessToken, null);
236+
AzureSession.Instance.AuthenticationFactory = previousFactory;
237+
}
238+
239+
[Fact]
240+
[Trait(Category.AcceptanceType, Category.CheckIn)]
241+
public void TestGetAccessTokenAsSecureStringWhenHasSecureString()
242+
{
243+
// Setup
244+
var cmdlet = CreateCommand();
135245
cmdlet.TenantId = tenantId;
136246
cmdlet.AsSecureString = true;
137247
var fakeToken = "eyfaketoken.eyfaketoken";

src/Accounts/Accounts/Az.Accounts.psd1

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
# Generated by: Microsoft Corporation
55
#
6-
# Generated on: 5/14/2025
6+
# Generated on: 5/23/2025
77
#
88

99
@{
@@ -12,7 +12,7 @@
1212
# RootModule = ''
1313

1414
# Version number of this module.
15-
ModuleVersion = '5.0.0'
15+
ModuleVersion = '5.0.1'
1616

1717
# Supported PSEditions
1818
CompatiblePSEditions = 'Core', 'Desktop'
@@ -146,9 +146,7 @@ PrivateData = @{
146146
# IconUri = ''
147147

148148
# ReleaseNotes of this module
149-
ReleaseNotes = '* Changed the default output access token of ''Get-AzAccessToken'' from plain text to ''SecureString''.
150-
* Removed the warning message about failing to initialize PSStyle in automation runbooks. [#26155]
151-
* Increased the timeout for tab-completion of location, resource group, etc. to 10 seconds.'
149+
ReleaseNotes = '* Force ''Get-AzAccessToken'' to always return SecureString as long as ''AsSecureString'' is set'
152150

153151
# Prerelease string of this module
154152
# Prerelease = ''

src/Accounts/Accounts/ChangeLog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
## Upcoming Release
2222
* Upgrade Azure.Core to 1.45.0
2323

24+
## Version 5.0.1
25+
* Force `Get-AzAccessToken` to always return SecureString as long as `AsSecureString` is set
26+
2427
## Version 5.0.0
2528
* Changed the default output access token of `Get-AzAccessToken` from plain text to `SecureString`.
2629
* Removed the warning message about failing to initialize PSStyle in automation runbooks. [#26155]

src/Accounts/Accounts/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343
// You can specify all the values or you can default the Build and Revision Numbers
4444
// by using the '*' as shown below:
4545

46-
[assembly: AssemblyVersion("5.0.0")]
47-
[assembly: AssemblyFileVersion("5.0.0")]
46+
[assembly: AssemblyVersion("5.0.1")]
47+
[assembly: AssemblyFileVersion("5.0.1")]
4848
#if !SIGN
4949
[assembly: InternalsVisibleTo("Microsoft.Azure.PowerShell.Cmdlets.Accounts.Test")]
5050
#endif

src/Accounts/Accounts/Token/GetAzureRmAccessToken.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public override void ExecuteCmdlet()
156156
//Throw exception when the caller doesn't have permission.
157157
//Use SecureString only when AZUREPS_OUTPUT_PLAINTEXT_AZACCESSTOKEN is successfully set.
158158
}
159-
if (usePlainText)
159+
if (usePlainText && !AsSecureString)
160160
{
161161
WriteObject(result);
162162
}

src/Accounts/AssemblyLoading/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,5 @@
4242
// You can specify all the values or you can default the Build and Revision Numbers
4343
// by using the '*' as shown below:
4444
// [assembly: AssemblyVersion("1.0.*")]
45-
[assembly: AssemblyVersion("5.0.0")]
46-
[assembly: AssemblyFileVersion("5.0.0")]
45+
[assembly: AssemblyVersion("5.0.1")]
46+
[assembly: AssemblyFileVersion("5.0.1")]

src/Accounts/Authentication/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343
// You can specify all the values or you can default the Build and Revision Numbers
4444
// by using the '*' as shown below:
4545
// [assembly: AssemblyVersion("1.0.*")]
46-
[assembly: AssemblyVersion("5.0.0")]
47-
[assembly: AssemblyFileVersion("5.0.0")]
46+
[assembly: AssemblyVersion("5.0.1")]
47+
[assembly: AssemblyFileVersion("5.0.1")]
4848
#if !SIGN
4949
[assembly: InternalsVisibleTo("Microsoft.Azure.PowerShell.Authentication.Test")]
5050
#endif

src/Accounts/AuthenticationAssemblyLoadContext/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,5 @@
4242
// You can specify all the values or you can default the Build and Revision Numbers
4343
// by using the '*' as shown below:
4444
// [assembly: AssemblyVersion("1.0.*")]
45-
[assembly: AssemblyVersion("5.0.0")]
46-
[assembly: AssemblyFileVersion("5.0.0")]
45+
[assembly: AssemblyVersion("5.0.1")]
46+
[assembly: AssemblyFileVersion("5.0.1")]

src/Accounts/Authenticators/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,5 @@
4848
// You can specify all the values or you can default the Build and Revision Numbers
4949
// by using the '*' as shown below:
5050
// [assembly: AssemblyVersion("1.0.*")]
51-
[assembly: AssemblyVersion("5.0.0")]
52-
[assembly: AssemblyFileVersion("5.0.0")]
51+
[assembly: AssemblyVersion("5.0.1")]
52+
[assembly: AssemblyFileVersion("5.0.1")]

tools/Az/Az.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ DotNetFrameworkVersion = '4.7.2'
5252
# ProcessorArchitecture = ''
5353

5454
# Modules that must be imported into the global environment prior to importing this module
55-
RequiredModules = @(@{ModuleName = 'Az.Accounts'; ModuleVersion = '5.0.0'; },
55+
RequiredModules = @(@{ModuleName = 'Az.Accounts'; ModuleVersion = '5.0.1'; },
5656
@{ModuleName = 'Az.Advisor'; RequiredVersion = '2.1.0'; },
5757
@{ModuleName = 'Az.Aks'; RequiredVersion = '7.0.0'; },
5858
@{ModuleName = 'Az.AnalysisServices'; RequiredVersion = '1.2.0'; },

0 commit comments

Comments
 (0)