Skip to content

Commit 8e808d6

Browse files
authored
Add support for Synapse AD only Authentication (#17730)
1 parent 28ce971 commit 8e808d6

18 files changed

+5242
-3
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
namespace Microsoft.Azure.Commands.Synapse.Test.ScenarioTests
16+
{
17+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
18+
using ServiceManagement.Common.Models;
19+
using Xunit;
20+
21+
public class ADOnlyAuthenticationTests : SynapseTestBase
22+
{
23+
public XunitTracingInterceptor _logger;
24+
25+
public ADOnlyAuthenticationTests(Xunit.Abstractions.ITestOutputHelper output)
26+
{
27+
_logger = new XunitTracingInterceptor(output);
28+
XunitTracingInterceptor.AddToContext(_logger);
29+
}
30+
31+
[Fact]
32+
[Trait(Category.AcceptanceType, Category.All)]
33+
public void TestEnableSynapseADOnlyAuthentication()
34+
{
35+
SynapseTestBase.NewInstance.RunPsTest(
36+
_logger,
37+
"Test-EnableSynapseADOnlyAuthentication");
38+
}
39+
40+
[Fact]
41+
public void TestDisableSynapseADOnlyAuthentication()
42+
{
43+
SynapseTestBase.NewInstance.RunPsTest(
44+
_logger,
45+
"Test-DisableSynapseADOnlyAuthentication");
46+
}
47+
}
48+
}
49+
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
<#
2+
.SYNOPSIS
3+
Tests Synapse Active Directory only authentication (enable,disable).
4+
#>
5+
function Test-DisableSynapseADOnlyAuthentication
6+
{
7+
# Setup
8+
$testSuffix = getAssetName
9+
Create-WorkspaceTestEnvironment $testSuffix
10+
$params = Get-WorkspaceTestEnvironmentParameters $testSuffix
11+
12+
$resourceGroupName = $params.rgname
13+
$workspaceName = $params.workspaceName
14+
15+
try
16+
{
17+
$disabledADOnlyAuthentication = Disable-AzSynapseActiveDirectoryOnlyAuthentication -ResourceGroupName $resourceGroupName -WorkspaceName $workspaceName
18+
# Wait for 10 seconds for the completion
19+
[Microsoft.Rest.ClientRuntime.Azure.TestFramework.TestUtilities]::Wait(10000)
20+
$disabledAuthenticationProperty = $disabledADOnlyAuthentication.AzureADOnlyAuthenticationProperty
21+
22+
Assert-NotNull {$disabledAuthenticationProperty}
23+
Assert-AreEqual $False $disabledAuthenticationProperty
24+
25+
$getADOnlyAuthentication = Get-AzSynapseActiveDirectoryOnlyAuthentication -ResourceGroupName $resourceGroupName -WorkspaceName $workspaceName
26+
$acquiredAuthenticationProperty = $getADOnlyAuthentication.AzureADOnlyAuthenticationProperty
27+
28+
Assert-NotNull {$acquiredAuthenticationProperty}
29+
Assert-AreEqual $False $acquiredAuthenticationProperty
30+
31+
Assert-AreEqual $disabledAuthenticationProperty $acquiredAuthenticationProperty
32+
}
33+
finally
34+
{
35+
# Cleanup
36+
Remove-WorkspaceTestEnvironment $testSuffix
37+
}
38+
}
39+
40+
function Test-EnableSynapseADOnlyAuthentication
41+
{
42+
# Setup
43+
$testSuffix = getAssetName
44+
Create-WorkspaceTestEnvironment $testSuffix
45+
$params = Get-WorkspaceTestEnvironmentParameters $testSuffix
46+
47+
$resourceGroupName = $params.rgname
48+
$workspaceName = $params.workspaceName
49+
50+
try
51+
{
52+
$enabledADOnlyAuthentication = Enable-AzSynapseActiveDirectoryOnlyAuthentication -ResourceGroupName $resourceGroupName -WorkspaceName $workspaceName
53+
# Wait for 10 seconds for the completion
54+
[Microsoft.Rest.ClientRuntime.Azure.TestFramework.TestUtilities]::Wait(10000)
55+
$enabledAuthenticationProperty = $enabledADOnlyAuthentication.AzureADOnlyAuthenticationProperty
56+
57+
Assert-NotNull {$enabledADOnlyAuthentication}
58+
Assert-AreEqual $True $enabledAuthenticationProperty
59+
60+
$getADOnlyAuthentication = Get-AzSynapseActiveDirectoryOnlyAuthentication -ResourceGroupName $resourceGroupName -WorkspaceName $workspaceName
61+
$acquiredAuthenticationProperty = $getADOnlyAuthentication.AzureADOnlyAuthenticationProperty
62+
63+
Assert-NotNull {$acquiredAuthenticationProperty}
64+
Assert-AreEqual $True $acquiredAuthenticationProperty
65+
66+
Assert-AreEqual $enabledAuthenticationProperty $acquiredAuthenticationProperty
67+
}
68+
finally
69+
{
70+
# Cleanup
71+
Remove-WorkspaceTestEnvironment $testSuffix
72+
}
73+
}
74+
75+
76+
<#
77+
.SYNOPSIS
78+
Creates the test environment needed to perform the tests
79+
#>
80+
function Create-WorkspaceTestEnvironment ($testSuffix)
81+
{
82+
$params = Get-WorkspaceTestEnvironmentParameters $testSuffix
83+
Create-WorkspaceTestEnvironmentWithParams $params $params.location
84+
}
85+
86+
<#
87+
.SYNOPSIS
88+
Creates the test environment needed to perform the Sql auditing tests
89+
#>
90+
function Create-WorkspaceTestEnvironmentWithParams ($params, $location, $denyAsNetworkRuleDefaultAction = $False)
91+
{
92+
New-AzResourceGroup -Name $params.rgname -Location $location
93+
New-AzStorageAccount -ResourceGroupName $params.rgname -Name $params.storageAccountName -Location $location -SkuName Standard_GRS -Kind StorageV2 -EnableHierarchicalNamespace $true
94+
$workspaceName = $params.workspaceName
95+
$workspaceLogin = $params.loginName
96+
$workspacePassword = $params.pwd
97+
$credentials = new-object System.Management.Automation.PSCredential($workspaceLogin, ($workspacePassword | ConvertTo-SecureString -asPlainText -Force))
98+
New-AzSynapseWorkspace -ResourceGroupName $params.rgname -WorkspaceName $params.workspaceName -Location $location -SqlAdministratorLoginCredential $credentials -DefaultDataLakeStorageAccountName $params.storageAccountName -DefaultDataLakeStorageFilesystem $params.fileSystemName -ManagedResourceGroupName $params.managedresourcegroupName
99+
Wait-Seconds 10
100+
}
101+
102+
<#
103+
.SYNOPSIS
104+
Gets the values of the parameters used at the tests
105+
#>
106+
function Get-WorkspaceTestEnvironmentParameters ($testSuffix)
107+
{
108+
return @{ rgname = "adonly-cmdlet-test-rg" +$testSuffix;
109+
workspaceName = "adonly-ws" +$testSuffix;
110+
managedresourcegroupName = "mrg" + $testSuffix;
111+
storageAccountName = "wsstorage" + $testSuffix;
112+
fileSystemName = "wscmdletfs" + $testSuffix;
113+
loginName = "testlogin";
114+
pwd = "testp@ssMakingIt1007Longer";
115+
location = "eastus2euap";
116+
}
117+
}
118+
119+
<#
120+
.SYNOPSIS
121+
Removes the test environment that was needed to perform the tests
122+
#>
123+
function Remove-WorkspaceTestEnvironment ($testSuffix)
124+
{
125+
$params = Get-WorkspaceTestEnvironmentParameters $testSuffix
126+
Remove-AzResourceGroup -Name $params.rgname -Force
127+
}

0 commit comments

Comments
 (0)