Skip to content

Commit 4a9f511

Browse files
fixing packet capture call to be async (#25888)
* fixing packet capture call to be async * fixing the test to return success * replaced the hard coded sasurl with sasurl generated on the fly * Adding session record for the fixed test * adding change summary to changelog.md * skipping test in cloud runner due to issues accessing deployed storage account * removing storage account actions, replacing the sessions recording and replacing the sasurl with a dummySAS as per recommendation * mask sas url in record json --------- Co-authored-by: Yabo Hu <[email protected]>
1 parent 9c0deae commit 4a9f511

File tree

4 files changed

+5516
-421
lines changed

4 files changed

+5516
-421
lines changed

src/Network/Network.Test/ScenarioTests/AzureFirewallTests.ps1

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2133,38 +2133,54 @@ function Test-GetAzureFirewallLearnedIpPrefixes {
21332133
Tests Invoke-AzureFirewallPacketCapture
21342134
#>
21352135
function Test-InvokeAzureFirewallPacketCapture {
2136+
# Setup
21362137
$rgname = Get-ResourceGroupName
21372138
$azureFirewallName = Get-ResourceName
21382139
$resourceTypeParent = "Microsoft.Network/AzureFirewalls"
21392140
$location = Get-ProviderLocation $resourceTypeParent "eastus"
21402141

21412142
$vnetName = Get-ResourceName
21422143
$subnetName = "AzureFirewallSubnet"
2143-
$publicIpName = Get-ResourceName
2144+
$mgmtSubnetName = "AzureFirewallManagementSubnet"
2145+
$publicIp1Name = Get-ResourceName
2146+
$mgmtPublicIpName = Get-ResourceName
21442147

21452148
try {
2146-
21472149
# Create the resource group
2148-
$resourceGroup = New-AzResourceGroup -Name $rgname -Location $location
2150+
$resourceGroup = New-AzResourceGroup -Name $rgname -Location $location -Tags @{ testtag = "testval" }
21492151

2150-
# Create public ip
2151-
$publicip = New-AzPublicIpAddress -ResourceGroupName $rgname -name $publicIpName -location $location -AllocationMethod Static -Sku Standard
2152+
# Create the Virtual Network
2153+
$subnet = New-AzVirtualNetworkSubnetConfig -Name $subnetName -AddressPrefix 10.0.0.0/24
2154+
$mgmtSubnet = New-AzVirtualNetworkSubnetConfig -Name $mgmtSubnetName -AddressPrefix 10.0.100.0/24
2155+
$vnet = New-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname -Location $location -AddressPrefix 10.0.0.0/16 -Subnet $subnet,$mgmtSubnet
2156+
2157+
# Get full subnet details
2158+
$subnet = Get-AzVirtualNetworkSubnetConfig -VirtualNetwork $vnet -Name $subnetName
2159+
$mgmtSubnet = Get-AzVirtualNetworkSubnetConfig -VirtualNetwork $vnet -Name $mgmtSubnetName
21522160

2153-
# Create AzureFirewall
2154-
$azureFirewall = New-AzFirewall -Name $azureFirewallName -ResourceGroupName $rgname -Location $location
2161+
# Create public ips
2162+
$publicip1 = New-AzPublicIpAddress -ResourceGroupName $rgname -name $publicIp1Name -location $location -AllocationMethod Static -Sku Standard
2163+
$mgmtPublicIp = New-AzPublicIpAddress -ResourceGroupName $rgname -name $mgmtPublicIpName -location $location -AllocationMethod Static -Sku Standard
21552164

2156-
# Verify
2157-
$azFirewall = Get-AzFirewall -Name $azureFirewallName -ResourceGroupName $rgname
2165+
# Create AzureFirewall with a management IP
2166+
$azureFirewall = New-AzFirewall -Name $azureFirewallName -ResourceGroupName $rgname -Location $location -VirtualNetwork $vnet -PublicIpAddress $publicip1 -ManagementPublicIpAddress $mgmtPublicIp
2167+
2168+
# Get AzureFirewall
2169+
$getAzureFirewall = Get-AzFirewall -name $azureFirewallName -ResourceGroupName $rgname
2170+
2171+
$sasurl = "https://powershellpacketcapture.blob.core.windows.net/testcapture?sp=wDummyURL"
21582172

21592173
# Create a filter rules
21602174
$filter1 = New-AzFirewallPacketCaptureRule -Source "10.0.0.2","192.123.12.1" -Destination "172.32.1.2" -DestinationPort "80","443"
21612175
$filter2 = New-AzFirewallPacketCaptureRule -Source "10.0.0.5" -Destination "172.20.10.2" -DestinationPort "80","443"
21622176

21632177
# Create the firewall packet capture parameters
2164-
$Params = New-AzFirewallPacketCaptureParameter -DurationInSeconds 300 -NumberOfPackets 5000 -SASUrl "ValidSasUrl" -Filename "AzFwPacketCapture" -Flag "Syn","Ack" -Protocol "Any" -Filter $Filter1, $Filter2
2178+
$Params = New-AzFirewallPacketCaptureParameter -DurationInSeconds 30 -NumberOfPackets 500 -SASUrl $sasurl -Filename "AzFwPowershellPacketCapture" -Flag "Syn","Ack" -Protocol "Any" -Filter $Filter1, $Filter2
21652179

21662180
# Invoke a firewall packet capture
2167-
Invoke-AzFirewallPacketCapture -AzureFirewall $azureFirewall -Parameter $Params
2181+
$response = Invoke-AzFirewallPacketCapture -AzureFirewall $azureFirewall -Parameter $Params
2182+
Assert-NotNull $response
2183+
Assert-AreEqual "Microsoft.Azure.Management.Network.Models.AzureFirewallsPacketCaptureHeaders" $response.GetType().fullname
21682184
}
21692185
finally {
21702186
# Cleanup

src/Network/Network.Test/SessionRecords/Commands.Network.Test.ScenarioTests.AzureFirewallTests/TestInvokeAzureFirewallPacketCapture.json

Lines changed: 5487 additions & 409 deletions
Large diffs are not rendered by default.

src/Network/Network/AzureFirewall/InvokeAzureFirewallPacketCaptureCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public override void Execute()
5858

5959

6060
// Execute the PUT AzureFirewall call
61-
var headers = this.AzureFirewallClient.PacketCaptureAsync(this.AzureFirewall.ResourceGroupName, this.AzureFirewall.Name, secureGwParamsModel);
61+
var headers = this.AzureFirewallClient.PacketCapture(this.AzureFirewall.ResourceGroupName, this.AzureFirewall.Name, secureGwParamsModel);
6262

6363
WriteObject(headers);
6464
}

src/Network/Network/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
--->
2020

2121
## Upcoming Release
22+
* Fixed a bug in cmdlet `Invoke-AzFirewallPacketCapture` which caused the packet capture request to be stuck in a waiting for activation state.
2223
* Updated cmdlet to add the property of `Sensitivity`, and updated corresponding cmdlets.
2324
- `New-AzApplicationGatewayFirewallPolicyManagedRuleOverride`
2425
* Added support for `DefaultOutboundAccess` property in `Set-AzVirtualNetworkSubnetConfig` command

0 commit comments

Comments
 (0)