Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Khushboo Baheti committed Apr 2, 2021
1 parent 597e261 commit 6f04587
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -420,11 +420,13 @@ function Test-VirtualNetworkGatewayConnectionCRUD

# Create VirtualNetworkGateway
$vnetIpConfig = New-AzVirtualNetworkGatewayIpConfig -Name $vnetGatewayConfigName -PublicIpAddress $publicip -Subnet $subnet

$actual = New-AzVirtualNetworkGateway -ResourceGroupName $rgname -name $rname -location $location -IpConfigurations $vnetIpConfig -GatewayType Vpn -VpnType RouteBased -EnableBgp $false
$natRule1 = New-AzVirtualNetworkGatewayNatRule -Name "natRule1" -Type "Static" -Mode "IngressSnat" -InternalMapping @("25.0.0.0/16") -ExternalMapping @("30.0.0.0/16")
$natRule2 = New-AzVirtualNetworkGatewayNatRule -Name "natRule2" -Type "Static" -Mode "EgressSnat" -InternalMapping @("20.0.0.0/16") -ExternalMapping @("50.0.0.0/16")
$actual = New-AzVirtualNetworkGateway -ResourceGroupName $rgname -name $rname -location $location -IpConfigurations $vnetIpConfig -GatewayType Vpn -VpnType RouteBased -EnableBgp $false -GatewaySku VpnGw2 -NaRule $natRule1,$natRule2
$vnetGateway = Get-AzVirtualNetworkGateway -ResourceGroupName $rgname -name $rname
Assert-AreEqual $vnetGateway.ResourceGroupName $actual.ResourceGroupName
Assert-AreEqual $vnetGateway.Name $actual.Name
Assert-AreEqual $vnetGateway.Name $actual.Name
Assert-AreEqual 2 @($vnetGateway.NatRules).Count
#Assert-AreEqual "Vpn" $expected.GatewayType
#Assert-AreEqual "RouteBased" $expected.VpnType

Expand All @@ -437,8 +439,12 @@ function Test-VirtualNetworkGatewayConnectionCRUD
Assert-AreEqual "192.168.0.0/16" $localnetGateway.LocalNetworkAddressSpace.AddressPrefixes[0]
$localnetGateway.Location = $location

# Get VirtualNetworkGatewayNatRules
$natRule1 = New-AzVirtualNetworkGatewayNatRule -Name "natRule1" -ResourceGroupName $rgname -ParentResourceName $rname
$natRule2 = New-AzVirtualNetworkGatewayNatRule -Name "natRule2" -ResourceGroupName $rgname -ParentResourceName $rname

# Create & Get VirtualNetworkGatewayConnection
$actual = New-AzVirtualNetworkGatewayConnection -ResourceGroupName $rgname -name $vnetConnectionName -location $location -VirtualNetworkGateway1 $vnetGateway -LocalNetworkGateway2 $localnetGateway -ConnectionType IPsec -RoutingWeight 3 -SharedKey abc -ConnectionProtocol IKEv1 -ConnectionMode "Default"
$actual = New-AzVirtualNetworkGatewayConnection -ResourceGroupName $rgname -name $vnetConnectionName -location $location -VirtualNetworkGateway1 $vnetGateway -LocalNetworkGateway2 $localnetGateway -ConnectionType IPsec -RoutingWeight 3 -SharedKey abc -ConnectionProtocol IKEv1 -ConnectionMode "Default" -IngressNatRule $natRule1 -EgressNatRule $natRule2
$expected = Get-AzVirtualNetworkGatewayConnection -ResourceGroupName $rgname -name $vnetConnectionName
Assert-AreEqual $expected.ResourceGroupName $actual.ResourceGroupName
Assert-AreEqual $expected.Name $actual.Name
Expand All @@ -447,6 +453,8 @@ function Test-VirtualNetworkGatewayConnectionCRUD
Assert-AreEqual "IKEv1" $expected.ConnectionProtocol
#Assert-AreEqual "abc" $expected.SharedKey
Assert-AreEqual $expected.ConnectionMode $actual.ConnectionMode
Assert-AreEqual 1 @($expected.IngressNatRules).Count
Assert-AreEqual 1 @($expected.EgressNatRules).Count

# List VirtualNetworkGatewayConnections
$list = Get-AzVirtualNetworkGatewayConnection -ResourceGroupName $rgname
Expand All @@ -467,11 +475,12 @@ function Test-VirtualNetworkGatewayConnectionCRUD
$expected.ConnectionMode = "ResponderOnly"

# Set/Update VirtualNetworkGatewayConnection Tags
$actual = Set-AzVirtualNetworkGatewayConnection -VirtualNetworkGatewayConnection $expected -Tag @{ testtagKey="SomeTagKey"; testtagValue="SomeKeyValue" } -Force
$actual = Set-AzVirtualNetworkGatewayConnection -VirtualNetworkGatewayConnection $expected -IngressNatRule @() -Tag @{ testtagKey="SomeTagKey"; testtagValue="SomeKeyValue" } -Force
$expected = Get-AzVirtualNetworkGatewayConnection -ResourceGroupName $rgname -name $vnetConnectionName
Assert-AreEqual 2 $expected.Tag.Count
Assert-AreEqual $true $expected.Tag.Contains("testtagKey")
Assert-AreEqual $expected.ConnectionMode $actual.ConnectionMode
Assert-AreEqual 0 $expected.IngressNatRules.Count

