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 @@ -2,7 +2,7 @@
// Licensed under the MIT License. See License.txt in the project root for
// license information.
//
// Code generated by Microsoft (R) AutoRest Code Generator 1.1.0.0
// Code generated by Microsoft (R) AutoRest Code Generator.
// Changes may cause incorrect behavior and will be lost if the code is
// regenerated.

Expand Down Expand Up @@ -63,19 +63,14 @@ public VirtualNetworkGateway()
/// configurations.</param>
/// <param name="bgpSettings">Virtual network gateway's BGP speaker
/// settings.</param>
/// <param name="radiusServer">The radius server address property of
/// the VirtualNetworkGateway resource for vpn client
/// connection.</param>
/// <param name="radiusSecret">The radius secret property of the
/// VirtualNetworkGateway resource for vpn client connection.</param>
/// <param name="resourceGuid">The resource GUID property of the
/// VirtualNetworkGateway resource.</param>
/// <param name="provisioningState">The provisioning state of the
/// VirtualNetworkGateway resource. Possible values are: 'Updating',
/// 'Deleting', and 'Failed'.</param>
/// <param name="etag">Gets a unique read-only string that changes
/// whenever the resource is updated.</param>
public VirtualNetworkGateway(string id = default(string), string name = default(string), string type = default(string), string location = default(string), IDictionary<string, string> tags = default(IDictionary<string, string>), IList<VirtualNetworkGatewayIPConfiguration> ipConfigurations = default(IList<VirtualNetworkGatewayIPConfiguration>), string gatewayType = default(string), string vpnType = default(string), bool? enableBgp = default(bool?), bool? activeActive = default(bool?), SubResource gatewayDefaultSite = default(SubResource), VirtualNetworkGatewaySku sku = default(VirtualNetworkGatewaySku), VpnClientConfiguration vpnClientConfiguration = default(VpnClientConfiguration), BgpSettings bgpSettings = default(BgpSettings), string radiusServer = default(string), string radiusSecret = default(string), string resourceGuid = default(string), string provisioningState = default(string), string etag = default(string))
public VirtualNetworkGateway(string id = default(string), string name = default(string), string type = default(string), string location = default(string), IDictionary<string, string> tags = default(IDictionary<string, string>), IList<VirtualNetworkGatewayIPConfiguration> ipConfigurations = default(IList<VirtualNetworkGatewayIPConfiguration>), string gatewayType = default(string), string vpnType = default(string), bool? enableBgp = default(bool?), bool? activeActive = default(bool?), SubResource gatewayDefaultSite = default(SubResource), VirtualNetworkGatewaySku sku = default(VirtualNetworkGatewaySku), VpnClientConfiguration vpnClientConfiguration = default(VpnClientConfiguration), BgpSettings bgpSettings = default(BgpSettings), string resourceGuid = default(string), string provisioningState = default(string), string etag = default(string))
: base(id, name, type, location, tags)
{
IpConfigurations = ipConfigurations;
Expand All @@ -87,8 +82,6 @@ public VirtualNetworkGateway()
Sku = sku;
VpnClientConfiguration = vpnClientConfiguration;
BgpSettings = bgpSettings;
RadiusServer = radiusServer;
RadiusSecret = radiusSecret;
ResourceGuid = resourceGuid;
ProvisioningState = provisioningState;
Etag = etag;
Expand Down Expand Up @@ -163,20 +156,6 @@ public VirtualNetworkGateway()
[JsonProperty(PropertyName = "properties.bgpSettings")]
public BgpSettings BgpSettings { get; set; }

/// <summary>
/// Gets or sets the radius server address property of the
/// VirtualNetworkGateway resource for vpn client connection.
/// </summary>
[JsonProperty(PropertyName = "properties.radiusServer")]
public string RadiusServer { get; set; }

/// <summary>
/// Gets or sets the radius secret property of the
/// VirtualNetworkGateway resource for vpn client connection.
/// </summary>
[JsonProperty(PropertyName = "properties.radiusSecret")]
public string RadiusSecret { get; set; }

/// <summary>
/// Gets or sets the resource GUID property of the
/// VirtualNetworkGateway resource.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT License. See License.txt in the project root for
// license information.
//
// Code generated by Microsoft (R) AutoRest Code Generator 1.1.0.0
// Code generated by Microsoft (R) AutoRest Code Generator.
// Changes may cause incorrect behavior and will be lost if the code is
// regenerated.

Expand Down Expand Up @@ -42,12 +42,19 @@ public VpnClientConfiguration()
/// Virtual network gateway.</param>
/// <param name="vpnClientProtocols">VpnClientProtocols for Virtual
/// network gateway.</param>
public VpnClientConfiguration(AddressSpace vpnClientAddressPool = default(AddressSpace), IList<VpnClientRootCertificate> vpnClientRootCertificates = default(IList<VpnClientRootCertificate>), IList<VpnClientRevokedCertificate> vpnClientRevokedCertificates = default(IList<VpnClientRevokedCertificate>), IList<string> vpnClientProtocols = default(IList<string>))
/// <param name="radiusServerAddress">The radius server address
/// property of the VirtualNetworkGateway resource for vpn client
/// connection.</param>
/// <param name="radiusServerSecret">The radius secret property of the
/// VirtualNetworkGateway resource for vpn client connection.</param>
public VpnClientConfiguration(AddressSpace vpnClientAddressPool = default(AddressSpace), IList<VpnClientRootCertificate> vpnClientRootCertificates = default(IList<VpnClientRootCertificate>), IList<VpnClientRevokedCertificate> vpnClientRevokedCertificates = default(IList<VpnClientRevokedCertificate>), IList<string> vpnClientProtocols = default(IList<string>), string radiusServerAddress = default(string), string radiusServerSecret = default(string))
{
VpnClientAddressPool = vpnClientAddressPool;
VpnClientRootCertificates = vpnClientRootCertificates;
VpnClientRevokedCertificates = vpnClientRevokedCertificates;
VpnClientProtocols = vpnClientProtocols;
RadiusServerAddress = radiusServerAddress;
RadiusServerSecret = radiusServerSecret;
CustomInit();
}

Expand Down Expand Up @@ -82,5 +89,19 @@ public VpnClientConfiguration()
[JsonProperty(PropertyName = "vpnClientProtocols")]
public IList<string> VpnClientProtocols { get; set; }

/// <summary>
/// Gets or sets the radius server address property of the
/// VirtualNetworkGateway resource for vpn client connection.
/// </summary>
[JsonProperty(PropertyName = "radiusServerAddress")]
public string RadiusServerAddress { get; set; }

/// <summary>
/// Gets or sets the radius secret property of the
/// VirtualNetworkGateway resource for vpn client connection.
/// </summary>
[JsonProperty(PropertyName = "radiusServerSecret")]
public string RadiusServerSecret { get; set; }

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ internal VirtualNetworkGatewaysOperations(NetworkManagementClient client)
{
// Send request
AzureOperationResponse<string> _response = await BeginGenerateVpnProfileWithHttpMessagesAsync(resourceGroupName, virtualNetworkGatewayName, parameters, customHeaders, cancellationToken).ConfigureAwait(false);
return await Client.GetPostOrDeleteOperationResultAsync(_response, customHeaders, cancellationToken).ConfigureAwait(false);
return await Client.GetLongRunningOperationResultAsync(_response, customHeaders, cancellationToken).ConfigureAwait(false);
}

/// <summary>
Expand Down Expand Up @@ -1589,7 +1589,7 @@ internal VirtualNetworkGatewaysOperations(NetworkManagementClient client)
HttpStatusCode _statusCode = _httpResponse.StatusCode;
cancellationToken.ThrowIfCancellationRequested();
string _responseContent = null;
if ((int)_statusCode != 200)
if ((int)_statusCode != 200 && (int)_statusCode != 202)
{
var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode));
try
Expand Down

