zaws 0.0.5 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/.travis.yml +9 -18
- data/Gemfile +0 -0
- data/Gemfile.lock +26 -35
- data/Gemfile.lock.linux +69 -0
- data/Gemfile.lock.mac +81 -0
- data/Gemfile.lock.windows +77 -0
- data/LICENSE +0 -0
- data/README.md +11 -0
- data/Rakefile +1 -7
- data/archive/cloud_trail/cloud_trail.feature +124 -0
- data/bin/win_zaws.bat +2 -0
- data/lib/zaws.rb +54 -41
- data/lib/zaws/command/ai.rb +34 -0
- data/lib/zaws/command/bucket.rb +35 -0
- data/lib/zaws/command/cloud_trail.rb +43 -0
- data/lib/zaws/command/compute.rb +152 -87
- data/lib/zaws/command/config.rb +42 -0
- data/lib/zaws/command/elasticip.rb +19 -9
- data/lib/zaws/command/hosted_zone.rb +31 -18
- data/lib/zaws/command/iam.rb +37 -0
- data/lib/zaws/command/load_balancer.rb +54 -51
- data/lib/zaws/command/nessus.rb +41 -0
- data/lib/zaws/command/newrelic.rb +30 -0
- data/lib/zaws/command/route_table.rb +135 -122
- data/lib/zaws/command/security_group.rb +95 -82
- data/lib/zaws/command/subnet.rb +58 -46
- data/lib/zaws/command/sumo.rb +34 -0
- data/lib/zaws/command/vpc.rb +53 -0
- data/lib/zaws/external/awscli/awscli.rb +65 -0
- data/lib/zaws/external/awscli/commands.rb +10 -0
- data/lib/zaws/external/awscli/commands/aws.rb +40 -0
- data/lib/zaws/external/awscli/commands/ec2.rb +74 -0
- data/lib/zaws/external/awscli/commands/ec2/allocate_address.rb +42 -0
- data/lib/zaws/external/awscli/commands/ec2/assign_private_ip_addresses.rb +49 -0
- data/lib/zaws/external/awscli/commands/ec2/associate_address.rb +48 -0
- data/lib/zaws/external/awscli/commands/ec2/associate_route_table.rb +48 -0
- data/lib/zaws/external/awscli/commands/ec2/authorize_security_group_ingress.rb +70 -0
- data/lib/zaws/external/awscli/commands/ec2/create_route.rb +60 -0
- data/lib/zaws/external/awscli/commands/ec2/create_route_table.rb +40 -0
- data/lib/zaws/external/awscli/commands/ec2/create_security_group.rb +58 -0
- data/lib/zaws/external/awscli/commands/ec2/create_subnet.rb +62 -0
- data/lib/zaws/external/awscli/commands/ec2/create_tags.rb +53 -0
- data/lib/zaws/external/awscli/commands/ec2/create_vpc.rb +21 -0
- data/lib/zaws/external/awscli/commands/ec2/delete_route.rb +54 -0
- data/lib/zaws/external/awscli/commands/ec2/delete_route_table.rb +46 -0
- data/lib/zaws/external/awscli/commands/ec2/delete_security_group.rb +46 -0
- data/lib/zaws/external/awscli/commands/ec2/delete_subnet.rb +46 -0
- data/lib/zaws/external/awscli/commands/ec2/describe_addresses.rb +41 -0
- data/lib/zaws/external/awscli/commands/ec2/describe_images.rb +58 -0
- data/lib/zaws/external/awscli/commands/ec2/describe_instances.rb +56 -0
- data/lib/zaws/external/awscli/commands/ec2/describe_route_tables.rb +44 -0
- data/lib/zaws/external/awscli/commands/ec2/describe_security_groups.rb +50 -0
- data/lib/zaws/external/awscli/commands/ec2/describe_subnets.rb +48 -0
- data/lib/zaws/external/awscli/commands/ec2/describe_vpc_peering_connections.rb +23 -0
- data/lib/zaws/external/awscli/commands/ec2/describe_vpcs.rb +26 -0
- data/lib/zaws/external/awscli/commands/ec2/disable_vgw_route_propagation.rb +48 -0
- data/lib/zaws/external/awscli/commands/ec2/disassociate-address.rb +42 -0
- data/lib/zaws/external/awscli/commands/ec2/disassociate_route_table.rb +41 -0
- data/lib/zaws/external/awscli/commands/ec2/enable_vgw_route_propagation.rb +48 -0
- data/lib/zaws/external/awscli/commands/ec2/filter.rb +115 -0
- data/lib/zaws/external/awscli/commands/ec2/modify_instance_attribute.rb +62 -0
- data/lib/zaws/external/awscli/commands/ec2/network_interfaces.rb +63 -0
- data/lib/zaws/external/awscli/commands/ec2/release_address.rb +42 -0
- data/lib/zaws/external/awscli/commands/ec2/revoke_security_group_ingress.rb +70 -0
- data/lib/zaws/external/awscli/commands/ec2/run_instances.rb +21 -0
- data/lib/zaws/external/awscli/commands/ec2/stop_instances.rb +21 -0
- data/lib/zaws/external/awscli/commands/ec2/terminate_instances.rb +40 -0
- data/lib/zaws/external/awscli/commands/ec2/unassign_private_ip_addresses.rb +49 -0
- data/lib/zaws/external/awscli/commands/elb.rb +19 -0
- data/lib/zaws/external/awscli/commands/elb/create_load_balancer.rb +64 -0
- data/lib/zaws/external/awscli/commands/elb/create_load_balancer_listeners.rb +47 -0
- data/lib/zaws/external/awscli/commands/elb/delete_load_balancer.rb +40 -0
- data/lib/zaws/external/awscli/commands/elb/delete_load_balancer_listeners.rb +49 -0
- data/lib/zaws/external/awscli/commands/elb/deregister_instances_with_load_balancer.rb +49 -0
- data/lib/zaws/external/awscli/commands/elb/describe_load_balancers.rb +30 -0
- data/lib/zaws/external/awscli/commands/elb/register_instances_with_load_balancer.rb +49 -0
- data/lib/zaws/external/awscli/commands/iam.rb +31 -0
- data/lib/zaws/external/awscli/commands/iam/GetPolicy.rb +21 -0
- data/lib/zaws/external/awscli/commands/iam/GetPolicyVersion.rb +21 -0
- data/lib/zaws/external/awscli/commands/iam/GetRolePolicy.rb +21 -0
- data/lib/zaws/external/awscli/commands/route53.rb +19 -0
- data/lib/zaws/external/awscli/commands/route53/list_hosted_zones.rb +30 -0
- data/lib/zaws/external/awscli/commands/route53/list_resource_record_sets.rb +41 -0
- data/lib/zaws/external/awscli/commands/s3/ls.rb +34 -0
- data/lib/zaws/external/awscli/commands/s3/mb.rb +41 -0
- data/lib/zaws/external/awscli/commands/s3/sync.rb +48 -0
- data/lib/zaws/external/awscli/credentials.rb +22 -0
- data/lib/zaws/external/awscli/data.rb +10 -0
- data/lib/zaws/external/awscli/data/ec2.rb +33 -0
- data/lib/zaws/external/awscli/data/ec2/instance.rb +162 -0
- data/lib/zaws/external/awscli/data/ec2/security_group.rb +51 -0
- data/lib/zaws/external/awscli/data/ec2/subnet.rb +59 -0
- data/lib/zaws/external/awscli/data/ec2/vpc.rb +85 -0
- data/lib/zaws/external/awscli/data/iam.rb +34 -0
- data/lib/zaws/external/awscli/data/iam/policy.rb +42 -0
- data/lib/zaws/external/awscli/data/iam/policy_document.rb +52 -0
- data/lib/zaws/external/awscli/data/iam/policy_version.rb +42 -0
- data/lib/zaws/external/awscli/data/iam/role_policy.rb +52 -0
- data/lib/zaws/external/awscli/generators/result/ec2/addresses.rb +70 -0
- data/lib/zaws/external/awscli/generators/result/ec2/allocation_id.rb +39 -0
- data/lib/zaws/external/awscli/generators/result/ec2/association_id.rb +29 -0
- data/lib/zaws/external/awscli/generators/result/ec2/images.rb +46 -0
- data/lib/zaws/external/awscli/generators/result/ec2/instances.rb +57 -0
- data/lib/zaws/external/awscli/generators/result/ec2/ip_permissions.rb +70 -0
- data/lib/zaws/external/awscli/generators/result/ec2/network_interfaces.rb +53 -0
- data/lib/zaws/external/awscli/generators/result/ec2/private_ip_addresses.rb +41 -0
- data/lib/zaws/external/awscli/generators/result/ec2/route_tables.rb +80 -0
- data/lib/zaws/external/awscli/generators/result/ec2/routes.rb +58 -0
- data/lib/zaws/external/awscli/generators/result/ec2/security_groups.rb +73 -0
- data/lib/zaws/external/awscli/generators/result/ec2/subnets.rb +88 -0
- data/lib/zaws/external/awscli/generators/result/ec2/tags.rb +34 -0
- data/lib/zaws/external/awscli/generators/result/ec2/virtual_gateway.rb +32 -0
- data/lib/zaws/external/awscli/generators/result/elb/listeners.rb +65 -0
- data/lib/zaws/external/awscli/generators/result/elb/load_balancers.rb +61 -0
- data/lib/zaws/external/awscli/generators/result/route53/hosted_zones.rb +52 -0
- data/lib/zaws/external/awscli/regions.rb +13 -0
- data/lib/zaws/external/nessusapi/data/agents.rb +36 -0
- data/lib/zaws/external/nessusapi/data/scanners.rb +35 -0
- data/lib/zaws/external/nessusapi/nessusapi.rb +57 -0
- data/lib/zaws/external/nessusapi/reources.rb +10 -0
- data/lib/zaws/external/nessusapi/resources/agents.rb +18 -0
- data/lib/zaws/external/nessusapi/resources/agents/list.rb +20 -0
- data/lib/zaws/external/nessusapi/resources/scanners.rb +18 -0
- data/lib/zaws/external/nessusapi/resources/scanners/list.rb +20 -0
- data/lib/zaws/external/newrelicapi/data/servers.rb +36 -0
- data/lib/zaws/external/newrelicapi/newrelic_client.rb +64 -0
- data/lib/zaws/external/newrelicapi/newrelic_creds.rb +60 -0
- data/lib/zaws/external/newrelicapi/newrelicapi.rb +46 -0
- data/lib/zaws/external/newrelicapi/resources/servers.rb +18 -0
- data/lib/zaws/external/newrelicapi/resources/servers/list.rb +20 -0
- data/lib/zaws/external/sumoapi/data/collectors.rb +35 -0
- data/lib/zaws/external/sumoapi/data/sources.rb +35 -0
- data/lib/zaws/external/sumoapi/resources/collectors.rb +18 -0
- data/lib/zaws/external/sumoapi/resources/collectors/list.rb +20 -0
- data/lib/zaws/external/sumoapi/resources/sources.rb +18 -0
- data/lib/zaws/external/sumoapi/resources/sources/list.rb +20 -0
- data/lib/zaws/external/sumoapi/sumo_client.rb +63 -0
- data/lib/zaws/external/sumoapi/sumo_creds.rb +67 -0
- data/lib/zaws/external/sumoapi/sumoapi.rb +56 -0
- data/lib/zaws/helper/data_lattice.rb +22 -0
- data/lib/zaws/helper/filestore.rb +48 -0
- data/lib/zaws/helper/filter.rb +15 -0
- data/lib/zaws/helper/inifile.rb +632 -0
- data/lib/zaws/helper/nessus_client.rb +143 -0
- data/lib/zaws/helper/nessus_creds.rb +67 -0
- data/lib/zaws/helper/option.rb +14 -15
- data/lib/zaws/helper/output.rb +81 -29
- data/lib/zaws/helper/process_hash.rb +47 -0
- data/lib/zaws/helper/shell.rb +0 -0
- data/lib/zaws/helper/verbose.rb +15 -0
- data/lib/zaws/helper/zfile.rb +8 -8
- data/lib/zaws/services/ai.rb +35 -0
- data/lib/zaws/services/ai/query.rb +135 -0
- data/lib/zaws/services/aws.rb +41 -0
- data/lib/zaws/services/chef.rb +0 -0
- data/lib/zaws/services/cloud_trail.rb +76 -0
- data/lib/zaws/services/config.rb +31 -0
- data/lib/zaws/services/ec2.rb +47 -0
- data/lib/zaws/services/ec2/compute.rb +352 -0
- data/lib/zaws/services/ec2/elasticip.rb +82 -0
- data/lib/zaws/services/ec2/route_table.rb +210 -0
- data/lib/zaws/services/ec2/security_group.rb +186 -0
- data/lib/zaws/services/ec2/subnet.rb +111 -0
- data/lib/zaws/services/ec2/vpc.rb +69 -0
- data/lib/zaws/{elb.rb → services/elb.rb} +3 -2
- data/lib/zaws/services/elb/load_balancer.rb +160 -0
- data/lib/zaws/services/iam.rb +25 -0
- data/lib/zaws/services/iam/policy.rb +25 -0
- data/lib/zaws/services/iam/role.rb +23 -0
- data/lib/zaws/services/nessus.rb +24 -0
- data/lib/zaws/services/nessus/agents.rb +19 -0
- data/lib/zaws/services/nessus/scanners.rb +19 -0
- data/lib/zaws/services/newrelic.rb +21 -0
- data/lib/zaws/services/newrelic/servers.rb +19 -0
- data/lib/zaws/{route53.rb → services/route53.rb} +1 -1
- data/lib/zaws/services/route53/hosted_zone.rb +36 -0
- data/lib/zaws/services/s3.rb +15 -0
- data/lib/zaws/services/s3/bucket.rb +42 -0
- data/lib/zaws/services/sumo.rb +21 -0
- data/lib/zaws/services/sumo/collectors.rb +19 -0
- data/lib/zaws/services/vmware.rb +0 -0
- data/lib/zaws/version.rb +1 -1
- data/shove_all.sh +6 -0
- data/shove_all_mac.sh +6 -0
- data/shove_all_windows.sh +6 -0
- data/spec/spec_helper.rb +0 -0
- data/spec/zaws/command/ec2/compute/assoc_security_group_spec.rb +135 -0
- data/spec/zaws/command/ec2/compute/compute_spec.rb +321 -0
- data/spec/zaws/command/ec2/compute/images_spec.rb +69 -0
- data/spec/zaws/command/ec2/compute/management_spec.rb +364 -0
- data/spec/zaws/command/ec2/compute/network_spec.rb +93 -0
- data/spec/zaws/command/ec2/compute/node_spec.rb +70 -0
- data/spec/zaws/command/ec2/compute/secondary_ip_spec.rb +212 -0
- data/spec/zaws/command/ec2/compute/storage_spec.rb +63 -0
- data/spec/zaws/command/ec2/elasticip_spec.rb +271 -0
- data/spec/zaws/command/ec2/route_table_spec.rb +844 -0
- data/spec/zaws/command/ec2/security_group_spec.rb +710 -0
- data/spec/zaws/command/ec2/subnet_spec.rb +273 -0
- data/spec/zaws/command/ec2/vpc_spec.rb +180 -0
- data/spec/zaws/command/elb/load_balancer_spec.rb +633 -0
- data/spec/zaws/command/iam/policy_spec.rb +101 -0
- data/spec/zaws/command/iam/role_policy_spec.rb +35 -0
- data/spec/zaws/command/route53/hosted_zone_spec.rb +100 -0
- data/spec/zaws/command/s3/bucket_spec.rb +70 -0
- data/spec/zaws/external/awscli/data/ec2/instance_spec.rb +90 -0
- data/spec/zaws/external/awscli/data/iam/policy_document_spec.rb +56 -0
- data/spec/zaws/external/awscli/data/iam/role_policy_spec.rb +54 -0
- data/spec/zaws/external/awscli/get_aws_version_spec.rb +18 -0
- data/spec/zaws/helper/option_spec.rb +54 -0
- data/spec/zaws/helper/output_spec.rb +144 -0
- data/spec/zaws/helper/process_hash_spec.rb +48 -0
- data/spec/zaws/helper/shell_spec.rb +56 -0
- data/spec/zaws/nessus/scanners.json +0 -0
- data/spec/zaws/version_spec.rb +18 -0
- data/zaws.gemspec +1 -3
- metadata +260 -189
- data/feature/compute/assoc_security_group.feature +0 -55
- data/feature/compute/compute.feature +0 -138
- data/feature/compute/secondary_ip.feature +0 -107
- data/feature/compute/view.feature +0 -23
- data/feature/compute/view_images.feature +0 -24
- data/feature/elasticip/elasticip.feature +0 -138
- data/feature/elasticip/view.feature +0 -18
- data/feature/hosted_zone/view.feature +0 -17
- data/feature/hosted_zone/view_record.feature +0 -29
- data/feature/load_balancer/instance_registration.feature +0 -120
- data/feature/load_balancer/listener.feature +0 -86
- data/feature/load_balancer/load_balancer.feature +0 -101
- data/feature/load_balancer/view.feature +0 -18
- data/feature/route_table/assoc_subnet.feature +0 -128
- data/feature/route_table/route_propagation.feature +0 -93
- data/feature/route_table/route_table.feature +0 -91
- data/feature/route_table/route_to_gateway.feature +0 -69
- data/feature/route_table/route_to_instance.feature +0 -115
- data/feature/route_table/view.feature +0 -25
- data/feature/security_group/ingress_cidr.feature +0 -144
- data/feature/security_group/ingress_group.feature +0 -184
- data/feature/security_group/security_group.feature +0 -107
- data/feature/security_group/view.feature +0 -23
- data/feature/subnet/subnet.feature +0 -94
- data/feature/subnet/view.feature +0 -24
- data/feature/support/env.rb +0 -14
- data/feature/version.feature +0 -6
- data/lib/zaws/aws.rb +0 -26
- data/lib/zaws/ec2.rb +0 -40
- data/lib/zaws/ec2/compute.rb +0 -247
- data/lib/zaws/ec2/elasticip.rb +0 -79
- data/lib/zaws/ec2/route_table.rb +0 -207
- data/lib/zaws/ec2/security_group.rb +0 -154
- data/lib/zaws/ec2/subnet.rb +0 -109
- data/lib/zaws/elb/load_balancer.rb +0 -157
- data/lib/zaws/route53/hosted_zone.rb +0 -36
- data/spec/zaws/ec2/compute/add_volume_spec.rb +0 -39
- data/spec/zaws/ec2/compute/block_device_mapping_spec.rb +0 -31
- data/spec/zaws/ec2/compute/instance_id_by_external_id_spec.rb +0 -23
- data/spec/zaws/ec2/compute/instance_ping_spec.rb +0 -34
- data/spec/zaws/ec2/compute/instance_running_spec.rb +0 -47
- data/spec/zaws/ec2/compute/network_interface_json_spec.rb +0 -57
- data/spec/zaws/ec2/compute/nosdcheck_spec.rb +0 -17
- data/spec/zaws/ec2/compute/tag_instance_spec.rb +0 -21
- data/spec/zaws/ec2/security_group/id_by_name_spec.rb +0 -32
- data/spec/zaws/ec2/subnet/available_spec.rb +0 -22
- data/spec/zaws/ec2/subnet/declare_spec.rb +0 -31
- data/spec/zaws/ec2/subnet/exists_spec.rb +0 -33
- data/spec/zaws/ec2/subnet/id_array_by_cidrblock_array_spec.rb +0 -48
- data/spec/zaws/ec2/subnet/id_by_cidrblock_spec.rb +0 -35
- data/spec/zaws/ec2/subnet/id_by_ip_spec.rb +0 -42
- data/spec/zaws/ec2/subnet/view_spec.rb +0 -34
- data/spec/zaws/elb/load_balancer/calculated_listener_spec.rb +0 -18
- data/spec/zaws/helper/option/absent_spec.rb +0 -14
- data/spec/zaws/helper/option/exclusive_spec.rb +0 -14
- data/spec/zaws/helper/option/exists_spec.rb +0 -18
- data/spec/zaws/helper/option/minimum_spec.rb +0 -14
- data/spec/zaws/helper/output/binary_nagios_check_spec.rb +0 -19
- data/spec/zaws/helper/output/colorize_spec.rb +0 -30
- data/spec/zaws/helper/output/opt_exclusive_spec.rb +0 -14
- data/spec/zaws/helper/output/opt_minimum_spec.rb +0 -15
- data/spec/zaws/helper/output/opt_required_spec.rb +0 -12
- data/spec/zaws/helper/shell/cli_spec.rb +0 -33
- data/spec/zaws/helper/shell/if_then_spec.rb +0 -24
@@ -0,0 +1,710 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ZAWS::Services::EC2::SecurityGroup do
|
4
|
+
|
5
|
+
let(:security_group_skip_deletion) { ZAWS::Helper::Output.colorize("Security Group does not exist. Skipping deletion.", AWS_consts::COLOR_GREEN) }
|
6
|
+
let(:security_group_deleted) { ZAWS::Helper::Output.colorize("Security Group deleted.", AWS_consts::COLOR_YELLOW) }
|
7
|
+
let(:security_group_exists) { ZAWS::Helper::Output.colorize("Security Group Exists Already. Skipping Creation.", AWS_consts::COLOR_GREEN) }
|
8
|
+
let(:security_group_created) { ZAWS::Helper::Output.colorize("Security Group Created.", AWS_consts::COLOR_YELLOW) }
|
9
|
+
let(:check_critical_security_group) { ZAWS::Helper::Output.colorize("CRITICAL: Security Group Does Not Exist.", AWS_consts::COLOR_RED) }
|
10
|
+
let(:check_ok_security_group) { ZAWS::Helper::Output.colorize("OK: Security Group Exists.", AWS_consts::COLOR_GREEN) }
|
11
|
+
let(:ingress_cidr_rule_created) { ZAWS::Helper::Output.colorize("Ingress cidr rule created.", AWS_consts::COLOR_YELLOW) }
|
12
|
+
let(:ingress_cidr_rule_not_created) { ZAWS::Helper::Output.colorize("Ingress cidr rule not created. Exists already.", AWS_consts::COLOR_GREEN) }
|
13
|
+
let(:critical_ingress_cidr_rule) { ZAWS::Helper::Output.colorize("CRITICAL: Security group ingress cidr rule does not exist.", AWS_consts::COLOR_RED) }
|
14
|
+
let(:ok_ingress_cidr_rule) { ZAWS::Helper::Output.colorize("OK: Security group ingress cidr rule exists.", AWS_consts::COLOR_GREEN) }
|
15
|
+
|
16
|
+
let(:ingress_cidr_rule_not_deleted) { ZAWS::Helper::Output.colorize("Security group ingress cidr rule does not exist. Skipping deletion.", AWS_consts::COLOR_GREEN) }
|
17
|
+
let(:ingress_cidr_rule_deleted) { ZAWS::Helper::Output.colorize("Security group ingress cidr rule deleted.", AWS_consts::COLOR_YELLOW) }
|
18
|
+
|
19
|
+
let(:ingress_group_rule_not_created) { ZAWS::Helper::Output.colorize("Ingress group rule not created. Exists already.", AWS_consts::COLOR_GREEN) }
|
20
|
+
let(:ingress_group_rule_created) { ZAWS::Helper::Output.colorize("Ingress group rule created.", AWS_consts::COLOR_YELLOW) }
|
21
|
+
|
22
|
+
let(:ok_ingress_group_rule) { ZAWS::Helper::Output.colorize("OK: Security group ingress group rule exists.", AWS_consts::COLOR_GREEN) }
|
23
|
+
let(:critical_ingress_group_rule) { ZAWS::Helper::Output.colorize("CRITICAL: Security group ingress group rule does not exist.", AWS_consts::COLOR_RED) }
|
24
|
+
|
25
|
+
let(:ingress_group_rule_not_deleted) { ZAWS::Helper::Output.colorize("Security group ingress group rule does not exist. Skipping deletion.", AWS_consts::COLOR_GREEN) }
|
26
|
+
let(:ingress_group_rule_deleted) { ZAWS::Helper::Output.colorize("Security group ingress group rule deleted.", AWS_consts::COLOR_YELLOW) }
|
27
|
+
|
28
|
+
|
29
|
+
let(:var_region) { "us-west-1" }
|
30
|
+
let(:security_group_name) { "my_security_group_name" }
|
31
|
+
let(:security_group_name2) { "my_security_group_name2" }
|
32
|
+
let(:var_security_group_id) { "sg-abcd123A" }
|
33
|
+
let(:security_group_id2) { "sg-abcd123B" }
|
34
|
+
let(:var_output_json) { "json" }
|
35
|
+
let(:var_output_table) { "table" }
|
36
|
+
let(:var_vpc_id) { "my_vpc_id" }
|
37
|
+
let(:var_sec_group_name) { "my_security_group_name" }
|
38
|
+
|
39
|
+
let(:empty_security_group) { ZAWS::External::AWSCLI::Generators::Result::EC2::SecurityGroups.new }
|
40
|
+
|
41
|
+
let(:ip_perms1) {
|
42
|
+
ip= ZAWS::External::AWSCLI::Generators::Result::EC2::IpPermissions.new
|
43
|
+
ip.to_port(0, 22).ip_protocol(0, "tcp").ip_ranges(0, "0.0.0.0/0").from_port(0, 22)
|
44
|
+
}
|
45
|
+
|
46
|
+
let(:ip_perms2) {
|
47
|
+
ip= ZAWS::External::AWSCLI::Generators::Result::EC2::IpPermissions.new
|
48
|
+
ip.to_port(0, 443).ip_protocol(0, "tcp").ip_ranges(0, "1.1.1.1/32").from_port(0, 443)
|
49
|
+
}
|
50
|
+
|
51
|
+
let(:group_perms) {
|
52
|
+
ip= ZAWS::External::AWSCLI::Generators::Result::EC2::IpPermissions.new
|
53
|
+
ip.to_port(0, 22).ip_protocol(0, "tcp").from_port(0, 22).user_id_group_pairs(0, "958601521864", security_group_id2)
|
54
|
+
}
|
55
|
+
|
56
|
+
let(:single_security_group) {
|
57
|
+
security_groups = ZAWS::External::AWSCLI::Generators::Result::EC2::SecurityGroups.new
|
58
|
+
security_groups.group_name(0, security_group_name).group_id(0, var_security_group_id)
|
59
|
+
security_groups.ip_permissions(0, ip_perms1).ip_permissions(0, ip_perms2)
|
60
|
+
}
|
61
|
+
|
62
|
+
let(:single_security_group2) {
|
63
|
+
security_groups = ZAWS::External::AWSCLI::Generators::Result::EC2::SecurityGroups.new
|
64
|
+
security_groups.group_name(0, security_group_name2).group_id(0, security_group_id2)
|
65
|
+
security_groups.ip_permissions(0, ip_perms1).ip_permissions(0, ip_perms2)
|
66
|
+
}
|
67
|
+
|
68
|
+
let(:single_security_group_group_perms) {
|
69
|
+
security_groups = ZAWS::External::AWSCLI::Generators::Result::EC2::SecurityGroups.new
|
70
|
+
security_groups.group_name(0, security_group_name2).group_id(0, security_group_id2)
|
71
|
+
security_groups.ip_permissions(0, group_perms)
|
72
|
+
}
|
73
|
+
|
74
|
+
|
75
|
+
let(:describe_security_groups_by_name_by_vpcid) {
|
76
|
+
desc_sec_grps = ZAWS::External::AWSCLI::Commands::EC2::DescribeSecurityGroups.new
|
77
|
+
desc_sec_grps.filter.group_name(security_group_name).vpc_id(var_vpc_id)
|
78
|
+
desc_sec_grps.aws.output(var_output_json).region(var_region)
|
79
|
+
desc_sec_grps }
|
80
|
+
|
81
|
+
let(:describe_security_groups_by_name_by_vpcid2) {
|
82
|
+
desc_sec_grps = ZAWS::External::AWSCLI::Commands::EC2::DescribeSecurityGroups.new
|
83
|
+
desc_sec_grps.filter.group_name(security_group_name2).vpc_id(var_vpc_id)
|
84
|
+
desc_sec_grps.aws.output(var_output_json).region(var_region)
|
85
|
+
desc_sec_grps }
|
86
|
+
|
87
|
+
let(:describe_security_groups_by_name) {
|
88
|
+
desc_sec_grps = ZAWS::External::AWSCLI::Commands::EC2::DescribeSecurityGroups.new
|
89
|
+
desc_sec_grps.filter.group_name(var_sec_group_name)
|
90
|
+
desc_sec_grps.aws.output(var_output_json).region(var_region)
|
91
|
+
desc_sec_grps }
|
92
|
+
|
93
|
+
|
94
|
+
let(:describe_security_groups_ip_permissions) {
|
95
|
+
desc_sec_grps = ZAWS::External::AWSCLI::Commands::EC2::DescribeSecurityGroups.new
|
96
|
+
desc_sec_grps.filter.vpc_id(var_vpc_id)
|
97
|
+
desc_sec_grps.filter.ip_permission_cidr("1.1.1.1/32").ip_permission_protocol("tcp")
|
98
|
+
desc_sec_grps.filter.ip_permission_to_port("22").group_id(var_security_group_id)
|
99
|
+
desc_sec_grps.aws.output(var_output_json).region(var_region)
|
100
|
+
desc_sec_grps }
|
101
|
+
|
102
|
+
let(:describe_security_groups_ip_permissions2) {
|
103
|
+
desc_sec_grps = ZAWS::External::AWSCLI::Commands::EC2::DescribeSecurityGroups.new
|
104
|
+
desc_sec_grps.filter.vpc_id(var_vpc_id)
|
105
|
+
desc_sec_grps.filter.ip_permission_cidr("0.0.0.0/0").ip_permission_protocol("tcp")
|
106
|
+
desc_sec_grps.filter.ip_permission_to_port("443").group_id(var_security_group_id)
|
107
|
+
desc_sec_grps.aws.output(var_output_json).region(var_region)
|
108
|
+
desc_sec_grps }
|
109
|
+
|
110
|
+
let(:describe_security_groups_ip_permissions3) {
|
111
|
+
desc_sec_grps = ZAWS::External::AWSCLI::Commands::EC2::DescribeSecurityGroups.new
|
112
|
+
desc_sec_grps.filter.vpc_id(var_vpc_id)
|
113
|
+
desc_sec_grps.filter.ip_permission_cidr("0.0.0.0/0").ip_permission_protocol("tcp")
|
114
|
+
desc_sec_grps.filter.ip_permission_to_port("22").group_id(var_security_group_id)
|
115
|
+
desc_sec_grps.aws.output(var_output_json).region(var_region)
|
116
|
+
desc_sec_grps }
|
117
|
+
|
118
|
+
let(:describe_security_groups_group_permissions) {
|
119
|
+
desc_sec_grps = ZAWS::External::AWSCLI::Commands::EC2::DescribeSecurityGroups.new
|
120
|
+
desc_sec_grps.filter.vpc_id(var_vpc_id)
|
121
|
+
desc_sec_grps.filter.ip_permission_group_id(security_group_id2).ip_permission_protocol("tcp")
|
122
|
+
desc_sec_grps.filter.ip_permission_to_port("22").group_id(var_security_group_id)
|
123
|
+
desc_sec_grps.aws.output(var_output_json).region(var_region)
|
124
|
+
desc_sec_grps }
|
125
|
+
|
126
|
+
let(:authorize_security_group_ingress) {
|
127
|
+
asgi = ZAWS::External::AWSCLI::Commands::EC2::AuthorizeSecurityGroupIngress.new
|
128
|
+
asgi.aws.region(var_region)
|
129
|
+
asgi.group_id(var_security_group_id).cidr('0.0.0.0/0').protocol('tcp').port(443)
|
130
|
+
}
|
131
|
+
|
132
|
+
let(:authorize_security_group_ingress_by_source_group) {
|
133
|
+
asgibsg = ZAWS::External::AWSCLI::Commands::EC2::AuthorizeSecurityGroupIngress.new
|
134
|
+
asgibsg.aws.region(var_region)
|
135
|
+
asgibsg.group_id(var_security_group_id).source_group(security_group_id2).protocol('tcp').port(22)
|
136
|
+
}
|
137
|
+
|
138
|
+
let(:revoke_security_group_ingress) {
|
139
|
+
asgi = ZAWS::External::AWSCLI::Commands::EC2::RevokeSecurityGroupIngress.new
|
140
|
+
asgi.aws.region(var_region)
|
141
|
+
asgi.group_id(var_security_group_id).cidr('0.0.0.0/0').protocol('tcp').port(443)
|
142
|
+
}
|
143
|
+
|
144
|
+
let(:revoke_security_group_ingress2) {
|
145
|
+
asgi = ZAWS::External::AWSCLI::Commands::EC2::RevokeSecurityGroupIngress.new
|
146
|
+
asgi.aws.region(var_region)
|
147
|
+
asgi.group_id(var_security_group_id).cidr('0.0.0.0/0').protocol('tcp').port(22)
|
148
|
+
}
|
149
|
+
|
150
|
+
let(:revoke_security_group_ingress_by_group) {
|
151
|
+
asgi = ZAWS::External::AWSCLI::Commands::EC2::RevokeSecurityGroupIngress.new
|
152
|
+
asgi.aws.region(var_region)
|
153
|
+
asgi.group_id(var_security_group_id).source_group(security_group_id2).protocol('tcp').port(22)
|
154
|
+
}
|
155
|
+
|
156
|
+
before(:each) {
|
157
|
+
|
158
|
+
@var_security_group_id="sg-abcd123A"
|
159
|
+
@var_output_json="json"
|
160
|
+
@var_output_table="table"
|
161
|
+
@var_vpc_id="my_vpc_id"
|
162
|
+
@var_sec_group_name="my_security_group_name"
|
163
|
+
|
164
|
+
options = {:region => var_region,
|
165
|
+
:verbose => false,
|
166
|
+
:check => false,
|
167
|
+
:undofile => false,
|
168
|
+
:viewtype => 'table',
|
169
|
+
}
|
170
|
+
|
171
|
+
|
172
|
+
options_json = {:region => var_region,
|
173
|
+
:verbose => false,
|
174
|
+
:check => false,
|
175
|
+
:undofile => false,
|
176
|
+
:viewtype => 'json'
|
177
|
+
}
|
178
|
+
|
179
|
+
options_json_vpcid = {:region => var_region,
|
180
|
+
:verbose => false,
|
181
|
+
:check => false,
|
182
|
+
:undofile => false,
|
183
|
+
:viewtype => 'json',
|
184
|
+
:vpcid => @var_vpc_id
|
185
|
+
}
|
186
|
+
|
187
|
+
options_json_unused = {:region => var_region,
|
188
|
+
:verbose => false,
|
189
|
+
:check => false,
|
190
|
+
:undofile => false,
|
191
|
+
:viewtype => 'json',
|
192
|
+
:unused => true
|
193
|
+
}
|
194
|
+
|
195
|
+
options_json_vpcid_check = {:region => var_region,
|
196
|
+
:verbose => false,
|
197
|
+
:check => true,
|
198
|
+
:undofile => false,
|
199
|
+
:viewtype => 'json',
|
200
|
+
:vpcid => @var_vpc_id}
|
201
|
+
|
202
|
+
options_json_vpcid_undo = {:region => var_region,
|
203
|
+
:verbose => false,
|
204
|
+
:check => false,
|
205
|
+
:undofile => 'undo.sh',
|
206
|
+
:viewtype => 'json',
|
207
|
+
:vpcid => @var_vpc_id}
|
208
|
+
|
209
|
+
@textout=double('outout')
|
210
|
+
@shellout=double('ZAWS::Helper::Shell')
|
211
|
+
@undofile=double('ZAWS::Helper::ZFile')
|
212
|
+
@aws=ZAWS::AWS.new(@shellout, ZAWS::AWSCLI.new(@shellout, true), @undofile)
|
213
|
+
@command_security_group = ZAWS::Command::Security_Group.new([], options, {})
|
214
|
+
@command_security_group.aws=@aws
|
215
|
+
@command_security_group.out=@textout
|
216
|
+
@command_security_group.print_exit_code = true
|
217
|
+
|
218
|
+
@command_security_group_json = ZAWS::Command::Security_Group.new([], options_json, {})
|
219
|
+
@command_security_group_json.aws=@aws
|
220
|
+
@command_security_group_json.out=@textout
|
221
|
+
@command_security_group_json.print_exit_code = true
|
222
|
+
|
223
|
+
@command_security_group_json_unused = ZAWS::Command::Security_Group.new([], options_json_unused, {})
|
224
|
+
@command_security_group_json_unused.aws=@aws
|
225
|
+
@command_security_group_json_unused.out=@textout
|
226
|
+
@command_security_group_json_unused.print_exit_code = true
|
227
|
+
|
228
|
+
@command_security_group_json_vpcid = ZAWS::Command::Security_Group.new([], options_json_vpcid, {})
|
229
|
+
@command_security_group_json_vpcid.aws=@aws
|
230
|
+
@command_security_group_json_vpcid.out=@textout
|
231
|
+
@command_security_group_json_vpcid.print_exit_code = true
|
232
|
+
|
233
|
+
@command_security_group_json_vpcid_check = ZAWS::Command::Security_Group.new([], options_json_vpcid_check, {})
|
234
|
+
@command_security_group_json_vpcid_check.aws=@aws
|
235
|
+
@command_security_group_json_vpcid_check.out=@textout
|
236
|
+
@command_security_group_json_vpcid_check.print_exit_code = true
|
237
|
+
|
238
|
+
@command_security_group_json_vpcid_undo = ZAWS::Command::Security_Group.new([], options_json_vpcid_undo, {})
|
239
|
+
@command_security_group_json_vpcid_undo.aws=@aws
|
240
|
+
@command_security_group_json_vpcid_undo.out=@textout
|
241
|
+
@command_security_group_json_vpcid_undo.print_exit_code = true
|
242
|
+
|
243
|
+
}
|
244
|
+
|
245
|
+
describe "#view" do
|
246
|
+
it "Get security groups in a human readable table." do
|
247
|
+
desc_sec_grps = ZAWS::External::AWSCLI::Commands::EC2::DescribeSecurityGroups.new
|
248
|
+
desc_sec_grps.aws.output(@var_output_table).region(var_region)
|
249
|
+
|
250
|
+
expect(@shellout).to receive(:cli).with(desc_sec_grps.aws.get_command, nil).ordered.and_return('test output')
|
251
|
+
expect(@textout).to receive(:puts).with('test output').ordered
|
252
|
+
@command_security_group.view()
|
253
|
+
end
|
254
|
+
|
255
|
+
it "Get security groups in JSON form" do
|
256
|
+
desc_sec_grps = ZAWS::External::AWSCLI::Commands::EC2::DescribeSecurityGroups.new
|
257
|
+
desc_sec_grps.aws.output(@var_output_json).region(var_region)
|
258
|
+
expect(@shellout).to receive(:cli).with(desc_sec_grps.aws.get_command, nil).ordered.and_return('test output')
|
259
|
+
expect(@textout).to receive(:puts).with('test output').ordered
|
260
|
+
@command_security_group_json.view
|
261
|
+
end
|
262
|
+
|
263
|
+
it "Get security groups from specified vpcid" do
|
264
|
+
desc_sec_grps = ZAWS::External::AWSCLI::Commands::EC2::DescribeSecurityGroups.new
|
265
|
+
desc_sec_grps.filter.vpc_id(@var_vpc_id)
|
266
|
+
desc_sec_grps.aws.output(@var_output_json).region(var_region)
|
267
|
+
expect(@shellout).to receive(:cli).with(desc_sec_grps.aws.get_command, nil).ordered.and_return('test output')
|
268
|
+
expect(@textout).to receive(:puts).with('test output').ordered
|
269
|
+
@command_security_group_json_vpcid.view
|
270
|
+
end
|
271
|
+
|
272
|
+
it "Get all security groups that are not actively associated to an instance" do
|
273
|
+
security_groups = ZAWS::External::AWSCLI::Generators::Result::EC2::SecurityGroups.new
|
274
|
+
security_groups = security_groups.group_name(0, "my_group_name").group_id(0, "sg-C2345678")
|
275
|
+
|
276
|
+
instances = ZAWS::External::AWSCLI::Generators::Result::EC2::Instances.new
|
277
|
+
net_interfaces= ZAWS::External::AWSCLI::Generators::Result::EC2::NetworkInterfaces.new
|
278
|
+
net_interfaces=net_interfaces.network_interface_id(0, "eni-12345678").groups(0, security_groups)
|
279
|
+
instances = instances.instance_id(0, "i-12345678")
|
280
|
+
instances = instances.security_groups(0, security_groups)
|
281
|
+
instances = instances.network_interfaces(0, net_interfaces)
|
282
|
+
|
283
|
+
desc_instances = ZAWS::External::AWSCLI::Commands::EC2::DescribeInstances.new
|
284
|
+
desc_instances.aws.output("json").region("us-west-1").subcommand(desc_instances)
|
285
|
+
|
286
|
+
expect(@shellout).to receive(:cli).with(desc_instances.aws.get_command, nil).and_return(instances.get_json)
|
287
|
+
|
288
|
+
security_groups = ZAWS::External::AWSCLI::Generators::Result::EC2::SecurityGroups.new
|
289
|
+
security_groups = security_groups.group_name(0, "my_group_name").vpc_id(0, "vpc-12345678").owner_id(0, "123456789012").group_id(0, "sg-C2345678")
|
290
|
+
security_groups = security_groups.group_name(1, "default").vpc_id(1, "vpc-1f6bb57a").owner_id(1, "123456789012").group_id(1, "sg-B2345678")
|
291
|
+
security_groups = security_groups.group_name(2, "my_unused_group").vpc_id(2, "vpc-12345678").owner_id(2, "123456789012").group_id(2, "sg-A2345678")
|
292
|
+
|
293
|
+
desc_sec_grps = ZAWS::External::AWSCLI::Commands::EC2::DescribeSecurityGroups.new
|
294
|
+
desc_sec_grps.aws.output(@var_output_json).region(var_region)
|
295
|
+
|
296
|
+
expect(@shellout).to receive(:cli).with(desc_sec_grps.aws.get_command, nil).ordered.and_return(security_groups.get_json)
|
297
|
+
|
298
|
+
expect(@textout).to receive(:puts).with("default\nmy_unused_group").ordered
|
299
|
+
@command_security_group_json_unused.view
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
describe "#exists" do
|
304
|
+
it "Determine a security group identified by name and vpc has NOT been created" do
|
305
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_by_name_by_vpcid.aws.get_command, nil).ordered.and_return(empty_security_group.get_json)
|
306
|
+
expect(@textout).to receive(:puts).with("false")
|
307
|
+
@command_security_group_json_vpcid.exists_by_name(@var_sec_group_name)
|
308
|
+
|
309
|
+
end
|
310
|
+
|
311
|
+
it "Determine a security group identified by name and vpc has been created" do
|
312
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_by_name_by_vpcid.aws.get_command, nil).ordered.and_return(single_security_group.get_json)
|
313
|
+
expect(@textout).to receive(:puts).with("true")
|
314
|
+
@command_security_group_json_vpcid.exists_by_name(@var_sec_group_name)
|
315
|
+
|
316
|
+
end
|
317
|
+
|
318
|
+
it "Determine a security group identified by name has NOT been created" do
|
319
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_by_name.aws.get_command, nil).ordered.and_return(empty_security_group.get_json)
|
320
|
+
expect(@textout).to receive(:puts).with("false")
|
321
|
+
@command_security_group_json.exists_by_name(@var_sec_group_name)
|
322
|
+
end
|
323
|
+
|
324
|
+
it "Determine a security group identified by name has been created" do
|
325
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_by_name.aws.get_command, nil).ordered.and_return(single_security_group.get_json)
|
326
|
+
expect(@textout).to receive(:puts).with("true")
|
327
|
+
@command_security_group_json.exists_by_name(@var_sec_group_name)
|
328
|
+
|
329
|
+
end
|
330
|
+
|
331
|
+
end
|
332
|
+
|
333
|
+
describe "#delete" do
|
334
|
+
|
335
|
+
it "Delete a security group in a vpc, but skip it cause it does not exist" do
|
336
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_by_name_by_vpcid.aws.get_command, nil).ordered.and_return(empty_security_group.get_json)
|
337
|
+
expect(@textout).to receive(:puts).with(security_group_skip_deletion)
|
338
|
+
@command_security_group_json_vpcid.delete(@var_sec_group_name)
|
339
|
+
end
|
340
|
+
|
341
|
+
it "Delete a security group in a vpc" do
|
342
|
+
security_groups = ZAWS::External::AWSCLI::Generators::Result::EC2::SecurityGroups.new
|
343
|
+
security_groups = security_groups.group_name(0, @var_sec_group_name).group_id(0, "sg-YYYYYY")
|
344
|
+
|
345
|
+
desc_sec_grps = ZAWS::External::AWSCLI::Commands::EC2::DescribeSecurityGroups.new
|
346
|
+
desc_sec_grps.filter.group_name(@var_sec_group_name)
|
347
|
+
desc_sec_grps.aws.output(@var_output_json).region(var_region)
|
348
|
+
|
349
|
+
delete_security_group = ZAWS::External::AWSCLI::Commands::EC2::DeleteSecurityGroup.new
|
350
|
+
delete_security_group.security_group_id("sg-YYYYYY")
|
351
|
+
delete_security_group.aws.region(var_region)
|
352
|
+
|
353
|
+
expect(@shellout).to receive(:cli).with(desc_sec_grps.aws.get_command, nil).ordered.and_return(security_groups.get_json)
|
354
|
+
expect(@shellout).to receive(:cli).with(delete_security_group.aws.get_command, nil).and_return('{ "return": "true" }')
|
355
|
+
expect(@textout).to receive(:puts).with(security_group_deleted)
|
356
|
+
@command_security_group_json.delete(@var_sec_group_name)
|
357
|
+
end
|
358
|
+
end
|
359
|
+
|
360
|
+
describe "#declare" do
|
361
|
+
context "security group exists" do
|
362
|
+
it "Declare a new security group in vpc, but don't create it" do
|
363
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_by_name_by_vpcid.aws.get_command, nil).ordered.and_return(single_security_group.get_json)
|
364
|
+
expect(@textout).to receive(:puts).with(security_group_exists)
|
365
|
+
begin
|
366
|
+
@command_security_group_json_vpcid.declare(@var_sec_group_name, "Description")
|
367
|
+
rescue SystemExit => e
|
368
|
+
expect(e.status).to eq(0)
|
369
|
+
end
|
370
|
+
end
|
371
|
+
end
|
372
|
+
|
373
|
+
context "security group does not exist" do
|
374
|
+
it "Declare a new security group in vpc, create it" do
|
375
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_by_name_by_vpcid.aws.get_command, nil).ordered.and_return(empty_security_group.get_json)
|
376
|
+
|
377
|
+
create_sec_grps = ZAWS::External::AWSCLI::Commands::EC2::CreateSecurityGroup.new
|
378
|
+
create_sec_grps.group_name(@var_sec_group_name).vpc_id(@var_vpc_id).description("Description")
|
379
|
+
create_sec_grps.aws.output(@var_output_json).region(var_region)
|
380
|
+
expect(@shellout).to receive(:cli).with(create_sec_grps.aws.get_command, nil).ordered.and_return('{ "return": "true" }')
|
381
|
+
|
382
|
+
expect(@textout).to receive(:puts).with(security_group_created)
|
383
|
+
begin
|
384
|
+
@command_security_group_json_vpcid.declare(@var_sec_group_name, "Description")
|
385
|
+
rescue SystemExit => e
|
386
|
+
expect(e.status).to eq(0)
|
387
|
+
end
|
388
|
+
end
|
389
|
+
end
|
390
|
+
|
391
|
+
context "check flag provided and security group does not exist" do
|
392
|
+
it "then alert user" do
|
393
|
+
|
394
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_by_name_by_vpcid.aws.get_command, nil).and_return(empty_security_group.get_json)
|
395
|
+
expect(@textout).to receive(:puts).with(check_critical_security_group)
|
396
|
+
begin
|
397
|
+
@command_security_group_json_vpcid_check.declare(@var_sec_group_name, "Description")
|
398
|
+
rescue SystemExit => e
|
399
|
+
expect(e.status).to eq(2)
|
400
|
+
end
|
401
|
+
end
|
402
|
+
end
|
403
|
+
|
404
|
+
context "check flag provided and subnet exists" do
|
405
|
+
it "check passes" do
|
406
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_by_name_by_vpcid.aws.get_command, nil).and_return(single_security_group.get_json)
|
407
|
+
expect(@textout).to receive(:puts).with(check_ok_security_group)
|
408
|
+
begin
|
409
|
+
@command_security_group_json_vpcid_check.declare(@var_sec_group_name, "Description")
|
410
|
+
rescue SystemExit => e
|
411
|
+
expect(e.status).to eq(0)
|
412
|
+
end
|
413
|
+
end
|
414
|
+
end
|
415
|
+
|
416
|
+
context "undo file provided and subnet exists" do
|
417
|
+
it "output delete statement to undo file" do
|
418
|
+
expect(@undofile).to receive(:prepend).with("zaws security_group delete #{@var_sec_group_name} --region #{var_region} --vpcid #{@var_vpc_id} $XTRA_OPTS", '#Delete security group', 'undo.sh')
|
419
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_by_name_by_vpcid.aws.get_command, nil).ordered.and_return(single_security_group.get_json)
|
420
|
+
expect(@textout).to receive(:puts).with(security_group_exists)
|
421
|
+
begin
|
422
|
+
@command_security_group_json_vpcid_undo.declare(@var_sec_group_name, "Description")
|
423
|
+
rescue SystemExit => e
|
424
|
+
expect(e.status).to eq(0)
|
425
|
+
end
|
426
|
+
end
|
427
|
+
end
|
428
|
+
|
429
|
+
end
|
430
|
+
|
431
|
+
describe "#id_by_name" do
|
432
|
+
|
433
|
+
it "security group id by group name" do
|
434
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_by_name_by_vpcid.aws.get_command, nil).and_return(single_security_group.get_json)
|
435
|
+
expect(@textout).to receive(:puts).with(@var_security_group_id)
|
436
|
+
@aws.ec2.security_group.id_by_name(var_region, @textout, nil, @var_vpc_id, @var_sec_group_name)
|
437
|
+
end
|
438
|
+
end
|
439
|
+
|
440
|
+
describe "#filter_groups_by_instances" do
|
441
|
+
it 'filters out groups with security group ids used on an instance provided' do
|
442
|
+
|
443
|
+
security_groups = ZAWS::External::AWSCLI::Generators::Result::EC2::SecurityGroups.new
|
444
|
+
security_groups = security_groups.group_name(0, "my_group_name").vpc_id(0, "vpc-12345678").owner_id(0, "123456789012").group_id(0, "sg-C2345678")
|
445
|
+
security_groups = security_groups.group_name(1, "default").vpc_id(1, "vpc-1f6bb57a").owner_id(1, "123456789012").group_id(1, "sg-B2345678")
|
446
|
+
security_groups = security_groups.group_name(2, "my_unused_group").vpc_id(2, "vpc-12345678").owner_id(2, "123456789012").group_id(2, "sg-A2345678")
|
447
|
+
security_groups_raw = security_groups.get_json
|
448
|
+
|
449
|
+
security_groups = ZAWS::External::AWSCLI::Generators::Result::EC2::SecurityGroups.new
|
450
|
+
security_groups = security_groups.group_name(0, "my_group_name").group_id(0, "sg-C2345678")
|
451
|
+
instances = ZAWS::External::AWSCLI::Generators::Result::EC2::Instances.new
|
452
|
+
net_interfaces= ZAWS::External::AWSCLI::Generators::Result::EC2::NetworkInterfaces.new
|
453
|
+
net_interfaces=net_interfaces.network_interface_id(0, "eni-1234568").groups(0, security_groups)
|
454
|
+
instances = instances.instance_id(0, "i-12345678")
|
455
|
+
instances = instances.security_groups(0, security_groups)
|
456
|
+
instances = instances.network_interfaces(0, net_interfaces)
|
457
|
+
instances_raw=instances.get_json
|
458
|
+
|
459
|
+
security_groups = ZAWS::External::AWSCLI::Generators::Result::EC2::SecurityGroups.new
|
460
|
+
security_groups = security_groups.group_name(0, "default").vpc_id(0, "vpc-1f6bb57a").owner_id(0, "123456789012").group_id(0, "sg-B2345678")
|
461
|
+
security_groups = security_groups.group_name(1, "my_unused_group").vpc_id(1, "vpc-12345678").owner_id(1, "123456789012").group_id(1, "sg-A2345678")
|
462
|
+
security_groups_filtered =security_groups.get_json.gsub(/\s+/, '')
|
463
|
+
|
464
|
+
expect(@aws.ec2.security_group.filter_groups_by_instances(security_groups_raw, instances_raw)).to eq(security_groups_filtered)
|
465
|
+
|
466
|
+
end
|
467
|
+
end
|
468
|
+
|
469
|
+
describe "#ingress_cidr_exists" do
|
470
|
+
context "Both the CIDR and port are in rules but not together" do
|
471
|
+
it "return false after determining a vpc securiry group ingress cidr rule identified by cidr and target has NOT been created" do
|
472
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_by_name_by_vpcid.aws.get_command, nil).ordered.and_return(single_security_group.get_json)
|
473
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_ip_permissions.aws.get_command, nil).ordered.and_return(single_security_group.get_json)
|
474
|
+
expect(@textout).to receive(:puts).with("false")
|
475
|
+
@command_security_group_json_vpcid.ingress_cidr_exists(@var_sec_group_name, "1.1.1.1/32", "tcp", 22)
|
476
|
+
end
|
477
|
+
end
|
478
|
+
context "cidr rule does not exist" do
|
479
|
+
it "returns false" do
|
480
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_by_name_by_vpcid.aws.get_command, nil).ordered.and_return(single_security_group.get_json)
|
481
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_ip_permissions2.aws.get_command, nil).ordered.and_return(empty_security_group.get_json)
|
482
|
+
expect(@textout).to receive(:puts).with("false")
|
483
|
+
@command_security_group_json_vpcid.ingress_cidr_exists(@var_sec_group_name, "0.0.0.0/0", "tcp", 443)
|
484
|
+
end
|
485
|
+
end
|
486
|
+
context "cidr rule does exist" do
|
487
|
+
it "returns true" do
|
488
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_by_name_by_vpcid.aws.get_command, nil).ordered.and_return(single_security_group.get_json)
|
489
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_ip_permissions3.aws.get_command, nil).ordered.and_return(single_security_group.get_json)
|
490
|
+
expect(@textout).to receive(:puts).with("true")
|
491
|
+
@command_security_group_json_vpcid.ingress_cidr_exists(@var_sec_group_name, "0.0.0.0/0", "tcp", 22)
|
492
|
+
end
|
493
|
+
end
|
494
|
+
end
|
495
|
+
|
496
|
+
describe "#declare_ingress_cidr" do
|
497
|
+
context "ingress cidr rule does not exist" do
|
498
|
+
it "create it" do
|
499
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_by_name_by_vpcid.aws.get_command, nil).ordered.and_return(single_security_group.get_json)
|
500
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_ip_permissions2.aws.get_command, nil).ordered.and_return(empty_security_group.get_json)
|
501
|
+
expect(@shellout).to receive(:cli).with(authorize_security_group_ingress.aws.get_command, nil).ordered.and_return('{ "return": "true" }')
|
502
|
+
expect(@textout).to receive(:puts).with(ingress_cidr_rule_created)
|
503
|
+
begin
|
504
|
+
@command_security_group_json_vpcid.declare_ingress_cidr(security_group_name, "0.0.0.0/0", "tcp", 443)
|
505
|
+
rescue SystemExit => e
|
506
|
+
expect(e.status).to eq(0)
|
507
|
+
end
|
508
|
+
|
509
|
+
end
|
510
|
+
end
|
511
|
+
context "ingress cidr rule does exist" do
|
512
|
+
it "do not create it" do
|
513
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_by_name_by_vpcid.aws.get_command, nil).ordered.and_return(single_security_group.get_json)
|
514
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_ip_permissions3.aws.get_command, nil).ordered.and_return(single_security_group.get_json)
|
515
|
+
expect(@textout).to receive(:puts).with(ingress_cidr_rule_not_created)
|
516
|
+
begin
|
517
|
+
@command_security_group_json_vpcid.declare_ingress_cidr(security_group_name, "0.0.0.0/0", "tcp", 22)
|
518
|
+
rescue SystemExit => e
|
519
|
+
expect(e.status).to eq(0)
|
520
|
+
end
|
521
|
+
end
|
522
|
+
end
|
523
|
+
|
524
|
+
context "undo file provided and cidr rule does exists" do
|
525
|
+
it "output delete statement to undo file" do
|
526
|
+
expect(@undofile).to receive(:prepend).with("zaws security_group delete_ingress_cidr #{security_group_name} 0.0.0.0/0 tcp 22 --region #{var_region} --vpcid #{var_vpc_id} $XTRA_OPTS", '#Delete cidr ingress group rule', 'undo.sh')
|
527
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_by_name_by_vpcid.aws.get_command, nil).ordered.and_return(single_security_group.get_json)
|
528
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_ip_permissions3.aws.get_command, nil).ordered.and_return(single_security_group.get_json)
|
529
|
+
expect(@textout).to receive(:puts).with(ingress_cidr_rule_not_created)
|
530
|
+
begin
|
531
|
+
@command_security_group_json_vpcid_undo.declare_ingress_cidr(security_group_name, "0.0.0.0/0", "tcp", 22)
|
532
|
+
rescue SystemExit => e
|
533
|
+
expect(e.status).to eq(0)
|
534
|
+
end
|
535
|
+
end
|
536
|
+
end
|
537
|
+
context "check flag set and ingress cidr rule does exist" do
|
538
|
+
it "returns ok" do
|
539
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_by_name_by_vpcid.aws.get_command, nil).ordered.and_return(single_security_group.get_json)
|
540
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_ip_permissions3.aws.get_command, nil).ordered.and_return(single_security_group.get_json)
|
541
|
+
expect(@textout).to receive(:puts).with(ok_ingress_cidr_rule)
|
542
|
+
begin
|
543
|
+
@command_security_group_json_vpcid_check.declare_ingress_cidr(security_group_name, "0.0.0.0/0", "tcp", 22)
|
544
|
+
rescue SystemExit => e
|
545
|
+
expect(e.status).to eq(0)
|
546
|
+
end
|
547
|
+
|
548
|
+
end
|
549
|
+
end
|
550
|
+
context "check flag set and ingress cidr rule does not exist" do
|
551
|
+
it "returns critical" do
|
552
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_by_name_by_vpcid.aws.get_command, nil).ordered.and_return(single_security_group.get_json)
|
553
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_ip_permissions2.aws.get_command, nil).ordered.and_return(empty_security_group.get_json)
|
554
|
+
expect(@textout).to receive(:puts).with(critical_ingress_cidr_rule)
|
555
|
+
begin
|
556
|
+
@command_security_group_json_vpcid_check.declare_ingress_cidr(security_group_name, "0.0.0.0/0", "tcp", 443)
|
557
|
+
rescue SystemExit => e
|
558
|
+
expect(e.status).to eq(2)
|
559
|
+
end
|
560
|
+
|
561
|
+
end
|
562
|
+
end
|
563
|
+
end
|
564
|
+
|
565
|
+
describe "#delete_ingress_cidr" do
|
566
|
+
context "ingress cidr rule does not exist" do
|
567
|
+
it "nothing to delete, skip it" do
|
568
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_by_name_by_vpcid.aws.get_command, nil).ordered.and_return(single_security_group.get_json)
|
569
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_ip_permissions2.aws.get_command, nil).ordered.and_return(empty_security_group.get_json)
|
570
|
+
expect(@textout).to receive(:puts).with(ingress_cidr_rule_not_deleted)
|
571
|
+
begin
|
572
|
+
@command_security_group_json_vpcid.delete_ingress_cidr(security_group_name, "0.0.0.0/0", "tcp", 443)
|
573
|
+
rescue SystemExit => e
|
574
|
+
expect(e.status).to eq(0)
|
575
|
+
end
|
576
|
+
|
577
|
+
end
|
578
|
+
end
|
579
|
+
context "ingress cidr rule does exist" do
|
580
|
+
it "delete it" do
|
581
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_by_name_by_vpcid.aws.get_command, nil).ordered.and_return(single_security_group.get_json)
|
582
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_ip_permissions3.aws.get_command, nil).ordered.and_return(single_security_group.get_json)
|
583
|
+
expect(@shellout).to receive(:cli).with(revoke_security_group_ingress2.aws.get_command, nil).ordered.and_return('{ "return": "true" }')
|
584
|
+
expect(@textout).to receive(:puts).with(ingress_cidr_rule_deleted)
|
585
|
+
begin
|
586
|
+
@command_security_group_json_vpcid.delete_ingress_cidr(security_group_name, "0.0.0.0/0", "tcp", 22)
|
587
|
+
rescue SystemExit => e
|
588
|
+
expect(e.status).to eq(0)
|
589
|
+
end
|
590
|
+
end
|
591
|
+
end
|
592
|
+
end
|
593
|
+
|
594
|
+
describe "#ingress_group_exists" do
|
595
|
+
context "group rule does not exist" do
|
596
|
+
it "returns false" do
|
597
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_by_name_by_vpcid.aws.get_command, nil).ordered.and_return(single_security_group.get_json)
|
598
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_by_name_by_vpcid2.aws.get_command, nil).ordered.and_return(single_security_group2.get_json)
|
599
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_group_permissions.aws.get_command, nil).ordered.and_return(empty_security_group.get_json)
|
600
|
+
expect(@textout).to receive(:puts).with("false")
|
601
|
+
@command_security_group_json_vpcid.ingress_group_exists(security_group_name, security_group_name2, "tcp", 22)
|
602
|
+
end
|
603
|
+
end
|
604
|
+
context "group rule does exist" do
|
605
|
+
it "returns true" do
|
606
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_by_name_by_vpcid.aws.get_command, nil).ordered.and_return(single_security_group.get_json)
|
607
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_by_name_by_vpcid2.aws.get_command, nil).ordered.and_return(single_security_group2.get_json)
|
608
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_group_permissions.aws.get_command, nil).ordered.and_return(single_security_group_group_perms.get_json)
|
609
|
+
expect(@textout).to receive(:puts).with("true")
|
610
|
+
@command_security_group_json_vpcid.ingress_group_exists(security_group_name, security_group_name2, "tcp", 22)
|
611
|
+
end
|
612
|
+
end
|
613
|
+
end
|
614
|
+
|
615
|
+
describe "#delete_ingress_group" do
|
616
|
+
context "ingress group rule does not exist" do
|
617
|
+
it "nothing to delete, skip it" do
|
618
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_by_name_by_vpcid.aws.get_command, nil).ordered.and_return(single_security_group.get_json)
|
619
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_by_name_by_vpcid2.aws.get_command, nil).ordered.and_return(single_security_group2.get_json)
|
620
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_group_permissions.aws.get_command, nil).ordered.and_return(empty_security_group.get_json)
|
621
|
+
expect(@textout).to receive(:puts).with(ingress_group_rule_not_deleted)
|
622
|
+
@command_security_group_json_vpcid.delete_ingress_group(security_group_name, security_group_name2, "tcp", 22)
|
623
|
+
end
|
624
|
+
end
|
625
|
+
context "ingress group rule does exist" do
|
626
|
+
it "delete it" do
|
627
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_by_name_by_vpcid.aws.get_command, nil).ordered.and_return(single_security_group.get_json)
|
628
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_by_name_by_vpcid2.aws.get_command, nil).ordered.and_return(single_security_group2.get_json)
|
629
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_group_permissions.aws.get_command, nil).ordered.and_return(single_security_group_group_perms.get_json)
|
630
|
+
expect(@shellout).to receive(:cli).with(revoke_security_group_ingress_by_group.aws.get_command, nil).ordered.and_return('{ "return": "true" }')
|
631
|
+
expect(@textout).to receive(:puts).with(ingress_group_rule_deleted)
|
632
|
+
@command_security_group_json_vpcid.delete_ingress_group(security_group_name, security_group_name2, "tcp", 22)
|
633
|
+
end
|
634
|
+
end
|
635
|
+
end
|
636
|
+
|
637
|
+
describe "#declare_ingress_group" do
|
638
|
+
context "ingress group rule does not exist" do
|
639
|
+
it "create it" do
|
640
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_by_name_by_vpcid.aws.get_command, nil).ordered.and_return(single_security_group.get_json)
|
641
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_by_name_by_vpcid2.aws.get_command, nil).ordered.and_return(single_security_group2.get_json)
|
642
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_group_permissions.aws.get_command, nil).ordered.and_return(empty_security_group.get_json)
|
643
|
+
expect(@shellout).to receive(:cli).with(authorize_security_group_ingress_by_source_group.aws.get_command, nil).ordered.and_return('{ "return": "true" }')
|
644
|
+
expect(@textout).to receive(:puts).with(ingress_group_rule_created)
|
645
|
+
begin
|
646
|
+
@command_security_group_json_vpcid.declare_ingress_group(security_group_name, security_group_name2, "tcp", 22)
|
647
|
+
rescue SystemExit => e
|
648
|
+
expect(e.status).to eq(0)
|
649
|
+
end
|
650
|
+
|
651
|
+
end
|
652
|
+
end
|
653
|
+
context "ingress group rule does exist" do
|
654
|
+
it "do not create it" do
|
655
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_by_name_by_vpcid.aws.get_command, nil).ordered.and_return(single_security_group.get_json)
|
656
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_by_name_by_vpcid2.aws.get_command, nil).ordered.and_return(single_security_group2.get_json)
|
657
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_group_permissions.aws.get_command, nil).ordered.and_return(single_security_group_group_perms.get_json)
|
658
|
+
expect(@textout).to receive(:puts).with(ingress_group_rule_not_created)
|
659
|
+
begin
|
660
|
+
@command_security_group_json_vpcid.declare_ingress_group(security_group_name, security_group_name2, "tcp", 22)
|
661
|
+
rescue SystemExit => e
|
662
|
+
expect(e.status).to eq(0)
|
663
|
+
end
|
664
|
+
end
|
665
|
+
end
|
666
|
+
|
667
|
+
context "undo file provided and cidr rule does exists" do
|
668
|
+
it "output delete statement to undo file" do
|
669
|
+
expect(@undofile).to receive(:prepend).with("zaws security_group delete_ingress_group #{security_group_name} #{security_group_name2} tcp 22 --region #{var_region} --vpcid #{var_vpc_id} $XTRA_OPTS", '#Delete security group ingress group rule', 'undo.sh')
|
670
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_by_name_by_vpcid.aws.get_command, nil).ordered.and_return(single_security_group.get_json)
|
671
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_by_name_by_vpcid2.aws.get_command, nil).ordered.and_return(single_security_group2.get_json)
|
672
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_group_permissions.aws.get_command, nil).ordered.and_return(single_security_group_group_perms.get_json)
|
673
|
+
expect(@textout).to receive(:puts).with(ingress_group_rule_not_created)
|
674
|
+
begin
|
675
|
+
@command_security_group_json_vpcid_undo.declare_ingress_group(security_group_name, security_group_name2, "tcp", 22)
|
676
|
+
rescue SystemExit => e
|
677
|
+
expect(e.status).to eq(0)
|
678
|
+
end
|
679
|
+
end
|
680
|
+
end
|
681
|
+
context "check flag set and ingress cidr rule does exist" do
|
682
|
+
it "returns ok" do
|
683
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_by_name_by_vpcid.aws.get_command, nil).ordered.and_return(single_security_group.get_json)
|
684
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_by_name_by_vpcid2.aws.get_command, nil).ordered.and_return(single_security_group2.get_json)
|
685
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_group_permissions.aws.get_command, nil).ordered.and_return(single_security_group_group_perms.get_json)
|
686
|
+
expect(@textout).to receive(:puts).with(ok_ingress_group_rule)
|
687
|
+
begin
|
688
|
+
@command_security_group_json_vpcid_check.declare_ingress_group(security_group_name, security_group_name2, "tcp", 22)
|
689
|
+
rescue SystemExit => e
|
690
|
+
expect(e.status).to eq(0)
|
691
|
+
end
|
692
|
+
end
|
693
|
+
end
|
694
|
+
context "check flag set and ingress cidr rule does not exist" do
|
695
|
+
it "returns critical" do
|
696
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_by_name_by_vpcid.aws.get_command, nil).ordered.and_return(single_security_group.get_json)
|
697
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_by_name_by_vpcid2.aws.get_command, nil).ordered.and_return(single_security_group2.get_json)
|
698
|
+
expect(@shellout).to receive(:cli).with(describe_security_groups_group_permissions.aws.get_command, nil).ordered.and_return(empty_security_group.get_json)
|
699
|
+
expect(@textout).to receive(:puts).with(critical_ingress_group_rule)
|
700
|
+
begin
|
701
|
+
@command_security_group_json_vpcid_check.declare_ingress_group(security_group_name, security_group_name2, "tcp", 22)
|
702
|
+
rescue SystemExit => e
|
703
|
+
expect(e.status).to eq(2)
|
704
|
+
end
|
705
|
+
end
|
706
|
+
end
|
707
|
+
end
|
708
|
+
|
709
|
+
end
|
710
|
+
|