Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ private static AccessToken DeserializeOutput(string output)
break;

case "ExpiresOn":
expiresOn = DateTimeOffset.Parse(e.Value, CultureInfo.InvariantCulture).ToUniversalTime();
expiresOn = DateTimeOffset.Parse(e.Value, CultureInfo.CurrentCulture).ToUniversalTime();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we maybe include a test using the case from the linked bug?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

break;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -34,7 +35,7 @@ public async Task AuthenticateWithAzurePowerShellCredential(
[Values(null, TenantId)] string explicitTenantId)
{
var context = new TokenRequestContext(new[] { Scope }, tenantId: tenantId);
var options = new AzurePowerShellCredentialOptions { TenantId = explicitTenantId, AllowMultiTenantAuthentication = allowMultiTenantAuthentication};
var options = new AzurePowerShellCredentialOptions { TenantId = explicitTenantId, AllowMultiTenantAuthentication = allowMultiTenantAuthentication };
string expectedTenantId = TenantIdResolver.Resolve(explicitTenantId, context, options.AllowMultiTenantAuthentication);
var (expectedToken, expectedExpiresOn, processOutput) = CredentialTestHelpers.CreateTokenForAzurePowerShell(TimeSpan.FromSeconds(30));

Expand Down Expand Up @@ -76,12 +77,37 @@ public void AuthenticateWithAzurePowerShellCredential_PwshNotInstalled(
Assert.AreEqual(AzurePowerShellCredential.PowerShellNotInstalledError, ex.Message);
}

[Test]
public async Task HandlesAlternateDateTimeFormats([Values("en-US", "nl-NL")] string culture)
{
CultureInfo curCulture = CultureInfo.CurrentCulture;
CultureInfo.CurrentCulture = new CultureInfo(culture);
try
{
var (expectedToken, expectedExpiresOn, processOutput) = CredentialTestHelpers.CreateTokenForAzurePowerShell(TimeSpan.FromSeconds(30));
TestContext.WriteLine(processOutput);
var testProcess = new TestProcess
{
Output = processOutput,
};
AzurePowerShellCredential credential = InstrumentClient(
new AzurePowerShellCredential(
new AzurePowerShellCredentialOptions(),
CredentialPipeline.GetInstance(null),
new TestProcessService(testProcess, true)));
await credential.GetTokenAsync(new TokenRequestContext(MockScopes.Default));
}
finally
{
CultureInfo.CurrentCulture = new CultureInfo(curCulture.Name);
}
}

[Test]
[RunOnlyOnPlatforms(Windows = true)]
public async Task FallsBackToLegacyPowershell()
{
bool fellBackToPowerShell = false;
//var testProcess = new TestProcess { Output = "'pwsh' is not recognized as an internal or external command," };
var testProcess = new TestProcess
{
Output = "'pwsh' is not recognized as an internal or external command,",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static (string Token, DateTimeOffset ExpiresOn, string Json) CreateTokenF
public static (string Token, DateTimeOffset ExpiresOn, string Json) CreateTokenForAzurePowerShell(TimeSpan expiresOffset)
{
var expiresOnString = DateTimeOffset.Now.Add(expiresOffset).ToString();
var expiresOn = DateTimeOffset.Parse(expiresOnString, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeLocal);
var expiresOn = DateTimeOffset.Parse(expiresOnString, CultureInfo.CurrentCulture, DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeLocal);
var token = Guid.NewGuid().ToString();
var xml = @$"<Object Type=""Microsoft.Azure.Commands.Profile.Models.PSAccessToken""><Property Name=""Token"" Type=""System.String"">{token}</Property><Property Name=""ExpiresOn"" Type=""System.DateTimeOffset"">{expiresOnString}</Property><Property Name=""TenantId"" Type=""System.String"">{Guid.NewGuid().ToString()}</Property><Property Name=""UserId"" Type=""System.String"">foo@contoso.com</Property><Property Name=""Type"" Type=""System.String"">Bearer</Property></Object>";
return (token, expiresOn, xml);
Expand Down