Ejemplo n.º 1
0
 public void Undo()
 {
     GatewaySetSharedKeyParameters oldParameters = new GatewaySetSharedKeyParameters()
     {
         Value = oldSharedKey,
     };
     gatewayClient.SetSharedKey(virtualNetworkSiteName, localNetworkSiteName, oldParameters);
 }
Ejemplo n.º 2
0
        public SetSharedKey(IGatewayOperations gatewayClient, string virtualNetworkSiteName, string localNetworkSiteName, GatewaySetSharedKeyParameters parameters)
        {
            this.gatewayClient = gatewayClient;
            this.virtualNetworkSiteName = virtualNetworkSiteName;
            this.localNetworkSiteName = localNetworkSiteName;
            this.parameters = parameters;

            oldSharedKey = gatewayClient.GetSharedKey(virtualNetworkSiteName, localNetworkSiteName).SharedKey;
        }
        public void SetSharedKeyWithEmptySharedKeyValue()
        {
            using (NetworkTestClient networkTestClient = new NetworkTestClient())
            {
                networkTestClient.Gateways.EnsureStaticRoutingGatewayExists();

                GatewaySetSharedKeyParameters setParameters = new GatewaySetSharedKeyParameters()
                {
                    Value = "",
                };

                try
                {
                    networkTestClient.Gateways.SetSharedKey(NetworkTestConstants.VirtualNetworkSiteName, NetworkTestConstants.LocalNetworkSiteName, setParameters);
                    Assert.False(true, "SetSharedKey should have thrown a BadRequest CloudException when the shared key value was empty.");
                }
                catch (Hyak.Common.CloudException e)
                {
                    Assert.Equal("BadRequest", e.Error.Code);
                }
            }
        }
 /// <summary>
 /// The Begin Set Virtual Network Gateway Shared Key operation sets the
 /// shared key on the virtual network gateway for the specified
 /// virtual network connection to the specified local network in
 /// Azure.  (see
 /// http://msdn.microsoft.com/en-us/library/windowsazure/jj154114.aspx
 /// for more information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.Network.IGatewayOperations.
 /// </param>
 /// <param name='networkName'>
 /// Required. The name of the virtual network for this gateway.
 /// </param>
 /// <param name='localNetworkName'>
 /// Required. The name of the local network.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to the Begin Virtual Network Gateway
 /// Set Shared Key request.
 /// </param>
 /// <returns>
 /// A standard service response including an HTTP status code and
 /// request ID.
 /// </returns>
 public static Task<GatewayOperationResponse> BeginSetSharedKeyAsync(this IGatewayOperations operations, string networkName, string localNetworkName, GatewaySetSharedKeyParameters parameters)
 {
     return operations.BeginSetSharedKeyAsync(networkName, localNetworkName, parameters, CancellationToken.None);
 }
 /// <summary>
 /// The Begin Set Virtual Network Gateway Shared Key operation sets the
 /// shared key on the virtual network gateway for the specified
 /// virtual network connection to the specified local network in
 /// Azure.  (see
 /// http://msdn.microsoft.com/en-us/library/windowsazure/jj154114.aspx
 /// for more information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.Network.IGatewayOperations.
 /// </param>
 /// <param name='networkName'>
 /// Required. The name of the virtual network for this gateway.
 /// </param>
 /// <param name='localNetworkName'>
 /// Required. The name of the local network.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to the Begin Virtual Network Gateway
 /// Set Shared Key request.
 /// </param>
 /// <returns>
 /// A standard service response including an HTTP status code and
 /// request ID.
 /// </returns>
 public static GatewayOperationResponse BeginSetSharedKey(this IGatewayOperations operations, string networkName, string localNetworkName, GatewaySetSharedKeyParameters parameters)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IGatewayOperations)s).BeginSetSharedKeyAsync(networkName, localNetworkName, parameters);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
        public void SetSharedKey()
        {
            using (NetworkTestClient networkTestClient = new NetworkTestClient())
            {
                networkTestClient.Gateways.EnsureStaticRoutingGatewayExists();

                GatewayResetSharedKeyParameters resetParameters = new GatewayResetSharedKeyParameters()
                {
                    KeyLength = 128,
                };
                GatewayGetOperationStatusResponse resetResponse = networkTestClient.Gateways.ResetSharedKey(NetworkTestConstants.VirtualNetworkSiteName, NetworkTestConstants.LocalNetworkSiteName, resetParameters);
                Assert.NotNull(resetResponse);
                Assert.Equal(HttpStatusCode.OK, resetResponse.HttpStatusCode);

                const string sharedKeyToSet = "ABC";

                GatewayGetSharedKeyResponse firstGetResponse = networkTestClient.Gateways.GetSharedKey(NetworkTestConstants.VirtualNetworkSiteName, NetworkTestConstants.LocalNetworkSiteName);
                Assert.NotEqual(sharedKeyToSet, firstGetResponse.SharedKey);

                GatewaySetSharedKeyParameters setParameters = new GatewaySetSharedKeyParameters()
                {
                    Value = sharedKeyToSet,
                };


                GatewayGetOperationStatusResponse setResponse = networkTestClient.Gateways.SetSharedKey(NetworkTestConstants.VirtualNetworkSiteName, NetworkTestConstants.LocalNetworkSiteName, setParameters);
                Assert.NotNull(setResponse);
                Assert.Equal(HttpStatusCode.OK, setResponse.HttpStatusCode);


                GatewayGetSharedKeyResponse secondGetResponse = networkTestClient.Gateways.GetSharedKey(NetworkTestConstants.VirtualNetworkSiteName, NetworkTestConstants.LocalNetworkSiteName);
                Assert.Equal(sharedKeyToSet, secondGetResponse.SharedKey);
            }
        }
 public GatewayGetOperationStatusResponse SetSharedKeyV2(string gatewayId, string connectedentityId, GatewaySetSharedKeyParameters parameters)
 {
     return gatewayClient.SetSharedKeyV2(gatewayId, connectedentityId, parameters);
 }
        public GatewayGetOperationStatusResponse SetSharedKey(string virtualNetworkSiteName, string localNetworkSiteName, GatewaySetSharedKeyParameters parameters)
        {
            SetSharedKey operation = new SetSharedKey(gatewayClient, virtualNetworkSiteName, localNetworkSiteName, parameters);

            testClient.InvokeTestOperation(operation);

            return operation.InvokeResponse;
        }
