Skip to content

Commit

Permalink
acctest zeroedIpRestrictionHeaders
Browse files Browse the repository at this point in the history
  • Loading branch information
Aris van Ommeren committed Apr 20, 2021
1 parent 01b8202 commit e573085
Showing 1 changed file with 153 additions and 0 deletions.
153 changes: 153 additions & 0 deletions azurerm/internal/services/web/app_service_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,75 @@ func TestAccAppService_zeroedIpRestriction(t *testing.T) {
})
}

func TestAccAppService_zeroedIpRestrictionHeaders(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_app_service", "test")
r := AppServiceResource{}

data.ResourceTest(t, r, []resource.TestStep{
{
// This configuration includes a single explicit ip_restriction with headers
Config: r.completeIpRestriction(data),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("site_config.0.ip_restriction.#").HasValue("1"),
check.That(data.ResourceName).Key("site_config.0.ip_restriction.0.headers.#").HasValue("1"),
check.That(data.ResourceName).Key("site_config.0.ip_restriction.0.headers.0.x_forwarded_for.#").HasValue("2"),
check.That(data.ResourceName).Key("site_config.0.ip_restriction.0.headers.0.x_forwarded_for.0").HasValue("2002::1234:abcd:ffff:c0a8:101/64"),
check.That(data.ResourceName).Key("site_config.0.ip_restriction.0.headers.0.x_forwarded_for.1").HasValue("9.9.9.9/32"),
check.That(data.ResourceName).Key("site_config.0.ip_restriction.0.headers.0.x_azure_fdid.#").HasValue("1"),
check.That(data.ResourceName).Key("site_config.0.ip_restriction.0.headers.0.x_azure_fdid.0").HasValue("55ce4ed1-4b06-4bf1-b40e-4638452104da"),
check.That(data.ResourceName).Key("site_config.0.ip_restriction.0.headers.0.x_fd_health_probe.#").HasValue("1"),
check.That(data.ResourceName).Key("site_config.0.ip_restriction.0.headers.0.x_fd_health_probe.0").HasValue("1"),
check.That(data.ResourceName).Key("site_config.0.ip_restriction.0.headers.0.x_forwarded_host.#").HasValue("1"),
check.That(data.ResourceName).Key("site_config.0.ip_restriction.0.headers.0.x_forwarded_host.0").HasValue("example.com"),
),
},
data.ImportStep(),
{
// This configuration includes a single explicit ip_restriction with one header
Config: r.completeIpRestrictionOneHeader(data),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("site_config.0.ip_restriction.#").HasValue("1"),
check.That(data.ResourceName).Key("site_config.0.ip_restriction.0.headers.#").HasValue("1"),
check.That(data.ResourceName).Key("site_config.0.ip_restriction.0.headers.0.x_forwarded_for.#").HasValue("1"),
check.That(data.ResourceName).Key("site_config.0.ip_restriction.0.headers.0.x_forwarded_for.0").HasValue("9.9.9.9/32"),
check.That(data.ResourceName).Key("site_config.0.ip_restriction.0.headers.0.x_forwarded_for.1").DoesNotExist(),
check.That(data.ResourceName).Key("site_config.0.ip_restriction.0.headers.0.x_azure_fdid").DoesNotExist(),
check.That(data.ResourceName).Key("site_config.0.ip_restriction.0.headers.0.x_fd_health_probe").DoesNotExist(),
check.That(data.ResourceName).Key("site_config.0.ip_restriction.0.headers.0.x_forwarded_host").DoesNotExist(),
),
},
data.ImportStep(),
{
// This configuration has no site_config blocks at all.
Config: r.basic(data),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("site_config.0.ip_restriction.#").HasValue("1"),
check.That(data.ResourceName).Key("site_config.0.ip_restriction.0.headers.#").HasValue("1"),
check.That(data.ResourceName).Key("site_config.0.ip_restriction.0.headers.0.x_forwarded_for.#").HasValue("1"),
check.That(data.ResourceName).Key("site_config.0.ip_restriction.0.headers.0.x_forwarded_for.0").HasValue("9.9.9.9/32"),
check.That(data.ResourceName).Key("site_config.0.ip_restriction.0.headers.0.x_forwarded_for.1").DoesNotExist(),
check.That(data.ResourceName).Key("site_config.0.ip_restriction.0.headers.0.x_azure_fdid").DoesNotExist(),
check.That(data.ResourceName).Key("site_config.0.ip_restriction.0.headers.0.x_fd_health_probe").DoesNotExist(),
check.That(data.ResourceName).Key("site_config.0.ip_restriction.0.headers.0.x_forwarded_host").DoesNotExist(),
),
},
data.ImportStep(),
{
// This configuration explicitly sets ip_restriction.headers to [] using attribute syntax.
Config: r.zeroedIpRestrictionHeaders(data),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("site_config.0.ip_restriction.#").HasValue("1"),
check.That(data.ResourceName).Key("site_config.0.ip_restriction.0.headers.#").HasValue("0"),
),
},
data.ImportStep(),
})
}

func TestAccAppService_manyIpRestrictions(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_app_service", "test")
r := AppServiceResource{}
Expand Down Expand Up @@ -2795,6 +2864,49 @@ resource "azurerm_app_service" "test" {
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger)
}

func (r AppServiceResource) completeIpRestrictionOneHeader(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}
resource "azurerm_app_service_plan" "test" {
name = "acctestASP-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
sku {
tier = "Standard"
size = "S1"
}
}
resource "azurerm_app_service" "test" {
name = "acctestAS-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
app_service_plan_id = azurerm_app_service_plan.test.id
site_config {
ip_restriction {
ip_address = "10.10.10.10/32"
name = "test-restriction"
priority = 123
action = "Allow"
headers {
x_forwarded_for = ["9.9.9.9/32"]
}
}
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger)
}

func (r AppServiceResource) manyCompleteIpRestrictions(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
Expand Down Expand Up @@ -2989,6 +3101,47 @@ resource "azurerm_app_service" "test" {
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger)
}

func (r AppServiceResource) zeroedIpRestrictionHeaders(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}
resource "azurerm_app_service_plan" "test" {
name = "acctestASP-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
sku {
tier = "Standard"
size = "S1"
}
}
resource "azurerm_app_service" "test" {
name = "acctestAS-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
app_service_plan_id = azurerm_app_service_plan.test.id
site_config {
ip_restriction {
ip_address = "10.10.10.10/32"
name = "test-restriction"
priority = 123
action = "Allow"
headers = []
}
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger)
}

func (r AppServiceResource) scmUseMainIPRestriction(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
Expand Down

0 comments on commit e573085

Please sign in to comment.