Skip to content

Commit 9260f98

Browse files
authored
Merge pull request Azure#11031 from ninweninwe/network-december
[Network January] Disconnect VPN connections
2 parents b4acbd1 + 9445979 commit 9260f98

File tree

13 files changed

+42631
-1
lines changed

13 files changed

+42631
-1
lines changed

src/Network/Network.Test/ScenarioTests/CortexTests.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,13 @@ public void TestP2SCortexCRUD()
5858
{
5959
TestRunner.RunTestScript("Test-P2SCortexCRUD");
6060
}
61+
62+
[Fact]
63+
[Trait(Category.AcceptanceType, Category.LiveOnly)]
64+
[Trait(Category.Owner, NrpTeamAlias.brooklynft)]
65+
public void TestDisconnectAzP2sVpnGatewayVpnConnection()
66+
{
67+
TestRunner.RunTestScript("Test-DisconnectAzP2sVpnGatewayVpnConnection");
68+
}
6169
}
6270
}

src/Network/Network.Test/ScenarioTests/CortexTests.ps1

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,89 @@ function Test-CortexExpressRouteCRUD
683683
$delete = Remove-AzVirtualWan -InputObject $virtualWan -Force -PassThru
684684
Assert-AreEqual $True $delete
685685

686+
Clean-ResourceGroup $rgname
687+
}
688+
}
689+
690+
<#
691+
.SYNOPSIS
692+
Disconnect Point to site vpn gateway vpn connection
693+
#>
694+
function Test-DisconnectAzP2sVpnGatewayVpnConnection
695+
{
696+
param
697+
(
698+
$basedir = ".\"
699+
)
700+
701+
# Setup
702+
$rgname = Get-ResourceGroupName
703+
$rglocation = "East US"
704+
705+
$virtualWanName = Get-ResourceName
706+
$virtualHubName = Get-ResourceName
707+
$VpnServerConfiguration1Name = Get-ResourceName
708+
$P2SVpnGatewayName = Get-ResourceName
709+
710+
try
711+
{
712+
# Create the resource group
713+
New-AzResourceGroup -Name $rgname -Location $rglocation
714+
715+
# Create the Virtual Wan
716+
New-AzVirtualWan -ResourceGroupName $rgName -Name $virtualWanName -Location $rglocation
717+
$virtualWan = Get-AzVirtualWan -ResourceGroupName $rgName -Name $virtualWanName
718+
Assert-AreEqual $virtualWanName $virtualWan.Name
719+
720+
# Create the Virtual Hub
721+
New-AzVirtualHub -ResourceGroupName $rgName -Name $virtualHubName -Location $rglocation -AddressPrefix "192.168.1.0/24" -VirtualWan $virtualWan
722+
$virtualHub = Get-AzVirtualHub -ResourceGroupName $rgName -Name $virtualHubName
723+
Assert-AreEqual $virtualHubName $virtualHub.Name
724+
Assert-AreEqual $virtualWan.Id $virtualhub.VirtualWan.Id
725+
726+
# Create the VpnServerConfiguration1 with VpnClient settings using New-AzVpnServerConfiguration
727+
$VpnServerConfigCertFilePath = Join-Path -Path $basedir -ChildPath "\ScenarioTests\Data\ApplicationGatewayAuthCert.cer"
728+
$listOfCerts = New-Object "System.Collections.Generic.List[String]"
729+
$listOfCerts.Add($VpnServerConfigCertFilePath)
730+
$vpnclientipsecpolicy1 = New-AzVpnClientIpsecPolicy -IpsecEncryption AES256 -IpsecIntegrity SHA256 -SALifeTime 86471 -SADataSize 429496 -IkeEncryption AES256 -IkeIntegrity SHA384 -DhGroup DHGroup14 -PfsGroup PFS14
731+
New-AzVpnServerConfiguration -Name $VpnServerConfiguration1Name -ResourceGroupName $rgName -VpnProtocol IkeV2 -VpnAuthenticationType Certificate -VpnClientRootCertificateFilesList $listOfCerts -VpnClientRevokedCertificateFilesList $listOfCerts -VpnClientIpsecPolicy $vpnclientipsecpolicy1 -Location $rglocation
732+
733+
# Get created VpnServerConfiguration using Get-AzVpnServerConfiguration
734+
$vpnServerConfig1 = Get-AzVpnServerConfiguration -ResourceGroupName $rgName -Name $VpnServerConfiguration1Name
735+
Assert-NotNull $vpnServerConfig1
736+
737+
# Create the P2SVpnGateway using New-AzP2sVpnGateway
738+
$vpnClientAddressSpaces = New-Object string[] 2
739+
$vpnClientAddressSpaces[0] = "192.168.2.0/24"
740+
$vpnClientAddressSpaces[1] = "192.168.3.0/24"
741+
New-AzP2sVpnGateway -ResourceGroupName $rgName -Name $P2SvpnGatewayName -VirtualHub $virtualHub -VpnGatewayScaleUnit 1 -VpnClientAddressPool $vpnClientAddressSpaces -VpnServerConfiguration $vpnServerConfig1
742+
743+
# Get the created P2SVpnGateway using Get-AzP2sVpnGateway
744+
$P2SVpnGateway = Get-AzP2sVpnGateway -ResourceGroupName $rgName -Name $P2SvpnGatewayName
745+
Assert-AreEqual $P2SvpnGatewayName $P2SVpnGateway.Name
746+
Assert-AreEqual "Succeeded" $P2SVpnGateway.ProvisioningState
747+
748+
$expected = Disconnect-AzP2SVpnGatewayVpnConnection -ResourceGroupName $rgname -ResourceName $P2SvpnGatewayName -VpnConnectionId @("IKEv2_1e1cfe59-5c7c-4315-a876-b11fbfdfeed4")
749+
Assert-AreEqual $expected.Name $P2SVpnGateway.Name
750+
}
751+
finally
752+
{
753+
# Delete P2SVpnGateway using Remove-AzP2sVpnGateway
754+
$delete = Remove-AzP2sVpnGateway -Name $P2SVpnGatewayName -ResourceGroupName $rgName -Force -PassThru
755+
Assert-AreEqual $True $delete
756+
757+
# Delete VpnServerConfiguration1 using Remove-AzVpnServerConfiguration
758+
$delete = Remove-AzVpnServerConfiguration -ResourceGroupName $rgName -Name $VpnServerConfiguration1Name -Force -PassThru
759+
Assert-AreEqual $True $delete
760+
761+
# Delete Virtual hub
762+
$delete = Remove-AzVirtualHub -ResourceGroupName $rgname -Name $virtualHubName -Force -PassThru
763+
Assert-AreEqual $True $delete
764+
765+
# Delete Virtual wan
766+
$delete = Remove-AzVirtualWan -InputObject $virtualWan -Force -PassThru
767+
Assert-AreEqual $True $delete
768+
686769
Clean-ResourceGroup $rgname
687770
}
688771
}

