From c1d8154c677418ab133e6798011024267aba2ee7 Mon Sep 17 00:00:00 2001 From: Yair Slobodin <154875779+YairSlobodin1@users.noreply.github.com> Date: Thu, 9 Jan 2025 10:24:10 +0200 Subject: [PATCH] a test for #248 example 1 (#256) --- .../config_object.json | 619 ++++++++++++++++++ .../details.txt | 24 + test/main_test_list.go | 12 + 3 files changed, 655 insertions(+) create mode 100644 test/data/optimize_acl6_issue248_example1/config_object.json create mode 100644 test/data/optimize_acl6_issue248_example1/details.txt diff --git a/test/data/optimize_acl6_issue248_example1/config_object.json b/test/data/optimize_acl6_issue248_example1/config_object.json new file mode 100644 index 00000000..7834f7c3 --- /dev/null +++ b/test/data/optimize_acl6_issue248_example1/config_object.json @@ -0,0 +1,619 @@ +{ + "collector_version": "0.11.0", + "provider": "ibm", + "vpcs": [ + { + "classic_access": false, + "created_at": "2024-06-25T12:20:44.000Z", + "crn": "crn:1", + "cse_source_ips": [ + { + "ip": { + "address": "10.249.196.114" + }, + "zone": { + "href": "href:5", + "name": "us-south-1" + } + }, + { + "ip": { + "address": "10.22.27.101" + }, + "zone": { + "href": "href:6", + "name": "us-south-2" + } + }, + { + "ip": { + "address": "10.249.81.251" + }, + "zone": { + "href": "href:7", + "name": "us-south-3" + } + } + ], + "default_network_acl": { + "crn": "crn:8", + "href": "href:9", + "id": "id:10", + "name": "disallow-laborious-compress-abiding" + }, + "default_routing_table": { + "crn": null, + "href": "href:11", + "id": "id:12", + "name": "traffic-overeasy-festoonery-illusive", + "resource_type": "routing_table" + }, + "default_security_group": { + "crn": "crn:13", + "href": "href:14", + "id": "id:15", + "name": "elevation-lyricist-elf-hassle" + }, + "dns": { + "enable_hub": false, + "resolution_binding_count": 0, + "resolver": { + "servers": [ + { + "address": "161.26.0.10" + }, + { + "address": "161.26.0.11" + } + ], + "type": "system", + "configuration": "default" + } + }, + "health_reasons": null, + "health_state": "ok", + "href": "href:2", + "id": "id:3", + "name": "testacl5-vpc", + "resource_group": { + "href": "href:16", + "id": "id:17", + "name": "name:4" + }, + "resource_type": "vpc", + "status": "available", + "region": "us-south", + "address_prefixes": [ + { + "cidr": "10.240.0.0/18", + "created_at": "2024-06-25T12:20:44.000Z", + "has_subnets": true, + "href": "href:18", + "id": "id:19", + "is_default": true, + "name": "blouse-armchair-fernlike-plus", + "zone": { + "href": "href:5", + "name": "us-south-1" + } + }, + { + "cidr": "10.240.64.0/18", + "created_at": "2024-06-25T12:20:44.000Z", + "has_subnets": true, + "href": "href:20", + "id": "id:21", + "is_default": true, + "name": "stowaway-chatty-opulently-durably", + "zone": { + "href": "href:6", + "name": "us-south-2" + } + }, + { + "cidr": "10.240.128.0/18", + "created_at": "2024-06-25T12:20:44.000Z", + "has_subnets": true, + "href": "href:22", + "id": "id:23", + "is_default": true, + "name": "trifle-renewably-decenary-protector", + "zone": { + "href": "href:7", + "name": "us-south-3" + } + } + ], + "tags": [ + "yair" + ] + } + ], + "subnets": [ + { + "available_ipv4_address_count": 251, + "created_at": "2024-06-25T12:22:10.000Z", + "crn": "crn:40", + "href": "href:41", + "id": "id:42", + "ip_version": "ipv4", + "ipv4_cidr_block": "1.1.1.0/24", + "name": "sub1-1", + "network_acl": { + "crn": "fake:crn:4", + "href": "fake:href:4", + "id": "fake:id:4", + "name": "testacl5-vpc--sub1-1" + }, + "public_gateway": { + "crn": "crn:46", + "href": "href:47", + "id": "id:48", + "name": "public-gw1", + "resource_type": "public_gateway" + }, + "resource_group": { + "href": "href:16", + "id": "id:17", + "name": "name:4" + }, + "resource_type": "subnet", + "routing_table": { + "crn": null, + "href": "href:11", + "id": "id:12", + "name": "traffic-overeasy-festoonery-illusive", + "resource_type": "routing_table" + }, + "status": "available", + "total_ipv4_address_count": 256, + "vpc": { + "crn": "crn:1", + "href": "href:2", + "id": "id:3", + "name": "testacl5-vpc", + "resource_type": "vpc" + }, + "zone": { + "href": "href:5", + "name": "us-south-1" + }, + "reserved_ips": [ + { + "address": "10.240.1.0", + "auto_delete": false, + "created_at": "2024-06-25T12:22:10.000Z", + "href": "href:49", + "id": "id:50", + "lifecycle_state": "stable", + "name": "ibm-network-address", + "owner": "provider", + "resource_type": "subnet_reserved_ip" + }, + { + "address": "10.240.1.1", + "auto_delete": false, + "created_at": "2024-06-25T12:22:10.000Z", + "href": "href:51", + "id": "id:52", + "lifecycle_state": "stable", + "name": "ibm-default-gateway", + "owner": "provider", + "resource_type": "subnet_reserved_ip" + }, + { + "address": "10.240.1.2", + "auto_delete": false, + "created_at": "2024-06-25T12:22:10.000Z", + "href": "href:53", + "id": "id:54", + "lifecycle_state": "stable", + "name": "ibm-dns-address", + "owner": "provider", + "resource_type": "subnet_reserved_ip" + }, + { + "address": "10.240.1.3", + "auto_delete": false, + "created_at": "2024-06-25T12:22:10.000Z", + "href": "href:55", + "id": "id:56", + "lifecycle_state": "stable", + "name": "ibm-reserved-address", + "owner": "provider", + "resource_type": "subnet_reserved_ip" + }, + { + "address": "10.240.1.255", + "auto_delete": false, + "created_at": "2024-06-25T12:22:10.000Z", + "href": "href:57", + "id": "id:58", + "lifecycle_state": "stable", + "name": "ibm-broadcast-address", + "owner": "provider", + "resource_type": "subnet_reserved_ip" + } + ], + "tags": [ + "yair" + ] + } + ], + "public_gateways": [ + { + "created_at": "2024-06-25T12:21:17.000Z", + "crn": "crn:46", + "floating_ip": { + "address": "52.118.146.248", + "crn": "crn:123", + "href": "href:124", + "id": "id:125", + "name": "public-gw1" + }, + "href": "href:47", + "id": "id:48", + "name": "public-gw1", + "resource_group": { + "href": "href:16", + "id": "id:17", + "name": "name:4" + }, + "resource_type": "public_gateway", + "status": "available", + "vpc": { + "crn": "crn:1", + "href": "href:2", + "id": "id:3", + "name": "testacl5-vpc", + "resource_type": "vpc" + }, + "zone": { + "href": "href:5", + "name": "us-south-1" + }, + "tags": [ + "yair" + ] + }, + { + "created_at": "2024-06-25T12:21:16.000Z", + "crn": "crn:65", + "floating_ip": { + "address": "169.47.95.195", + "crn": "crn:126", + "href": "href:127", + "id": "id:128", + "name": "public-gw2" + }, + "href": "href:66", + "id": "id:67", + "name": "public-gw2", + "resource_group": { + "href": "href:16", + "id": "id:17", + "name": "name:4" + }, + "resource_type": "public_gateway", + "status": "available", + "vpc": { + "crn": "crn:1", + "href": "href:2", + "id": "id:3", + "name": "testacl5-vpc", + "resource_type": "vpc" + }, + "zone": { + "href": "href:6", + "name": "us-south-2" + }, + "tags": [ + "yair" + ] + } + ], + "floating_ips": [ + { + "address": "52.118.146.248", + "created_at": "2024-06-25T12:21:16.000Z", + "crn": "crn:123", + "href": "href:124", + "id": "id:125", + "name": "public-gw1", + "resource_group": { + "href": "href:16", + "id": "id:17", + "name": "name:4" + }, + "status": "available", + "target": { + "href": "href:47", + "id": "id:48", + "name": "public-gw1", + "resource_type": "public_gateway", + "crn": "crn:46" + }, + "zone": { + "href": "href:5", + "name": "us-south-1" + }, + "tags": [] + }, + { + "address": "169.47.95.195", + "created_at": "2024-06-25T12:21:16.000Z", + "crn": "crn:126", + "href": "href:127", + "id": "id:128", + "name": "public-gw2", + "resource_group": { + "href": "href:16", + "id": "id:17", + "name": "name:4" + }, + "status": "available", + "target": { + "href": "href:66", + "id": "id:67", + "name": "public-gw2", + "resource_type": "public_gateway", + "crn": "crn:65" + }, + "zone": { + "href": "href:6", + "name": "us-south-2" + }, + "tags": [] + } + ], + "network_acls": [ + { + "created_at": null, + "crn": "fake:crn:4", + "href": "fake:href:4", + "id": "fake:id:4", + "name": "testacl5-vpc--sub1-1", + "resource_group": { + "href": "href:16", + "id": "id:17", + "name": "name:4" + }, + "rules": [ + { + "action": "allow", + "source": "1.1.1.0/31", + "destination": "2.2.2.0/30", + "direction": "outbound", + "protocol": "all" + }, + { + "action": "allow", + "source": "1.1.1.2", + "destination": "2.2.2.0/31", + "direction": "outbound", + "protocol": "all" + }, + { + "action": "allow", + "source": "1.1.1.2", + "destination": "2.2.2.3", + "direction": "outbound", + "protocol": "all" + }, + { + "action": "allow", + "source": "1.1.1.3", + "destination": "2.2.2.0/30", + "direction": "outbound", + "protocol": "all" + } + + ], + "subnets": [ + { + "crn": "crn:40", + "href": "href:41", + "id": "id:42", + "name": "sub1-1", + "resource_type": "subnet" + } + ], + "vpc": { + "crn": "crn:1", + "href": "href:2", + "id": "id:3", + "name": "testacl5-vpc", + "resource_type": "vpc" + }, + "tags": [] + } + ], + "security_groups": [ + { + "created_at": "2024-06-25T12:21:16.000Z", + "crn": "crn:185", + "href": "href:186", + "id": "id:187", + "name": "sg1", + "resource_group": { + "href": "href:16", + "id": "id:17", + "name": "name:4" + }, + "rules": [ + { + "direction": "outbound", + "href": "href:188", + "id": "id:189", + "ip_version": "ipv4", + "local": { + "cidr_block": "0.0.0.0/0" + }, + "remote": { + "cidr_block": "0.0.0.0/0" + }, + "protocol": "all" + }, + { + "direction": "inbound", + "href": "href:190", + "id": "id:191", + "ip_version": "ipv4", + "local": { + "cidr_block": "0.0.0.0/0" + }, + "remote": { + "cidr_block": "0.0.0.0/0" + }, + "protocol": "all" + } + ], + "targets": [], + "vpc": { + "crn": "crn:1", + "href": "href:2", + "id": "id:3", + "name": "testacl5-vpc", + "resource_type": "vpc" + }, + "tags": [] + }, + { + "created_at": "2024-06-25T12:20:45.000Z", + "crn": "crn:13", + "href": "href:14", + "id": "id:15", + "name": "elevation-lyricist-elf-hassle", + "resource_group": { + "href": "href:16", + "id": "id:17", + "name": "name:4" + }, + "rules": [ + { + "direction": "outbound", + "href": "href:192", + "id": "id:193", + "ip_version": "ipv4", + "local": { + "cidr_block": "0.0.0.0/0" + }, + "remote": { + "cidr_block": "0.0.0.0/0" + }, + "protocol": "all" + }, + { + "direction": "inbound", + "href": "href:194", + "id": "id:195", + "ip_version": "ipv4", + "local": { + "cidr_block": "0.0.0.0/0" + }, + "remote": { + "crn": "crn:13", + "href": "href:14", + "id": "id:15", + "name": "elevation-lyricist-elf-hassle" + }, + "protocol": "all" + } + ], + "targets": [], + "vpc": { + "crn": "crn:1", + "href": "href:2", + "id": "id:3", + "name": "testacl5-vpc", + "resource_type": "vpc" + }, + "tags": [] + } + ], + "endpoint_gateways": [], + "instances": [], + "virtual_nis": null, + "routing_tables": [ + { + "accept_routes_from": [ + { + "resource_type": "vpn_gateway" + }, + { + "resource_type": "vpn_server" + } + ], + "advertise_routes_to": [], + "created_at": "2024-06-25T12:20:45.000Z", + "crn": null, + "href": "href:11", + "id": "id:12", + "is_default": true, + "lifecycle_state": "stable", + "name": "traffic-overeasy-festoonery-illusive", + "resource_group": null, + "resource_type": "routing_table", + "route_direct_link_ingress": false, + "route_internet_ingress": false, + "route_transit_gateway_ingress": false, + "route_vpc_zone_ingress": false, + "subnets": [ + { + "crn": "crn:24", + "href": "href:25", + "id": "id:26", + "name": "sub1-2", + "resource_type": "subnet" + }, + { + "crn": "crn:40", + "href": "href:41", + "id": "id:42", + "name": "sub1-1", + "resource_type": "subnet" + }, + { + "crn": "crn:59", + "href": "href:60", + "id": "id:61", + "name": "sub2-1", + "resource_type": "subnet" + }, + { + "crn": "crn:78", + "href": "href:79", + "id": "id:80", + "name": "sub1-3", + "resource_type": "subnet" + }, + { + "crn": "crn:91", + "href": "href:92", + "id": "id:93", + "name": "sub2-2", + "resource_type": "subnet" + }, + { + "crn": "crn:107", + "href": "href:108", + "id": "id:109", + "name": "sub3-1", + "resource_type": "subnet" + } + ], + "routes": [], + "vpc": { + "crn": "crn:1", + "href": "href:2", + "id": "id:3", + "name": "testacl5-vpc", + "resource_type": "vpc" + } + } + ], + "load_balancers": [], + "transit_connections": null, + "transit_gateways": null, + "iks_clusters": [] +} \ No newline at end of file diff --git a/test/data/optimize_acl6_issue248_example1/details.txt b/test/data/optimize_acl6_issue248_example1/details.txt new file mode 100644 index 00000000..7a68cfa5 --- /dev/null +++ b/test/data/optimize_acl6_issue248_example1/details.txt @@ -0,0 +1,24 @@ +######## BEFORE ######## + + +-------------------- +| any | +| | +| ------ | +| |deny| | +| ------ | +| | +| | +-------------------- + + +1.1.1.0/31 --> 2.2.2.0/30 (allow any) +1.1.1.2 --> 2.2.2.0/31 (allow any) +1.1.1.2 --> 2.2.2.3 (allow any) +1.1.1.3 --> 2.2.2.0/30 (allow any) + + +######## AFTER ######## + +1.1.1.2 --> 2.2.2.2 (deny any) +1.1.1.0/30 --> 2.2.2.0/30 (allow any) \ No newline at end of file diff --git a/test/main_test_list.go b/test/main_test_list.go index 8e7f4964..b1c15720 100644 --- a/test/main_test_list.go +++ b/test/main_test_list.go @@ -23,6 +23,7 @@ const ( optimizeACL3Config = "%s/optimize_acl3/config_object.json" optimizeACL4Config = "%s/optimize_acl4/config_object.json" optimizeACL5Config = "%s/optimize_acl5/config_object.json" + optimizeACL6Config = "%s/optimize_acl6_issue248_example1/config_object.json" optimizeACLAnyProtocolConfig = "%s/optimize_acl_anyProtocol/config_object.json" optimizeSGProtocolsToAllConfig = "%s/optimize_sg_protocols_to_all/config_object.json" @@ -598,5 +599,16 @@ func optimizeACLTestsLists() []testCase { outputFile: "%s/optimize_acl5_tf/nacl_expected.tf", }, }, + // Test that matches issue #248 Example 1 + // + // { + // testName: "optimize_acl6_issue248_example1_tf", + // args: &command{ + // cmd: optimize, + // subcmd: acl, + // config: optimizeACL6Config, + // outputFile: "%s/optimize_acl6_issue248_example1_tf/nacl_expected.tf", + // }, + // }, } }