Skip to content

Commit 84039d9

Browse files
authored
Merge pull request #8227 from talhers/master
Adding Advanced Threat Protection and Vulnerability Assessment cmdlets on Managed Instance
2 parents a708cac + f0f4127 commit 84039d9

File tree

97 files changed

+63843
-455
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+63843
-455
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
using Microsoft.Azure.Commands.ScenarioTest.SqlTests;
16+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
17+
using Xunit;
18+
using Xunit.Abstractions;
19+
using RestTestFramework = Microsoft.Rest.ClientRuntime.Azure.TestFramework;
20+
21+
namespace Microsoft.Azure.Commands.Sql.Test.ScenarioTests
22+
{
23+
public class AdvancedDataSecurityManagedInstanceTests : SqlTestsBase
24+
{
25+
protected override void SetupManagementClients(RestTestFramework.MockContext context)
26+
{
27+
var sqlClient = GetSqlClient(context);
28+
var resourcesClient = GetResourcesClient(context);
29+
var networkClient = GetNetworkClient(context);
30+
Helper.SetupSomeOfManagementClients(sqlClient, networkClient, resourcesClient);
31+
}
32+
33+
public AdvancedDataSecurityManagedInstanceTests(ITestOutputHelper output) : base(output)
34+
{
35+
}
36+
37+
[Fact]
38+
[Trait(Category.AcceptanceType, Category.CheckIn)]
39+
public void AdvancedDataSecurityPolicyTest()
40+
{
41+
RunPowerShellTest("Test-AdvancedDataSecurityPolicyManagedInstanceTest");
42+
}
43+
}
44+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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+
<#
16+
.SYNOPSIS
17+
Tests the Advanced Threat Protection Policy cmdlets
18+
#>
19+
function Test-AdvancedDataSecurityPolicyManagedInstanceTest
20+
{
21+
# Setup
22+
$testSuffix = getAssetName
23+
Create-AdvancedThreatProtectionManagedInstanceTestEnvironment $testSuffix
24+
$params = Get-SqlAdvancedThreatProtectionManagedInstanceTestEnvironmentParameters $testSuffix
25+
26+
try
27+
{
28+
# Get Advanced Threat Protection Policy
29+
$policy = Get-AzSqlInstanceAdvancedDataSecurityPolicy -ResourceGroupName $params.rgname -InstanceName $params.serverName
30+
31+
# Validate the policy
32+
Assert-AreEqual $params.rgname $policy.ResourceGroupName
33+
Assert-AreEqual $params.serverName $policy.ManagedInstanceName
34+
Assert-False { $policy.IsEnabled }
35+
36+
# Enabled Advanced Threat Protection Policy
37+
Enable-AzSqlInstanceAdvancedDataSecurity -ResourceGroupName $params.rgname -InstanceName $params.serverName
38+
$policy = Get-AzSqlInstanceAdvancedDataSecurityPolicy -ResourceGroupName $params.rgname -InstanceName $params.serverName
39+
40+
# Validate the policy
41+
Assert-AreEqual $params.rgname $policy.ResourceGroupName
42+
Assert-AreEqual $params.serverName $policy.ManagedInstanceName
43+
Assert-True { $policy.IsEnabled }
44+
45+
# Disable Advanced Threat Protection Policy
46+
Disable-AzSqlInstanceAdvancedDataSecurity -ResourceGroupName $params.rgname -InstanceName $params.serverName
47+
$policy = Get-AzSqlInstanceAdvancedDataSecurityPolicy -ResourceGroupName $params.rgname -InstanceName $params.serverName
48+
49+
# Validate the policy
50+
Assert-AreEqual $params.rgname $policy.ResourceGroupName
51+
Assert-AreEqual $params.serverName $policy.ManagedInstanceName
52+
Assert-False { $policy.IsEnabled }
53+
}
54+
finally
55+
{
56+
# Cleanup
57+
Remove-AdvancedThreatProtectionManagedInstanceTestEnvironment $testSuffix
58+
}
59+
}
60+
61+
<#
62+
.SYNOPSIS
63+
Creates the test environment needed to perform the tests
64+
#>
65+
function Create-AdvancedThreatProtectionManagedInstanceTestEnvironment ($testSuffix, $location = "West Central US")
66+
{
67+
$params = Get-SqlAdvancedThreatProtectionManagedInstanceTestEnvironmentParameters $testSuffix
68+
Create-BasicManagedTestEnvironmentWithParams $params $location
69+
}
70+
71+
<#
72+
.SYNOPSIS
73+
Gets the values of the parameters used at the tests
74+
#>
75+
function Get-SqlAdvancedThreatProtectionManagedInstanceTestEnvironmentParameters ($testSuffix)
76+
{
77+
return @{ rgname = "sql-atp-cmdlet-test-rg" +$testSuffix;
78+
serverName = "sql-atp-cmdlet-server" +$testSuffix;
79+
databaseName = "sql-atp-cmdlet-db" + $testSuffix;
80+
}
81+
}
82+
83+
<#
84+
.SYNOPSIS
85+
Removes the test environment that was needed to perform the tests
86+
#>
87+
function Remove-AdvancedThreatProtectionManagedInstanceTestEnvironment ($testSuffix)
88+
{
89+
$params = Get-SqlAdvancedThreatProtectionManagedInstanceTestEnvironmentParameters $testSuffix
90+
Remove-AzureRmResourceGroup -Name $params.rgname -Force
91+
}

src/Sql/Sql.Test/ScenarioTests/Common.ps1

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,17 @@ function Create-TestEnvironmentWithParams ($params, $location, $serverVersion)
144144
Wait-Seconds 10
145145
}
146146

147+
<#
148+
.SYNOPSIS
149+
Creates the test environment needed to perform the Sql vulnerability assessment tests on managed instance
150+
#>
151+
function Create-InstanceTestEnvironmentWithParams ($params, $location)
152+
{
153+
Create-BasicManagedTestEnvironmentWithParams $params $location
154+
155+
New-AzureRmStorageAccount -StorageAccountName $params.storageAccount -ResourceGroupName $params.rgname -Location $location -Type Standard_GRS
156+
}
157+
147158
<#
148159
.SYNOPSIS
149160
Creates the test environment needed to perform the Sql auditing tests
@@ -177,6 +188,33 @@ function Create-BasicTestEnvironmentWithParams ($params, $location, $serverVersi
177188
New-AzSqlDatabase -DatabaseName $params.databaseName -ResourceGroupName $params.rgname -ServerName $params.serverName -Edition Basic
178189
}
179190

191+
<#
192+
.SYNOPSIS
193+
Creates the basic test environment needed to perform the Sql data security tests - resource group, managed instance and managed database
194+
#>
195+
function Create-BasicManagedTestEnvironmentWithParams ($params, $location)
196+
{
197+
New-AzureRmResourceGroup -Name $params.rgname -Location $location
198+
199+
# Setup VNET
200+
$vnetName = "cl_initial"
201+
$subnetName = "Cool"
202+
$virtualNetwork1 = CreateAndGetVirtualNetworkForManagedInstance $vnetName $subnetName
203+
$subnetId = $virtualNetwork1.Subnets.where({ $_.Name -eq $subnetName }).Id
204+
$credentials = Get-ServerCredential
205+
$licenseType = "BasePrice"
206+
$storageSizeInGB = 32
207+
$vCore = 16
208+
$skuName = "GP_Gen4"
209+
$collation = "SQL_Latin1_General_CP1_CI_AS"
210+
211+
$managedInstance = New-AzureRmSqlInstance -ResourceGroupName $params.rgname -Name $params.serverName `
212+
-Location $location -AdministratorCredential $credentials -SubnetId $subnetId `
213+
-LicenseType $licenseType -StorageSizeInGB $storageSizeInGB -Vcore $vCore -SkuName $skuName
214+
215+
New-AzureRmSqlInstanceDatabase -ResourceGroupName $params.rgname -InstanceName $params.serverName -Name $params.databaseName -Collation $collation
216+
}
217+
180218
<#
181219
.SYNOPSIS
182220
Creates the test environment needed to perform the Sql data masking tests
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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+
using Microsoft.Azure.Commands.ScenarioTest.SqlTests;
16+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
17+
using Xunit;
18+
using Xunit.Abstractions;
19+
using RestTestFramework = Microsoft.Rest.ClientRuntime.Azure.TestFramework;
20+
21+
namespace Microsoft.Azure.Commands.Sql.Test.ScenarioTests
22+
{
23+
public class VulnerabilityAssessmentMiTests : SqlTestsBase
24+
{
25+
protected override void SetupManagementClients(RestTestFramework.MockContext context)
26+
{
27+
var sqlClient = GetSqlClient(context);
28+
var storageV2Client = GetStorageManagementClient(context);
29+
var newResourcesClient = GetResourcesClient(context);
30+
var networkClient = GetNetworkClient(context);
31+
Helper.SetupSomeOfManagementClients(sqlClient, storageV2Client, newResourcesClient, networkClient);
32+
33+
}
34+
35+
public VulnerabilityAssessmentMiTests(ITestOutputHelper output) : base(output)
36+
{
37+
}
38+
39+
#region Policy Tests
40+
41+
[Fact]
42+
[Trait(Category.AcceptanceType, Category.CheckIn)]
43+
public void VulnerabilityAssessmentManagedInstanceWithAtpOffTest()
44+
{
45+
RunPowerShellTest("Test-VulnerabilityAssessmentManagedInstanceWithAtpOffTest");
46+
}
47+
48+
[Fact]
49+
[Trait(Category.AcceptanceType, Category.CheckIn)]
50+
public void VulnerabilityAssessmentManagedInstanceWithSettingsNotDefinedTest()
51+
{
52+
RunPowerShellTest("Test-VulnerabilityAssessmentManagedInstanceWithSettingsNotDefinedTest");
53+
}
54+
55+
[Fact]
56+
[Trait(Category.AcceptanceType, Category.CheckIn)]
57+
public void VulnerabilityAssessmentManagedInstanceSettingsTest()
58+
{
59+
RunPowerShellTest("Test-VulnerabilityAssessmentManagedInstanceSettingsTest");
60+
}
61+
62+
#endregion
63+
64+
#region Baseline Tests
65+
66+
[Fact]
67+
[Trait(Category.AcceptanceType, Category.CheckIn)]
68+
public void VulnerabilityAssessmentManagedInstanceBaselineTest()
69+
{
70+
RunPowerShellTest("Test-VulnerabilityAssessmentManagedInstanceBaselineTest");
71+
}
72+
73+
#endregion
74+
75+
#region Scan Tests
76+
77+
[Fact]
78+
[Trait(Category.AcceptanceType, Category.CheckIn)]
79+
public void VulnerabilityAssessmentManagedInstanceScanRecordGetListTest()
80+
{
81+
RunPowerShellTest("Test-VulnerabilityAssessmentManagedInstanceScanRecordGetListTest");
82+
}
83+
84+
[Fact]
85+
[Trait(Category.AcceptanceType, Category.CheckIn)]
86+
public void VulnerabilityAssessmentManagedInstanceScanConvertTest()
87+
{
88+
RunPowerShellTest("Test-VulnerabilityAssessmentManagedInstanceScanConvertTest");
89+
}
90+
91+
#endregion
92+
}
93+
}

0 commit comments

Comments
 (0)