public async Task TestSetUp() { var client = GetArmClient(); var _ = await client.GetDefaultSubscriptionAsync(); // TODO: hack to avoid mismatch of recordings so we don't need to re-record for the change. Remove when you need to run live tests next time. _resourceGroup = await client.GetResourceGroupResource(_resourceGroupIdentifier).GetAsync(); VirtualNetworkResource vnet = await _resourceGroup.GetVirtualNetworks().GetAsync(_subnetIdentifier.Parent.Name); _subnet = await vnet.GetSubnets().GetAsync(_subnetIdentifier.Name); _publicIPAddress = await _resourceGroup.GetPublicIPAddresses().GetAsync(_publicIPAddressIdentifier.Name); }
private ApplicationGatewayData CreateApplicationGateway(string location, SubnetResource subnet, string resourceGroupName, string appGwName, string subscriptionId) { string gatewayIPConfigName = Recording.GenerateAssetName("azsmnet"); string frontendIPConfigName = Recording.GenerateAssetName("azsmnet"); string frontendPort1Name = Recording.GenerateAssetName("azsmnet"); string frontendPort2Name = Recording.GenerateAssetName("azsmnet"); string frontendPort3Name = Recording.GenerateAssetName("azsmnet"); string frontendPort4Name = Recording.GenerateAssetName("azsmnet"); string backendAddressPoolName = Recording.GenerateAssetName("azsmnet"); string nicBackendAddressPoolName = Recording.GenerateAssetName("azsmnet"); string backendHttpSettings1Name = Recording.GenerateAssetName("azsmnet"); string backendHttpSettings2Name = Recording.GenerateAssetName("azsmnet"); string requestRoutingRule1Name = Recording.GenerateAssetName("azsmnet"); string requestRoutingRule2Name = Recording.GenerateAssetName("azsmnet"); string requestRoutingRule3Name = Recording.GenerateAssetName("azsmnet"); string requestRoutingRule4Name = Recording.GenerateAssetName("azsmnet"); string httpListener1Name = Recording.GenerateAssetName("azsmnet"); string httpListener2Name = Recording.GenerateAssetName("azsmnet"); string httpListener3Name = Recording.GenerateAssetName("azsmnet"); string httpListener4Name = Recording.GenerateAssetName("azsmnet"); string probeName = Recording.GenerateAssetName("azsmnet"); string sslCertName = Recording.GenerateAssetName("azsmnet"); string authCertName = Recording.GenerateAssetName("azsmnet"); string redirectConfiguration1Name = Recording.GenerateAssetName("azsmnet"); string redirectConfiguration2Name = Recording.GenerateAssetName("azsmnet"); string urlPathMapName = Recording.GenerateAssetName("azsmnet"); string pathRuleName = Recording.GenerateAssetName("azsmnet"); var appGw = new ApplicationGatewayData() { Location = location, Sku = new ApplicationGatewaySku() { Name = ApplicationGatewaySkuName.WAFMedium, Tier = ApplicationGatewayTier.WAF, Capacity = 2 }, GatewayIPConfigurations = { new ApplicationGatewayIPConfiguration() { Name = gatewayIPConfigName, Subnet = new WritableSubResource() { Id = subnet.Id } } }, FrontendIPConfigurations = { new ApplicationGatewayFrontendIPConfiguration() { Name = frontendIPConfigName, PrivateIPAllocationMethod = IPAllocationMethod.Dynamic, Subnet = new WritableSubResource() { Id = subnet.Id } } }, FrontendPorts = { new ApplicationGatewayFrontendPort() { Name = frontendPort1Name, Port = 80 }, new ApplicationGatewayFrontendPort() { Name = frontendPort2Name, Port = 443 }, new ApplicationGatewayFrontendPort() { Name = frontendPort3Name, Port = 8080 }, new ApplicationGatewayFrontendPort() { Name = frontendPort4Name, Port = 8081 } }, Probes = { new ApplicationGatewayProbe() { Name = probeName, Protocol = ApplicationGatewayProtocol.Http, Path = "/path/path.htm", Interval = 17, Timeout = 17, UnhealthyThreshold = 5, PickHostNameFromBackendHttpSettings = true, Match = new ApplicationGatewayProbeHealthResponseMatch { Body = "helloworld", StatusCodes ={ "200-300", "403" } } } }, BackendAddressPools = { new ApplicationGatewayBackendAddressPool() { Name = backendAddressPoolName, BackendAddresses = { new ApplicationGatewayBackendAddress() { IPAddress = "hello1.azurewebsites.net" }, new ApplicationGatewayBackendAddress() { IPAddress = "hello2.azurewebsites.net" } } }, new ApplicationGatewayBackendAddressPool() { Name = nicBackendAddressPoolName } }, BackendHttpSettingsCollection = { new ApplicationGatewayBackendHttpSettings() { Name = backendHttpSettings1Name, Port = 80, Protocol = ApplicationGatewayProtocol.Http, CookieBasedAffinity = ApplicationGatewayCookieBasedAffinity.Disabled, RequestTimeout = 69, Probe = new WritableSubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "probes", probeName) }, ConnectionDraining = new ApplicationGatewayConnectionDraining(true, 42), ProbeEnabled = true, PickHostNameFromBackendAddress = true }, new ApplicationGatewayBackendHttpSettings() { Name = backendHttpSettings2Name, Port = 443, Protocol = ApplicationGatewayProtocol.Https, CookieBasedAffinity = ApplicationGatewayCookieBasedAffinity.Enabled, AuthenticationCertificates = { new WritableSubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "authenticationCertificates", authCertName) } } } }, HttpListeners = { new ApplicationGatewayHttpListener() { Name = httpListener1Name, FrontendPort = new WritableSubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "frontendPorts", frontendPort1Name) }, FrontendIPConfiguration = new WritableSubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "frontendIPConfigurations", frontendIPConfigName) }, SslCertificate = null, Protocol = ApplicationGatewayProtocol.Http }, new ApplicationGatewayHttpListener() { Name = httpListener2Name, FrontendPort = new WritableSubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "frontendPorts", frontendPort2Name) }, FrontendIPConfiguration = new WritableSubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "frontendIPConfigurations", frontendIPConfigName) }, SslCertificate = new WritableSubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "sslCertificates", sslCertName) }, Protocol = ApplicationGatewayProtocol.Https }, new ApplicationGatewayHttpListener() { Name = httpListener3Name, FrontendPort = new WritableSubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "frontendPorts", frontendPort3Name) }, FrontendIPConfiguration = new WritableSubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "frontendIPConfigurations", frontendIPConfigName) }, SslCertificate = new WritableSubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "sslCertificates", sslCertName) }, Protocol = ApplicationGatewayProtocol.Https }, new ApplicationGatewayHttpListener() { Name = httpListener4Name, FrontendPort = new WritableSubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "frontendPorts", frontendPort4Name) }, FrontendIPConfiguration = new WritableSubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "frontendIPConfigurations", frontendIPConfigName) }, SslCertificate = new WritableSubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "sslCertificates", sslCertName) }, Protocol = ApplicationGatewayProtocol.Https } }, UrlPathMaps = { new ApplicationGatewayUrlPathMap { Name = urlPathMapName, DefaultRedirectConfiguration = new WritableSubResource { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "redirectConfigurations", redirectConfiguration2Name) }, PathRules = { new ApplicationGatewayPathRule { Name = pathRuleName, Paths = { "/paa"}, BackendAddressPool = new WritableSubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "backendAddressPools", backendAddressPoolName) }, BackendHttpSettings = new WritableSubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "backendHttpSettingsCollection", backendHttpSettings1Name) } } } } }, RequestRoutingRules = { new ApplicationGatewayRequestRoutingRule() { Name = requestRoutingRule1Name, RuleType = ApplicationGatewayRequestRoutingRuleType.Basic, HttpListener = new WritableSubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "httpListeners", httpListener1Name) }, BackendAddressPool = new WritableSubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "backendAddressPools", backendAddressPoolName) }, BackendHttpSettings = new WritableSubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "backendHttpSettingsCollection", backendHttpSettings1Name) } }, new ApplicationGatewayRequestRoutingRule() { Name = requestRoutingRule2Name, RuleType = ApplicationGatewayRequestRoutingRuleType.Basic, HttpListener = new WritableSubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "httpListeners", httpListener2Name) }, RedirectConfiguration = new WritableSubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "redirectConfigurations", redirectConfiguration1Name) } }, new ApplicationGatewayRequestRoutingRule() { Name = requestRoutingRule3Name, RuleType = ApplicationGatewayRequestRoutingRuleType.PathBasedRouting, HttpListener = new WritableSubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "httpListeners", httpListener3Name) }, UrlPathMap = new WritableSubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "urlPathMaps", urlPathMapName) } }, new ApplicationGatewayRequestRoutingRule() { Name = requestRoutingRule4Name, RuleType = ApplicationGatewayRequestRoutingRuleType.Basic, HttpListener = new WritableSubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "httpListeners", httpListener4Name) }, BackendAddressPool = new WritableSubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "backendAddressPools", nicBackendAddressPoolName) }, BackendHttpSettings = new WritableSubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "backendHttpSettingsCollection", backendHttpSettings2Name) } }, }, AuthenticationCertificates = { CreateAuthCertificate(authCertName) }, WebApplicationFirewallConfiguration = new ApplicationGatewayWebApplicationFirewallConfiguration(true, ApplicationGatewayFirewallMode.Prevention, "OWASP", "2.2.9") { DisabledRuleGroups = { new ApplicationGatewayFirewallDisabledRuleGroup("crs_41_sql_injection_attacks") { Rules ={ 981318, 981320 } }, new ApplicationGatewayFirewallDisabledRuleGroup("crs_35_bad_robots") } }, SslPolicy = new ApplicationGatewaySslPolicy() { PolicyType = "Predefined", PolicyName = "AppGwSslPolicy20170401" }, RedirectConfigurations = { new ApplicationGatewayRedirectConfiguration { Name = redirectConfiguration1Name, RedirectType = ApplicationGatewayRedirectType.Permanent, TargetListener = new WritableSubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "httpListeners", httpListener1Name) }, }, new ApplicationGatewayRedirectConfiguration { Name = redirectConfiguration2Name, RedirectType = ApplicationGatewayRedirectType.Permanent, TargetUri = new Uri("http://www.bing.com") } }, //SslCertificates = CreateSslCertificate(sslCertName, "abc") }; return(appGw); }
private ApplicationGatewayData CreateApplicationGatewayWithoutSsl(string location, SubnetResource subnet, string resourceGroupName, string appGwName, string subscriptionId, string[] ipAddresses) { string gatewayIPConfigName = Recording.GenerateAssetName("azsmnet"); string frontendIPConfigName = Recording.GenerateAssetName("azsmnet"); string frontendPort1Name = Recording.GenerateAssetName("azsmnet"); string backendAddressPoolName = Recording.GenerateAssetName("azsmnet"); string nicBackendAddressPoolName = Recording.GenerateAssetName("azsmnet"); string backendHttpSettings1Name = Recording.GenerateAssetName("azsmnet"); string requestRoutingRule1Name = Recording.GenerateAssetName("azsmnet"); string httpListener1Name = Recording.GenerateAssetName("azsmnet"); var appGw = new ApplicationGatewayData() { Location = location, Sku = new ApplicationGatewaySku() { Name = ApplicationGatewaySkuName.WAFMedium, Tier = ApplicationGatewayTier.WAF, Capacity = 2 }, GatewayIPConfigurations = { new ApplicationGatewayIPConfiguration() { Name = gatewayIPConfigName, Subnet = new WritableSubResource() { Id = subnet.Id } } }, FrontendIPConfigurations = { new ApplicationGatewayFrontendIPConfiguration() { Name = frontendIPConfigName, PrivateIPAllocationMethod = IPAllocationMethod.Dynamic, Subnet = new WritableSubResource() { Id = subnet.Id } } }, FrontendPorts = { new ApplicationGatewayFrontendPort() { Name = frontendPort1Name, Port = 80 } }, Probes = { }, BackendAddressPools = { new ApplicationGatewayBackendAddressPool() { Name = backendAddressPoolName, BackendAddresses = { new ApplicationGatewayBackendAddress() { IPAddress = ipAddresses[0] }, new ApplicationGatewayBackendAddress() { IPAddress = ipAddresses[1] } } }, new ApplicationGatewayBackendAddressPool() { Name = nicBackendAddressPoolName } }, BackendHttpSettingsCollection = { new ApplicationGatewayBackendHttpSettings() { Name = backendHttpSettings1Name, Port = 80, Protocol = ApplicationGatewayProtocol.Http, CookieBasedAffinity = ApplicationGatewayCookieBasedAffinity.Disabled, RequestTimeout = 20, } }, HttpListeners = { new ApplicationGatewayHttpListener() { Name = httpListener1Name, FrontendPort = new WritableSubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "frontendPorts", frontendPort1Name) }, FrontendIPConfiguration = new WritableSubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "frontendIPConfigurations", frontendIPConfigName) }, SslCertificate = null, Protocol = ApplicationGatewayProtocol.Http } }, UrlPathMaps = { }, RequestRoutingRules = { new ApplicationGatewayRequestRoutingRule() { Name = requestRoutingRule1Name, RuleType = ApplicationGatewayRequestRoutingRuleType.Basic, HttpListener = new WritableSubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "httpListeners", httpListener1Name) }, BackendAddressPool = new WritableSubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "backendAddressPools", backendAddressPoolName) }, BackendHttpSettings = new WritableSubResource() { Id = GetChildAppGwResourceId(subscriptionId, resourceGroupName, appGwName, "backendHttpSettingsCollection", backendHttpSettings1Name) } } }, RedirectConfigurations = { }, }; return(appGw); }