Exemplo n.º 1
0
        public void VirtualNetworkGatewayConnectionWithBgpTest()
        {
            using (NetworkTestClient networkTestClient = new NetworkTestClient())
            {
                string virtualNetworkSiteName = "gatewayVirtualNetworkSiteName";
                string vnetGatewayName        = "bgpTestVirtualNetworkGateway";

                networkTestClient.SetNetworkConfiguration(NetworkTestConstants.GatewayNetworkConfigurationParameters);

                // Put a virtual network gateway with a feature set that allows BGP (dynamic routing, >= standard)
                GatewayGetOperationStatusResponse response = networkTestClient.Gateways.CreateVirtualNetworkGateway(
                    virtualNetworkSiteName,
                    new VirtualNetworkGatewayCreateParameters()
                {
                    GatewayName = vnetGatewayName,
                    GatewayType = GatewayType.DynamicRouting,
                    GatewaySKU  = GatewaySKU.Standard
                });
                Assert.NotNull(response);
                Assert.Equal(HttpStatusCode.OK, response.HttpStatusCode);

                // Call list, make sure the virtual network gateway exists, then check for BgpSettings
                ListVirtualNetworkGatewaysResponse listVirtualNetworkGatewaysResponse = networkTestClient.Gateways.ListVirtualNetworkGateways();
                Assert.True(listVirtualNetworkGatewaysResponse.VirtualNetworkGateways.Count >= 1);
                ListVirtualNetworkGatewaysResponse.VirtualNetworkGateway vnetGateway =
                    listVirtualNetworkGatewaysResponse.VirtualNetworkGateways.First(gw => gw.GatewayName.Equals(vnetGatewayName));
                Assert.NotNull(vnetGateway.BgpSettings);
                string virtualNetworkGatewayId = vnetGateway.GatewayId.ToString();

                // Create a local network gateway with BGP settings
                string localNetworkGatewayName = "bgpTestLocalNetworkGateway";
                var    param = new LocalNetworkGatewayCreateParameters()
                {
                    AddressSpace = new LazyList <string>()
                    {
                        addressSpace
                    },
                    GatewayName = localNetworkGatewayName,
                    IpAddress   = localNetworkGatewayIpAddress,
                    BgpSettings = new BgpSettings()
                    {
                        Asn = 1234,
                        BgpPeeringAddress = "200.168.1.1",
                        PeerWeight        = 5
                    }
                };

                LocalNetworkGatewayCreateResponse localNetworkGatewayCreateResponse = networkTestClient.Gateways.CreateLocalNetworkGateway(param);
                Assert.NotNull(localNetworkGatewayCreateResponse);
                Assert.Equal(HttpStatusCode.OK, localNetworkGatewayCreateResponse.StatusCode);

                ListLocalNetworkGatewaysResponse listLocalNetworkGatewaysResponse = networkTestClient.Gateways.ListLocalNetworkGateways();
                Assert.NotNull(listLocalNetworkGatewaysResponse);
                Assert.Equal(HttpStatusCode.OK, listLocalNetworkGatewaysResponse.StatusCode);
                ListLocalNetworkGatewaysResponse.LocalNetworkGateway localNetworkGateway =
                    listLocalNetworkGatewaysResponse.LocalNetworkGateways.First(gw => gw.GatewayName.Equals(localNetworkGatewayName));
                string localNetworkGatewayId = localNetworkGateway.Id.ToString();

                // Create a connection from the virtual network gateway to the local network gateway
                // with BGP enabled
                string gatewayConnectionName = "bgpTestConnection";

                GatewayGetOperationStatusResponse gatewayGetOperationStatusResponse =
                    networkTestClient.Gateways.CreateGatewayConnection(
                        new GatewayConnectionCreateParameters()
                {
                    ConnectedEntityId       = localNetworkGatewayId,
                    GatewayConnectionName   = gatewayConnectionName,
                    GatewayConnectionType   = GatewayConnectionType.IPsec,
                    VirtualNetworkGatewayId = vnetGateway.GatewayId,
                    RoutingWeight           = 3,
                    SharedKey = "abc",
                    EnableBgp = true
                }
                        );
                Assert.NotNull(gatewayGetOperationStatusResponse);
                Assert.Equal(HttpStatusCode.OK, gatewayGetOperationStatusResponse.HttpStatusCode);

                GatewayConnectionGetResponse gatewayConnectionGetResponse = networkTestClient.Gateways.GetGatewayConnection(virtualNetworkGatewayId, localNetworkGatewayId);
                Assert.True(gatewayConnectionGetResponse.EnableBgp, "Connection should have BGP enabled");

                gatewayGetOperationStatusResponse = networkTestClient.Gateways.DeleteGatewayConnection(virtualNetworkGatewayId, localNetworkGatewayId);
                Assert.NotNull(gatewayGetOperationStatusResponse);
                Assert.Equal(HttpStatusCode.OK, gatewayGetOperationStatusResponse.HttpStatusCode);

                response = networkTestClient.Gateways.DeleteVirtualNetworkGateway(virtualNetworkGatewayId);
                Assert.NotNull(response);
                Assert.Equal(HttpStatusCode.OK, response.HttpStatusCode);

                AzureOperationResponse deleteLocalNetworkGatewayResponse = networkTestClient.Gateways.DeleteLocalNetworkGateway(localNetworkGatewayId);
                Assert.NotNull(deleteLocalNetworkGatewayResponse);
                Assert.Equal(HttpStatusCode.OK, deleteLocalNetworkGatewayResponse.StatusCode);
            }
        }