Large diffs are not rendered by default.

155 changes: 155 additions & 0 deletions src/SDKs/Network/Network.Tests/Tests/GatewayOperationsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1552,5 +1552,160 @@ public void VirtualNetworkGatewayBgpRouteApiTest()
Assert.True(gw1Peers.Count() > 0, "At least one peer should be connected");
}
}

[Fact]
public void VirtualNetworkGatewayGenerateVpnProfileTest()
{
var handler1 = new RecordedDelegatingHandler {StatusCodeToReturn = HttpStatusCode.OK};
var handler2 = new RecordedDelegatingHandler {StatusCodeToReturn = HttpStatusCode.OK};

using (MockContext context = MockContext.Start(this.GetType().FullName))
{
var resourcesClient =
ResourcesManagementTestUtilities.GetResourceManagementClientWithHandler(context, handler1);
var networkManagementClient =
NetworkManagementTestUtilities.GetNetworkManagementClientWithHandler(context, handler2);

var location =
NetworkManagementTestUtilities.GetResourceLocation(resourcesClient,
"Microsoft.Network/virtualnetworkgateways");

string resourceGroupName = TestUtilities.GenerateName("csmrg");
resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName,
new ResourceGroup
{
Location = location
});


// 1.CreateVirtualNetworkGateway
// A.Prerequisite:-Create PublicIPAddress(Gateway Ip) using Put PublicIPAddress API
string publicIpName = TestUtilities.GenerateName();
string domainNameLabel = TestUtilities.GenerateName();
var nic1publicIp = TestHelper.CreateDefaultPublicIpAddress(publicIpName, resourceGroupName,
domainNameLabel, location, networkManagementClient);
Console.WriteLine("PublicIPAddress(Gateway Ip) :{0}", nic1publicIp.Id);


// B.Prerequisite:-Create Virtual Network using Put VirtualNetwork API
string vnetName = TestUtilities.GenerateName();
string subnetName = "GatewaySubnet";

var virtualNetwork = TestHelper.CreateVirtualNetwork(vnetName, subnetName, resourceGroupName, location,
networkManagementClient);
var getSubnetResponse = networkManagementClient.Subnets.Get(resourceGroupName, vnetName, subnetName);
Console.WriteLine("Virtual Network GatewaySubnet Id: {0}", getSubnetResponse.Id);

// C.CreateVirtualNetworkGateway API with P2S client Address Pool defined
string virtualNetworkGatewayName = TestUtilities.GenerateName();
string ipConfigName = TestUtilities.GenerateName();
string addressPrefixes = "192.168.0.0/16";
string clientRootCertName = "BrkLiteTestMSFTRootCA.cer";
string samplePublicCertData = "MIIDUzCCAj+gAwIBAgIQRggGmrpGj4pCblTanQRNUjAJBgUrDgMCHQUAMDQxEjAQBgNVBAoTCU1pY3Jvc29mdDEeMBwGA1UEAxMVQnJrIExpdGUgVGVzdCBSb290IENBMB4XDTEzMDExOTAwMjQxOFoXDTIxMDExOTAwMjQxN1owNDESMBAGA1UEChMJTWljcm9zb2Z0MR4wHAYDVQQDExVCcmsgTGl0ZSBUZXN0IFJvb3QgQ0EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC7SmE+iPULK0Rs7mQBO/6a6B6/G9BaMxHgDGzAmSG0Qsyt5e08aqgFnPdkMl3zRJw3lPKGha/JCvHRNrO8UpeAfc4IXWaqxx2iBipHjwmHPHh7+VB8lU0EJcUe7WBAI2n/sgfCwc+xKtuyRVlOhT6qw/nAi8e5don/iHPU6q7GCcnqoqtceQ/pJ8m66cvAnxwJlBFOTninhb2VjtvOfMQ07zPP+ZuYDPxvX5v3nd6yDa98yW4dZPuiGO2s6zJAfOPT2BrtyvLekItnSgAw3U5C0bOb+8XVKaDZQXbGEtOw6NZvD4L2yLd47nGkN2QXloiPLGyetrj3Z2pZYcrZBo8hAgMBAAGjaTBnMGUGA1UdAQReMFyAEOncRAPNcvJDoe4WP/gH2U+hNjA0MRIwEAYDVQQKEwlNaWNyb3NvZnQxHjAcBgNVBAMTFUJyayBMaXRlIFRlc3QgUm9vdCBDQYIQRggGmrpGj4pCblTanQRNUjAJBgUrDgMCHQUAA4IBAQCGyHhMdygS0g2tEUtRT4KFM+qqUY5HBpbIXNAav1a1dmXpHQCziuuxxzu3iq4XwnWUF1OabdDE2cpxNDOWxSsIxfEBf9ifaoz/O1ToJ0K757q2Rm2NWqQ7bNN8ArhvkNWa95S9gk9ZHZLUcjqanf0F8taJCYgzcbUSp+VBe9DcN89sJpYvfiBiAsMVqGPc/fHJgTScK+8QYrTRMubtFmXHbzBSO/KTAP5rBTxse88EGjK5F8wcedvge2Ksk6XjL3sZ19+Oj8KTQ72wihN900p1WQldHrrnbixSpmHBXbHr9U0NQigrJp5NphfuU5j81C8ixvfUdwyLmTv7rNA7GTAD";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ritwikbasu please pass all data via your connection string.
Refer to https://github.com/Azure/azure-powershell/blob/preview/documentation/Using-Azure-TestFramework.md#5-change-test-environment-settings-at-run-time
This shows how you can add any custom key-value pair to your connection string and use it in your test.
This way you don't have to hardcode any data in your tests.
All data comes from your connection string.
And if you want you can store your connection string in a keyVault as a secret.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will fix this in a later PR - this is the tracking issue #3536

VpnClientRootCertificate clientRootCert = new VpnClientRootCertificate()
{
Name = clientRootCertName,
PublicCertData = samplePublicCertData
};

var virtualNetworkGateway = new VirtualNetworkGateway()
{
Location = location,
Tags = new Dictionary<string, string>()
{
{"key", "value"}
},
EnableBgp = false,
GatewayType = VirtualNetworkGatewayType.Vpn,
VpnType = VpnType.RouteBased,
IpConfigurations = new List<VirtualNetworkGatewayIPConfiguration>()
{
new VirtualNetworkGatewayIPConfiguration()
{
Name = ipConfigName,
PrivateIPAllocationMethod = IPAllocationMethod.Dynamic,
PublicIPAddress = new SubResource()
{
Id = nic1publicIp.Id
},
Subnet = new SubResource()
{
Id = getSubnetResponse.Id
}
}
},
VpnClientConfiguration = new VpnClientConfiguration()
{
VpnClientAddressPool = new AddressSpace()
{
AddressPrefixes = new List<string>()
{
addressPrefixes
},
}
},
Sku = new VirtualNetworkGatewaySku()
{
Name = VirtualNetworkGatewaySkuName.VpnGw2,
Tier = VirtualNetworkGatewaySkuTier.VpnGw2
}
};

var putVirtualNetworkGatewayResponse =
networkManagementClient.VirtualNetworkGateways.CreateOrUpdate(resourceGroupName,
virtualNetworkGatewayName, virtualNetworkGateway);
Assert.Equal("Succeeded", putVirtualNetworkGatewayResponse.ProvisioningState);

// 2.GetVirtualNetworkGateway API
var getVirtualNetworkGatewayResponse =
networkManagementClient.VirtualNetworkGateways.Get(resourceGroupName, virtualNetworkGatewayName);
Console.WriteLine(
"Gateway details:- GatewayLocation:{0}, GatewayId:{1}, GatewayName:{2}, GatewayType:{3}, VpnType={4} GatewaySku: name-{5} Tier-{6}",
getVirtualNetworkGatewayResponse.Location,
getVirtualNetworkGatewayResponse.Id, getVirtualNetworkGatewayResponse.Name,
getVirtualNetworkGatewayResponse.GatewayType, getVirtualNetworkGatewayResponse.VpnType,
getVirtualNetworkGatewayResponse.Sku.Name, getVirtualNetworkGatewayResponse.Sku.Tier);
Assert.Equal(VirtualNetworkGatewayType.Vpn, getVirtualNetworkGatewayResponse.GatewayType);
Assert.Equal(VpnType.RouteBased, getVirtualNetworkGatewayResponse.VpnType);
Assert.Equal(VirtualNetworkGatewaySkuTier.VpnGw2, getVirtualNetworkGatewayResponse.Sku.Tier);
Assert.NotNull(getVirtualNetworkGatewayResponse.VpnClientConfiguration);
Assert.NotNull(getVirtualNetworkGatewayResponse.VpnClientConfiguration.VpnClientAddressPool);
Assert.True(getVirtualNetworkGatewayResponse.VpnClientConfiguration.VpnClientAddressPool.AddressPrefixes
.Count == 1 &&
getVirtualNetworkGatewayResponse.VpnClientConfiguration.VpnClientAddressPool
.AddressPrefixes[0].Equals(addressPrefixes),
"P2S client Address Pool is not set on Gateway!");

// Update P2S VPNClient Address Pool and add radius settings
string newAddressPrefixes = "200.168.0.0/16";
getVirtualNetworkGatewayResponse.VpnClientConfiguration = new VpnClientConfiguration()
{
VpnClientAddressPool = new AddressSpace()
{
AddressPrefixes = new List<string>()
{
newAddressPrefixes
}
},
RadiusServerAddress = @"8.8.8.8",
RadiusServerSecret = @"TestRadiusSecret",
};
getVirtualNetworkGatewayResponse.VpnClientConfiguration.VpnClientAddressPool.AddressPrefixes = new List<string>() { newAddressPrefixes };
putVirtualNetworkGatewayResponse = networkManagementClient.VirtualNetworkGateways.CreateOrUpdate(resourceGroupName, virtualNetworkGatewayName, getVirtualNetworkGatewayResponse);
Assert.Equal("Succeeded", putVirtualNetworkGatewayResponse.ProvisioningState);

// 5.Generate P2S Vpnclient package
var vpnClientParameters = new VpnClientParameters()
{
RadiusServerAuthCertificate = samplePublicCertData,
AuthenticationMethod = AuthenticationMethod.EAPTLS
};

string packageUrl = networkManagementClient.VirtualNetworkGateways.GenerateVpnProfile(resourceGroupName, virtualNetworkGatewayName, vpnClientParameters);
//Assert.NotNull(packageUrl);
//Assert.NotEmpty(packageUrl);
Console.WriteLine("Vpn client package Url = {0}", packageUrl);
}
}
}
}