specinfra 2.37.4 → 2.37.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/specinfra/command/module/ss.rb +38 -0
- data/lib/specinfra/command/redhat/base/port.rb +2 -0
- data/lib/specinfra/command/redhat/v7/port.rb +5 -0
- data/lib/specinfra/command.rb +2 -0
- data/lib/specinfra/version.rb +1 -1
- data/spec/command/module/ss_spec.rb +17 -0
- data/spec/command/redhat7/port_spec.rb +8 -0
- metadata +8 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 26aae46d93a52fe9be0bf48a361b4fc7df7dac7d
|
4
|
+
data.tar.gz: 8d5d8091031b25961d6fa92ccc173be8e698bda9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c4dc1b2806c1d9e4eb821cfebb64c25c9404bc2357f2db47eb60a15f82450828a00cd9e78ed828bd70ce43f7e18e87a9324cd1616b37fdac61a24e9a658ee76
|
7
|
+
data.tar.gz: b6152e6dc12d93169fd73c60e2d6ca037998b6fc33eeff9c28f86fc14426d76f17cacbf26d7334d4b4077c0f72f9715936f1d055480f594cf8c341800ebd5c8b
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Specinfra
|
2
|
+
module Command
|
3
|
+
module Module
|
4
|
+
module Ss
|
5
|
+
def check_is_listening(port, options={})
|
6
|
+
pattern = ":#{port} "
|
7
|
+
pattern = " #{inaddr_any_to_asterisk(options[:local_address])}#{pattern}" if options[:local_address]
|
8
|
+
"ss #{command_options(options[:protocol])} | grep -- #{escape(pattern)}"
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
# WORKAROUND:
|
14
|
+
# ss displays "*" instead of "0.0.0.0".
|
15
|
+
# But serverspec validates IP address by `valid_ip_address?` method:
|
16
|
+
# https://github.com/serverspec/serverspec/blob/master/lib/serverspec/type/port.rb
|
17
|
+
def inaddr_any_to_asterisk(local_address)
|
18
|
+
if local_address == '0.0.0.0'
|
19
|
+
'*'
|
20
|
+
else
|
21
|
+
local_address
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def command_options(protocol)
|
26
|
+
case protocol
|
27
|
+
when /\Atcp/
|
28
|
+
"-tnl"
|
29
|
+
when /\Audp/
|
30
|
+
"-unl"
|
31
|
+
else
|
32
|
+
"-tunl"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/specinfra/command.rb
CHANGED
@@ -16,6 +16,7 @@ require 'specinfra/command/module/service/god'
|
|
16
16
|
require 'specinfra/command/module/service/delegator'
|
17
17
|
require 'specinfra/command/module/systemd'
|
18
18
|
require 'specinfra/command/module/zfs'
|
19
|
+
require 'specinfra/command/module/ss'
|
19
20
|
|
20
21
|
# Base
|
21
22
|
require 'specinfra/command/base'
|
@@ -90,6 +91,7 @@ require 'specinfra/command/redhat/v5/iptables'
|
|
90
91
|
# RedHat V7 (inherit RedHat)
|
91
92
|
require 'specinfra/command/redhat/v7'
|
92
93
|
require 'specinfra/command/redhat/v7/service'
|
94
|
+
require 'specinfra/command/redhat/v7/port'
|
93
95
|
|
94
96
|
# Fedora (inherit RedhHat)
|
95
97
|
require 'specinfra/command/fedora'
|
data/lib/specinfra/version.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Specinfra::Command::Module::Ss do
|
4
|
+
class Specinfra::Command::Module::Ss::Test < Specinfra::Command::Base
|
5
|
+
extend Specinfra::Command::Module::Ss
|
6
|
+
end
|
7
|
+
let(:klass) { Specinfra::Command::Module::Ss::Test }
|
8
|
+
it { expect(klass.check_is_listening('80')).to eq 'ss -tunl | grep -- :80\ ' }
|
9
|
+
it { expect(klass.check_is_listening('80', options={:protocol => 'tcp'})).to eq 'ss -tnl | grep -- :80\ ' }
|
10
|
+
it { expect(klass.check_is_listening('80', options={:protocol => 'udp'})).to eq 'ss -unl | grep -- :80\ ' }
|
11
|
+
it { expect(klass.check_is_listening('80', options={:local_address => '0.0.0.0'})).to eq 'ss -tunl | grep -- \ \*:80\ ' }
|
12
|
+
it { expect(klass.check_is_listening('80', options={:local_address => '0.0.0.0', :protocol => 'tcp'})).to eq 'ss -tnl | grep -- \ \*:80\ ' }
|
13
|
+
it { expect(klass.check_is_listening('80', options={:local_address => '0.0.0.0', :protocol => 'udp'})).to eq 'ss -unl | grep -- \ \*:80\ ' }
|
14
|
+
it { expect(klass.check_is_listening('80', options={:local_address => '1.2.3.4'})).to eq 'ss -tunl | grep -- \ 1.2.3.4:80\ ' }
|
15
|
+
it { expect(klass.check_is_listening('80', options={:local_address => '1.2.3.4', :protocol => 'tcp'})).to eq 'ss -tnl | grep -- \ 1.2.3.4:80\ ' }
|
16
|
+
it { expect(klass.check_is_listening('80', options={:local_address => '1.2.3.4', :protocol => 'udp'})).to eq 'ss -unl | grep -- \ 1.2.3.4:80\ ' }
|
17
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: specinfra
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.37.
|
4
|
+
version: 2.37.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gosuke Miyashita
|
@@ -294,6 +294,7 @@ files:
|
|
294
294
|
- lib/specinfra/command/module/service/supervisor.rb
|
295
295
|
- lib/specinfra/command/module/service/systemd.rb
|
296
296
|
- lib/specinfra/command/module/service/upstart.rb
|
297
|
+
- lib/specinfra/command/module/ss.rb
|
297
298
|
- lib/specinfra/command/module/systemd.rb
|
298
299
|
- lib/specinfra/command/module/zfs.rb
|
299
300
|
- lib/specinfra/command/nixos.rb
|
@@ -326,11 +327,13 @@ files:
|
|
326
327
|
- lib/specinfra/command/redhat/base/file.rb
|
327
328
|
- lib/specinfra/command/redhat/base/iptables.rb
|
328
329
|
- lib/specinfra/command/redhat/base/package.rb
|
330
|
+
- lib/specinfra/command/redhat/base/port.rb
|
329
331
|
- lib/specinfra/command/redhat/base/service.rb
|
330
332
|
- lib/specinfra/command/redhat/base/yumrepo.rb
|
331
333
|
- lib/specinfra/command/redhat/v5.rb
|
332
334
|
- lib/specinfra/command/redhat/v5/iptables.rb
|
333
335
|
- lib/specinfra/command/redhat/v7.rb
|
336
|
+
- lib/specinfra/command/redhat/v7/port.rb
|
334
337
|
- lib/specinfra/command/redhat/v7/service.rb
|
335
338
|
- lib/specinfra/command/smartos.rb
|
336
339
|
- lib/specinfra/command/smartos/base.rb
|
@@ -460,12 +463,14 @@ files:
|
|
460
463
|
- spec/command/module/service/daemontools_spec.rb
|
461
464
|
- spec/command/module/service/init_spec.rb
|
462
465
|
- spec/command/module/service/systemd_spec.rb
|
466
|
+
- spec/command/module/ss_spec.rb
|
463
467
|
- spec/command/module/systemd_spec.rb
|
464
468
|
- spec/command/module/zfs_spec.rb
|
465
469
|
- spec/command/openbsd/file_spec.rb
|
466
470
|
- spec/command/redhat/interface_spec.rb
|
467
471
|
- spec/command/redhat/package_spec.rb
|
468
472
|
- spec/command/redhat/service_spec.rb
|
473
|
+
- spec/command/redhat7/port_spec.rb
|
469
474
|
- spec/command/redhat7/service_spec.rb
|
470
475
|
- spec/command/ubuntu/ppa_spec.rb
|
471
476
|
- spec/command/windows/registry_key_spec.rb
|
@@ -543,12 +548,14 @@ test_files:
|
|
543
548
|
- spec/command/module/service/daemontools_spec.rb
|
544
549
|
- spec/command/module/service/init_spec.rb
|
545
550
|
- spec/command/module/service/systemd_spec.rb
|
551
|
+
- spec/command/module/ss_spec.rb
|
546
552
|
- spec/command/module/systemd_spec.rb
|
547
553
|
- spec/command/module/zfs_spec.rb
|
548
554
|
- spec/command/openbsd/file_spec.rb
|
549
555
|
- spec/command/redhat/interface_spec.rb
|
550
556
|
- spec/command/redhat/package_spec.rb
|
551
557
|
- spec/command/redhat/service_spec.rb
|
558
|
+
- spec/command/redhat7/port_spec.rb
|
552
559
|
- spec/command/redhat7/service_spec.rb
|
553
560
|
- spec/command/ubuntu/ppa_spec.rb
|
554
561
|
- spec/command/windows/registry_key_spec.rb
|