serverspec 2.0.0.beta7 → 2.0.0.beta8
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 +4 -4
- data/lib/serverspec/matchers/be_listening.rb +6 -2
- data/lib/serverspec/type/port.rb +32 -8
- data/lib/serverspec/version.rb +1 -1
- data/spec/type/port_spec.rb +24 -18
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22d2a873870ecdddc00919f06be8c80c0a3d4f41
|
4
|
+
data.tar.gz: f2c1d92a9211eeda7a2f080dca4fc8a5eabf03c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f4f893ae50ce59810c2f2ebde4a94f4a0d95e5d25601702b64b6d39b0511e5d85d751968a005d1f0e3c5608f1e60f0eccdee4fb744011b9ff87df36de451166c
|
7
|
+
data.tar.gz: d0698d14a569d5b855b5237ae41a8c8f307b066b13b907ba1f0f74c2af25d307e49ed6966c900ffb315ccc25a4b2e74094317cdd724ed6af928d548d5fc1da6c
|
@@ -1,9 +1,13 @@
|
|
1
1
|
RSpec::Matchers.define :be_listening do
|
2
2
|
match do |port|
|
3
|
-
port.listening?
|
3
|
+
port.listening? @with, @local_address
|
4
4
|
end
|
5
5
|
|
6
6
|
chain :with do |with|
|
7
|
-
@with = with
|
7
|
+
@with = with
|
8
|
+
end
|
9
|
+
|
10
|
+
chain :on do |local_address|
|
11
|
+
@local_address = local_address
|
8
12
|
end
|
9
13
|
end
|
data/lib/serverspec/type/port.rb
CHANGED
@@ -1,18 +1,42 @@
|
|
1
|
+
require 'resolv'
|
2
|
+
|
1
3
|
module Serverspec
|
2
4
|
module Type
|
3
5
|
class Port < Base
|
4
|
-
def
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
def protocols
|
7
|
+
%w(udp tcp tcp6 udp6)
|
8
|
+
end
|
9
|
+
|
10
|
+
def options
|
11
|
+
@options ||= {}
|
12
|
+
end
|
13
|
+
|
14
|
+
def protocol_matcher(protocol)
|
15
|
+
protocol = protocol.to_s.downcase
|
16
|
+
if protocols.include?(protocol)
|
17
|
+
options[:protocol] = protocol
|
18
|
+
else
|
19
|
+
raise ArgumentError.new("`be_listening` matcher doesn't support #{protocol}")
|
20
|
+
end
|
21
|
+
end
|
10
22
|
|
11
|
-
|
23
|
+
def local_address_matcher(local_address)
|
24
|
+
if valid_ip_address?(local_address)
|
25
|
+
options[:local_address] = local_address
|
12
26
|
else
|
13
|
-
|
27
|
+
raise ArgumentError.new("`be_listening` matcher requires valid IPv4 or IPv6 address")
|
14
28
|
end
|
15
29
|
end
|
30
|
+
|
31
|
+
def listening?(protocol, local_address)
|
32
|
+
protocol_matcher(protocol) if protocol
|
33
|
+
local_address_matcher(local_address) if local_address
|
34
|
+
@runner.check_listening(@name, options)
|
35
|
+
end
|
36
|
+
|
37
|
+
def valid_ip_address?(ip_address)
|
38
|
+
!!(ip_address =~ Resolv::IPv4::Regex) || !!(ip_address =~ Resolv::IPv6::Regex)
|
39
|
+
end
|
16
40
|
end
|
17
41
|
end
|
18
42
|
end
|
data/lib/serverspec/version.rb
CHANGED
data/spec/type/port_spec.rb
CHANGED
@@ -2,26 +2,32 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
include Specinfra::Helper::RedHat
|
4
4
|
|
5
|
-
describe
|
6
|
-
|
7
|
-
|
5
|
+
describe Serverspec::Type::Port do
|
6
|
+
describe port(80) do
|
7
|
+
it { should be_listening }
|
8
8
|
|
9
|
-
|
10
|
-
it { should_not be_listening }
|
11
|
-
end
|
9
|
+
it('protocol: tcp') { should be_listening.with('tcp') }
|
12
10
|
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
it 'invalid protocol raises error' do
|
12
|
+
expect {
|
13
|
+
should be_listening.with('not implemented')
|
14
|
+
}.to raise_error(ArgumentError, %r/\A`be_listening` matcher doesn\'t support/)
|
15
|
+
end
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
end
|
17
|
+
it('on: 127.0.0.1') do
|
18
|
+
should be_listening.on('127.0.0.1')
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'invalid local address raises error' do
|
22
|
+
expect{ should be_listening.on('') }.to raise_error(ArgumentError)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe port('invalid') do
|
27
|
+
it { should_not be_listening }
|
28
|
+
end
|
20
29
|
|
21
|
-
describe port(
|
22
|
-
|
23
|
-
|
24
|
-
should be_listening.with('not implemented')
|
25
|
-
}.to raise_error(ArgumentError, %r/\A`be_listening` matcher doesn\'t support/)
|
26
|
-
}
|
30
|
+
describe port(123) do
|
31
|
+
it { should be_listening.with("udp") }
|
32
|
+
end
|
27
33
|
end
|