Ejemplo n.º 9
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);
            }
        }
 /// <summary>
 /// The Set Virtual Network Gateway Shared Key V2 operation sets the
 /// shared key used between the gateway and customer vpn for the
 /// specified site.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.Network.IGatewayOperations.
 /// </param>
 /// <param name='gatewayId'>
 /// Required. The virtual network for this gateway Id.
 /// </param>
 /// <param name='connectedentityId'>
 /// Required. The connected entity Id.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to Virtual Network Gateway Set Shared
 /// Key V2 request.
 /// </param>
 /// <returns>
 /// The response body contains the status of the specified asynchronous
 /// operation, indicating whether it has succeeded, is in progress, or
 /// has failed. Note that this status is distinct from the HTTP status
 /// code returned for the Get Operation Status operation itself. If
 /// the asynchronous operation succeeded, the response body includes
 /// the HTTP status code for the successful request. If the
 /// asynchronous operation failed, the response body includes the HTTP
 /// status code for the failed request, and also includes error
 /// information regarding the failure.
 /// </returns>
 public static Task<GatewayGetOperationStatusResponse> SetSharedKeyV2Async(this IGatewayOperations operations, string gatewayId, string connectedentityId, GatewaySetSharedKeyParameters parameters)
 {
     return operations.SetSharedKeyV2Async(gatewayId, connectedentityId, parameters, CancellationToken.None);
 }
 /// <summary>
 /// The Set Virtual Network Gateway Shared Key V2 operation sets the
 /// shared key used between the gateway and customer vpn for the
 /// specified site.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.Network.IGatewayOperations.
 /// </param>
 /// <param name='gatewayId'>
 /// Required. The virtual network for this gateway Id.
 /// </param>
 /// <param name='connectedentityId'>
 /// Required. The connected entity Id.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to Virtual Network Gateway Set Shared
 /// Key V2 request.
 /// </param>
 /// <returns>
 /// The response body contains the status of the specified asynchronous
 /// operation, indicating whether it has succeeded, is in progress, or
 /// has failed. Note that this status is distinct from the HTTP status
 /// code returned for the Get Operation Status operation itself. If
 /// the asynchronous operation succeeded, the response body includes
 /// the HTTP status code for the successful request. If the
 /// asynchronous operation failed, the response body includes the HTTP
 /// status code for the failed request, and also includes error
 /// information regarding the failure.
 /// </returns>
 public static GatewayGetOperationStatusResponse SetSharedKeyV2(this IGatewayOperations operations, string gatewayId, string connectedentityId, GatewaySetSharedKeyParameters parameters)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IGatewayOperations)s).SetSharedKeyV2Async(gatewayId, connectedentityId, parameters);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }