@@ -481,4 +481,208 @@ function Test-CortexExpressRouteCRUD
481
481
{
482
482
Clean - ResourceGroup $rgname
483
483
}
484
+ }
485
+
486
+ <# . SYNOPSIS
487
+ Point to site Cortex feature tests
488
+ #>
489
+ function Test-P2SCortexCRUD
490
+ {
491
+ param
492
+ (
493
+ $basedir = " .\"
494
+ )
495
+
496
+ # Setup
497
+ $rgname = Get-ResourceGroupName
498
+ $rglocation = Get-ProviderLocation " Microsoft.Network/VirtualWans"
499
+
500
+ $virtualWanName = Get-ResourceName
501
+ $virtualHubName = Get-ResourceName
502
+ $VpnServerConfiguration1Name = Get-ResourceName
503
+ $VpnServerConfiguration2Name = Get-ResourceName
504
+ $P2SVpnGatewayName = Get-ResourceName
505
+ $vpnclientAuthMethod = " EAPTLS"
506
+
507
+ $storeName = ' blob' + $rgName
508
+
509
+ try
510
+ {
511
+ # Create the resource group
512
+ $resourceGroup = New-AzResourceGroup - Name $rgname - Location $rglocation
513
+
514
+ # Create the Virtual Wan
515
+ $createdVirtualWan = New-AzVirtualWan - ResourceGroupName $rgName - Name $virtualWanName - Location $rglocation
516
+ $virtualWan = Get-AzVirtualWan - ResourceGroupName $rgName - Name $virtualWanName
517
+ Assert-AreEqual $rgName $virtualWan.ResourceGroupName
518
+ Assert-AreEqual $virtualWanName $virtualWan.Name
519
+
520
+ # Create the Virtual Hub
521
+ $createdVirtualHub = New-AzVirtualHub - ResourceGroupName $rgName - Name $virtualHubName - Location $rglocation - AddressPrefix " 192.168.1.0/24" - VirtualWan $virtualWan
522
+ $virtualHub = Get-AzVirtualHub - ResourceGroupName $rgName - Name $virtualHubName
523
+ Assert-AreEqual $rgName $virtualHub.ResourceGroupName
524
+ Assert-AreEqual $virtualHubName $virtualHub.Name
525
+ Assert-AreEqual $virtualWan.Id $virtualhub.VirtualWan.Id
526
+
527
+ # Create the VpnServerConfiguration1 with VpnClient settings using New-AzVpnServerConfiguration
528
+ $VpnServerConfigCertFilePath = Join-Path - Path $basedir - ChildPath " \ScenarioTests\Data\ApplicationGatewayAuthCert.cer"
529
+ $listOfCerts = New-Object " System.Collections.Generic.List[String]"
530
+ $listOfCerts.Add ($VpnServerConfigCertFilePath )
531
+ $vpnclientipsecpolicy1 = New-AzVpnClientIpsecPolicy - IpsecEncryption AES256 - IpsecIntegrity SHA256 - SALifeTime 86471 - SADataSize 429496 - IkeEncryption AES256 - IkeIntegrity SHA384 - DhGroup DHGroup14 - PfsGroup PFS14
532
+ New-AzVpnServerConfiguration - Name $VpnServerConfiguration1Name - ResourceGroupName $rgName - VpnProtocol IkeV2 - VpnAuthenticationType Certificate - VpnClientRootCertificateFilesList $listOfCerts - VpnClientRevokedCertificateFilesList $listOfCerts - VpnClientIpsecPolicy $vpnclientipsecpolicy1 - Location $rglocation
533
+
534
+ # Get created VpnServerConfiguration using Get-AzVpnServerConfiguration
535
+ $vpnServerConfig1 = Get-AzVpnServerConfiguration - ResourceGroupName $rgName - Name $VpnServerConfiguration1Name
536
+ Assert-NotNull $vpnServerConfig1
537
+ Assert-AreEqual $rgName $vpnServerConfig1.ResourceGroupName
538
+ Assert-AreEqual $VpnServerConfiguration1Name $vpnServerConfig1.Name
539
+ $protocols = $vpnServerConfig1.VpnProtocols
540
+ Assert-AreEqual 1 @ ($protocols ).Count
541
+ Assert-AreEqual " IkeV2" $protocols [0 ]
542
+ $authenticationTypes = $vpnServerConfig1.VpnAuthenticationTypes
543
+ Assert-AreEqual 1 @ ($authenticationTypes ).Count
544
+ Assert-AreEqual " Certificate" $authenticationTypes [0 ]
545
+
546
+ # Create the P2SVpnGateway using New-AzP2sVpnGateway
547
+ $vpnClientAddressSpaces = New-Object string[] 2
548
+ $vpnClientAddressSpaces [0 ] = " 192.168.2.0/24"
549
+ $vpnClientAddressSpaces [1 ] = " 192.168.3.0/24"
550
+ $createdP2SVpnGateway = New-AzP2sVpnGateway - ResourceGroupName $rgName - Name $P2SvpnGatewayName - VirtualHub $virtualHub - VpnGatewayScaleUnit 1 - VpnClientAddressPool $vpnClientAddressSpaces - VpnServerConfiguration $vpnServerConfig1
551
+ Assert-AreEqual " Succeeded" $createdP2SVpnGateway.ProvisioningState
552
+
553
+ # Get the created P2SVpnGateway using Get-AzP2sVpnGateway
554
+ $P2SVpnGateway = Get-AzP2sVpnGateway - ResourceGroupName $rgName - Name $P2SvpnGatewayName
555
+ Assert-AreEqual $rgName $P2SVpnGateway.ResourceGroupName
556
+ Assert-AreEqual $P2SvpnGatewayName $P2SVpnGateway.Name
557
+ Assert-AreEqual $vpnServerConfig1.Id $P2SVpnGateway.VpnServerConfiguration.Id
558
+ Assert-AreEqual " Succeeded" $P2SVpnGateway.ProvisioningState
559
+
560
+ # Get all associated VpnServerConfigurations at Wan level using Get-AzVirtualWanVpnServerConfiguration
561
+ $associatedVpnServerConfigs = Get-AzVirtualWanVpnServerConfiguration - Name $virtualWanName - ResourceGroupName $rgName
562
+ Assert-NotNull $associatedVpnServerConfigs
563
+ Assert-AreEqual 1 @ ($associatedVpnServerConfigs.VpnServerConfigurationResourceIds ).Count
564
+ Assert-AreEqual $vpnServerConfig1.Id $associatedVpnServerConfigs.VpnServerConfigurationResourceIds [0 ]
565
+
566
+ # Get VpnServerConfiguration1 and see that it shows as attached to P2SVpnGateway created.
567
+ $vpnServerConfig1 = Get-AzVpnServerConfiguration - ResourceGroupName $rgName - Name $VpnServerConfiguration1Name
568
+ Assert-NotNull $vpnServerConfig1
569
+ Assert-AreEqual $vpnServerConfig1.P2sVpnGateways [0 ].Id $P2SVpnGateway.Id
570
+
571
+ # List all VpnServerConfigurations under Resource group
572
+ $vpnServerConfigs = Get-AzVpnServerConfiguration - ResourceGroupName $rgName
573
+ Assert-NotNull $vpnServerConfigs
574
+ Assert-AreEqual 1 @ ($vpnServerConfigs ).Count
575
+
576
+ # Generate vpn profile at Hub/P2SVpnGateway level using Get-AzP2sVpnGatewayVpnProfile
577
+ $vpnProfileResponse = Get-AzP2sVpnGatewayVpnProfile - Name $P2SVpnGatewayName - ResourceGroupName $rgName - AuthenticationMethod $vpnclientAuthMethod
578
+ Assert-NotNull $vpnProfileResponse.ProfileUrl
579
+ Assert-AreEqual True ($vpnProfileResponse.ProfileUrl -Match " zip" )
580
+
581
+ # Generate vpn profile at Wan-VpnServerConfiguration combination level using Get-AzP2sVpnGatewayVpnProfile
582
+ $vpnProfileWanResponse = Get-AzVirtualWanVpnServerConfigurationVpnProfile - Name $virtualWanName - ResourceGroupName $rgName - AuthenticationMethod $vpnclientAuthMethod - VpnServerConfiguration $vpnServerConfig1
583
+ Assert-NotNull $vpnProfileWanResponse.ProfileUrl
584
+ Assert-AreEqual True ($vpnProfileWanResponse.ProfileUrl -Match " zip" )
585
+
586
+ # Create the VpnServerConfiguration2 with RadiusClient settings using New-AzVpnServerConfiguration
587
+ # [SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Test passwords only valid for the duration of the test")]
588
+ $Secure_String_Pwd = ConvertTo-SecureString " TestRadiusServerPassword" - AsPlainText - Force
589
+ New-AzVpnServerConfiguration - Name $VpnServerConfiguration2Name - ResourceGroupName $rgName - VpnProtocol IkeV2 - VpnAuthenticationType Radius - RadiusServerAddress " TestRadiusServer" - RadiusServerSecret $Secure_String_Pwd - RadiusServerRootCertificateFilesList $listOfCerts - RadiusClientRootCertificateFilesList $listOfCerts - Location $rglocation
590
+
591
+ $vpnServerConfig2 = Get-AzVpnServerConfiguration - ResourceGroupName $rgName - Name $VpnServerConfiguration2Name
592
+ Assert-AreEqual " Succeeded" $vpnServerConfig2.ProvisioningState
593
+ Assert-AreEqual " TestRadiusServer" $vpnServerConfig2.RadiusServerAddress
594
+
595
+ # List all VpnServerConfigurations under Resource group
596
+ $vpnServerConfigs = Get-AzVpnServerConfiguration - ResourceGroupName $rgName
597
+ Assert-NotNull $vpnServerConfigs
598
+ Assert-AreEqual 2 @ ($vpnServerConfigs ).Count
599
+
600
+ # Update existing VpnServerConfiguration2 using Update-AzVpnServerConfiguration
601
+ Update-AzVpnServerConfiguration - Name $VpnServerConfiguration2Name - ResourceGroupName $rgName - RadiusServerAddress " TestRadiusServer1"
602
+ $VpnServerConfig2 = Get-AzVpnServerConfiguration - Name $VpnServerConfiguration2Name - ResourceGroupName $rgName
603
+ Assert-AreEqual $VpnServerConfiguration2Name $VpnServerConfig2.Name
604
+ Assert-AreEqual " TestRadiusServer1" $VpnServerConfig2.RadiusServerAddress
605
+
606
+ Update-AzVpnServerConfiguration - ResourceId $VpnServerConfig2.Id - RadiusServerAddress " TestRadiusServer2"
607
+ $VpnServerConfig2Get = Get-AzVpnServerConfiguration - ResourceGroupName $rgName - Name $VpnServerConfiguration2Name
608
+ Assert-AreEqual " TestRadiusServer2" $VpnServerConfig2Get.RadiusServerAddress
609
+
610
+ Update-AzVpnServerConfiguration - InputObject $VpnServerConfig2Get - RadiusServerAddress " TestRadiusServer3"
611
+ $VpnServerConfig2Get = Get-AzVpnServerConfiguration - ResourceGroupName $rgName - Name $VpnServerConfiguration2Name
612
+ Assert-AreEqual " TestRadiusServer3" $VpnServerConfig2Get.RadiusServerAddress
613
+
614
+ # Update existing P2SVpnGateway with new VpnClientAddressPool using Update-AzP2sVpnGateway
615
+ $vpnClientAddressSpaces [1 ] = " 192.168.4.0/24"
616
+ $updatedP2SVpnGateway = Update-AzP2sVpnGateway - ResourceGroupName $rgName - Name $P2SvpnGatewayName - VpnClientAddressPool $vpnClientAddressSpaces
617
+
618
+ $P2SVpnGateway = Get-AzP2sVpnGateway - ResourceGroupName $rgName - Name $P2SvpnGatewayName
619
+ Assert-AreEqual $P2SvpnGatewayName $P2SVpnGateway.Name
620
+ Assert-AreEqual " Succeeded" $P2SVpnGateway.ProvisioningState
621
+ Assert-AreEqual $vpnServerConfig1.Id $P2SVpnGateway.VpnServerConfiguration.Id
622
+ $setVpnClientAddressSpacesString = [system.String ]::Join(" " , $vpnClientAddressSpaces )
623
+ Assert-AreEqual $setVpnClientAddressSpacesString $P2SVpnGateway.P2SConnectionConfigurations [0 ].VpnClientAddressPool.AddressPrefixes
624
+
625
+ $associatedVpnServerConfigs = Get-AzVirtualWanVpnServerConfiguration - ResourceId $virtualWan.Id
626
+ Assert-NotNull $associatedVpnServerConfigs
627
+ Assert-AreEqual 1 @ ($associatedVpnServerConfigs.VpnServerConfigurationResourceIds ).Count
628
+ Assert-AreEqual $vpnServerConfig1.Id $associatedVpnServerConfigs.VpnServerConfigurationResourceIds [0 ]
629
+
630
+ # Delete VpnServerConfiguration2 using Remove-AzVirtualWanVpnServerConfiguration
631
+ $delete = Remove-AzVpnServerConfiguration - InputObject $VpnServerConfig2Get - Force - PassThru
632
+ Assert-AreEqual $True $delete
633
+
634
+ $vpnServerConfigs = Get-AzVpnServerConfiguration - ResourceGroupName $rgName
635
+ Assert-NotNull $vpnServerConfigs
636
+ Assert-AreEqual 1 @ ($vpnServerConfigs ).Count
637
+
638
+ # Get aggreagated point to site connections health from P2SVpnGateway
639
+ # $aggregatedConnectionHealth = Get-AzP2sVpnGatewayConnectionHealth -Name $P2SvpnGatewayName -ResourceGroupName $rgName
640
+ # Assert-NotNull $aggregatedConnectionHealth
641
+ # Assert-NotNull $aggregatedConnectionHealth.VpnClientConnectionHealth
642
+ # Assert-AreEqual 0 $aggregatedConnectionHealth.VpnClientConnectionHealth.VpnClientConnectionsCount
643
+
644
+ # Get a SAS url for getting detained point to site connections health details.
645
+ $storetype = ' Standard_GRS'
646
+ $containerName = " cont$ ( $rgName ) "
647
+ New-AzStorageAccount - ResourceGroupName $rgName - Name $storeName - Location $rglocation - Type $storetype
648
+ $key = Get-AzStorageAccountKey - ResourceGroupName $rgName - Name $storeName
649
+ $context = New-AzStorageContext - StorageAccountName $storeName - StorageAccountKey $key [0 ].Value
650
+ New-AzStorageContainer - Name $containerName - Context $context
651
+ $container = Get-AzStorageContainer - Name $containerName - Context $context
652
+ New-Item - Name EmptyFile.txt - ItemType File - Force
653
+ Set-AzStorageBlobContent - File " EmptyFile.txt" - Container $containerName - Blob " emptyfile.txt" - Context $context
654
+ $now = get-date
655
+ $blobSasUrl = New-AzStorageBlobSASToken - Container $containerName - Blob emptyfile.txt - Context $context - Permission " rwd" - StartTime $now.AddHours (-1 ) - ExpiryTime $now.AddDays (1 ) - FullUri
656
+
657
+ # Get detailed point to site connections health from P2SVpnGateway
658
+ $detailedConnectionHealth = Get-AzP2sVpnGatewayDetailedConnectionHealth - Name $P2SvpnGatewayName - ResourceGroupName $rgName - OutputBlobSasUrl $blobSasUrl
659
+ Assert-NotNull $detailedConnectionHealth
660
+ Assert-NotNull $detailedConnectionHealth.SasUrl
661
+ Assert-AreEqual $blobSasUrl $detailedConnectionHealth.SasUrl
662
+ }
663
+ finally
664
+ {
665
+ # Delete P2SVpnGateway using Remove-AzP2sVpnGateway
666
+ $delete = Remove-AzP2sVpnGateway - Name $P2SVpnGatewayName - ResourceGroupName $rgName - Force - PassThru
667
+ Assert-AreEqual $True $delete
668
+
669
+ # Verify that there are no associated VpnServerConfigurations to Virtual wan anymore
670
+ $associatedVpnServerConfigs = Get-AzVirtualWanVpnServerConfiguration - Name $virtualWanName - ResourceGroupName $rgName
671
+ Assert-NotNull $associatedVpnServerConfigs
672
+ Assert-AreEqual 0 @ ($associatedVpnServerConfigs.VpnServerConfigurationResourceIds ).Count
673
+
674
+ # Delete VpnServerConfiguration1 using Remove-AzVpnServerConfiguration
675
+ $delete = Remove-AzVpnServerConfiguration - ResourceGroupName $rgName - Name $VpnServerConfiguration1Name - Force - PassThru
676
+ Assert-AreEqual $True $delete
677
+
678
+ # Delete Virtual hub
679
+ $delete = Remove-AzVirtualHub - ResourceGroupName $rgname - Name $virtualHubName - Force - PassThru
680
+ Assert-AreEqual $True $delete
681
+
682
+ # Delete Virtual wan
683
+ $delete = Remove-AzVirtualWan - InputObject $virtualWan - Force - PassThru
684
+ Assert-AreEqual $True $delete
685
+
686
+ Clean - ResourceGroup $rgname
687
+ }
484
688
}
0 commit comments