Fixed tab size on tests
This commit is contained in:
@@ -21,23 +21,29 @@ FIXTURES_DIR = os.path.join(os.path.dirname(__file__), "fixture")
|
||||
|
||||
|
||||
def test_firewall(plan_runner):
|
||||
"Test hierarchical firewall rules from conf/rules"
|
||||
_, resources = plan_runner(FIXTURES_DIR)
|
||||
assert len(resources) == 6
|
||||
assert set(r["type"] for r in resources) == set([
|
||||
"google_compute_organization_security_policy_rule", "google_compute_organization_security_policy_association", "google_compute_organization_security_policy"
|
||||
])
|
||||
rule_ssh = [r["values"] for r in resources if r["type"]== "google_compute_organization_security_policy_rule" and r["values"]["priority"]==1001]
|
||||
rule_icmp = [r["values"] for r in resources if r["type"]== "google_compute_organization_security_policy_rule" and r["values"]["priority"]==1000]
|
||||
association_org = [r["values"] for r in resources if r["type"]== "google_compute_organization_security_policy_association" and r["values"]["attachment_id"]=="organizations/1234567890"]
|
||||
association_folder = [r["values"] for r in resources if r["type"]== "google_compute_organization_security_policy_association" and r["values"]["attachment_id"]=="folders/0987654321"]
|
||||
policies_org = [r["values"] for r in resources if r["type"]== "google_compute_organization_security_policy" and r["values"]["parent"]=="organizations/1234567890"]
|
||||
policies_folder = [r["values"] for r in resources if r["type"]== "google_compute_organization_security_policy" and r["values"]["parent"]=="folders/0987654321"]
|
||||
|
||||
assert set(rule_ssh[0]["match"][0]["config"][0]["src_ip_ranges"])==set(["10.0.0.0/24", "10.0.10.0/24", "192.168.1.1/32"])
|
||||
assert rule_icmp[0]["match"][0]["config"][0]["layer4_config"][0]["ip_protocol"]=="icmp"
|
||||
assert association_org[0]["name"]=="hierarchical-fw-policy-organizations-1234567890"
|
||||
assert association_folder[0]["name"]=="hierarchical-fw-policy-folders-0987654321"
|
||||
assert policies_org[0]["display_name"]=="hierarchical-fw-policy-organizations-1234567890"
|
||||
assert policies_folder[0]["display_name"]=="hierarchical-fw-policy-folders-0987654321"
|
||||
|
||||
"Test hierarchical firewall rules from conf/rules"
|
||||
_, resources = plan_runner(FIXTURES_DIR)
|
||||
assert len(resources) == 6
|
||||
assert set(r["type"] for r in resources) == set([
|
||||
"google_compute_organization_security_policy_rule", "google_compute_organization_security_policy_association", "google_compute_organization_security_policy"
|
||||
])
|
||||
rule_ssh = [r["values"] for r in resources if r["type"] ==
|
||||
"google_compute_organization_security_policy_rule" and r["values"]["priority"] == 1001]
|
||||
rule_icmp = [r["values"] for r in resources if r["type"] ==
|
||||
"google_compute_organization_security_policy_rule" and r["values"]["priority"] == 1000]
|
||||
association_org = [r["values"] for r in resources if r["type"] ==
|
||||
"google_compute_organization_security_policy_association" and r["values"]["attachment_id"] == "organizations/1234567890"]
|
||||
association_folder = [r["values"] for r in resources if r["type"] ==
|
||||
"google_compute_organization_security_policy_association" and r["values"]["attachment_id"] == "folders/0987654321"]
|
||||
policies_org = [r["values"] for r in resources if r["type"] ==
|
||||
"google_compute_organization_security_policy" and r["values"]["parent"] == "organizations/1234567890"]
|
||||
policies_folder = [r["values"] for r in resources if r["type"] ==
|
||||
"google_compute_organization_security_policy" and r["values"]["parent"] == "folders/0987654321"]
|
||||
|
||||
assert set(rule_ssh[0]["match"][0]["config"][0]["src_ip_ranges"]) == set(
|
||||
["10.0.0.0/24", "10.0.10.0/24", "192.168.1.1/32"])
|
||||
assert rule_icmp[0]["match"][0]["config"][0]["layer4_config"][0]["ip_protocol"] == "icmp"
|
||||
assert association_org[0]["name"] == "hierarchical-fw-policy-organizations-1234567890"
|
||||
assert association_folder[0]["name"] == "hierarchical-fw-policy-folders-0987654321"
|
||||
assert policies_org[0]["display_name"] == "hierarchical-fw-policy-organizations-1234567890"
|
||||
assert policies_folder[0]["display_name"] == "hierarchical-fw-policy-folders-0987654321"
|
||||
|
||||
@@ -23,45 +23,45 @@ def test_firewall(plan_runner):
|
||||
_, resources = plan_runner(FIXTURES_DIR)
|
||||
assert len(resources) == 6
|
||||
assert set(r["type"] for r in resources) == set(
|
||||
["google_compute_subnetwork", "google_compute_subnetwork_iam_binding"])
|
||||
["google_compute_subnetwork", "google_compute_subnetwork_iam_binding"])
|
||||
subnets = [
|
||||
r["values"] for r in resources
|
||||
if r["type"] == "google_compute_subnetwork"
|
||||
r["values"] for r in resources
|
||||
if r["type"] == "google_compute_subnetwork"
|
||||
]
|
||||
iam_bindings = [
|
||||
r["values"] for r in resources
|
||||
if r["type"] == "google_compute_subnetwork_iam_binding"
|
||||
r["values"] for r in resources
|
||||
if r["type"] == "google_compute_subnetwork_iam_binding"
|
||||
]
|
||||
|
||||
subnet_a_a = [
|
||||
s for s in subnets if s["project"] == "project-a"
|
||||
and s["network"] == "vpc-a" and s["name"] == "subnet-a"
|
||||
s for s in subnets if s["project"] == "project-a"
|
||||
and s["network"] == "vpc-a" and s["name"] == "subnet-a"
|
||||
][0]
|
||||
assert subnet_a_a["ip_cidr_range"] == "10.0.0.0/24"
|
||||
assert subnet_a_a["private_ip_google_access"] == True
|
||||
assert subnet_a_a["region"] == "europe-west1"
|
||||
assert subnet_a_a["secondary_ip_range"] == [{
|
||||
"ip_cidr_range":
|
||||
"192.168.0.0/24",
|
||||
"range_name":
|
||||
"secondary-range-a"
|
||||
"ip_cidr_range":
|
||||
"192.168.0.0/24",
|
||||
"range_name":
|
||||
"secondary-range-a"
|
||||
}, {
|
||||
"ip_cidr_range":
|
||||
"192.168.1.0/24",
|
||||
"range_name":
|
||||
"secondary-range-b"
|
||||
"ip_cidr_range":
|
||||
"192.168.1.0/24",
|
||||
"range_name":
|
||||
"secondary-range-b"
|
||||
}]
|
||||
|
||||
subnet_a_b = [
|
||||
s for s in subnets if s["project"] == "project-a"
|
||||
and s["network"] == "vpc-a" and s["name"] == "subnet-b"
|
||||
s for s in subnets if s["project"] == "project-a"
|
||||
and s["network"] == "vpc-a" and s["name"] == "subnet-b"
|
||||
][0]
|
||||
assert subnet_a_b["private_ip_google_access"] == False
|
||||
|
||||
iam_binding_b_alpha = [
|
||||
b for b in iam_bindings if b["project"] == "project-b"
|
||||
b for b in iam_bindings if b["project"] == "project-b"
|
||||
][0]
|
||||
assert set(iam_binding_b_alpha["members"]) == set(
|
||||
["user:sruffilli@google.com"])
|
||||
["user:sruffilli@google.com"])
|
||||
assert iam_binding_b_alpha["role"] == "roles/compute.networkUser"
|
||||
assert iam_binding_b_alpha["subnetwork"] == "subnet-alpha"
|
||||
|
||||
@@ -19,27 +19,27 @@ FIXTURES_DIR = os.path.join(os.path.dirname(__file__), "fixture")
|
||||
|
||||
|
||||
def test_firewall(plan_runner):
|
||||
"Test hierarchical firewall rules from conf/rules"
|
||||
_, resources = plan_runner(FIXTURES_DIR)
|
||||
assert len(resources) == 2
|
||||
"Test hierarchical firewall rules from conf/rules"
|
||||
_, resources = plan_runner(FIXTURES_DIR)
|
||||
assert len(resources) == 2
|
||||
|
||||
assert set(r["type"]
|
||||
for r in resources) == set(["google_compute_firewall"])
|
||||
assert set(r["type"]
|
||||
for r in resources) == set(["google_compute_firewall"])
|
||||
|
||||
rule_hc = [
|
||||
r["values"] for r in resources
|
||||
if r["values"]["name"] == "allow-healthchecks-vpc-a"
|
||||
][0]
|
||||
rule_be = [
|
||||
r["values"] for r in resources
|
||||
if r["values"]["description"] == "Allow traffic to LB backend"
|
||||
][0]
|
||||
rule_hc = [
|
||||
r["values"] for r in resources
|
||||
if r["values"]["name"] == "allow-healthchecks-vpc-a"
|
||||
][0]
|
||||
rule_be = [
|
||||
r["values"] for r in resources
|
||||
if r["values"]["description"] == "Allow traffic to LB backend"
|
||||
][0]
|
||||
|
||||
assert set(rule_hc["source_ranges"]) == set(
|
||||
["130.211.0.0/22", "35.191.0.0/16"])
|
||||
assert rule_hc["direction"] == "INGRESS"
|
||||
assert rule_hc["network"] == "vpc-a"
|
||||
assert rule_hc["priority"] == 1000
|
||||
assert rule_hc["project"] == "resource-factory-playground"
|
||||
assert rule_hc["allow"][0] == {'ports': ['80'], 'protocol': 'tcp'}
|
||||
assert rule_be["log_config"][0] == {'metadata': 'INCLUDE_ALL_METADATA'}
|
||||
assert set(rule_hc["source_ranges"]) == set(
|
||||
["130.211.0.0/22", "35.191.0.0/16"])
|
||||
assert rule_hc["direction"] == "INGRESS"
|
||||
assert rule_hc["network"] == "vpc-a"
|
||||
assert rule_hc["priority"] == 1000
|
||||
assert rule_hc["project"] == "resource-factory-playground"
|
||||
assert rule_hc["allow"][0] == {'ports': ['80'], 'protocol': 'tcp'}
|
||||
assert rule_be["log_config"][0] == {'metadata': 'INCLUDE_ALL_METADATA'}
|
||||
|
||||
Reference in New Issue
Block a user