-
Notifications
You must be signed in to change notification settings - Fork 190
Bugfix/issue 416 #546
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Bugfix/issue 416 #546
Changes from 12 commits
5b3012e
14b9e9a
e1f3ea9
5272f58
6be52d7
efb6bd6
58221ff
89f7938
34766f9
48552dd
fe67270
3e01684
0901e55
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,31 +1,65 @@ | ||
| require 'spec_helper' | ||
| require 'awspec/error' | ||
|
|
||
| Awspec::Stub.load 'security_group' | ||
|
|
||
| describe security_group('sg-1a2b3cd4') do | ||
| it { should exist } | ||
| its(:inbound) { should be_opened(80) } | ||
| it do | ||
| # only way found to force and test the exception | ||
| subject.inbound | ||
| expect { subject.opened?(nil) }.to raise_error(Awspec::MissingPortSpecification, /protocol\sis\s-1$/) | ||
| end | ||
| its(:inbound) { should_not be_opened(80) } | ||
| its(:inbound) { should_not be_opened(80).protocol(-1) } | ||
| its(:inbound) { should be_opened(80).protocol(-1).for('sg-3a4b5cd6') } | ||
| its(:inbound) { should be_opened(80).protocol('tcp').for('123.45.68.89/32') } | ||
| its(:inbound) { should be_opened(80).protocol('tcp').for('123.45.67.0/25') } | ||
| its(:inbound) { should be_opened(80).protocol('tcp').for('123.45.67.1/32') } | ||
| its(:inbound) { should_not be_opened(80).protocol('tcp').for('123.45.0.0/16') } | ||
| its(:inbound) { should be_opened(22) } | ||
|
|
||
| its(:inbound) { should be_opened(22).protocol('tcp').for('sg-1a2b3cd4') } | ||
| its(:inbound) { should be_opened(22).protocol('udp').for('sg-1a2b3cd4') } | ||
| its(:inbound) { should be_opened(22).protocol('-1').for('sg-1a2b3cd4') } | ||
| its(:inbound) { should be_opened(22).protocol('icmp').for('sg-1a2b3cd4') } | ||
|
|
||
| its(:inbound) { should be_opened(22).protocol('tcp').for('sg-5a6b7cd8') } | ||
| its(:inbound) { should be_opened('50000-50009').protocol('tcp').for('123.45.67.89/32') } | ||
| its(:inbound) { should_not be_opened('50010-50019').protocol('tcp').for('123.45.67.89/32') } | ||
| its(:outbound) { should be_opened(50_000) } | ||
|
|
||
| its(:outbound) { should be_opened(50_000).protocol('tcp').for('sg-1a2b3cd4') } | ||
| its(:outbound) { should be_opened(50_000).protocol('udp').for('sg-1a2b3cd4') } | ||
| its(:outbound) { should be_opened(50_000).protocol('icmp').for('sg-1a2b3cd4') } | ||
| its(:outbound) { should be_opened(50_000).protocol('-1').for('sg-1a2b3cd4') } | ||
|
|
||
| its(:outbound) { should be_opened(8080).protocol('tcp').for('sg-9a8b7c6d') } | ||
| its(:outbound) { should be_opened(8080).protocol('tcp').for('group-in-other-aws-account-with-vpc-peering') } | ||
| its(:inbound) { should be_opened_only(60_000).protocol('tcp').for('100.45.67.12/32') } | ||
| its(:inbound) { should be_opened_only(70_000).protocol('tcp').for(['100.45.67.89/32', '100.45.67.12/32']) } | ||
| its(:outbound) { should be_opened_only(50_000).protocol('tcp').for('100.45.67.12/32') } | ||
| its(:inbound) { should be_opened.protocol('all').for('sg-3a4b5cd6') } | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm concerned about the loss of the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can safely create an alias for it. Let me try and get back to you. |
||
| its(:outbound) { should be_opened.protocol('tcp').for('pl-a5321fa3') } | ||
| its(:inbound) { should be_opened.protocol('-1').for('sg-3a4b5cd6') } | ||
|
|
||
| it do | ||
| # only way found to force and test the exception | ||
| subject.outbound | ||
| expect { subject.opened?(nil, 'tcp', 'pl-a5321fa3') }.to raise_error( | ||
| Awspec::MissingPortSpecification, /protocol\sis\s-1$/) | ||
| end | ||
| its(:outbound) { should be_opened('443').protocol('tcp').for('pl-a5321fa3') } | ||
| its(:outbound) { should be_opened(443).protocol('tcp').for('pl-a5321fa3') } | ||
| its(:outbound) { should be_opened('443-443').protocol('tcp').for('pl-a5321fa3') } | ||
| it do | ||
| # only way found to force and test the exception | ||
| subject.outbound | ||
| expect { subject.opened?('yada-443-yada', 'tcp', 'pl-a5321fa3') }.to raise_error(Awspec::InvalidPortRange) | ||
| end | ||
|
|
||
| its(:inbound_permissions_count) { should eq 7 } | ||
| its(:ip_permissions_count) { should eq 7 } | ||
| its(:outbound_permissions_count) { should eq 3 } | ||
| its(:ip_permissions_egress_count) { should eq 3 } | ||
| its(:outbound_permissions_count) { should eq 4 } | ||
| its(:ip_permissions_egress_count) { should eq 4 } | ||
| its(:inbound_rule_count) { should eq 8 } | ||
| its(:outbound_rule_count) { should eq 2 } | ||
| its(:outbound_rule_count) { should eq 3 } | ||
|
|
||
| it { should belong_to_vpc('vpc-ab123cde') } | ||
| it { should belong_to_vpc('my-vpc') } | ||
|
|
@@ -95,14 +129,15 @@ | |
|
|
||
| describe security_group('my-security-group-name') do | ||
| it { should exist } | ||
| its(:outbound) { should be_opened(50_000) } | ||
| its(:inbound) { should be_opened(80) } | ||
| its(:outbound) { should_not be_opened(50_000) } | ||
| its(:outbound) { should_not be_opened(50_000).protocol('tcp') } | ||
| its(:outbound) { should be_opened(50_000).protocol('tcp').target('100.45.67.12/32') } | ||
| its(:outbound) { should be_opened(443).protocol('tcp').target('0.0.0.0/0') } | ||
| its(:outbound) { should be_opened(443).protocol('tcp') } | ||
| its(:inbound) { should_not be_opened(80) } | ||
| its(:inbound) { should_not be_opened(80).protocol('tcp') } | ||
| its(:inbound) { should be_opened(80).protocol('tcp').for('123.45.67.0/24') } | ||
| its(:inbound) { should be_opened(80).protocol('tcp').for('123.45.68.89/32') } | ||
| it { should belong_to_vpc('my-vpc') } | ||
| it { should have_tag('env').value('dev') } | ||
| end | ||
|
|
||
| describe security_group('my-security-tag-name') do | ||
| its(:outbound) { should be_opened(50_000) } | ||
| its(:inbound) { should be_opened(80) } | ||
| it { should belong_to_vpc('my-vpc') } | ||
| end | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that there are times when you just want to test that the port is open. So I'd like to see support for this notation as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure, I would need to test from both console and SDK, but my guess is that is not acceptable to create a security group with such rule, without specifying protocol and CIDR. You can, of course, specify anywhere and all protocols, but at least this is rigidly defined.
Even if it would work, it would be a security flaw in my opinion: there is a big different about asserting that a port is opened for a specific IP or the whole internet (0.0.0.0).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
Yes. This test does not specify the IP and protocol, so it will be to make sure that port 22 is open with some protocol on some IP.
Another way to say it is the negation of
should_not be_opened(22).