Exemplo n.º 2
0
        public void LocalNetworkGatewayAPIsTests()
        {
            using (NetworkTestClient networkTestClient = new NetworkTestClient())
            {
                string localnetGatewayName = "coexistenceLocalnetGateway";

                // 1.CreateLocalNetworkGateway API
                var param = new LocalNetworkGatewayCreateParameters()
                {
                    AddressSpace = new LazyList <string>()
                    {
                        addressSpace
                    },
                    GatewayName = localnetGatewayName,
                    IpAddress   = localNetworkGatewayIpAddress,
                };

                LocalNetworkGatewayCreateResponse localNetworkGatewayCreateResponse = networkTestClient.Gateways.CreateLocalNetworkGateway(param);
                Assert.NotNull(localNetworkGatewayCreateResponse);
                Assert.Equal(HttpStatusCode.OK, localNetworkGatewayCreateResponse.StatusCode);
                Assert.NotNull(localNetworkGatewayCreateResponse.LocalNetworkGatewayId);

                // 2.Listvirtualnetworkgateways API
                ListLocalNetworkGatewaysResponse listLocalNetworkGatewaysResponse = networkTestClient.Gateways.ListLocalNetworkGateways();
                Assert.NotNull(listLocalNetworkGatewaysResponse);
                Assert.Equal(HttpStatusCode.OK, listLocalNetworkGatewaysResponse.StatusCode);

                ListLocalNetworkGatewaysResponse.LocalNetworkGateway localNetworkGateway = null;
                foreach (ListLocalNetworkGatewaysResponse.LocalNetworkGateway lng in listLocalNetworkGatewaysResponse.LocalNetworkGateways)
                {
                    if (localNetworkGatewayCreateResponse.LocalNetworkGatewayId.IndexOf(lng.Id.ToString(), StringComparison.OrdinalIgnoreCase) >= 0)
                    {
                        localNetworkGateway = lng;
                    }
                }

                Assert.True(localNetworkGateway != null, "The created local network gateway's ID should show up when local network gateways are listed");
                Assert.Equal(localnetGatewayName, localNetworkGateway.GatewayName);
                Assert.Equal(localNetworkGatewayIpAddress, localNetworkGateway.IpAddress);
                Assert.True(localNetworkGateway.AddressSpace.Contains(addressSpace), "CreateLocalNetworkGateway API failed as AddressSpace parameter is not set properly!");

                string localnetGatewayId = listLocalNetworkGatewaysResponse.LocalNetworkGateways.First(localnetGateway =>
                                                                                                       localnetGateway.GatewayName.Equals(localnetGatewayName)).Id.ToString();
                Assert.True(!string.IsNullOrEmpty(localnetGatewayId), "CreateLocalNetworkGateway API Failed as local network gateway: "
                            + localnetGatewayName + "not found!");

                // 3.UpdateLocalNetworkGateway API
                addressSpace = "200.168.0.0/24";
                UpdateLocalNetworkGatewayParameters parameters = new UpdateLocalNetworkGatewayParameters()
                {
                    AddressSpace = new List <string>(new string[] { addressSpace })
                };
                AzureOperationResponse updateLocalNetworkGatewayResponse = networkTestClient.Gateways.UpdateLocalNetworkGateway(localnetGatewayId, parameters);
                Assert.NotNull(updateLocalNetworkGatewayResponse);
                Assert.Equal(HttpStatusCode.OK, updateLocalNetworkGatewayResponse.StatusCode);

                // 4.GetLocalNetworkGateway API
                LocalNetworkGatewayGetResponse localNetworkGatewayGetResponse = networkTestClient.Gateways.GetLocalNetworkGateway(localnetGatewayId);
                Assert.NotNull(localNetworkGatewayGetResponse);
                Assert.Equal(HttpStatusCode.OK, localNetworkGatewayGetResponse.StatusCode);
                Assert.Equal(localnetGatewayName, localNetworkGatewayGetResponse.GatewayName);
                Assert.Equal(localNetworkGatewayIpAddress, localNetworkGatewayGetResponse.IpAddress);
                Assert.True(localNetworkGatewayGetResponse.AddressSpace.Contains(addressSpace), "UpdateLocalNetworkGateway API failed!");

                // 5.DeleteLocalNetworkGateway API
                AzureOperationResponse deleteLocalNetworkGatewayResponse = networkTestClient.Gateways.DeleteLocalNetworkGateway(localnetGatewayId);
                Assert.NotNull(deleteLocalNetworkGatewayResponse);
                Assert.Equal(HttpStatusCode.OK, deleteLocalNetworkGatewayResponse.StatusCode);

                listLocalNetworkGatewaysResponse = networkTestClient.Gateways.ListLocalNetworkGateways();
                Assert.NotNull(listLocalNetworkGatewaysResponse);
                Assert.Equal(HttpStatusCode.OK, listLocalNetworkGatewaysResponse.StatusCode);
                Assert.False(listLocalNetworkGatewaysResponse.LocalNetworkGateways.Any(localnetGateway => localnetGateway.GatewayName.Equals(localnetGatewayName)),
                             "Local network gateway: " + localnetGatewayName + " is not deleted even after DeleteLocalNetworkGateway API call!");
            }
        }
