Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cheenamalhotra committed Mar 25, 2021
1 parent 05a3c0c commit f8abb46
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
<value>6</value>
</ActiveDirectoryDeviceCodeFlow>
<ActiveDirectoryManagedIdentity>
<summary>The authentication method uses Active Directory Managed Identity. Use System Assigned or User Assigned Managed Identity to connect to SQL Database from Azure client environments that have enabled support for Managed Identity. For User Assigned Managed Identity, 'User Id' or 'UID' is required to be set to the object ID of the user identity.</summary>
<summary>The authentication method uses Active Directory Managed Identity. Use System Assigned or User Assigned Managed Identity to connect to SQL Database from Azure client environments that have enabled support for Managed Identity. For User Assigned Managed Identity, 'User Id' or 'UID' is required to be set to the "client ID" of the user identity.</summary>
<value>7</value>
</ActiveDirectoryManagedIdentity>
<ActiveDirectoryMSI>
<summary>Alias for "Active Directory Managed Identity" authentication method. Use System Assigned or User Assigned Managed Identity to connect to SQL Database from Azure client environments that have enabled support for Managed Identity. For User Assigned Managed Identity, 'User Id' or 'UID' is required to be set to the object ID of the user identity.</summary>
<summary>Alias for "Active Directory Managed Identity" authentication method. Use System Assigned or User Assigned Managed Identity to connect to SQL Database from Azure client environments that have enabled support for Managed Identity. For User Assigned Managed Identity, 'User Id' or 'UID' is required to be set to the "client ID" of the user identity.</summary>
<value>8</value>
</ActiveDirectoryMSI>
</members>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public static async Task<string> AzureActiveDirectoryAuthenticationCallback(stri
return result.AccessToken;
}

public static async Task<string> GetManagedIdentityToken(string objectId = null) =>
await new MockManagedIdentityTokenProvider().AcquireTokenAsync(objectId).ConfigureAwait(false);
public static async Task<string> GetManagedIdentityToken(string clientId = null) =>
await new MockManagedIdentityTokenProvider().AcquireTokenAsync(clientId).ConfigureAwait(false);

}

Expand Down Expand Up @@ -59,20 +59,20 @@ internal class MockManagedIdentityTokenProvider
internal readonly int _retryTimeoutInSeconds = DefaultRetryTimeout;
internal readonly int _maxRetryCount = DefaultMaxRetryCount;

public async Task<string> AcquireTokenAsync(string objectId = null)
public async Task<string> AcquireTokenAsync(string clientId = null)
{
// Use the httpClient specified in the constructor. If it was not specified in the constructor, use the default httpClient.
HttpClient httpClient = s_defaultHttpClient;

try
{
// If user assigned managed identity is specified, include object ID parameter in request
string objectIdParameter = objectId != null
? $"&object_id={objectId}"
// If user assigned managed identity is specified, include client Id parameter in request
string clientId = clientId != null
? $"&client_id={clientId}"
: string.Empty;

// Craft request as per the MSI protocol
var requestUrl = $"{AzureVmImdsEndpoint}?resource={Resource}{objectIdParameter}{AzureVmImdsApiVersion}";
var requestUrl = $"{AzureVmImdsEndpoint}?resource={Resource}{clientIdParameter}{AzureVmImdsApiVersion}";

HttpResponseMessage response = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static class DataTestUtility
public static readonly string DNSCachingServerTR = null; // this is for the tenant ring
public static readonly bool IsDNSCachingSupportedCR = false; // this is for the control ring
public static readonly bool IsDNSCachingSupportedTR = false; // this is for the tenant ring
public static readonly string UserManagedIdentityObjectId = null;
public static readonly string UserManagedIdentityClientId = null;

public static readonly string EnclaveAzureDatabaseConnString = null;
public static bool ManagedIdentitySupported = true;
Expand Down Expand Up @@ -93,7 +93,7 @@ static DataTestUtility()
IsDNSCachingSupportedCR = c.IsDNSCachingSupportedCR;
IsDNSCachingSupportedTR = c.IsDNSCachingSupportedTR;
EnclaveAzureDatabaseConnString = c.EnclaveAzureDatabaseConnString;
UserManagedIdentityObjectId = c.UserManagedIdentityObjectId;
UserManagedIdentityClientId = c.UserManagedIdentityClientId;

System.Net.ServicePointManager.SecurityProtocol |= System.Net.SecurityProtocolType.Tls12;

Expand Down Expand Up @@ -459,8 +459,8 @@ public static string GetUserIdentityAccessToken()
{
if (true == ManagedIdentitySupported && null == AADUserIdentityAccessToken && IsAADPasswordConnStrSetup())
{
// Pass User Assigned Managed Identity Object Id here.
AADUserIdentityAccessToken = AADUtility.GetManagedIdentityToken(UserManagedIdentityObjectId).GetAwaiter().GetResult();
// Pass User Assigned Managed Identity Client Id here.
AADUserIdentityAccessToken = AADUtility.GetManagedIdentityToken(UserManagedIdentityClientId).GetAwaiter().GetResult();
if (AADUserIdentityAccessToken == null)
{
ManagedIdentitySupported = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ public static void UserAssigned_ManagedIdentityTest()
{
string[] removeKeys = { "Authentication", "User ID", "Password", "UID", "PWD" };
string connStr = DataTestUtility.RemoveKeysInConnStr(DataTestUtility.AADPasswordConnectionString, removeKeys) +
$"Authentication=Active Directory Managed Identity; User Id={DataTestUtility.UserManagedIdentityObjectId};";
$"Authentication=Active Directory Managed Identity; User Id={DataTestUtility.UserManagedIdentityClientId};";
ConnectAndDisconnect(connStr);
}

Expand Down Expand Up @@ -543,7 +543,7 @@ public static void Azure_UserManagedIdentityTest()
{
string[] removeKeys = { "Authentication", "User ID", "Password", "UID", "PWD", "Trusted_Connection", "Integrated Security" };
string connectionString = DataTestUtility.RemoveKeysInConnStr(DataTestUtility.TCPConnectionString, removeKeys)
+ $"Authentication=Active Directory Managed Identity; User Id={DataTestUtility.UserManagedIdentityObjectId}";
+ $"Authentication=Active Directory Managed Identity; User Id={DataTestUtility.UserManagedIdentityClientId}";

using (SqlConnection conn = new SqlConnection(connectionString))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class Config
public bool IsDNSCachingSupportedCR = false; // this is for the control ring
public bool IsDNSCachingSupportedTR = false; // this is for the tenant ring
public string EnclaveAzureDatabaseConnString = null;
public string UserManagedIdentityObjectId = null;
public string UserManagedIdentityClientId = null;

public static Config Load(string configPath = @"config.json")
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
"UseManagedSNIOnWindows": false,
"IsAzureSynapse": false,
"EnclaveAzureDatabaseConnString": "",
"UserManagedIdentityObjectId": ""
"UserManagedIdentityClientId": ""
}

0 comments on commit f8abb46

Please sign in to comment.