serverspec 0.4.9 → 0.4.10
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/serverspec/commands/darwin.rb +2 -2
- data/lib/serverspec/version.rb +1 -1
- data/spec/darwin/commands_spec.rb +29 -162
- data/spec/debian/commands_spec.rb +39 -227
- data/spec/gentoo/commands_spec.rb +39 -225
- data/spec/redhat/commands_spec.rb +38 -209
- data/spec/solaris/commands_spec.rb +35 -140
- data/spec/support/shared_commands_examples.rb +236 -7
- metadata +2 -2
@@ -3,103 +3,52 @@ require 'spec_helper'
|
|
3
3
|
include Serverspec::Helper::Solaris
|
4
4
|
|
5
5
|
describe 'Serverspec commands of Solaris family' do
|
6
|
+
it_behaves_like 'support command check_file', '/etc/passwd'
|
7
|
+
it_behaves_like 'support command check_directory', '/var/log'
|
8
|
+
|
6
9
|
it_behaves_like 'support command check_installed_by_gem', 'jekyll'
|
7
10
|
it_behaves_like 'support command check_installed_by_gem', 'jekyll', '1.0.2'
|
8
|
-
end
|
9
11
|
|
10
|
-
|
11
|
-
subject { commands.check_enabled('httpd') }
|
12
|
-
it { should eq "svcs -l httpd 2> /dev/null | grep 'enabled true'" }
|
13
|
-
end
|
12
|
+
it_behaves_like 'support command check_mounted', '/'
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
14
|
+
it_behaves_like 'support command check_routing_table', '192.168.100.1/24'
|
15
|
+
it_behaves_like 'support command check_reachable'
|
16
|
+
it_behaves_like 'support command check_resolvable'
|
19
17
|
|
20
|
-
|
21
|
-
|
22
|
-
it { should eq "mount | grep -w -- on\\ /" }
|
23
|
-
end
|
18
|
+
it_behaves_like 'support command check_user', 'root'
|
19
|
+
it_behaves_like 'support command check_user', 'wheel'
|
24
20
|
|
25
|
-
|
26
|
-
subject { commands.check_routing_table('192.168.100.0/24') }
|
27
|
-
it { should eq "/sbin/ip route | grep -E '^192.168.100.0/24 |^default '" }
|
28
|
-
end
|
21
|
+
it_behaves_like 'support command check_file_md5checksum', '/etc/passewd', '96c8c50f81a29965f7af6de371ab4250'
|
29
22
|
|
30
|
-
|
31
|
-
|
32
|
-
subject { commands.check_reachable('localhost', 'ssh', 'tcp', 1) }
|
33
|
-
it { should eq "nc -vvvvzt localhost ssh -w 1" }
|
34
|
-
end
|
35
|
-
context "connect with ip and port 11111 and timeout of 5" do
|
36
|
-
subject { commands.check_reachable('127.0.0.1', '11111', 'udp', 5) }
|
37
|
-
it { should eq "nc -vvvvzu 127.0.0.1 11111 -w 5" }
|
38
|
-
end
|
39
|
-
context "do a ping" do
|
40
|
-
subject { commands.check_reachable('127.0.0.1', nil, 'icmp', 1) }
|
41
|
-
it { should eq "ping -n 127.0.0.1 -w 1 -c 2" }
|
42
|
-
end
|
43
|
-
end
|
23
|
+
it_behaves_like 'support command check_running_under_supervisor', 'httpd'
|
24
|
+
it_behaves_like 'support command check_process', 'httpd'
|
44
25
|
|
45
|
-
|
46
|
-
context "resolve localhost by hosts" do
|
47
|
-
subject { commands.check_resolvable('localhost', 'hosts') }
|
48
|
-
it { should eq "grep -w -- localhost /etc/hosts" }
|
49
|
-
end
|
50
|
-
context "resolve localhost by dns" do
|
51
|
-
subject { commands.check_resolvable('localhost', 'dns') }
|
52
|
-
it { should eq "nslookup -timeout=1 localhost" }
|
53
|
-
end
|
54
|
-
context "resolve localhost with default settings" do
|
55
|
-
subject { commands.check_resolvable('localhost',nil) }
|
56
|
-
it { should eq 'getent hosts localhost' }
|
57
|
-
end
|
58
|
-
end
|
26
|
+
it_behaves_like 'support command check_file_contain', '/etc/passwd', 'root'
|
59
27
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
end
|
64
|
-
|
65
|
-
describe 'check_user' do
|
66
|
-
subject { commands.check_user('root') }
|
67
|
-
it { should eq 'id root' }
|
68
|
-
end
|
28
|
+
it_behaves_like 'support command check_mode', '/etc/sudoers', 440
|
29
|
+
it_behaves_like 'support command check_owner', '/etc/sudoers', 'root'
|
30
|
+
it_behaves_like 'support command check_grouped', '/etc/sudoers', 'wheel'
|
69
31
|
|
70
|
-
|
71
|
-
subject { commands.check_group('wheel') }
|
72
|
-
it { should eq 'getent group | grep -wq -- wheel' }
|
73
|
-
end
|
32
|
+
it_behaves_like 'support command check_link', '/etc/system-release', '/etc/redhat-release'
|
74
33
|
|
75
|
-
|
76
|
-
subject { commands.check_installed('httpd') }
|
77
|
-
it { should eq 'pkg list -H httpd 2> /dev/null' }
|
78
|
-
end
|
34
|
+
it_behaves_like 'support command check_uid', 'root', 0
|
79
35
|
|
80
|
-
|
81
|
-
|
82
|
-
it { should eq "netstat -an 2> /dev/null | egrep 'LISTEN|Idle' | grep -- .80\\ " }
|
83
|
-
end
|
36
|
+
it_behaves_like 'support command check_login_shell', 'root', '/bin/bash'
|
37
|
+
it_behaves_like 'support command check_home_directory', 'root', '/root'
|
84
38
|
|
85
|
-
|
86
|
-
subject { commands.check_running('httpd') }
|
87
|
-
it { should eq "svcs -l httpd status 2> /dev/null |grep 'state online'" }
|
88
|
-
end
|
39
|
+
it_behaves_like 'support command check_authorized_key'
|
89
40
|
|
90
|
-
|
91
|
-
subject { commands.check_running_under_supervisor('httpd') }
|
92
|
-
it { should eq 'supervisorctl status httpd' }
|
41
|
+
it_behaves_like 'support command get_mode'
|
93
42
|
end
|
94
43
|
|
95
|
-
describe '
|
96
|
-
subject { commands.
|
97
|
-
it { should eq
|
44
|
+
describe 'check_enabled' do
|
45
|
+
subject { commands.check_enabled('httpd') }
|
46
|
+
it { should eq "svcs -l httpd 2> /dev/null | grep 'enabled true'" }
|
98
47
|
end
|
99
48
|
|
100
|
-
describe '
|
101
|
-
subject { commands.
|
102
|
-
it { should eq
|
49
|
+
describe 'check_installed' do
|
50
|
+
subject { commands.check_installed('httpd') }
|
51
|
+
it { should eq 'pkg list -H httpd 2> /dev/null' }
|
103
52
|
end
|
104
53
|
|
105
54
|
describe 'check_file_contain_within' do
|
@@ -124,24 +73,14 @@ describe 'check_file_contain_within' do
|
|
124
73
|
end
|
125
74
|
end
|
126
75
|
|
127
|
-
describe '
|
128
|
-
subject { commands.
|
129
|
-
it { should eq "
|
130
|
-
end
|
131
|
-
|
132
|
-
describe 'check_mode' do
|
133
|
-
subject { commands.check_mode('/etc/sudoers', 440) }
|
134
|
-
it { should eq 'stat -c %a /etc/sudoers | grep -- \\^440\\$' }
|
135
|
-
end
|
136
|
-
|
137
|
-
describe 'check_owner' do
|
138
|
-
subject { commands.check_owner('/etc/passwd', 'root') }
|
139
|
-
it { should eq 'stat -c %U /etc/passwd | grep -- \\^root\\$' }
|
76
|
+
describe 'check_listening' do
|
77
|
+
subject { commands.check_listening(80) }
|
78
|
+
it { should eq "netstat -an 2> /dev/null | egrep 'LISTEN|Idle' | grep -- .80\\ " }
|
140
79
|
end
|
141
80
|
|
142
|
-
describe '
|
143
|
-
subject { commands.
|
144
|
-
it { should eq
|
81
|
+
describe 'check_running' do
|
82
|
+
subject { commands.check_running('httpd') }
|
83
|
+
it { should eq "svcs -l httpd status 2> /dev/null |grep 'state online'" }
|
145
84
|
end
|
146
85
|
|
147
86
|
describe 'check_cron_entry' do
|
@@ -156,54 +95,16 @@ describe 'check_cron_entry' do
|
|
156
95
|
end
|
157
96
|
end
|
158
97
|
|
159
|
-
describe 'check_link' do
|
160
|
-
subject { commands.check_link('/etc/system-release', '/etc/redhat-release') }
|
161
|
-
it { should eq 'stat -c %N /etc/system-release | grep -- /etc/redhat-release' }
|
162
|
-
end
|
163
|
-
|
164
98
|
describe 'check_belonging_group' do
|
165
99
|
subject { commands.check_belonging_group('root', 'wheel') }
|
166
100
|
it { should eq "id -Gn root | grep -- wheel" }
|
167
101
|
end
|
168
102
|
|
169
|
-
describe '
|
103
|
+
describe 'check_gid' do
|
170
104
|
subject { commands.check_gid('root', 0) }
|
171
105
|
it { should eq "getent group | grep -- \\^root: | cut -f 3 -d ':' | grep -w -- 0" }
|
172
106
|
end
|
173
107
|
|
174
|
-
describe 'have_uid' do
|
175
|
-
subject { commands.check_uid('root', 0) }
|
176
|
-
it { should eq "id root | grep -- \\^uid\\=0\\(" }
|
177
|
-
end
|
178
|
-
|
179
|
-
describe 'have_login_shell' do
|
180
|
-
subject { commands.check_login_shell('root', '/bin/bash') }
|
181
|
-
it { should eq "getent passwd root | cut -f 7 -d ':' | grep -w -- /bin/bash" }
|
182
|
-
end
|
183
|
-
|
184
|
-
describe 'have_home_directory' do
|
185
|
-
subject { commands.check_home_directory('root', '/root') }
|
186
|
-
it { should eq "getent passwd root | cut -f 6 -d ':' | grep -w -- /root" }
|
187
|
-
end
|
188
|
-
|
189
|
-
describe 'have_authorized_key' do
|
190
|
-
key = "ssh-rsa ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGH"
|
191
|
-
escaped_key = key.gsub(/ /, '\ ')
|
192
|
-
|
193
|
-
context 'with commented publickey' do
|
194
|
-
commented_key = key + " foo@bar.local"
|
195
|
-
subject { commands.check_authorized_key('root', commented_key) }
|
196
|
-
describe 'when command insert publickey is removed comment' do
|
197
|
-
it { should eq "grep -w -- #{escaped_key} ~root/.ssh/authorized_keys" }
|
198
|
-
end
|
199
|
-
end
|
200
|
-
|
201
|
-
context 'with uncomented publickey' do
|
202
|
-
subject { commands.check_authorized_key('root', key) }
|
203
|
-
it { should eq "grep -w -- #{escaped_key} ~root/.ssh/authorized_keys" }
|
204
|
-
end
|
205
|
-
end
|
206
|
-
|
207
108
|
describe 'check_zfs' do
|
208
109
|
context 'check without properties' do
|
209
110
|
subject { commands.check_zfs('rpool') }
|
@@ -221,11 +122,6 @@ describe 'check_zfs' do
|
|
221
122
|
end
|
222
123
|
end
|
223
124
|
|
224
|
-
describe 'get_mode' do
|
225
|
-
subject { commands.get_mode('/dev') }
|
226
|
-
it { should eq 'stat -c %a /dev' }
|
227
|
-
end
|
228
|
-
|
229
125
|
describe 'check_ip_filter_rule' do
|
230
126
|
subject { commands.check_ipfilter_rule('pass in quick on lo0 all') }
|
231
127
|
it { should eq "/sbin/ipfstat -io 2> /dev/null | grep -- pass\\ in\\ quick\\ on\\ lo0\\ all" }
|
@@ -267,4 +163,3 @@ describe 'check_access_by_user' do
|
|
267
163
|
it { should eq 'su dummyuser3 -c "/usr/bin/test -x /tmp/somethingx"' }
|
268
164
|
end
|
269
165
|
end
|
270
|
-
|
@@ -1,13 +1,242 @@
|
|
1
1
|
shared_examples_for 'support command check_installed_by_gem' do |package|
|
2
|
-
|
3
|
-
|
4
|
-
it { should eq "gem list --local | grep -w -- ^#{package}" }
|
5
|
-
end
|
2
|
+
subject { commands.check_installed_by_gem(package) }
|
3
|
+
it { should eq "gem list --local | grep -w -- ^#{package}" }
|
6
4
|
end
|
7
5
|
|
8
6
|
shared_examples_for 'support command check_installed_by_gem with_version' do |package, version|
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
subject { commands.check_installed_by_gem(package) }
|
8
|
+
it { should eq "gem list --local | grep -w -- ^#{package} | grep -w -- ^#{version}" }
|
9
|
+
end
|
10
|
+
|
11
|
+
shared_examples_for 'support command check_file' do |file|
|
12
|
+
subject { commands.check_file(file) }
|
13
|
+
it { should eq "test -f #{file}" }
|
14
|
+
end
|
15
|
+
|
16
|
+
shared_examples_for 'support command check_directory' do |dir|
|
17
|
+
subject { commands.check_directory(dir) }
|
18
|
+
it { should eq "test -d #{dir}" }
|
19
|
+
end
|
20
|
+
|
21
|
+
shared_examples_for 'support command check_mounted' do |path|
|
22
|
+
subject { commands.check_mounted('/') }
|
23
|
+
it { should eq "mount | grep -w -- on\\ #{path}" }
|
24
|
+
end
|
25
|
+
|
26
|
+
shared_examples_for 'support command check_routing_table' do |dest|
|
27
|
+
subject { commands.check_routing_table(dest) }
|
28
|
+
it { should eq "/sbin/ip route | grep -E '^#{dest} |^default '" }
|
29
|
+
end
|
30
|
+
|
31
|
+
shared_examples_for 'support command check_reachable' do
|
32
|
+
context "connect with name from /etc/services to localhost" do
|
33
|
+
subject { commands.check_reachable('localhost', 'ssh', 'tcp', 1) }
|
34
|
+
it { should eq "nc -vvvvzt localhost ssh -w 1" }
|
35
|
+
end
|
36
|
+
context "connect with ip and port 11111 and timeout of 5" do
|
37
|
+
subject { commands.check_reachable('127.0.0.1', '11111', 'udp', 5) }
|
38
|
+
it { should eq "nc -vvvvzu 127.0.0.1 11111 -w 5" }
|
39
|
+
end
|
40
|
+
context "do a ping" do
|
41
|
+
subject { commands.check_reachable('127.0.0.1', nil, 'icmp', 1) }
|
42
|
+
it { should eq "ping -n 127.0.0.1 -w 1 -c 2" }
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
shared_examples_for 'support command check_resolvable' do
|
47
|
+
context "resolve localhost by hosts" do
|
48
|
+
subject { commands.check_resolvable('localhost', 'hosts') }
|
49
|
+
it { should eq "grep -w -- localhost /etc/hosts" }
|
50
|
+
end
|
51
|
+
context "resolve localhost by dns" do
|
52
|
+
subject { commands.check_resolvable('localhost', 'dns') }
|
53
|
+
it { should eq "nslookup -timeout=1 localhost" }
|
54
|
+
end
|
55
|
+
context "resolve localhost with default settings" do
|
56
|
+
subject { commands.check_resolvable('localhost',nil) }
|
57
|
+
it { should eq 'getent hosts localhost' }
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
shared_examples_for 'support command check_user' do |user|
|
62
|
+
subject { commands.check_user(user) }
|
63
|
+
it { should eq "id #{user}" }
|
64
|
+
end
|
65
|
+
|
66
|
+
shared_examples_for 'support command check_group' do |group|
|
67
|
+
subject { commands.check_group(group) }
|
68
|
+
it { should eq "getent group | grep -wq -- #{group}" }
|
69
|
+
end
|
70
|
+
|
71
|
+
shared_examples_for 'support command check_listening' do |port|
|
72
|
+
subject { commands.check_listening(port) }
|
73
|
+
it { should eq "netstat -tunl | grep -- :#{port}\\ " }
|
74
|
+
end
|
75
|
+
|
76
|
+
shared_examples_for 'support command check_file_md5checksum' do |file, md5sum|
|
77
|
+
subject { commands.check_file_md5checksum(file, md5sum) }
|
78
|
+
it { should eq "md5sum #{file} | grep -iw -- ^#{md5sum}" }
|
79
|
+
end
|
80
|
+
|
81
|
+
shared_examples_for 'support command check_running_under_supervisor' do |service|
|
82
|
+
subject { commands.check_running_under_supervisor(service) }
|
83
|
+
it { should eq "supervisorctl status #{service}" }
|
84
|
+
end
|
85
|
+
|
86
|
+
shared_examples_for 'support command check_process' do |process|
|
87
|
+
subject { commands.check_process(process) }
|
88
|
+
it { should eq "ps aux | grep -w -- #{process} | grep -qv grep" }
|
89
|
+
end
|
90
|
+
|
91
|
+
shared_examples_for 'support command check_file_contain' do |file, content|
|
92
|
+
subject { commands.check_file_contain(file, content) }
|
93
|
+
it { should eq "grep -q -- #{content} #{file}" }
|
94
|
+
end
|
95
|
+
|
96
|
+
shared_examples_for 'support command check_file_contain_within' do
|
97
|
+
context 'contain a pattern in the file' do
|
98
|
+
subject { commands.check_file_contain_within('Gemfile', 'rspec') }
|
99
|
+
it { should eq "sed -n 1,\\$p Gemfile | grep -q -- rspec -" }
|
100
|
+
end
|
101
|
+
|
102
|
+
context 'contain a pattern after a line in a file' do
|
103
|
+
subject { commands.check_file_contain_within('Gemfile', 'rspec', '/^group :test do/') }
|
104
|
+
it { should eq "sed -n /\\^group\\ :test\\ do/,\\$p Gemfile | grep -q -- rspec -" }
|
105
|
+
end
|
106
|
+
|
107
|
+
context 'contain a pattern before a line in a file' do
|
108
|
+
subject {commands.check_file_contain_within('Gemfile', 'rspec', nil, '/^end/') }
|
109
|
+
it { should eq "sed -n 1,/\\^end/p Gemfile | grep -q -- rspec -" }
|
110
|
+
end
|
111
|
+
|
112
|
+
context 'contain a pattern from within a line and another line in a file' do
|
113
|
+
subject { commands.check_file_contain_within('Gemfile', 'rspec', '/^group :test do/', '/^end/') }
|
114
|
+
it { should eq "sed -n /\\^group\\ :test\\ do/,/\\^end/p Gemfile | grep -q -- rspec -" }
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
shared_examples_for 'support command check_mode' do |file, mode|
|
119
|
+
subject { commands.check_mode(file, mode) }
|
120
|
+
it { should eq "stat -c %a #{file} | grep -- \\^#{mode}\\$" }
|
121
|
+
end
|
122
|
+
|
123
|
+
shared_examples_for 'support command check_owner' do |file, owner|
|
124
|
+
subject { commands.check_owner(file, owner) }
|
125
|
+
it { should eq "stat -c %U #{file} | grep -- \\^#{owner}\\$" }
|
126
|
+
end
|
127
|
+
|
128
|
+
shared_examples_for 'support command check_grouped' do |file, group|
|
129
|
+
subject { commands.check_grouped(file, group) }
|
130
|
+
it { should eq "stat -c %G #{file} | grep -- \\^#{group}\\$" }
|
131
|
+
end
|
132
|
+
|
133
|
+
shared_examples_for 'support command check_cron_entry' do
|
134
|
+
context 'specify root user' do
|
135
|
+
subject { commands.check_cron_entry('root', '* * * * * /usr/local/bin/batch.sh') }
|
136
|
+
it { should eq 'crontab -u root -l | grep -- \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ /usr/local/bin/batch.sh' }
|
137
|
+
end
|
138
|
+
|
139
|
+
context 'no specified user' do
|
140
|
+
subject { commands.check_cron_entry(nil, '* * * * * /usr/local/bin/batch.sh') }
|
141
|
+
it { should eq 'crontab -l | grep -- \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ /usr/local/bin/batch.sh' }
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
shared_examples_for 'support command check_link' do |link, target|
|
146
|
+
subject { commands.check_link(link, target) }
|
147
|
+
it { should eq "stat -c %N #{link} | grep -- #{target}" }
|
148
|
+
end
|
149
|
+
|
150
|
+
shared_examples_for 'support command check_belonging_group' do |user, group|
|
151
|
+
subject { commands.check_belonging_group(user, group) }
|
152
|
+
it { should eq "id #{user} | awk '{print $3}' | grep -- #{group}" }
|
153
|
+
end
|
154
|
+
|
155
|
+
shared_examples_for 'support command check_uid' do |user, uid|
|
156
|
+
subject { commands.check_uid('root', 0) }
|
157
|
+
it { should eq "id #{user} | grep -- \\^uid\\=#{uid}\\(" }
|
158
|
+
end
|
159
|
+
|
160
|
+
shared_examples_for 'support command check_gid' do |group, gid|
|
161
|
+
subject { commands.check_gid('root', 0) }
|
162
|
+
it { should eq "getent group | grep -w -- \\^#{group} | cut -f 3 -d ':' | grep -w -- #{gid}" }
|
163
|
+
end
|
164
|
+
|
165
|
+
shared_examples_for 'support command check_login_shell' do |user, shell|
|
166
|
+
subject { commands.check_login_shell(user, shell) }
|
167
|
+
it { should eq "getent passwd #{user} | cut -f 7 -d ':' | grep -w -- #{shell}" }
|
168
|
+
end
|
169
|
+
|
170
|
+
shared_examples_for 'support command check_home_directory' do |user, home|
|
171
|
+
subject { commands.check_home_directory(user, home) }
|
172
|
+
it { should eq "getent passwd #{user} | cut -f 6 -d ':' | grep -w -- #{home}" }
|
173
|
+
end
|
174
|
+
|
175
|
+
shared_examples_for 'support command check_authorized_key' do
|
176
|
+
key = "ssh-rsa ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGH"
|
177
|
+
escaped_key = key.gsub(/ /, '\ ')
|
178
|
+
|
179
|
+
context 'with commented publickey' do
|
180
|
+
commented_key = key + " foo@bar.local"
|
181
|
+
subject { commands.check_authorized_key('root', commented_key) }
|
182
|
+
describe 'when command insert publickey is removed comment' do
|
183
|
+
it { should eq "grep -w -- #{escaped_key} ~root/.ssh/authorized_keys" }
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
context 'with uncomented publickey' do
|
188
|
+
subject { commands.check_authorized_key('root', key) }
|
189
|
+
it { should eq "grep -w -- #{escaped_key} ~root/.ssh/authorized_keys" }
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
shared_examples_for 'support command check_iptables' do
|
194
|
+
context 'check a rule without a table and a chain' do
|
195
|
+
subject { commands.check_iptables_rule('-P INPUT ACCEPT') }
|
196
|
+
it { should eq "/sbin/iptables -S | grep -- -P\\ INPUT\\ ACCEPT" }
|
197
|
+
end
|
198
|
+
|
199
|
+
context 'chack a rule with a table and a chain' do
|
200
|
+
subject { commands.check_iptables_rule('-P INPUT ACCEPT', 'mangle', 'INPUT') }
|
201
|
+
it { should eq "/sbin/iptables -t mangle -S INPUT | grep -- -P\\ INPUT\\ ACCEPT" }
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
shared_examples_for 'support command check_selinux' do
|
206
|
+
context 'enforcing' do
|
207
|
+
subject { commands.check_selinux('enforcing') }
|
208
|
+
it { should eq "/usr/sbin/getenforce | grep -i -- enforcing" }
|
209
|
+
end
|
210
|
+
|
211
|
+
context 'permissive' do
|
212
|
+
subject { commands.check_selinux('permissive') }
|
213
|
+
it { should eq "/usr/sbin/getenforce | grep -i -- permissive" }
|
214
|
+
end
|
215
|
+
|
216
|
+
context 'disabled' do
|
217
|
+
subject { commands.check_selinux('disabled') }
|
218
|
+
it { should eq "/usr/sbin/getenforce | grep -i -- disabled" }
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
shared_examples_for 'support command get_mode' do
|
223
|
+
subject { commands.get_mode('/dev') }
|
224
|
+
it { should eq 'stat -c %a /dev' }
|
225
|
+
end
|
226
|
+
|
227
|
+
shared_examples_for 'support command check_access_by_user' do
|
228
|
+
context 'read access' do
|
229
|
+
subject {commands.check_access_by_user '/tmp/something', 'dummyuser1', 'r'}
|
230
|
+
it { should eq 'su -s /bin/sh -c "/usr/bin/test -r /tmp/something" dummyuser1' }
|
231
|
+
end
|
232
|
+
|
233
|
+
context 'write access' do
|
234
|
+
subject {commands.check_access_by_user '/tmp/somethingw', 'dummyuser2', 'w'}
|
235
|
+
it { should eq 'su -s /bin/sh -c "/usr/bin/test -w /tmp/somethingw" dummyuser2' }
|
236
|
+
end
|
237
|
+
|
238
|
+
context 'execute access' do
|
239
|
+
subject {commands.check_access_by_user '/tmp/somethingx', 'dummyuser3', 'x'}
|
240
|
+
it { should eq 'su -s /bin/sh -c "/usr/bin/test -x /tmp/somethingx" dummyuser3' }
|
12
241
|
end
|
13
242
|
end
|