Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' != 'net472'">
<PackageReference Include="Microsoft.Azure.Management.Sql" Version="1.20.0-preview" />
<PackageReference Include="Microsoft.Azure.Management.Sql" Version="1.20.1-preview" />
<PackageReference Include="Microsoft.Azure.Management.Network" Version="19.5.0-preview" />
<PackageReference Include="Microsoft.Azure.Graph.RBAC" Version="3.2.0-preview" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
</Reference>
<Reference Include="Microsoft.Azure.Management.Sql, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Sql.1.20.0-preview\lib\net452\Microsoft.Azure.Management.Sql.dll</HintPath>
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Sql.1.20.1-preview\lib\net452\Microsoft.Azure.Management.Sql.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Azure.Management.Storage">
Expand All @@ -67,6 +67,7 @@
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="ScenarioTests\ManagedInstanceCrudScenarioTests.cs" />
<Compile Include="ScenarioTests\ManagedInstanceProtectorTests.cs" />
<Compile Include="ScenarioTests\ManagedInstanceKeyVaultKeyTests.cs" />
<Compile Include="ScenarioTests\TDECertificateTests.cs" />
Expand All @@ -89,6 +90,9 @@
<Compile Include="ScenarioTests\DatabaseReplicationTests.cs" />
<Compile Include="ScenarioTests\DatabaseCrudTests.cs" />
<Compile Include="ScenarioTests\DataMaskingTests.cs" />
<None Include="ScenarioTests\ManagedInstanceCrudScenarioTests.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="ScenarioTests\ManagedInstanceProtectorTests.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down Expand Up @@ -987,6 +991,24 @@
<None Include=".\SessionRecords\Microsoft.Azure.Commands.Sql.Test.ScenarioTests.ManagedInstanceProtectorTests\TestSetGetManagedInstanceEncryptionProtectorByokFailsWithoutKeyId.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include=".\SessionRecords\Microsoft.Azure.Commands.Sql.Test.ScenarioTests.ManagedInstanceCrudScenarioTests\TestCreateManagedInstance.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include=".\SessionRecords\Microsoft.Azure.Commands.Sql.Test.ScenarioTests.ManagedInstanceCrudScenarioTests\TestCreateManagedInstanceWithIdentity.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include=".\SessionRecords\Microsoft.Azure.Commands.Sql.Test.ScenarioTests.ManagedInstanceCrudScenarioTests\TestGetManagedInstance.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include=".\SessionRecords\Microsoft.Azure.Commands.Sql.Test.ScenarioTests.ManagedInstanceCrudScenarioTests\TestRemoveManagedInstance.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include=".\SessionRecords\Microsoft.Azure.Commands.Sql.Test.ScenarioTests.ManagedInstanceCrudScenarioTests\TestSetManagedInstance.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include=".\SessionRecords\Microsoft.Azure.Commands.Sql.Test.ScenarioTests.ManagedInstanceCrudScenarioTests\TestUpdateManagedInstance.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Properties\Resources.resx">
Expand Down
23 changes: 23 additions & 0 deletions src/ResourceManager/Sql/Commands.Sql.Test/ScenarioTests/Common.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ function Create-BasicTestEnvironmentWithParams ($params, $location, $serverVersi
New-AzureRmResourceGroup -Name $params.rgname -Location $location
$serverName = $params.serverName
$serverLogin = "testusername"
<#[SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Test passwords only valid for the duration of the test")]#>
$serverPassword = "t357ingP@s5w0rd!Sec"
$credentials = new-object System.Management.Automation.PSCredential($serverLogin, ($serverPassword | ConvertTo-SecureString -asPlainText -Force))
New-AzureRmSqlServer -ResourceGroupName $params.rgname -ServerName $params.serverName -Location $location -ServerVersion $serverVersion -SqlAdministratorCredentials $credentials
Expand Down Expand Up @@ -297,6 +298,7 @@ function Create-ServerKeyVaultKeyTestEnvironment ($params)

# Create Server
$serverLogin = "testusername"
<#[SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Test passwords only valid for the duration of the test")]#>
$serverPassword = "t357ingP@s5w0rd!"
$credentials = new-object System.Management.Automation.PSCredential($serverLogin, ($serverPassword | ConvertTo-SecureString -asPlainText -Force))
$server = New-AzureRmSqlServer -ResourceGroupName $rg.ResourceGroupName -ServerName $params.serverName -Location $params.location -ServerVersion "12.0" -SqlAdministratorCredentials $credentials
Expand Down Expand Up @@ -481,6 +483,15 @@ function Get-ManagedDatabaseName
return getAssetName
}

<#
.SYNOPSIS
Gets valid managed instance name
#>
function Get-VNetName
{
return getAssetName
}

<#
.SYNOPSIS
Gets test mode - 'Record' or 'Playback'
Expand Down Expand Up @@ -543,6 +554,17 @@ function Create-ResourceGroupForTest ($location = "westcentralus")
return $rg
}

<#
.SYNOPSIS
Creates a resource group for tests
#>
function Create-ResourceGroupWithName ($rgName, $location = "westcentralus")
{
$rg = New-AzureRmResourceGroup -Name $rgName -Location $location

return $rg
}

<#
.SYNOPSIS
removes a resource group that was used for testing
Expand Down Expand Up @@ -573,6 +595,7 @@ function Get-Credential ($serverLogin)
{
$serverLogin = Get-UserName
}
<#[SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Test passwords only valid for the duration of the test")]#>
$serverPassword = "t357ingP@s5w0rd!"
$credentials = new-object System.Management.Automation.PSCredential($serverLogin, ($serverPassword | ConvertTo-SecureString -asPlainText -Force))
return $credentials
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,20 @@
using Microsoft.WindowsAzure.Commands.ScenarioTest;
using Xunit;
using Xunit.Abstractions;
using RestTestFramework = Microsoft.Rest.ClientRuntime.Azure.TestFramework;

namespace Microsoft.Azure.Commands.Sql.Test.ScenarioTests
{
public class ManagedInstanceCrudScenarioTests : SqlTestsBase
{
protected override void SetupManagementClients(RestTestFramework.MockContext context)
{
var sqlClient = GetSqlClient(context);
var newResourcesClient = GetResourcesClient(context);
var networkClient = GetNetworkClient(context);
Helper.SetupSomeOfManagementClients(sqlClient, newResourcesClient, networkClient);
}

public ManagedInstanceCrudScenarioTests(ITestOutputHelper output) : base(output)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@
function Test-CreateManagedInstance
{
# Setup
$rg = Create-ResourceGroupForTest

$rgName = "ps2110"
$rg = Create-ResourceGroupWithName($rgName)
$vnetName1 = "ps2255"
$managedInstanceName = Get-ManagedInstanceName
$version = "12.0"
$managedInstanceLogin = "dummylogin"
<#[SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Test passwords only valid for the duration of the test")]#>
$managedInstancePassword = "Un53cuRE!"
$subnetId = "/subscriptions/ee5ea899-0791-418f-9270-77cd8273794b/resourceGroups/cl_one/providers/Microsoft.Network/virtualNetworks/cl_initial/subnets/CooL"
$licenseType = "BasePrice"
$storageSizeInGB = 32
$vCore = 16
Expand All @@ -36,10 +37,14 @@ function Test-CreateManagedInstance

try
{
# Setup VNET
$virtualNetwork1 = CreateAndGetVirtualNetworkForManagedInstance $rg $vnetName1 $rg.Location
$subnetId = $virtualNetwork1.Subnets[0].Id

# With SKU name specified
$job = New-AzureRmSqlManagedInstance -ResourceGroupName $rg.ResourceGroupName -Name $managedInstanceName `
-Location $rg.Location -AdministratorCredential $credentials -SubnetId $subnetId `
-LicenseType $licenseType -StorageSizeInGB $storageSizeInGB -Vcore $vCore -SkuName $skuName -AsJob
-LicenseType $licenseType -StorageSizeInGB $storageSizeInGB -Vcore $vCore -SkuName $skuName -AsJob
$job | Wait-Job
$managedInstance1 = $job.Output

Expand All @@ -56,12 +61,13 @@ function Test-CreateManagedInstance

$edition = "GeneralPurpose"
$computeGeneration = "Gen4"
$dnsZonePartner = $managedInstance1.ResourceId
$managedInstanceName = Get-ManagedInstanceName

# With edition and computeGeneration specified
$job = New-AzureRmSqlManagedInstance -ResourceGroupName $rg.ResourceGroupName -Name $managedInstanceName `
-Location $rg.Location -AdministratorCredential $credentials -SubnetId $subnetId `
-LicenseType $licenseType -StorageSizeInGB $storageSizeInGB -Vcore $vCore -Edition $edition -ComputeGeneration $computeGeneration -AsJob
-LicenseType $licenseType -StorageSizeInGB $storageSizeInGB -Vcore $vCore -Edition $edition -ComputeGeneration $computeGeneration -DnsZonePartner $dnsZonePartner -AsJob
$job | Wait-Job
$managedInstance1 = $job.Output

Expand Down Expand Up @@ -97,6 +103,7 @@ function Test-SetManagedInstance
try
{
# Test using parameters
<#[SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Test passwords only valid for the duration of the test")]#>
$managedInstancePassword = "n3wc00lP@55w0rd"
$licenseType = "BasePrice"
$storageSizeInGB = 64
Expand All @@ -115,6 +122,7 @@ function Test-SetManagedInstance
Assert-StartsWith ($managedInstance1.ManagedInstanceName + ".") $managedInstance1.FullyQualifiedDomainName

# Test using piping
<#[SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Test passwords only valid for the duration of the test")]#>
$managedInstancePassword = "n3wc00lP@55w0rd!!!"
$secureString = ConvertTo-SecureString $managedInstancePassword -AsPlainText -Force

Expand All @@ -133,6 +141,7 @@ function Test-SetManagedInstance
Assert-StartsWith ($managedInstance2.ManagedInstanceName + ".") $managedInstance2.FullyQualifiedDomainName

# Test Set using InputObject
<#[SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Test passwords only valid for the duration of the test")]#>
$managedInstancePassword = "n3wc00lP@55w0rd4321"
$licenseType = "BasePrice"
$storageSizeInGB = 64
Expand All @@ -151,6 +160,7 @@ function Test-SetManagedInstance
Assert-StartsWith ($managedInstance3.ManagedInstanceName + ".") $managedInstance3.FullyQualifiedDomainName

# Test Set using ResourceId
<#[SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Test passwords only valid for the duration of the test")]#>
$managedInstancePassword = "n3wc00lP@55w0rd4321"
$licenseType = "BasePrice"
$storageSizeInGB = 32
Expand Down Expand Up @@ -189,6 +199,7 @@ function Test-UpdateManagedInstance
try
{
# Test update using all parameters
<#[SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Test passwords only valid for the duration of the test")]#>
$managedInstancePassword = "n3wc00lP@55w0rd"
$licenseType = "BasePrice"
$storageSizeInGB = 64
Expand All @@ -207,6 +218,7 @@ function Test-UpdateManagedInstance
Assert-StartsWith ($managedInstance1.ManagedInstanceName + ".") $managedInstance1.FullyQualifiedDomainName

# Test update using piping
<#[SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Test passwords only valid for the duration of the test")]#>
$managedInstancePassword = "n3wc00lP@55w0rd1234!!!"
$secureString = ConvertTo-SecureString $managedInstancePassword -AsPlainText -Force

Expand All @@ -225,6 +237,7 @@ function Test-UpdateManagedInstance
Assert-StartsWith ($managedInstance2.ManagedInstanceName + ".") $managedInstance2.FullyQualifiedDomainName

# Test update using InputObject
<#[SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Test passwords only valid for the duration of the test")]#>
$managedInstancePassword = "n3wc00lP@55w0rd4321"
$licenseType = "BasePrice"
$storageSizeInGB = 64
Expand All @@ -243,6 +256,7 @@ function Test-UpdateManagedInstance
Assert-StartsWith ($managedInstance3.ManagedInstanceName + ".") $managedInstance3.FullyQualifiedDomainName

# Test update using ResourceId
<#[SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Test passwords only valid for the duration of the test")]#>
$managedInstancePassword = "n3wc00lP@55w0rd4321"
$licenseType = "BasePrice"
$storageSizeInGB = 32
Expand Down Expand Up @@ -360,6 +374,7 @@ function Test-CreateManagedInstanceWithIdentity
$managedInstanceName = Get-ManagedInstanceName
$version = "12.0"
$managedInstanceLogin = "login"
<#[SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Test passwords only valid for the duration of the test")]#>
$managedInstancePassword = "Un5!"
$subnetId = "/subscriptions/ee5ea899-0791-418f-9270-77cd8273794b/resourceGroups/cl_one/providers/Microsoft.Network/virtualNetworks/cl_initial/subnets/CooL"
$licenseType = "BasePrice"
Expand All @@ -382,4 +397,54 @@ function Test-CreateManagedInstanceWithIdentity
{
Remove-ResourceGroupForTest $rg
}
}


<#
.SYNOPSIS
Create a virtual network
#>
function CreateAndGetVirtualNetworkForManagedInstance ($resourceGroup, $vnetName, $location = "westcentralus")
{
$vNetAddressPrefix = "10.0.0.0/16"
$defaultSubnetName = "default"
$defaultSubnetAddressPrefix = "10.0.0.0/24"

$virtualNetwork = New-AzureRmVirtualNetwork `
-ResourceGroupName $resourceGroup.ResourceGroupName `
-Location $location `
-Name $vNetName `
-AddressPrefix $vNetAddressPrefix

$subnetConfig = Add-AzureRmVirtualNetworkSubnetConfig `
-Name $defaultSubnetName `
-AddressPrefix $defaultSubnetAddressPrefix `
-VirtualNetwork $virtualNetwork

$virtualNetwork | Set-AzureRmVirtualNetwork

$routeTableMiManagementService = New-AzureRmRouteTable `
-Name 'myRouteTableMiManagementService' `
-ResourceGroupName $resourceGroup.ResourceGroupName `
-location $location

Set-AzureRmVirtualNetworkSubnetConfig `
-VirtualNetwork $virtualNetwork `
-Name $defaultSubnetName `
-AddressPrefix $defaultSubnetAddressPrefix `
-RouteTable $routeTableMiManagementService | `
Set-AzureRmVirtualNetwork

Get-AzureRmRouteTable `
-ResourceGroupName $resourceGroup.ResourceGroupName `
-Name "myRouteTableMiManagementService" `
| Add-AzureRmRouteConfig `
-Name "ToManagedInstanceManagementService" `
-AddressPrefix 0.0.0.0/0 `
-NextHopType "Internet" `
| Set-AzureRmRouteTable

$getVnet = Get-AzureRmVirtualNetwork -Name $vnetName -ResourceGroupName $resourceGroup.ResourceGroupName

return $getVnet
}
Loading