Skip to content
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

Add EnvVar AuthorityHost #10780

Merged
merged 8 commits into from
Apr 6, 2020
Merged
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
69 changes: 69 additions & 0 deletions sdk/identity/Azure.Identity/tests/TokenCredentialOptionsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using Azure.Core.Testing;
using NUnit.Framework;

namespace Azure.Identity.Tests
{
public class TokenCredentialOptionsTests : ClientTestBase
{
public TokenCredentialOptionsTests(bool isAsync) : base(isAsync)
{
}

[Test]
public void InvalidEnvAuthorityHost()
{
using (new TestEnvVar("AZURE_AUTHORITY_HOST", "mock-env-authority-host"))
{
schaabs marked this conversation as resolved.
Show resolved Hide resolved
TokenCredentialOptions option = new TokenCredentialOptions();

Assert.Throws<UriFormatException>(() => { Uri finalUri = option.AuthorityHost; });
}
}

[Test]
public void EnvAuthorityHost()
{
string envHostValue = KnownAuthorityHosts.AzureChinaCloud.ToString();

using (new TestEnvVar("AZURE_AUTHORITY_HOST", envHostValue))
{
TokenCredentialOptions option = new TokenCredentialOptions();
Uri finalUri = option.AuthorityHost;

Assert.AreEqual(finalUri, new Uri(envHostValue));
}
}

[Test]
public void CustomAuthorityHost()
{
string envHostValue = KnownAuthorityHosts.AzureGermanCloud.ToString();

using (new TestEnvVar("AZURE_AUTHORITY_HOST", envHostValue))
{
Uri customUri = KnownAuthorityHosts.AzureChinaCloud;

TokenCredentialOptions option = new TokenCredentialOptions() { AuthorityHost = customUri };
Uri finalUri = option.AuthorityHost;

Assert.AreNotEqual(finalUri, new Uri(envHostValue));
Assert.AreEqual(finalUri, customUri);
}
}

[Test]
public void DefaultAuthorityHost()
{
using (new TestEnvVar("AZURE_AUTHORITY_HOST", null))
{
TokenCredentialOptions option = new TokenCredentialOptions();

Assert.AreEqual(option.AuthorityHost, KnownAuthorityHosts.AzureCloud);
}
}
}
}