///GENMHASH:D5E00812BB08739BCD6D0F2DF92124A9:0AEB7EFD7127E8DCF73C7CF7661FF62C
        public IApplicationGatewayRedirectConfiguration RedirectConfiguration()
        {
            SubResource r = Inner.RedirectConfiguration;
            IApplicationGatewayRedirectConfiguration config = null;

            if (r != null)
            {
                Parent.RedirectConfigurations().TryGetValue(ResourceUtils.NameFromResourceId(r.Id), out config);
            }
            return(config);
        }
Example #2
0
        public override IApplicationGateway CreateResource(IApplicationGateways resources)
        {
            testPips = new List <IPublicIPAddress>(applicationGatewayHelper.EnsurePIPs(resources.Manager.PublicIPAddresses));
            networks = resources.Manager.Networks;

            INetwork vnet = networks.Define("net" + applicationGatewayHelper.TestId)
                            .WithRegion(applicationGatewayHelper.Region)
                            .WithNewResourceGroup(applicationGatewayHelper.GroupName)
                            .WithAddressSpace("10.0.0.0/28")
                            .WithSubnet("subnet1", "10.0.0.0/29")
                            .WithSubnet("subnet2", "10.0.0.8/29")
                            .Create();

            Thread creationThread = new Thread(() =>
            {
                Thread.CurrentThread.IsBackground = true;
                // Create an application gateway
                resources.Define(applicationGatewayHelper.AppGatewayName)
                .WithRegion(applicationGatewayHelper.Region)
                .WithExistingResourceGroup(applicationGatewayHelper.GroupName)

                // Request routing rules
                .DefineRequestRoutingRule("rule80")
                .FromPrivateFrontend()
                .FromFrontendHttpPort(80)
                .ToBackendHttpPort(8080)
                .ToBackendIPAddress("11.1.1.1")
                .ToBackendIPAddress("11.1.1.2")
                .WithCookieBasedAffinity()
                .Attach()
                .DefineRequestRoutingRule("rule443")
                .FromPrivateFrontend()
                .FromFrontendHttpsPort(443)
                .WithSslCertificateFromPfxFile(new FileInfo(Path.Combine("Assets", "myTest._pfx")))
                .WithSslCertificatePassword("Abc123")
                .ToBackendHttpConfiguration("config1")
                .ToBackend("backend1")
                .Attach()
                .DefineRequestRoutingRule("rule9000")
                .FromListener("listener1")
                .ToBackendHttpConfiguration("config1")
                .ToBackend("backend1")
                .Attach()
                .DefineRequestRoutingRule("ruleRedirect")
                .FromPrivateFrontend()
                .FromFrontendHttpsPort(444)
                .WithSslCertificate("cert1")
                .WithRedirectConfiguration("redirect1")
                .Attach()

                // Additional/explicit backend HTTP setting configs
                .DefineBackendHttpConfiguration("config1")
                .WithPort(8081)
                .WithRequestTimeout(45)
                .Attach()
                .DefineBackendHttpConfiguration("config2")
                .Attach()

                // Additional/explicit backends
                .DefineBackend("backend1")
                .WithIPAddress("11.1.1.3")
                .WithIPAddress("11.1.1.4")
                .Attach()
                .DefineBackend("backend2")
                .Attach()

                // Additional/explicit frontend listeners
                .DefineListener("listener1")
                .WithPrivateFrontend()
                .WithFrontendPort(9000)
                .WithHttp()
                .Attach()

                // Additional/explicit certificates
                .DefineSslCertificate("cert1")
                .WithPfxFromFile(new FileInfo(Path.Combine("Assets", "myTest2._pfx")))
                .WithPfxPassword("Abc123")
                .Attach()

                // Authentication certificates
                .DefineAuthenticationCertificate("auth2")
                .FromFile(new FileInfo(Path.Combine("Assets", "myTest2.cer")))
                .Attach()

                // Additional/explicit backend HTTP setting configs
                .DefineBackendHttpConfiguration("config1")
                .WithPort(8081)
                .WithRequestTimeout(45)
                .WithHttps()
                .WithAuthenticationCertificateFromFile(new FileInfo(Path.Combine("Assets", "myTest.cer")))
                .Attach()

                .DefineBackendHttpConfiguration("config2")
                .WithPort(8082)
                .WithHttps()
                .WithAuthenticationCertificate("auth2")
                // Add the same cert, so only one should be added
                .WithAuthenticationCertificateFromFile(new FileInfo(Path.Combine("Assets", "myTest2.cer")))
                .Attach()

                // Redirect configurations
                .DefineRedirectConfiguration("redirect1")
                .WithType(ApplicationGatewayRedirectType.Permanent)
                .WithTargetListener("listener1")
                .WithPathIncluded()
                .Attach()
                .DefineRedirectConfiguration("redirect2")
                .WithType(ApplicationGatewayRedirectType.Temporary)
                .WithTargetUrl("http://www.microsoft.com")
                .WithQueryStringIncluded()
                .Attach()

                .WithExistingSubnet(vnet, "subnet1")
                .WithSize(ApplicationGatewaySkuName.StandardMedium)
                .WithInstanceCount(2)
                .Create();
            });

            // Start creating in a separate thread...
            creationThread.Start();

            // ...But don't wait till the end - not needed for the test, 30 sec should be enough
            TestHelper.Delay(30 * 1000);

            // Get the resource as created so far
            string resourceId = applicationGatewayHelper.CreateResourceId(resources.Manager.SubscriptionId);
            IApplicationGateway appGateway = resources.GetById(resourceId);

            Assert.NotNull(appGateway);
            Assert.Equal(ApplicationGatewayTier.Standard, appGateway.Tier);
            Assert.Equal(ApplicationGatewaySkuName.StandardMedium, appGateway.Size);
            Assert.Equal(2, appGateway.InstanceCount);
            Assert.False(appGateway.IsPublic);
            Assert.True(appGateway.IsPrivate);
            Assert.Single(appGateway.IPConfigurations);

            // Verify redirect configurations
            Assert.Equal(2, appGateway.RedirectConfigurations.Count);
            IApplicationGatewayRedirectConfiguration redirect = null;

            Assert.True(appGateway.RedirectConfigurations.TryGetValue("redirect1", out redirect));
            Assert.NotNull(redirect);
            Assert.Equal(ApplicationGatewayRedirectType.Permanent, redirect.Type);
            Assert.NotNull(redirect.TargetListener);
            Assert.Equal("listener1", redirect.TargetListener.Name, true);
            Assert.Null(redirect.TargetUrl);
            Assert.True(redirect.IsPathIncluded);
            Assert.False(redirect.IsQueryStringIncluded);
            Assert.Single(redirect.RequestRoutingRules);

            Assert.True(appGateway.RedirectConfigurations.TryGetValue("redirect2", out redirect));
            Assert.NotNull(redirect);
            Assert.Equal(ApplicationGatewayRedirectType.Temporary, redirect.Type);
            Assert.Null(redirect.TargetListener);
            Assert.NotNull(redirect.TargetUrl);
            Assert.Equal("http://www.microsoft.com", redirect.TargetUrl, true);
            Assert.True(redirect.IsQueryStringIncluded);
            Assert.False(redirect.IsPathIncluded);

            // Verify frontend ports
            Assert.Equal(4, appGateway.FrontendPorts.Count);
            Assert.NotNull(appGateway.FrontendPortNameFromNumber(80));
            Assert.NotNull(appGateway.FrontendPortNameFromNumber(443));
            Assert.NotNull(appGateway.FrontendPortNameFromNumber(9000));
            Assert.NotNull(appGateway.FrontendPortNameFromNumber(444));

            // Verify frontends
            Assert.Single(appGateway.Frontends);
            Assert.Empty(appGateway.PublicFrontends);
            Assert.Single(appGateway.PrivateFrontends);
            IApplicationGatewayFrontend frontend = appGateway.PrivateFrontends.Values.FirstOrDefault();

            Assert.False(frontend.IsPublic);
            Assert.True(frontend.IsPrivate);

            // Verify listeners
            Assert.Equal(4, appGateway.Listeners.Count);
            IApplicationGatewayListener listener = appGateway.Listeners["listener1"];

            Assert.NotNull(listener);
            Assert.Equal(9000, listener.FrontendPortNumber);
            Assert.Equal(ApplicationGatewayProtocol.Http, listener.Protocol);
            Assert.NotNull(listener.Frontend);
            Assert.True(listener.Frontend.IsPrivate);
            Assert.False(listener.Frontend.IsPublic);
            Assert.NotNull(appGateway.ListenerByPortNumber(80));
            Assert.NotNull(appGateway.ListenerByPortNumber(443));
            Assert.NotNull(appGateway.ListenerByPortNumber(444));

            // Verify SSL certificates
            Assert.Equal(2, appGateway.SslCertificates.Count);
            Assert.Contains("cert1", appGateway.SslCertificates.Keys);

            // Verify backend HTTP settings configs
            Assert.Equal(3, appGateway.BackendHttpConfigurations.Count);
            IApplicationGatewayBackendHttpConfiguration config = appGateway.BackendHttpConfigurations["config1"];

            Assert.NotNull(config);
            Assert.Equal(8081, config.Port);
            Assert.Equal(45, config.RequestTimeout);
            Assert.Single(config.AuthenticationCertificates);

            var config2 = appGateway.BackendHttpConfigurations["config2"];

            Assert.NotNull(config2);

            // Verify authentication certificates
            Assert.Equal(2, appGateway.AuthenticationCertificates.Count);
            var authCert2 = appGateway.AuthenticationCertificates["auth2"];

            Assert.NotNull(authCert2);
            Assert.NotNull(authCert2.Data);

            var authCert = config.AuthenticationCertificates.Values.FirstOrDefault();

            Assert.NotNull(authCert);

            Assert.Single(config2.AuthenticationCertificates);
            Assert.Equal(authCert2.Name, config2.AuthenticationCertificates.Values.FirstOrDefault().Name, true);

            // Verify backends
            Assert.Equal(3, appGateway.Backends.Count);
            IApplicationGatewayBackend backend = appGateway.Backends["backend1"];

            Assert.NotNull(backend);
            Assert.Equal(2, backend.Addresses.Count);
            Assert.True(backend.ContainsIPAddress("11.1.1.3"));
            Assert.True(backend.ContainsIPAddress("11.1.1.4"));
            Assert.True(appGateway.Backends.ContainsKey("backend2"));

            // Verify request routing rules
            Assert.Equal(4, appGateway.RequestRoutingRules.Count);
            IApplicationGatewayRequestRoutingRule rule;

            rule = appGateway.RequestRoutingRules["rule80"];
            Assert.NotNull(rule);
            Assert.Equal(vnet.Id, rule.Listener.Frontend.NetworkId);
            Assert.Equal(80, rule.FrontendPort);
            Assert.Equal(8080, rule.BackendPort);
            Assert.True(rule.CookieBasedAffinity);
            Assert.Equal(2, rule.BackendAddresses.Count);
            Assert.True(rule.Backend.ContainsIPAddress("11.1.1.1"));
            Assert.True(rule.Backend.ContainsIPAddress("11.1.1.2"));

            rule = appGateway.RequestRoutingRules["rule443"];
            Assert.NotNull(rule);
            Assert.Equal(vnet.Id, rule.Listener.Frontend.NetworkId);
            Assert.Equal(443, rule.FrontendPort);
            Assert.Equal(ApplicationGatewayProtocol.Https, rule.FrontendProtocol);
            Assert.NotNull(rule.SslCertificate);
            Assert.NotNull(rule.BackendHttpConfiguration);
            Assert.Equal("config1", rule.BackendHttpConfiguration.Name, true);
            Assert.NotNull(rule.Backend);
            Assert.Equal("backend1", rule.Backend.Name, true);

            rule = appGateway.RequestRoutingRules["rule9000"];
            Assert.NotNull(rule);
            Assert.NotNull(rule.Listener);
            Assert.Equal("listener1", rule.Listener.Name);
            Assert.NotNull(rule.Listener.SubnetName);
            Assert.NotNull(rule.Listener.NetworkId);
            Assert.NotNull(rule.BackendHttpConfiguration);
            Assert.Equal("config1", rule.BackendHttpConfiguration.Name, true);
            Assert.NotNull(rule.Backend);
            Assert.Equal("backend1", rule.Backend.Name, true);

            rule = appGateway.RequestRoutingRules["ruleRedirect"];
            Assert.NotNull(rule);
            Assert.NotNull(rule.RedirectConfiguration);
            Assert.Equal("redirect1", rule.RedirectConfiguration.Name, true);

            creationThread.Join();

            return(appGateway);
        }