src/Network/Network.Test/ScenarioTests/VirtualNetworkGatewayTests.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,5 +131,13 @@ public void TestVirtualNetworKGatewayPacketCapture()
131131
{
132132
TestRunner.RunTestScript("Test-VirtualNetworKGatewayPacketCapture");
133133
}
134+
135+
[Fact]
136+
[Trait(Category.AcceptanceType, Category.CheckIn)]
137+
[Trait(Category.Owner, NrpTeamAlias.brooklynft_subset2)]
138+
public void TestDisconnectVirtualNetworkGatewayVpnConnection()
139+
{
140+
TestRunner.RunTestScript("Test-DisconnectVNGVpnConnection");
141+
}
134142
}
135143
}

src/Network/Network.Test/ScenarioTests/VirtualNetworkGatewayTests.ps1

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1065,4 +1065,61 @@ function Test-VirtualNetworKGatewayPacketCapture
10651065
# Cleanup
10661066
Clean-ResourceGroup $rgname
10671067
}
1068-
}
1068+
}
1069+
1070+
<#
1071+
.SYNOPSIS
1072+
Disconnect Virtual network gateway Vpn Client Connection
1073+
#>
1074+
function Test-DisconnectVNGVpnConnection
1075+
{
1076+
param
1077+
(
1078+
$basedir = ".\"
1079+
)
1080+
1081+
# Setup
1082+
$rgname = Get-ResourceGroupName
1083+
$rname = Get-ResourceName
1084+
$domainNameLabel = Get-ResourceName
1085+
$vnetName = Get-ResourceName
1086+
$publicIpName = Get-ResourceName
1087+
$vnetGatewayConfigName = Get-ResourceName
1088+
$rglocation = "East US"
1089+
$location = $rglocation
1090+
1091+
try
1092+
{
1093+
# Create the resource group
1094+
New-AzResourceGroup -Name $rgname -Location $rglocation -Tags @{ testtag = "testval" }
1095+
1096+
# create the client root cert
1097+
$clientRootCertName = "BrkLiteTestMSFTRootCA.cer"
1098+
#[SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine")]
1099+
$samplePublicCertData = "MIIDUzCCAj+gAwIBAgIQRggGmrpGj4pCblTanQRNUjAJBgUrDgMCHQUAMDQxEjAQBgNVBAoTCU1pY3Jvc29mdDEeMBwGA1UEAxMVQnJrIExpdGUgVGVzdCBSb290IENBMB4XDTEzMDExOTAwMjQxOFoXDTIxMDExOTAwMjQxN1owNDESMBAGA1UEChMJTWljcm9zb2Z0MR4wHAYDVQQDExVCcmsgTGl0ZSBUZXN0IFJvb3QgQ0EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC7SmE+iPULK0Rs7mQBO/6a6B6/G9BaMxHgDGzAmSG0Qsyt5e08aqgFnPdkMl3zRJw3lPKGha/JCvHRNrO8UpeAfc4IXWaqxx2iBipHjwmHPHh7+VB8lU0EJcUe7WBAI2n/sgfCwc+xKtuyRVlOhT6qw/nAi8e5don/iHPU6q7GCcnqoqtceQ/pJ8m66cvAnxwJlBFOTninhb2VjtvOfMQ07zPP+ZuYDPxvX5v3nd6yDa98yW4dZPuiGO2s6zJAfOPT2BrtyvLekItnSgAw3U5C0bOb+8XVKaDZQXbGEtOw6NZvD4L2yLd47nGkN2QXloiPLGyetrj3Z2pZYcrZBo8hAgMBAAGjaTBnMGUGA1UdAQReMFyAEOncRAPNcvJDoe4WP/gH2U+hNjA0MRIwEAYDVQQKEwlNaWNyb3NvZnQxHjAcBgNVBAMTFUJyayBMaXRlIFRlc3QgUm9vdCBDQYIQRggGmrpGj4pCblTanQRNUjAJBgUrDgMCHQUAA4IBAQCGyHhMdygS0g2tEUtRT4KFM+qqUY5HBpbIXNAav1a1dmXpHQCziuuxxzu3iq4XwnWUF1OabdDE2cpxNDOWxSsIxfEBf9ifaoz/O1ToJ0K757q2Rm2NWqQ7bNN8ArhvkNWa95S9gk9ZHZLUcjqanf0F8taJCYgzcbUSp+VBe9DcN89sJpYvfiBiAsMVqGPc/fHJgTScK+8QYrTRMubtFmXHbzBSO/KTAP5rBTxse88EGjK5F8wcedvge2Ksk6XjL3sZ19+Oj8KTQ72wihN900p1WQldHrrnbixSpmHBXbHr9U0NQigrJp5NphfuU5j81C8ixvfUdwyLmTv7rNA7GTAD";
1100+
$rootCert = New-AzVpnClientRootCertificate -Name $clientRootCertName -PublicCertData $samplePublicCertData
1101+
1102+
# Create the Virtual Network
1103+
$subnet = New-AzVirtualNetworkSubnetConfig -Name "GatewaySubnet" -AddressPrefix 10.0.0.0/24
1104+
$vnet = New-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname -Location $location -AddressPrefix 10.0.0.0/16 -Subnet $subnet
1105+
$vnet = Get-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname
1106+
$subnet = Get-AzVirtualNetworkSubnetConfig -Name "GatewaySubnet" -VirtualNetwork $vnet
1107+
1108+
# Create the IP config
1109+
$publicip = New-AzPublicIpAddress -ResourceGroupName $rgname -name $publicIpName -location $location -AllocationMethod Dynamic -DomainNameLabel $domainNameLabel
1110+
$vnetIpConfig = New-AzVirtualNetworkGatewayIpConfig -Name $vnetGatewayConfigName -PublicIpAddress $publicip -Subnet $subnet
1111+
1112+
# Create & Get P2S virtualnetworkgateway
1113+
New-AzVirtualNetworkGateway -ResourceGroupName $rgname -name $rname -location $location -IpConfigurations $vnetIpConfig -GatewayType Vpn -VpnType RouteBased -EnableBgp $false -GatewaySku VpnGw1 -VpnClientAddressPool 201.169.0.0/16 -VpnClientRootCertificates $rootCert
1114+
$actual = Get-AzVirtualNetworkGateway -ResourceGroupName $rgname -name $rname
1115+
Assert-AreEqual "Succeeded" $actual.ProvisioningState
1116+
1117+
$expected = Disconnect-AzVirtualNetworkGatewayVpnConnection -ResourceGroupName $rgname -ResourceName $rname -VpnConnectionId @("IKEv2_1e1cfe59-5c7c-4315-a876-b11fbfdfeed4")
1118+
Assert-AreEqual $expected.Name $actual.Name
1119+
}
1120+
finally
1121+
{
1122+
# Cleanup
1123+
Clean-ResourceGroup $rgname
1124+
}
1125+
}

0 commit comments

Comments
 (0)