Exemplo n.º 3
0
        public void VirtualNetworkGatewayConnectionAPIsTests()
        {
            using (NetworkTestClient networkTestClient = new NetworkTestClient())
            {
                // 1.CreateGatewayConnection API :-

                // a.CreateVirtualnetworkGateway API
                string virtualNetworkSiteName = "coexistenceVirtualNetworkSiteName";
                string vnetGatewayName        = "coexistenceVnetGateway";

                networkTestClient.EnsureNoNetworkConfigurationExists(virtualNetworkSiteName);

                networkTestClient.SetNetworkConfiguration(NetworkTestConstants.CoexistenceFeatureNetworkConfigurationParameters);
                NetworkListResponse listResponse = networkTestClient.ListNetworkConfigurations();
                Assert.NotNull(listResponse);
                Assert.True(listResponse.VirtualNetworkSites.Any(vnet => vnet.Name.Equals(virtualNetworkSiteName)),
                            "Virtual network:" + virtualNetworkSiteName + " is not found!");
                string vnetId = listResponse.First(vnet => vnet.Name.Equals(virtualNetworkSiteName)).Id;

                GatewayGetOperationStatusResponse response =
                    networkTestClient.Gateways.CreateVirtualNetworkGateway(
                        virtualNetworkSiteName,
                        new VirtualNetworkGatewayCreateParameters()
                {
                    GatewayName = vnetGatewayName,
                    GatewayType = GatewayType.DynamicRouting
                });
                Assert.NotNull(response);
                Assert.Equal(HttpStatusCode.OK, response.HttpStatusCode);

                ListVirtualNetworkGatewaysResponse listVirtualNetworkGatewaysResponse = networkTestClient.Gateways.ListVirtualNetworkGateways();
                Assert.True(listVirtualNetworkGatewaysResponse.VirtualNetworkGateways.Count >= 1);
                Guid vnetGatewayId = listVirtualNetworkGatewaysResponse.VirtualNetworkGateways.First(vnetGateway => vnetGateway.GatewayName.Equals(vnetGatewayName)).GatewayId;

                // b.CreateLocalNetworkGateway API
                string localnetGatewayName = "coexistenceLocalnetGateway";

                var param = new LocalNetworkGatewayCreateParameters()
                {
                    AddressSpace = new LazyList <string>()
                    {
                        addressSpace
                    },
                    GatewayName = localnetGatewayName,
                    IpAddress   = localNetworkGatewayIpAddress,
                };

                LocalNetworkGatewayCreateResponse localNetworkGatewayCreateResponse = networkTestClient.Gateways.CreateLocalNetworkGateway(param);
                Assert.NotNull(localNetworkGatewayCreateResponse);
                Assert.Equal(HttpStatusCode.OK, localNetworkGatewayCreateResponse.StatusCode);
                Assert.NotNull(localNetworkGatewayCreateResponse.LocalNetworkGatewayId);

                ListLocalNetworkGatewaysResponse listLocalNetworkGatewaysResponse = networkTestClient.Gateways.ListLocalNetworkGateways();
                Assert.NotNull(listLocalNetworkGatewaysResponse);
                Assert.Equal(HttpStatusCode.OK, listLocalNetworkGatewaysResponse.StatusCode);
                Assert.Equal(1, listLocalNetworkGatewaysResponse.LocalNetworkGateways.Count);
                string localNetworkGatewayId = listLocalNetworkGatewaysResponse.LocalNetworkGateways.First(localnetGateway =>
                                                                                                           localnetGateway.GatewayName.Equals(localnetGatewayName)).Id.ToString();

                // c.CreateGatewayConnection API
                string gatewayConnectionName = "coexistenceGatewayConnection";

                GatewayGetOperationStatusResponse gatewayGetOperationStatusResponse =
                    networkTestClient.Gateways.CreateGatewayConnection(
                        new GatewayConnectionCreateParameters()
                {
                    ConnectedEntityId       = localNetworkGatewayId,
                    GatewayConnectionName   = gatewayConnectionName,
                    GatewayConnectionType   = GatewayConnectionType.IPsec,
                    VirtualNetworkGatewayId = vnetGatewayId,
                    RoutingWeight           = 3,
                    SharedKey = "abc"
                }
                        );
                Assert.NotNull(gatewayGetOperationStatusResponse);
                Assert.Equal(HttpStatusCode.OK, gatewayGetOperationStatusResponse.HttpStatusCode);

                // 2.GetGatewayConnection API
                GatewayConnectionGetResponse gatewayConnectionGetResponse = networkTestClient.Gateways.GetGatewayConnection(vnetGatewayId.ToString(), localNetworkGatewayId);
                Assert.NotNull(gatewayConnectionGetResponse);
                Assert.Equal(HttpStatusCode.OK, gatewayConnectionGetResponse.StatusCode);
                Assert.Equal(vnetGatewayId, gatewayConnectionGetResponse.VirtualNetworkGatewayId);
                Assert.Equal(localNetworkGatewayId, gatewayConnectionGetResponse.ConnectedEntityId);
                Assert.Equal(gatewayConnectionName, gatewayConnectionGetResponse.GatewayConnectionName);
                Assert.Equal(GatewayConnectionType.IPsec, gatewayConnectionGetResponse.GatewayConnectionType);
                Assert.Equal(3, gatewayConnectionGetResponse.RoutingWeight);
                Assert.Equal("abc", gatewayConnectionGetResponse.SharedKey);

                // 3.UpdateGatewayConnection API
                gatewayGetOperationStatusResponse = networkTestClient.Gateways.UpdateGatewayConnection(
                    vnetGatewayId.ToString(), localNetworkGatewayId,
                    new UpdateGatewayConnectionParameters()
                {
                    RoutingWeight = 4,
                    SharedKey     = "xyz"
                });
                Assert.NotNull(gatewayGetOperationStatusResponse);
                Assert.Equal(HttpStatusCode.OK, gatewayGetOperationStatusResponse.HttpStatusCode);

                // GetGatewayConnection API after UpdateGatewayConnection API
                gatewayConnectionGetResponse = networkTestClient.Gateways.GetGatewayConnection(vnetGatewayId.ToString(), localNetworkGatewayId);
                Assert.NotNull(gatewayConnectionGetResponse);
                Assert.Equal(HttpStatusCode.OK, gatewayConnectionGetResponse.StatusCode);
                Assert.Equal(4, gatewayConnectionGetResponse.RoutingWeight);
                Assert.Equal("xyz", gatewayConnectionGetResponse.SharedKey);

                // 4.ListGatewayConnections API
                GatewayListGatewayConnectionsResponse gatewayListGatewayConnectionsResponse = networkTestClient.Gateways.ListGatewayConnections();
                Assert.NotNull(gatewayListGatewayConnectionsResponse);
                Assert.Equal(HttpStatusCode.OK, gatewayListGatewayConnectionsResponse.StatusCode);
                Assert.Equal(1, gatewayListGatewayConnectionsResponse.VirtualNetworkGatewayConnections.Count);
                Assert.True(gatewayListGatewayConnectionsResponse.VirtualNetworkGatewayConnections.Any(vnetGatewayConnection =>
                                                                                                       vnetGatewayConnection.GatewayConnectionName.Equals(gatewayConnectionName)), "Gateway connection " + gatewayConnectionName + " not found!");

                // 5.DeleteGatewayConnection API
                gatewayGetOperationStatusResponse = networkTestClient.Gateways.DeleteGatewayConnection(vnetGatewayId.ToString(), localNetworkGatewayId);
                Assert.NotNull(gatewayGetOperationStatusResponse);
                Assert.Equal(HttpStatusCode.OK, gatewayGetOperationStatusResponse.HttpStatusCode);

                gatewayListGatewayConnectionsResponse = networkTestClient.Gateways.ListGatewayConnections();
                Assert.False(gatewayListGatewayConnectionsResponse.VirtualNetworkGatewayConnections.Any(vnetGatewayConnection => vnetGatewayConnection.GatewayConnectionName.Equals(gatewayConnectionName)),
                             "Virtual network gateway connection: " + gatewayConnectionName + " is not deleted even after DeleteGatewayConnection API call!");

                // Cleanup test setup at end
                response = networkTestClient.Gateways.DeleteVirtualNetworkGateway(vnetGatewayId.ToString());
                Assert.NotNull(response);
                Assert.Equal(HttpStatusCode.OK, response.HttpStatusCode);

                AzureOperationResponse deleteLocalNetworkGatewayResponse = networkTestClient.Gateways.DeleteLocalNetworkGateway(localNetworkGatewayId);
                Assert.NotNull(deleteLocalNetworkGatewayResponse);
                Assert.Equal(HttpStatusCode.OK, deleteLocalNetworkGatewayResponse.StatusCode);
            }
        }
