Skip to content

Commit

Permalink
[WAFD] throttling test (#2462)
Browse files Browse the repository at this point in the history
[WAFD] throttling test

Summary of the Pull Request
PR Checklist

 Refers to: #2460
 Tests added/passed.
 Documentation updated.
 Schema updated.
 Release notes added.

Acceptance Steps Performed
=== RUN   TestThrottlingWafDedicatedConfiguration
--- PASS: TestThrottlingWafDedicatedConfiguration (406.18s)
PASS

Process finished with the exit code 0

Reviewed-by: Aloento
Reviewed-by: Artem Lifshits
Reviewed-by: Sergei Martynov
  • Loading branch information
anton-sidelnikov committed Mar 12, 2024
1 parent 77f59bf commit d10830f
Show file tree
Hide file tree
Showing 4 changed files with 221 additions and 0 deletions.
90 changes: 90 additions & 0 deletions opentelekomcloud/acceptance/throttling/src/wafdmain.tf.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package src

const WafdMain = `
##############
# NETWORK part
##############
resource "opentelekomcloud_vpc_v1" "vpc" {
name = var.environment
cidr = var.vpc_cidr
shared = true
}
resource "opentelekomcloud_vpc_subnet_v1" "subnet" {
name = var.environment
vpc_id = opentelekomcloud_vpc_v1.vpc.id
cidr = var.subnet_cidr
gateway_ip = var.subnet_gateway_ip
primary_dns = var.subnet_primary_dns
secondary_dns = var.subnet_secondary_dns
}
data "opentelekomcloud_networking_secgroup_v2" "default_secgroup" {
name = "default"
}
####################
# WAFD INSTANCE part
####################
resource "opentelekomcloud_waf_dedicated_instance_v1" "wafd_1" {
name = "wafd_throttling_test"
availability_zone = var.wafd_az
specification = "waf.instance.professional"
flavor = var.wafd_flavor
architecture = var.wafd_arch
vpc_id = opentelekomcloud_vpc_subnet_v1.subnet.vpc_id
subnet_id = opentelekomcloud_vpc_subnet_v1.subnet.network_id
security_group = [
data.opentelekomcloud_networking_secgroup_v2.default_secgroup.id
]
}
##################
# WAFD DOMAIN part
##################
resource "opentelekomcloud_waf_dedicated_policy_v1" "policy_1" {
name = "policy_throttling"
}
resource "opentelekomcloud_waf_dedicated_domain_v1" "domain_1" {
domain = "www.wafd.throttling-test.com"
keep_policy = true
proxy = true
policy_id = opentelekomcloud_waf_dedicated_policy_v1.policy_1.id
server {
client_protocol = "HTTP"
server_protocol = "HTTP"
address = "10.1.0.10"
port = 8080
type = "ipv4"
vpc_id = opentelekomcloud_vpc_subnet_v1.subnet.vpc_id
}
}
######################
# WAFD RULES part / 30
######################
resource "opentelekomcloud_waf_dedicated_cc_rule_v1" "rule_cc" {
count = 30
policy_id = opentelekomcloud_waf_dedicated_policy_v1.policy_1.id
mode = 0
url = "/abc_${count.index}"
limit_num = 10
limit_period = 60
lock_time = 10
tag_type = "cookie"
tag_index = "sessionid"
action {
category = "block"
content_type = "application/json"
content = "{\"error\":\"forbidden\"}"
}
}
`
96 changes: 96 additions & 0 deletions opentelekomcloud/acceptance/throttling/src/wafdvars.tf.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package src

const WafdVars = `
#############
# Environment
#############
variable "environment" {
default = "throttle-wafd-test"
}
###################
# OTC auth config
###################
variable "region" {
default = "eu-de"
}
variable "otc_domain" {
default = "eu-de"
}
variable "auth_url" {
default = "https://iam.eu-de.otc.t-systems.com:443/v3"
}
variable "tenant_name" {
default = "eu-de"
}
variable "access_key" {
default = ""
}
variable "secret_key" {
default = ""
}
variable "key" {
default = ""
}
##########
# VPC vars
##########
variable "vpc_cidr" {
description = "CIDR of the VPC"
default = "10.1.0.0/24"
}
#############
# Subnet vars
#############
variable "subnet_cidr" {
description = "CIDR of the Subnet"
default = "10.1.0.0/24"
}
variable "subnet_gateway_ip" {
description = "Default gateway of the Subnet"
default = "10.1.0.1"
}
variable "subnet_primary_dns" {
description = "Primary DNS server of the Subnet"
default = "100.125.4.25"
}
variable "subnet_secondary_dns" {
description = "Secondary DNS server of the Subnet"
default = "100.125.129.199"
}
###########
# WAFD vars
###########
variable "wafd_az" {
description = "Availability Zone 1 (Biere)"
default = "eu-de-01"
}
variable "wafd_flavor" {
description = "Name of the wafd flavor"
default = "s2.large.2"
}
variable "wafd_arch" {
description = "Name of the wafd arch"
default = "x86"
}
`
32 changes: 32 additions & 0 deletions opentelekomcloud/acceptance/throttling/throttling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,35 @@ func TestThrottlingConfiguration(t *testing.T) {
},
})
}

var mergedWafdConfigs = fmt.Sprintf("%s\n%s\n", src.WafdVars, src.WafdMain)

func TestThrottlingWafDedicatedConfiguration(t *testing.T) {
if os.Getenv("OS_THROTTLING_WAFD") == "" {
t.Skip("OS_THROTTLING_WAFD is not set; skipping OpenTelekomCloud WAFD THROTTLING test.")
}
err := os.Setenv("OS_MAX_BACKOFF_RETRIES", "30")
if err != nil {
return
}
err = os.Setenv("OS_BACKOFF_RETRY_TIMEOUT", "60")
if err != nil {
return
}
resource.Test(t, resource.TestCase{
PreCheck: func() {
common.TestAccPreCheck(t)
},
ProviderFactories: common.TestAccProviderFactories,
Steps: []resource.TestStep{
{
Config: mergedWafdConfigs,
PlanOnly: true,
ExpectNonEmptyPlan: true,
},
{
Config: mergedWafdConfigs,
},
},
})
}
3 changes: 3 additions & 0 deletions releasenotes/notes/wafd-throttling-test-91d42034fee3a795.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
other:
- |
**[WAFD]** Added test in ``acceptance/throttling_test.go`` (`#2462 <https://github.com/opentelekomcloud/terraform-provider-opentelekomcloud/pull/2462>`_)

0 comments on commit d10830f

Please sign in to comment.