This repository has been archived by the owner on Jun 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 217
/
ingress_rules_spec.rb
144 lines (115 loc) · 4.65 KB
/
ingress_rules_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
require 'spec_helper'
require 'puppet_x/puppetlabs/aws_ingress_rules_parser'
describe PuppetX::Puppetlabs::AwsIngressRulesParser do
context 'starting with a blank rule set' do
let(:parser) { PuppetX::Puppetlabs::AwsIngressRulesParser.new([]) }
describe '#rules_to_create' do
it 'should be empty if passed a blank rule set' do
expect(parser.rules_to_create([])).to be_empty
end
end
describe '#to_delete' do
it 'should be empty if passed a blank rule set' do
expect(parser.rules_to_delete([])).to be_empty
end
end
end
context 'starting with a single port' do
let(:rules) { [{ 'port' => 80 }] }
let(:parser) { PuppetX::Puppetlabs::AwsIngressRulesParser.new(rules) }
context 'compared a blank rule set' do
describe '#rules_to_create' do
it 'should expand the protocols, and use to_ and from_ keys' do
expect(parser.rules_to_create([])).to eq([
{"from_port"=>"80", "to_port"=>"80", "protocol"=>"tcp"},
{"from_port"=>"80", "to_port"=>"80", "protocol"=>"udp"},
{"from_port"=>"-1", "to_port"=>"-1", "protocol"=>"icmp"}
])
end
end
describe '#to_delete' do
it 'should be empty' do
expect(parser.rules_to_delete([])).to be_empty
end
end
end
end
context 'starting with a single security group' do
let(:rules) { [{ 'security_group' => 'sample-group' }] }
let(:parser) { PuppetX::Puppetlabs::AwsIngressRulesParser.new(rules) }
context 'compared to a blank rule set' do
describe '#rules_to_create' do
it 'should expand the protocols, and use to_ and from_ keys' do
expect(parser.rules_to_create([])).to eq([
{"security_group"=>"sample-group", "from_port"=>"1", "to_port"=>"65535", "protocol"=>"tcp"},
{"security_group"=>"sample-group", "from_port"=>"1", "to_port"=>"65535", "protocol"=>"udp"},
{"security_group"=>"sample-group", "from_port"=>"-1", "to_port"=>"-1", "protocol"=>"icmp"}
])
end
end
describe '#to_delete' do
it 'should be empty' do
expect(parser.rules_to_delete([])).to be_empty
end
end
end
end
context 'starting with a single cidr group' do
let(:rules) { [{ 'cidr' => '0.0.0.0/0' }] }
let(:parser) { PuppetX::Puppetlabs::AwsIngressRulesParser.new(rules) }
context 'compared to a blank rule set' do
describe '#rules_to_create' do
it 'should expand the protocols, and use to_ and from_ keys' do
expect(parser.rules_to_create([])).to eq([
{"cidr"=>"0.0.0.0/0", "from_port"=>"1", "to_port"=>"65535", "protocol"=>"tcp"},
{"cidr"=>"0.0.0.0/0", "from_port"=>"1", "to_port"=>"65535", "protocol"=>"udp"},
{"cidr"=>"0.0.0.0/0", "from_port"=>"-1", "to_port"=>"-1", "protocol"=>"icmp"}
])
end
end
describe '#to_delete' do
it 'should be empty' do
expect(parser.rules_to_delete([])).to be_empty
end
end
end
end
context 'starting with a rule with a protocol' do
let(:rules) { [{ 'security_group' => 'sample-group', 'protocol' => 'tcp' }] }
let(:parser) { PuppetX::Puppetlabs::AwsIngressRulesParser.new(rules) }
context 'compared to a blank rule set' do
describe '#rules_to_create' do
it 'should not expand the protocols, but should use to_ and from_ keys' do
expect(parser.rules_to_create([])).to eq([
{"security_group"=>"sample-group", "from_port"=>"1", "to_port"=>"65535", "protocol"=>"tcp"},
])
end
end
describe '#to_delete' do
it 'should be empty' do
expect(parser.rules_to_delete([])).to be_empty
end
end
end
end
context 'starting with a rule with port' do
let(:rules) { [{ 'security_group' => 'sample-group', 'port' => 80 }] }
let(:parser) { PuppetX::Puppetlabs::AwsIngressRulesParser.new(rules) }
context 'compared to a blank rule set' do
describe '#rules_to_create' do
it 'should not expand the protocols, but should use to_ and from_ keys' do
expect(parser.rules_to_create([])).to eq([
{"security_group"=>"sample-group", "from_port"=>"80", "to_port"=>"80", "protocol"=>"tcp"},
{"security_group"=>"sample-group", "from_port"=>"80", "to_port"=>"80", "protocol"=>"udp"},
{"security_group"=>"sample-group", "from_port"=>"-1", "to_port"=>"-1", "protocol"=>"icmp"},
])
end
end
describe '#to_delete' do
it 'should be empty' do
expect(parser.rules_to_delete([])).to be_empty
end
end
end
end
end