Exemplo n.º 4
0
        public void LocalNetworkGatewayAPITestsWithBgp()
        {
            using (NetworkTestClient networkTestClient = new NetworkTestClient())
            {
                // CreateLocalNetworkGateway, with BGP settings
                string localNetworkGatewayName = "BgpLocalNetworkGateway";
                uint   localNetworkGatewayAsn  = 1234;
                string localNetworkGatewayBgpPeeringAddress = "192.168.1.2";
                int    localNetworkGatewayPeerWeight        = 5;

                LocalNetworkGatewayCreateParameters createParameters = new LocalNetworkGatewayCreateParameters()
                {
                    AddressSpace = new LazyList <string>()
                    {
                        addressSpace
                    },
                    GatewayName = localNetworkGatewayName,
                    IpAddress   = localNetworkGatewayIpAddress,
                    BgpSettings = new BgpSettings()
                    {
                        Asn = localNetworkGatewayAsn,
                        BgpPeeringAddress = localNetworkGatewayBgpPeeringAddress,
                        PeerWeight        = localNetworkGatewayPeerWeight,
                    }
                };

                LocalNetworkGatewayCreateResponse localNetworkGatewayCreateResponse = networkTestClient.Gateways.CreateLocalNetworkGateway(createParameters);
                Assert.NotNull(localNetworkGatewayCreateResponse);
                Assert.Equal(HttpStatusCode.OK, localNetworkGatewayCreateResponse.StatusCode);
                Assert.NotNull(localNetworkGatewayCreateResponse.LocalNetworkGatewayId);

                // Call ListLocalNetworkGateways, find one with a matching name to get the ID
                ListLocalNetworkGatewaysResponse lngListResponse = networkTestClient.Gateways.ListLocalNetworkGateways();
                ListLocalNetworkGatewaysResponse.LocalNetworkGateway localNetworkGateway = null;

                foreach (ListLocalNetworkGatewaysResponse.LocalNetworkGateway lng in lngListResponse.LocalNetworkGateways)
                {
                    if (lng.GatewayName.Equals(localNetworkGatewayName))
                    {
                        localNetworkGateway = lng;
                        break;
                    }
                }

                Assert.NotNull(localNetworkGateway);
                string localNetworkGatewayId = localNetworkGateway.Id.ToString();

                // BgpSettings should be respected
                // If generated code would generate an equals method, that would have been convenient.
                Assert.Equal(localNetworkGateway.BgpSettings.Asn, localNetworkGatewayAsn);
                Assert.True(localNetworkGateway.BgpSettings.BgpPeeringAddress.Equals(localNetworkGatewayBgpPeeringAddress));
                Assert.Equal(localNetworkGateway.BgpSettings.PeerWeight, localNetworkGatewayPeerWeight);

                // Try an update, with different BgpSettings
                localNetworkGatewayAsn = 5678;
                UpdateLocalNetworkGatewayParameters updateParameters = new UpdateLocalNetworkGatewayParameters()
                {
                    AddressSpace = new List <string>(new string[] { addressSpace }),
                    BgpSettings  = new BgpSettings()
                    {
                        Asn = localNetworkGatewayAsn,
                        BgpPeeringAddress = localNetworkGatewayBgpPeeringAddress,
                        PeerWeight        = localNetworkGatewayPeerWeight
                    }
                };

                AzureOperationResponse updateLocalNetworkGatewayResponse = networkTestClient.Gateways.UpdateLocalNetworkGateway(localNetworkGatewayId, updateParameters);
                Assert.NotNull(updateLocalNetworkGatewayResponse);
                Assert.Equal(HttpStatusCode.OK, updateLocalNetworkGatewayResponse.StatusCode);

                // Call GetLocalNetworkGateway again, and make sure the updated ASN shows up
                LocalNetworkGatewayGetResponse lngGetResponse = networkTestClient.Gateways.GetLocalNetworkGateway(localNetworkGatewayId);
                Assert.NotNull(lngGetResponse);
                Assert.NotNull(lngGetResponse.BgpSettings);
                Assert.Equal(lngGetResponse.BgpSettings.Asn, localNetworkGatewayAsn);

                // Delete
                AzureOperationResponse deleteLocalNetworkGatewayResponse = networkTestClient.Gateways.DeleteLocalNetworkGateway(localNetworkGatewayId);
                Assert.NotNull(deleteLocalNetworkGatewayResponse);
                Assert.Equal(HttpStatusCode.OK, deleteLocalNetworkGatewayResponse.StatusCode);

                // Call list again and make sure the local network gateway isn't there anymore
                lngListResponse     = networkTestClient.Gateways.ListLocalNetworkGateways();
                localNetworkGateway = null;

                foreach (ListLocalNetworkGatewaysResponse.LocalNetworkGateway lng in lngListResponse.LocalNetworkGateways)
                {
                    if (lng.GatewayName.Equals(localNetworkGatewayName))
                    {
                        localNetworkGateway = lng;
                        break;
                    }
                }

                Assert.Null(localNetworkGateway);
            }
        }
