Skip to content

Commit

Permalink
Fix aad graph endpoint for SQL server and managed instance APIs (Azur…
Browse files Browse the repository at this point in the history
…e#19712)

* Fixed batch test recording issue (Azure#19706)

* fix aad graph endpoint

Co-authored-by: Vincent Dai <23257217+vidai-msft@users.noreply.github.com>
Co-authored-by: Dingmeng Xue <dixue@microsoft.com>
Co-authored-by: Yunchi Wang <54880216+wyunchi-ms@users.noreply.github.com>
  • Loading branch information
4 people authored Sep 30, 2022
1 parent 02c9afc commit 71c638a
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@

using Microsoft.WindowsAzure.Commands.ScenarioTest;
using Xunit;
using Xunit.Sdk;

namespace Microsoft.Azure.Commands.DevTestLabs.Test.ScenarioTests
{
public class PolicyTests : DevTestLabsTestRunner
{

public PolicyTests(TestOutputHelper output) : base(output)
public PolicyTests(Xunit.Abstractions.ITestOutputHelper output) : base(output)
{

}
Expand Down
1 change: 1 addition & 0 deletions src/Sql/Sql/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
* Removed the following aliases: `Enable-AzSqlServerAdvancedThreatProtection`, `Disable-AzSqlServerAdvancedThreatProtection`, `Get-AzSqlServerThreatDetectionSetting`, `Remove-AzSqlServerThreatDetectionSetting`, `Set-AzSqlServerThreatDetectionSetting`, `Get-AzSqlDatabaseThreatDetectionSetting`, `Set-AzSqlDatabaseThreatDetectionSetting` and `Remove-AzSqlDatabaseThreatDetectionSetting`
* Changed the returned object for the following cmdlets: `Get-AzSqlServerAdvancedThreatProtectionSetting` and `Get-AzSqlDatabaseAdvancedThreatProtectionSetting`
* Changed the parameters for the following cmdlets: `Update-AzSqlServerAdvancedThreatProtectionSetting` and `Update-AzSqlDatabaseAdvancedThreatProtectionSetting`. Only `Enable` parameter is now supported.
* Changed endpoint used in SQL Server and SQL Instance from AD Graph to MS Graph

## Version 3.11.0
* Removed the warning messages for MSGraph migration [#18856]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public MicrosoftGraphClient MicrosoftGraphClient
{
if (_microsoftGraphClient == null)
{
_microsoftGraphClient = AzureSession.Instance.ClientFactory.CreateArmClient<MicrosoftGraphClient>(Context, AzureEnvironment.Endpoint.Graph);
_microsoftGraphClient = AzureSession.Instance.ClientFactory.CreateArmClient<MicrosoftGraphClient>(Context, AzureEnvironment.ExtendedEndpoint.MicrosoftGraphUrl);
_microsoftGraphClient.TenantID = Context.Tenant.Id;
}
return _microsoftGraphClient;
Expand Down
2 changes: 1 addition & 1 deletion src/Sql/Sql/Server/Services/AzureSqlServerAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public MicrosoftGraphClient MicrosoftGraphClient
{
if (_microsoftGraphClient == null)
{
_microsoftGraphClient = AzureSession.Instance.ClientFactory.CreateArmClient<MicrosoftGraphClient>(Context, AzureEnvironment.Endpoint.Graph);
_microsoftGraphClient = AzureSession.Instance.ClientFactory.CreateArmClient<MicrosoftGraphClient>(Context, AzureEnvironment.ExtendedEndpoint.MicrosoftGraphUrl);
_microsoftGraphClient.TenantID = Context.Tenant.Id;
}
return _microsoftGraphClient;
Expand Down
51 changes: 23 additions & 28 deletions tools/TestFx/TestEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ public TestEnvironment(string connectionString)

InitTokenDictionary();
SetupHttpRecorderMode();
RecorderModeSettings();
}

private void InitTestEndPoints()
Expand Down Expand Up @@ -186,31 +185,6 @@ private void SetupHttpRecorderMode()
}
}

private void RecorderModeSettings()
{
if (HttpMockServer.Mode == HttpRecorderMode.Record)
{
//Restore/Add Subscription Id in MockServer from supplied connection string
if (HttpMockServer.Variables.ContainsCaseInsensitiveKey(ConnectionStringKeys.SubscriptionIdKey))
{
HttpMockServer.Variables.UpdateDictionary(ConnectionStringKeys.SubscriptionIdKey, SubscriptionId);
}
else
{
HttpMockServer.Variables.Add(ConnectionStringKeys.SubscriptionIdKey, SubscriptionId);
}

// If User has provided Access Token in RawToken/GraphToken Key-Value, we don't need to authenticate
// We currently only check for RawToken and do not check if GraphToken is provided
if (string.IsNullOrEmpty(ConnectionString.GetValue(ConnectionStringKeys.RawTokenKey)))
{
Login();
}

VerifyAuthTokens();
}
}

private void Login()
{
string userPassword = ConnectionString.GetValue(ConnectionStringKeys.PasswordKey);
Expand Down Expand Up @@ -413,9 +387,30 @@ private void VerifyGraphToken()
}
}

internal void SetRecordedEnvironmentVariables()
internal void SetEnvironmentVariables()
{
if (HttpMockServer.Mode == HttpRecorderMode.Playback)
if (HttpMockServer.Mode == HttpRecorderMode.Record)
{
//Restore/Add Subscription Id in MockServer from supplied connection string
if (HttpMockServer.Variables.ContainsCaseInsensitiveKey(ConnectionStringKeys.SubscriptionIdKey))
{
HttpMockServer.Variables.UpdateDictionary(ConnectionStringKeys.SubscriptionIdKey, SubscriptionId);
}
else
{
HttpMockServer.Variables.Add(ConnectionStringKeys.SubscriptionIdKey, SubscriptionId);
}

// If User has provided Access Token in RawToken/GraphToken Key-Value, we don't need to authenticate
// We currently only check for RawToken and do not check if GraphToken is provided
if (string.IsNullOrEmpty(ConnectionString.GetValue(ConnectionStringKeys.RawTokenKey)))
{
Login();
}

VerifyAuthTokens();
}
else if (HttpMockServer.Mode == HttpRecorderMode.Playback)
{
//Get Subscription Id from MockServer. Otherwise, assign zero guid
if (HttpMockServer.Variables.ContainsCaseInsensitiveKey(ConnectionStringKeys.SubscriptionIdKey))
Expand Down
2 changes: 1 addition & 1 deletion tools/TestFx/TestEnvironmentFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static TestEnvironmentFactory()

internal static TestEnvironment BuildTestFxEnvironment()
{
_environment.SetRecordedEnvironmentVariables();
_environment.SetEnvironmentVariables();
return _environment;
}

Expand Down

0 comments on commit 71c638a

Please sign in to comment.