# Delete VirtualNetworkGatewayConnection
$delete = Remove-AzVirtualNetworkGatewayConnection -ResourceGroupName $actual.ResourceGroupName -name $vnetConnectionName -PassThru -Force
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,13 @@ public void TestDisconnectVirtualNetworkGatewayVpnConnection()
{
TestRunner.RunTestScript("Test-DisconnectVNGVpnConnection");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
[Trait(Category.Owner, NrpTeamAlias.brooklynft_subset2)]
public void TestVirtualNetworkGatewayNatRuleCRUD()
{
TestRunner.RunTestScript("Test-VirtualNetworkGatewayNatRuleCRUD");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1241,3 +1241,87 @@ function Test-DisconnectVNGVpnConnection
Clean-ResourceGroup $rgname
}
}

<#
.SYNOPSIS
Virtual network gateway NatRule tests
#>
function Test-VirtualNetworkGatewayNatRuleCRUD
{
# Setup
$rgname = Get-ResourceGroupName
$rname = Get-ResourceName
$domainNameLabel = Get-ResourceName
$vnetName = Get-ResourceName
$publicIpName = Get-ResourceName
$vnetGatewayConfigName = Get-ResourceName
$rglocation = Get-ProviderLocation ResourceManagement
$resourceTypeParent = "Microsoft.Network/virtualNetworkGateways"
$location = Get-ProviderLocation $resourceTypeParent

try
{
# Create the resource group
$resourceGroup = New-AzResourceGroup -Name $rgname -Location $rglocation -Tags @{ testtag = "testval" }

# Create the Virtual Network
$subnet = New-AzVirtualNetworkSubnetConfig -Name "GatewaySubnet" -AddressPrefix 10.0.0.0/24
$vnet = New-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname -Location $location -AddressPrefix 10.0.0.0/16 -Subnet $subnet
$vnet = Get-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname
$subnet = Get-AzVirtualNetworkSubnetConfig -Name "GatewaySubnet" -VirtualNetwork $vnet

# Create the publicip
$publicip = New-AzPublicIpAddress -ResourceGroupName $rgname -name $publicIpName -location $location -AllocationMethod Dynamic -DomainNameLabel $domainNameLabel

# Create & Get virtualnetworkgateway with NatRules
$vnetIpConfig = New-AzVirtualNetworkGatewayIpConfig -Name $vnetGatewayConfigName -PublicIpAddress $publicip -Subnet $subnet
$ipconfigurationId = $vnetIpConfig.id
$natRule = New-AzVirtualNetworkGatewayNatRule -Name "natRule1" -Type "Static" -Mode "IngressSnat" -InternalMapping @("25.0.0.0/16") -ExternalMapping @("30.0.0.0/16")
$job = New-AzVirtualNetworkGateway -ResourceGroupName $rgname -name $rname -location $location -IpConfigurations $vnetIpConfig -GatewayType Vpn -VpnType RouteBased -GatewaySku VpnGw2 -NatRule $natRule -EnableBgpRouteTranslationForNatFlag -AsJob
$job | Wait-Job
$actual = $job | Receive-Job
$expected = Get-AzVirtualNetworkGateway -ResourceGroupName $rgname -name $rname
Assert-AreEqual $expected.ResourceGroupName $actual.ResourceGroupName
Assert-AreEqual $expected.Name $actual.Name
Assert-AreEqual "Vpn" $expected.GatewayType
Assert-AreEqual "RouteBased" $expected.VpnType
Assert-AreEqual 1 @($expected.NatRules).Count

# Updates & Get virtualnetworkgateway with NatRules
$gateway = Get-AzVirtualNetworkGateway -ResourceGroupName $rgname -name $rname
$vngNatRules = $gateway.NatRules
$natRule = New-AzVirtualNetworkGatewayNatRule -Name "natRule2" -Type "Static" -Mode "EgressSnat" -InternalMapping @("20.0.0.0/16") -ExternalMapping @("50.0.0.0/16")
$vngNatRules.Add($natrule)
$updatedGateway = Set-AzVirtualNetworkGateway -VirtualNetworkGateway $gateway -NatRule $vngNatRules
Assert-AreEqual 2 @($updatedGateway.NatRules).Count

# List virtualNetworkGateways NatRules
$list = Get-AzVirtualNetworkGatewayNatRule -ResourceGroupName $rgname -ParentResourceName $rname
Assert-AreEqual 2 @($list).Count

# update virtualNetworkGateways NatRule
$natrule = Get-AzVirtualNetworkGatewayNatRule -ResourceGroupName $rgname -ParentResourceName $rname -Name "natRule2"
$updatedNatRule = Update-AzVirtualNetworkGatewayNatRule -InputObject $natrule -ExternalMapping @("40.0.0.0/16")
Assert-AreEqual "Succeeded" $updatedNatRule.ProvisioningState

# Delete virtualNetworkGatewayNatRules
$job = Remove-AzVirtualNetworkGatewayNatRule -ResourceGroupName $rgname -ParentResourceName $rname -Name natRule1 -PassThru -Force -AsJob
$job | Wait-Job
$delete = $job | Receive-Job
Assert-AreEqual true $delete

# Delete virtualNetworkGateway
$job = Remove-AzVirtualNetworkGateway -ResourceGroupName $actual.ResourceGroupName -name $rname -PassThru -Force -AsJob
$job | Wait-Job
$delete = $job | Receive-Job
Assert-AreEqual true $delete

$list = Get-AzVirtualNetworkGateway -ResourceGroupName $actual.ResourceGroupName
Assert-AreEqual 0 @($list).Count
}
finally
{
# Cleanup
Clean-ResourceGroup $rgname
}
}

0 comments on commit 6f04587

Please sign in to comment.