Exemplo n.º 5
0
        public void LocalNetworkGatewayAPIsTests()
        {
            using (NetworkTestClient networkTestClient = new NetworkTestClient())
            {
                string localnetGatewayName = "coexistenceLocalnetGateway";

                // 1.CreateLocalNetworkGateway API
                string addressSpace = "200.168.0.0/16";

                var param = new LocalNetworkGatewayCreateParameters()
                {
                    AddressSpace = new LazyList <string>()
                    {
                        addressSpace
                    },
                    GatewayName = localnetGatewayName,
                    IpAddress   = "204.95.99.237",
                };

                LocalNetworkGatewayCreateResponse localNetworkGatewayCreateResponse = networkTestClient.Gateways.CreateLocalNetworkGateway(param);
                Assert.NotNull(localNetworkGatewayCreateResponse);
                Assert.Equal(HttpStatusCode.OK, localNetworkGatewayCreateResponse.StatusCode);
                Assert.NotNull(localNetworkGatewayCreateResponse.LocalNetworkGatewayId);

                // 2.Listvirtualnetworkgateways API
                ListLocalNetworkGatewaysResponse listLocalNetworkGatewaysResponse = networkTestClient.Gateways.ListLocalNetworkGateways();
                Assert.NotNull(listLocalNetworkGatewaysResponse);
                Assert.Equal(HttpStatusCode.OK, listLocalNetworkGatewaysResponse.StatusCode);
                Assert.Equal(1, listLocalNetworkGatewaysResponse.LocalNetworkGateways.Count);

                ListLocalNetworkGatewaysResponse.LocalNetworkGateway localNetworkGateway = listLocalNetworkGatewaysResponse.LocalNetworkGateways.First();
                Assert.Equal(localnetGatewayName, localNetworkGateway.GatewayName);
                Assert.Equal("204.95.99.237", localNetworkGateway.IpAddress);
                Assert.True(localNetworkGateway.AddressSpace.Contains(addressSpace), "CreateLocalNetworkGateway API failed as AddressSpace parameter is not set properly!");

                string localnetGatewayId = listLocalNetworkGatewaysResponse.LocalNetworkGateways.First(localnetGateway =>
                                                                                                       localnetGateway.GatewayName.Equals(localnetGatewayName)).Id.ToString();
                Assert.True(!string.IsNullOrEmpty(localnetGatewayId), "CreateLocalNetworkGateway API Failed as local network gateway: "
                            + localnetGatewayName + "not found!");

                // 3.UpdateLocalNetworkGateway API
                addressSpace = "200.168.0.0/24";
                UpdateLocalNetworkGatewayParameters parameters = new UpdateLocalNetworkGatewayParameters()
                {
                    AddressSpace = new List <string>(new string[] { addressSpace })
                };
                AzureOperationResponse updateLocalNetworkGatewayResponse = networkTestClient.Gateways.UpdateLocalNetworkGateway(localnetGatewayId, parameters);
                Assert.NotNull(updateLocalNetworkGatewayResponse);
                Assert.Equal(HttpStatusCode.OK, updateLocalNetworkGatewayResponse.StatusCode);

                // 4.GetLocalNetworkGateway API
                LocalNetworkGatewayGetResponse localNetworkGatewayGetResponse = networkTestClient.Gateways.GetLocalNetworkGateway(localnetGatewayId);
                Assert.NotNull(localNetworkGatewayGetResponse);
                Assert.Equal(HttpStatusCode.OK, localNetworkGatewayGetResponse.StatusCode);
                Assert.Equal(localnetGatewayName, localNetworkGatewayGetResponse.GatewayName);
                Assert.Equal("204.95.99.237", localNetworkGatewayGetResponse.IpAddress);
                Assert.True(localNetworkGatewayGetResponse.AddressSpace.Contains(addressSpace), "UpdateLocalNetworkGateway API failed!");

                // 5.DeleteLocalNetworkGateway API
                AzureOperationResponse deleteLocalNetworkGatewayResponse = networkTestClient.Gateways.DeleteLocalNetworkGateway(localnetGatewayId);
                Assert.NotNull(deleteLocalNetworkGatewayResponse);
                Assert.Equal(HttpStatusCode.OK, deleteLocalNetworkGatewayResponse.StatusCode);

                listLocalNetworkGatewaysResponse = networkTestClient.Gateways.ListLocalNetworkGateways();
                Assert.NotNull(listLocalNetworkGatewaysResponse);
                Assert.Equal(HttpStatusCode.OK, listLocalNetworkGatewaysResponse.StatusCode);
                Assert.Equal(0, listLocalNetworkGatewaysResponse.LocalNetworkGateways.Count);
                Assert.False(listLocalNetworkGatewaysResponse.LocalNetworkGateways.Any(localnetGateway => localnetGateway.GatewayName.Equals(localnetGatewayName)),
                             "Local network gateway: " + localnetGatewayName + " is not deleted even after DeleteLocalNetworkGateway API call!");
            }
        }
Exemplo n.º 6
0
        public void SharedKeyV2APIsTests()
        {
            using (NetworkTestClient networkTestClient = new NetworkTestClient())
            {
                // 1.ResetSharedKeyV2 API:-
                // a.CreateVirtualnetworkGateway API
                string virtualNetworkSiteName = "coexistenceVirtualNetworkSiteName";
                string vnetGatewayName        = "coexistenceVnetGateway";

                networkTestClient.EnsureNoNetworkConfigurationExists(virtualNetworkSiteName);

                networkTestClient.SetNetworkConfiguration(NetworkTestConstants.CoexistenceFeatureNetworkConfigurationParameters);
                NetworkListResponse listResponse = networkTestClient.ListNetworkConfigurations();
                Assert.NotNull(listResponse);
                Assert.True(listResponse.VirtualNetworkSites.Any(vnet => vnet.Name.Equals(virtualNetworkSiteName)),
                            "Virtual network:" + virtualNetworkSiteName + " is not found!");
                string vnetId = listResponse.First(vnet => vnet.Name.Equals(virtualNetworkSiteName)).Id;

                GatewayGetOperationStatusResponse response =
                    networkTestClient.Gateways.CreateVirtualNetworkGateway(
                        virtualNetworkSiteName,
                        new VirtualNetworkGatewayCreateParameters()
                {
                    GatewayName = vnetGatewayName,
                    GatewayType = GatewayType.DynamicRouting
                });
                Assert.NotNull(response);
                Assert.Equal(HttpStatusCode.OK, response.HttpStatusCode);

                ListVirtualNetworkGatewaysResponse listVirtualNetworkGatewaysResponse = networkTestClient.Gateways.ListVirtualNetworkGateways();
                Assert.True(listVirtualNetworkGatewaysResponse.VirtualNetworkGateways.Count >= 1);
                Guid vnetGatewayId = listVirtualNetworkGatewaysResponse.VirtualNetworkGateways.First(vnetGateway => vnetGateway.GatewayName.Equals(vnetGatewayName)).GatewayId;

                // b.CreateLocalNetworkGateway API
                string localnetGatewayName = "coexistenceLocalnetGateway";
                string addressSpace        = "200.168.0.0/16";

                var param = new LocalNetworkGatewayCreateParameters()
                {
                    AddressSpace = new LazyList <string>()
                    {
                        addressSpace
                    },
                    GatewayName = localnetGatewayName,
                    IpAddress   = "204.95.99.237",
                };

                LocalNetworkGatewayCreateResponse localNetworkGatewayCreateResponse = networkTestClient.Gateways.CreateLocalNetworkGateway(param);
                Assert.NotNull(localNetworkGatewayCreateResponse);
                Assert.Equal(HttpStatusCode.OK, localNetworkGatewayCreateResponse.StatusCode);
                Assert.NotNull(localNetworkGatewayCreateResponse.LocalNetworkGatewayId);

                ListLocalNetworkGatewaysResponse listLocalNetworkGatewaysResponse = networkTestClient.Gateways.ListLocalNetworkGateways();
                Assert.NotNull(listLocalNetworkGatewaysResponse);
                Assert.Equal(HttpStatusCode.OK, listLocalNetworkGatewaysResponse.StatusCode);
                Assert.Equal(1, listLocalNetworkGatewaysResponse.LocalNetworkGateways.Count);
                string localNetworkGatewayId = listLocalNetworkGatewaysResponse.LocalNetworkGateways.First(localnetGateway =>
                                                                                                           localnetGateway.GatewayName.Equals(localnetGatewayName)).Id.ToString();

                // c.CreateGatewayConnection API
                string gatewayConnectionName = "coexistenceGatewayConnection";

                GatewayGetOperationStatusResponse gatewayGetOperationStatusResponse =
                    networkTestClient.Gateways.CreateGatewayConnection(
                        new GatewayConnectionCreateParameters()
                {
                    ConnectedEntityId       = localNetworkGatewayId,
                    GatewayConnectionName   = gatewayConnectionName,
                    GatewayConnectionType   = GatewayConnectionType.IPsec,
                    VirtualNetworkGatewayId = vnetGatewayId,
                    RoutingWeight           = 3,
                    SharedKey = "abc"
                }
                        );
                Assert.NotNull(gatewayGetOperationStatusResponse);
                Assert.Equal(HttpStatusCode.OK, gatewayGetOperationStatusResponse.HttpStatusCode);

                // d.ResetSharedKeyV2 API
                GatewayResetSharedKeyParameters resetParameters = new GatewayResetSharedKeyParameters()
                {
                    KeyLength = 128,
                };
                GatewayGetOperationStatusResponse resetResponse = networkTestClient.Gateways.ResetSharedKeyV2(vnetGatewayId.ToString(), localNetworkGatewayId, resetParameters);
                Assert.NotNull(resetResponse);
                Assert.Equal(HttpStatusCode.OK, resetResponse.HttpStatusCode);

                // 2.GetSharedKeyV2 API
                const string sharedKeyToSet = "MNO";
                GatewayGetSharedKeyResponse firstGetResponse = networkTestClient.Gateways.GetSharedKeyV2(vnetGatewayId.ToString(), localNetworkGatewayId);
                Assert.NotNull(firstGetResponse);
                Assert.Equal(HttpStatusCode.OK, firstGetResponse.StatusCode);
                Assert.NotEqual(sharedKeyToSet, firstGetResponse.SharedKey);

                // 3. SetSharedKeyV2 API
                GatewaySetSharedKeyParameters setParameters = new GatewaySetSharedKeyParameters()
                {
                    Value = sharedKeyToSet
                };

                GatewayGetOperationStatusResponse setResponse = networkTestClient.Gateways.SetSharedKeyV2(vnetGatewayId.ToString(), localNetworkGatewayId, setParameters);
                Assert.NotNull(setResponse);
                Assert.Equal(HttpStatusCode.OK, setResponse.HttpStatusCode);

                // GetSharedKeyV2 API after SetSharedKeyV2 API
                GatewayGetSharedKeyResponse secondGetResponse = networkTestClient.Gateways.GetSharedKeyV2(vnetGatewayId.ToString(), localNetworkGatewayId);
                Assert.NotNull(secondGetResponse);
                Assert.Equal(HttpStatusCode.OK, secondGetResponse.StatusCode);
                Assert.Equal(sharedKeyToSet, secondGetResponse.SharedKey);

                // Cleanup test setup at end
                gatewayGetOperationStatusResponse = networkTestClient.Gateways.DeleteGatewayConnection(vnetGatewayId.ToString(), localNetworkGatewayId);
                Assert.NotNull(gatewayGetOperationStatusResponse);
                Assert.Equal(HttpStatusCode.OK, gatewayGetOperationStatusResponse.HttpStatusCode);

                response = networkTestClient.Gateways.DeleteVirtualNetworkGateway(vnetGatewayId.ToString());
                Assert.NotNull(response);
                Assert.Equal(HttpStatusCode.OK, response.HttpStatusCode);

                AzureOperationResponse deleteLocalNetworkGatewayResponse = networkTestClient.Gateways.DeleteLocalNetworkGateway(localNetworkGatewayId);
                Assert.NotNull(deleteLocalNetworkGatewayResponse);
                Assert.Equal(HttpStatusCode.OK, deleteLocalNetworkGatewayResponse.StatusCode);
            }
        }
Exemplo n.º 7
0
 public LocalNetworkGatewayCreateResponse CreateLocalNetworkGateway(LocalNetworkGatewayCreateParameters parameters)
 {
     return(gatewayClient.CreateLocalNetworkGateway(parameters));
 }
        public void IPsecParametersV2APIsTests()
        {
            using (NetworkTestClient networkTestClient = new NetworkTestClient())
            {
                // 1.SetIPsecParametersV2 API:-
                // a.CreateVirtualnetworkGateway API
                string virtualNetworkSiteName = "coexistenceVirtualNetworkSiteName";
                string vnetGatewayName        = "coexistenceVnetGateway";

                networkTestClient.EnsureNoNetworkConfigurationExists(virtualNetworkSiteName);

                networkTestClient.SetNetworkConfiguration(NetworkTestConstants.CoexistenceFeatureNetworkConfigurationParameters);
                NetworkListResponse listResponse = networkTestClient.ListNetworkConfigurations();
                Assert.NotNull(listResponse);
                Assert.True(listResponse.VirtualNetworkSites.Any(vnet => vnet.Name.Equals(virtualNetworkSiteName)),
                            "Virtual network:" + virtualNetworkSiteName + " is not found!");
                string vnetId = listResponse.First(vnet => vnet.Name.Equals(virtualNetworkSiteName)).Id;

                GatewayGetOperationStatusResponse response =
                    networkTestClient.Gateways.CreateVirtualNetworkGateway(
                        virtualNetworkSiteName,
                        new VirtualNetworkGatewayCreateParameters()
                {
                    GatewayName = vnetGatewayName,
                    GatewayType = GatewayType.DynamicRouting
                });
                Assert.NotNull(response);
                Assert.Equal(HttpStatusCode.OK, response.HttpStatusCode);

                ListVirtualNetworkGatewaysResponse listVirtualNetworkGatewaysResponse = networkTestClient.Gateways.ListVirtualNetworkGateways();
                Assert.True(listVirtualNetworkGatewaysResponse.VirtualNetworkGateways.Count >= 1);
                Guid vnetGatewayId = listVirtualNetworkGatewaysResponse.VirtualNetworkGateways.First(vnetGateway => vnetGateway.GatewayName.Equals(vnetGatewayName)).GatewayId;

                // b.CreateLocalNetworkGateway API
                string localnetGatewayName = "coexistenceLocalnetGateway";
                string addressSpace        = "200.168.0.0/16";

                var param = new LocalNetworkGatewayCreateParameters()
                {
                    AddressSpace = new LazyList <string>()
                    {
                        addressSpace
                    },
                    GatewayName = localnetGatewayName,
                    IpAddress   = "204.95.99.237",
                };

                LocalNetworkGatewayCreateResponse localNetworkGatewayCreateResponse = networkTestClient.Gateways.CreateLocalNetworkGateway(param);
                Assert.NotNull(localNetworkGatewayCreateResponse);
                Assert.Equal(HttpStatusCode.OK, localNetworkGatewayCreateResponse.StatusCode);
                Assert.NotNull(localNetworkGatewayCreateResponse.LocalNetworkGatewayId);

                ListLocalNetworkGatewaysResponse listLocalNetworkGatewaysResponse = networkTestClient.Gateways.ListLocalNetworkGateways();
                Assert.NotNull(listLocalNetworkGatewaysResponse);
                Assert.Equal(HttpStatusCode.OK, listLocalNetworkGatewaysResponse.StatusCode);
                Assert.Equal(1, listLocalNetworkGatewaysResponse.LocalNetworkGateways.Count);
                string localNetworkGatewayId = listLocalNetworkGatewaysResponse.LocalNetworkGateways.First(localnetGateway =>
                                                                                                           localnetGateway.GatewayName.Equals(localnetGatewayName)).Id.ToString();

                // c.CreateGatewayConnection API
                string gatewayConnectionName = "coexistenceGatewayConnection";

                GatewayGetOperationStatusResponse gatewayGetOperationStatusResponse =
                    networkTestClient.Gateways.CreateGatewayConnection(
                        new GatewayConnectionCreateParameters()
                {
                    ConnectedEntityId       = localNetworkGatewayId,
                    GatewayConnectionName   = gatewayConnectionName,
                    GatewayConnectionType   = GatewayConnectionType.IPsec,
                    VirtualNetworkGatewayId = vnetGatewayId,
                    RoutingWeight           = 3,
                    SharedKey = "abc"
                }
                        );
                Assert.NotNull(gatewayGetOperationStatusResponse);
                Assert.Equal(HttpStatusCode.OK, gatewayGetOperationStatusResponse.HttpStatusCode);

                //d. SetIPsecParametersV2 API
                GatewaySetIPsecParametersParameters setParameters = CreateIPSecParameters();
                response = networkTestClient.Gateways.SetIPsecParametersV2(vnetGatewayId.ToString(), localNetworkGatewayId, setParameters);
                Assert.NotNull(response);
                Assert.Equal(HttpStatusCode.OK, response.HttpStatusCode);
                Assert.NotNull(response.Id);

                // 2.GetIPsecParametersV2 API
                GatewayGetIPsecParametersResponse paramResponse = networkTestClient.Gateways.GetIPsecParametersV2(vnetGatewayId.ToString(), localNetworkGatewayId);
                Assert.NotNull(paramResponse);
                Assert.Equal(HttpStatusCode.OK, paramResponse.StatusCode);
                Assert.NotNull(paramResponse.IPsecParameters);
                Assert.Equal(EncryptionType.NoEncryption, paramResponse.IPsecParameters.EncryptionType);
                Assert.Equal(PfsGroup.PFS1, paramResponse.IPsecParameters.PfsGroup);
                Assert.Equal(102400000, paramResponse.IPsecParameters.SADataSizeKilobytes); //Check for default value
                Assert.Equal(3600, paramResponse.IPsecParameters.SALifeTimeSeconds);        //Check for default value
                Assert.Equal("SHA1", paramResponse.IPsecParameters.HashAlgorithm);          //Check for default value

                // Cleanup test setup at end
                gatewayGetOperationStatusResponse = networkTestClient.Gateways.DeleteGatewayConnection(vnetGatewayId.ToString(), localNetworkGatewayId);
                Assert.NotNull(gatewayGetOperationStatusResponse);
                Assert.Equal(HttpStatusCode.OK, gatewayGetOperationStatusResponse.HttpStatusCode);

                response = networkTestClient.Gateways.DeleteVirtualNetworkGateway(vnetGatewayId.ToString());
                Assert.NotNull(response);
                Assert.Equal(HttpStatusCode.OK, response.HttpStatusCode);

                AzureOperationResponse deleteLocalNetworkGatewayResponse = networkTestClient.Gateways.DeleteLocalNetworkGateway(localNetworkGatewayId);
                Assert.NotNull(deleteLocalNetworkGatewayResponse);
                Assert.Equal(HttpStatusCode.OK, deleteLocalNetworkGatewayResponse.StatusCode);
            }
        }