serverspec 0.2.16 → 0.2.17

Sign up to get free protection for your applications and to get access to all the features.
@@ -83,6 +83,22 @@ module Serverspec
83
83
  "id #{user} | awk '{print $3}' | grep #{group}"
84
84
  end
85
85
 
86
+ def check_gid group, gid
87
+ "getent group | grep -w ^#{group} | cut -f 3 -d ':' | grep -w #{gid}"
88
+ end
89
+
90
+ def check_uid user, uid
91
+ "id #{user} | grep uid=#{uid}("
92
+ end
93
+
94
+ def check_login_shell user, path_to_shell
95
+ "grep -w ^#{user} /etc/passwd | cut -f 7 -d ':' | grep -w #{path_to_shell}"
96
+ end
97
+
98
+ def check_home_directory user, path_to_home
99
+ "grep -w ^#{user} /etc/passwd | cut -f 6 -d ':' | grep -w #{path_to_home}"
100
+ end
101
+
86
102
  def check_iptables_rule rule, table=nil, chain=nil
87
103
  cmd = "iptables"
88
104
  cmd += " -t #{table}" if table
@@ -53,6 +53,17 @@ module Serverspec
53
53
  end
54
54
  commands.join(' && ')
55
55
  end
56
+
57
+ def check_file_contain_within file, expected_pattern, from=nil, to=nil
58
+ from ||= '1'
59
+ to ||= '$'
60
+ checker = check_file_contain("/dev/stdin", expected_pattern)
61
+ "sed -n '#{from},#{to}p' #{file} | #{checker}"
62
+ end
63
+
64
+ def check_belonging_group user, group
65
+ "id -Gn #{user} | grep #{group}"
66
+ end
56
67
  end
57
68
  end
58
69
  end
@@ -14,6 +14,10 @@ require 'serverspec/matchers/have_cron_entry'
14
14
  require 'serverspec/matchers/be_linked_to'
15
15
  require 'serverspec/matchers/be_installed_by_gem'
16
16
  require 'serverspec/matchers/belong_to_group'
17
+ require 'serverspec/matchers/have_gid'
18
+ require 'serverspec/matchers/have_uid'
19
+ require 'serverspec/matchers/have_login_shell'
20
+ require 'serverspec/matchers/have_home_directory'
17
21
  require 'serverspec/matchers/have_iptables_rule'
18
22
  require 'serverspec/matchers/get_stdout'
19
23
  require 'serverspec/matchers/be_zfs'
@@ -0,0 +1,6 @@
1
+ RSpec::Matchers.define :have_gid do |gid|
2
+ match do |group|
3
+ backend.check_gid(example, group, gid)
4
+ end
5
+ end
6
+
@@ -0,0 +1,6 @@
1
+ RSpec::Matchers.define :have_home_directory do |path_to_home|
2
+ match do |user|
3
+ backend.check_home_directory(example, user, path_to_home)
4
+ end
5
+ end
6
+
@@ -0,0 +1,6 @@
1
+ RSpec::Matchers.define :have_login_shell do |path_to_shell|
2
+ match do |user|
3
+ backend.check_login_shell(example, user, path_to_shell)
4
+ end
5
+ end
6
+
@@ -0,0 +1,6 @@
1
+ RSpec::Matchers.define :have_uid do |uid|
2
+ match do |user|
3
+ backend.check_uid(example, user, uid)
4
+ end
5
+ end
6
+
@@ -1,3 +1,3 @@
1
1
  module Serverspec
2
- VERSION = "0.2.16"
2
+ VERSION = "0.2.17"
3
3
  end
@@ -113,6 +113,26 @@ describe 'check_belonging_group', :os => :debian do
113
113
  it { should eq "id root | awk '{print $3}' | grep wheel" }
114
114
  end
115
115
 
116
+ describe 'have_gid', :os => :debian do
117
+ subject { commands.check_gid('root', 0) }
118
+ it { should eq "getent group | grep -w ^root | cut -f 3 -d ':' | grep -w 0" }
119
+ end
120
+
121
+ describe 'have_uid', :os => :debian do
122
+ subject { commands.check_uid('root', 0) }
123
+ it { should eq "id root | grep uid=0(" }
124
+ end
125
+
126
+ describe 'have_login_shell', :os => :debian do
127
+ subject { commands.check_login_shell('root', '/bin/bash') }
128
+ it { should eq "grep -w ^root /etc/passwd | cut -f 7 -d ':' | grep -w /bin/bash" }
129
+ end
130
+
131
+ describe 'have_home_directory', :os => :debian do
132
+ subject { commands.check_home_directory('root', '/root') }
133
+ it { should eq "grep -w ^root /etc/passwd | cut -f 6 -d ':' | grep -w /root" }
134
+ end
135
+
116
136
  describe 'check_ipatbles', :os => :debian do
117
137
  context 'check a rule without a table and a chain' do
118
138
  subject { commands.check_iptables_rule('-P INPUT ACCEPT') }
@@ -31,6 +31,10 @@ describe 'Serverspec matchers of Debian family', :os => :debian do
31
31
  it_behaves_like 'support be_installed.by(gem).with_version matcher', 'jekyll', '1.0.0'
32
32
 
33
33
  it_behaves_like 'support belong_to_group matcher', 'root', 'root'
34
+ it_behaves_like 'support have_gid matcher', 'root', 0
35
+ it_behaves_like 'support have_uid matcher', 'root', 0
36
+ it_behaves_like 'support have_login_shell matcher', 'root', '/bin/bash'
37
+ it_behaves_like 'support have_home_directory matcher', 'root', '/root'
34
38
 
35
39
  it_behaves_like 'support have_iptables_rule matcher', '-P INPUT ACCEPT'
36
40
  it_behaves_like 'support have_iptables_rule.with_table.with_chain matcher', '-P INPUT ACCEPT', 'mangle', 'INPUT'
@@ -112,6 +112,26 @@ describe 'check_belonging_group', :os => :gentoo do
112
112
  it { should eq "id root | awk '{print $3}' | grep wheel" }
113
113
  end
114
114
 
115
+ describe 'have_gid', :os => :gentoo do
116
+ subject { commands.check_gid('root', 0) }
117
+ it { should eq "getent group | grep -w ^root | cut -f 3 -d ':' | grep -w 0" }
118
+ end
119
+
120
+ describe 'have_uid', :os => :gentoo do
121
+ subject { commands.check_uid('root', 0) }
122
+ it { should eq "id root | grep uid=0(" }
123
+ end
124
+
125
+ describe 'have_login_shell', :os => :gentoo do
126
+ subject { commands.check_login_shell('root', '/bin/bash') }
127
+ it { should eq "grep -w ^root /etc/passwd | cut -f 7 -d ':' | grep -w /bin/bash" }
128
+ end
129
+
130
+ describe 'have_home_directory', :os => :gentoo do
131
+ subject { commands.check_home_directory('root', '/root') }
132
+ it { should eq "grep -w ^root /etc/passwd | cut -f 6 -d ':' | grep -w /root" }
133
+ end
134
+
115
135
  describe 'check_ipatbles', :os => :gentoo do
116
136
  context 'check a rule without a table and a chain' do
117
137
  subject { commands.check_iptables_rule('-P INPUT ACCEPT') }
@@ -32,6 +32,10 @@ describe 'Serverspec matchers of Gentoo family', :os => :gentoo do
32
32
  it_behaves_like 'support be_installed.by(gem).with_version matcher', 'jekyll', '1.0.0'
33
33
 
34
34
  it_behaves_like 'support belong_to_group matcher', 'root', 'root'
35
+ it_behaves_like 'support have_gid matcher', 'root', 0
36
+ it_behaves_like 'support have_uid matcher', 'root', 0
37
+ it_behaves_like 'support have_login_shell matcher', 'root', '/bin/bash'
38
+ it_behaves_like 'support have_home_directory matcher', 'root', '/root'
35
39
 
36
40
  it_behaves_like 'support have_iptables_rule matcher', '-P INPUT ACCEPT'
37
41
  it_behaves_like 'support have_iptables_rule.with_table.with_chain matcher', '-P INPUT ACCEPT', 'mangle', 'INPUT'
@@ -112,6 +112,26 @@ describe 'check_belonging_group', :os => :redhat do
112
112
  it { should eq "id root | awk '{print $3}' | grep wheel" }
113
113
  end
114
114
 
115
+ describe 'have_gid', :os => :redhat do
116
+ subject { commands.check_gid('root', 0) }
117
+ it { should eq "getent group | grep -w ^root | cut -f 3 -d ':' | grep -w 0" }
118
+ end
119
+
120
+ describe 'have_uid', :os => :redhat do
121
+ subject { commands.check_uid('root', 0) }
122
+ it { should eq "id root | grep uid=0(" }
123
+ end
124
+
125
+ describe 'have_login_shell', :os => :redhat do
126
+ subject { commands.check_login_shell('root', '/bin/bash') }
127
+ it { should eq "grep -w ^root /etc/passwd | cut -f 7 -d ':' | grep -w /bin/bash" }
128
+ end
129
+
130
+ describe 'have_home_directory', :os => :redhat do
131
+ subject { commands.check_home_directory('root', '/root') }
132
+ it { should eq "grep -w ^root /etc/passwd | cut -f 6 -d ':' | grep -w /root" }
133
+ end
134
+
115
135
  describe 'check_ipatbles', :os => :redhat do
116
136
  context 'check a rule without a table and a chain' do
117
137
  subject { commands.check_iptables_rule('-P INPUT ACCEPT') }
@@ -33,6 +33,10 @@ describe 'Serverspec matchers of Red Hat family', :os => :redhat do
33
33
  it_behaves_like 'support be_installed.by(gem).with_version matcher', 'jekyll', '1.0.0'
34
34
 
35
35
  it_behaves_like 'support belong_to_group matcher', 'root', 'root'
36
+ it_behaves_like 'support have_gid matcher', 'root', 0
37
+ it_behaves_like 'support have_uid matcher', 'root', 0
38
+ it_behaves_like 'support have_login_shell matcher', 'root', '/bin/bash'
39
+ it_behaves_like 'support have_home_directory matcher', 'root', '/root'
36
40
 
37
41
  it_behaves_like 'support have_iptables_rule matcher', '-P INPUT ACCEPT'
38
42
  it_behaves_like 'support have_iptables_rule.with_table.with_chain matcher', '-P INPUT ACCEPT', 'mangle', 'INPUT'
@@ -58,22 +58,22 @@ end
58
58
  describe 'check_file_contain_within', :os => :solaris do
59
59
  context 'contain a pattern in the file' do
60
60
  subject { commands.check_file_contain_within('Gemfile', 'rspec') }
61
- it { should eq "sed -n '1,$p' Gemfile | grep -q 'rspec' -" }
61
+ it { should eq "sed -n '1,$p' Gemfile | grep -q 'rspec' /dev/stdin" }
62
62
  end
63
63
 
64
64
  context 'contain a pattern after a line in a file' do
65
65
  subject { commands.check_file_contain_within('Gemfile', 'rspec', '/^group :test do/') }
66
- it { should eq "sed -n '/^group :test do/,$p' Gemfile | grep -q 'rspec' -" }
66
+ it { should eq "sed -n '/^group :test do/,$p' Gemfile | grep -q 'rspec' /dev/stdin" }
67
67
  end
68
68
 
69
69
  context 'contain a pattern before a line in a file' do
70
70
  subject {commands.check_file_contain_within('Gemfile', 'rspec', nil, '/^end/') }
71
- it { should eq "sed -n '1,/^end/p' Gemfile | grep -q 'rspec' -" }
71
+ it { should eq "sed -n '1,/^end/p' Gemfile | grep -q 'rspec' /dev/stdin" }
72
72
  end
73
73
 
74
74
  context 'contain a pattern from within a line and another line in a file' do
75
75
  subject { commands.check_file_contain_within('Gemfile', 'rspec', '/^group :test do/', '/^end/') }
76
- it { should eq "sed -n '/^group :test do/,/^end/p' Gemfile | grep -q 'rspec' -" }
76
+ it { should eq "sed -n '/^group :test do/,/^end/p' Gemfile | grep -q 'rspec' /dev/stdin" }
77
77
  end
78
78
  end
79
79
 
@@ -109,9 +109,28 @@ end
109
109
 
110
110
  describe 'check_belonging_group', :os => :solaris do
111
111
  subject { commands.check_belonging_group('root', 'wheel') }
112
- it { should eq "id root | awk '{print $3}' | grep wheel" }
112
+ it { should eq "id -Gn root | grep wheel" }
113
113
  end
114
114
 
115
+ describe 'have_gid', :os => :solaris do
116
+ subject { commands.check_gid('root', 0) }
117
+ it { should eq "getent group | grep -w ^root | cut -f 3 -d ':' | grep -w 0" }
118
+ end
119
+
120
+ describe 'have_uid', :os => :solaris do
121
+ subject { commands.check_uid('root', 0) }
122
+ it { should eq "id root | grep uid=0(" }
123
+ end
124
+
125
+ describe 'have_login_shell', :os => :solaris do
126
+ subject { commands.check_login_shell('root', '/bin/bash') }
127
+ it { should eq "grep -w ^root /etc/passwd | cut -f 7 -d ':' | grep -w /bin/bash" }
128
+ end
129
+
130
+ describe 'have_home_directory', :os => :solaris do
131
+ subject { commands.check_home_directory('root', '/root') }
132
+ it { should eq "grep -w ^root /etc/passwd | cut -f 6 -d ':' | grep -w /root" }
133
+ end
115
134
 
116
135
  describe 'check_zfs', :os => :solaris do
117
136
  context 'check without properties' do
@@ -32,6 +32,10 @@ describe 'Serverspec matchers of Solaris family', :os => :solaris do
32
32
  it_behaves_like 'support be_installed.by(gem).with_version matcher', 'jekyll', '1.0.0'
33
33
 
34
34
  it_behaves_like 'support belong_to_group matcher', 'root', 'root'
35
+ it_behaves_like 'support have_gid matcher', 'root', 0
36
+ it_behaves_like 'support have_uid matcher', 'root', 0
37
+ it_behaves_like 'support have_login_shell matcher', 'root', '/bin/bash'
38
+ it_behaves_like 'support have_home_directory matcher', 'root', '/root'
35
39
 
36
40
  it_behaves_like 'support be_zfs matcher', 'rpool'
37
41
  it_behaves_like 'support be_zfs.property matcher', 'rpool', { 'mountpoint' => '/rpool' }
@@ -322,6 +322,54 @@ shared_examples_for 'support belong_to_group matcher' do |user, group|
322
322
  end
323
323
  end
324
324
 
325
+ shared_examples_for 'support have_gid matcher' do |group, gid|
326
+ describe 'have_gid' do
327
+ describe group do
328
+ it { should have_gid gid }
329
+ end
330
+
331
+ describe 'dummygroup' do
332
+ it { should_not have_gid 'invalid-gid' }
333
+ end
334
+ end
335
+ end
336
+
337
+ shared_examples_for 'support have_uid matcher' do |user, uid|
338
+ describe 'have_uid' do
339
+ describe user do
340
+ it { should have_uid uid }
341
+ end
342
+
343
+ describe 'dummyuser' do
344
+ it { should_not have_uid 'invalid-uid' }
345
+ end
346
+ end
347
+ end
348
+
349
+ shared_examples_for 'support have_login_shell matcher' do |user, path_to_shell|
350
+ describe 'have_login_shell' do
351
+ describe user do
352
+ it { should have_login_shell path_to_shell }
353
+ end
354
+
355
+ describe 'dummyuser' do
356
+ it { should_not have_login_shell 'invalid-login-shell' }
357
+ end
358
+ end
359
+ end
360
+
361
+ shared_examples_for 'support have_home_directory matcher' do |user, path_to_home|
362
+ describe 'have_home_directory' do
363
+ describe user do
364
+ it { should have_home_directory path_to_home }
365
+ end
366
+
367
+ describe 'dummyuser' do
368
+ it { should_not have_home_directory 'invalid-home-directory' }
369
+ end
370
+ end
371
+ end
372
+
325
373
  shared_examples_for 'support have_iptables_rule matcher' do |rule|
326
374
  describe 'have_iptables_rule' do
327
375
  describe 'iptables' do
metadata CHANGED
@@ -1,105 +1,104 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: serverspec
3
- version: !ruby/object:Gem::Version
4
- version: 0.2.16
5
- prerelease:
3
+ version: !ruby/object:Gem::Version
4
+ hash: 53
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 2
9
+ - 17
10
+ version: 0.2.17
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Gosuke Miyashita
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2013-04-29 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
17
+
18
+ date: 2013-05-01 00:00:00 +09:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
15
22
  name: net-ssh
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0'
22
- type: :runtime
23
23
  prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
29
- version: '0'
30
- - !ruby/object:Gem::Dependency
31
- name: rspec
32
- requirement: !ruby/object:Gem::Requirement
24
+ requirement: &id001 !ruby/object:Gem::Requirement
33
25
  none: false
34
- requirements:
35
- - - ! '>='
36
- - !ruby/object:Gem::Version
37
- version: '0'
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
38
33
  type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: rspec
39
37
  prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
45
- version: '0'
46
- - !ruby/object:Gem::Dependency
47
- name: highline
48
- requirement: !ruby/object:Gem::Requirement
38
+ requirement: &id002 !ruby/object:Gem::Requirement
49
39
  none: false
50
- requirements:
51
- - - ! '>='
52
- - !ruby/object:Gem::Version
53
- version: '0'
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
54
47
  type: :runtime
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: highline
55
51
  prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
52
+ requirement: &id003 !ruby/object:Gem::Requirement
57
53
  none: false
58
- requirements:
59
- - - ! '>='
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- - !ruby/object:Gem::Dependency
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ type: :runtime
62
+ version_requirements: *id003
63
+ - !ruby/object:Gem::Dependency
63
64
  name: bundler
64
- requirement: !ruby/object:Gem::Requirement
65
- none: false
66
- requirements:
67
- - - ~>
68
- - !ruby/object:Gem::Version
69
- version: '1.3'
70
- type: :development
71
65
  prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
66
+ requirement: &id004 !ruby/object:Gem::Requirement
73
67
  none: false
74
- requirements:
68
+ requirements:
75
69
  - - ~>
76
- - !ruby/object:Gem::Version
77
- version: '1.3'
78
- - !ruby/object:Gem::Dependency
79
- name: rake
80
- requirement: !ruby/object:Gem::Requirement
81
- none: false
82
- requirements:
83
- - - ! '>='
84
- - !ruby/object:Gem::Version
85
- version: '0'
70
+ - !ruby/object:Gem::Version
71
+ hash: 9
72
+ segments:
73
+ - 1
74
+ - 3
75
+ version: "1.3"
86
76
  type: :development
77
+ version_requirements: *id004
78
+ - !ruby/object:Gem::Dependency
79
+ name: rake
87
80
  prerelease: false
88
- version_requirements: !ruby/object:Gem::Requirement
81
+ requirement: &id005 !ruby/object:Gem::Requirement
89
82
  none: false
90
- requirements:
91
- - - ! '>='
92
- - !ruby/object:Gem::Version
93
- version: '0'
94
- description: RSpec tests for your servers provisioned by Puppet, Chef or anything
95
- else
96
- email:
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ hash: 3
87
+ segments:
88
+ - 0
89
+ version: "0"
90
+ type: :development
91
+ version_requirements: *id005
92
+ description: RSpec tests for your servers provisioned by Puppet, Chef or anything else
93
+ email:
97
94
  - gosukenator@gmail.com
98
- executables:
95
+ executables:
99
96
  - serverspec-init
100
97
  extensions: []
98
+
101
99
  extra_rdoc_files: []
102
- files:
100
+
101
+ files:
103
102
  - .gitignore
104
103
  - .travis.yml
105
104
  - Gemfile
@@ -153,11 +152,15 @@ files:
153
152
  - lib/serverspec/matchers/contain.rb
154
153
  - lib/serverspec/matchers/get_stdout.rb
155
154
  - lib/serverspec/matchers/have_cron_entry.rb
155
+ - lib/serverspec/matchers/have_gid.rb
156
+ - lib/serverspec/matchers/have_home_directory.rb
156
157
  - lib/serverspec/matchers/have_ipfilter_rule.rb
157
158
  - lib/serverspec/matchers/have_ipnat_rule.rb
158
159
  - lib/serverspec/matchers/have_iptables_rule.rb
160
+ - lib/serverspec/matchers/have_login_shell.rb
159
161
  - lib/serverspec/matchers/have_svcprop.rb
160
162
  - lib/serverspec/matchers/have_svcprops.rb
163
+ - lib/serverspec/matchers/have_uid.rb
161
164
  - lib/serverspec/matchers/return_exit_status.rb
162
165
  - lib/serverspec/matchers/return_stderr.rb
163
166
  - lib/serverspec/matchers/return_stdout.rb
@@ -175,32 +178,41 @@ files:
175
178
  - spec/solaris/matchers_spec.rb
176
179
  - spec/spec_helper.rb
177
180
  - spec/support/shared_matcher_examples.rb
181
+ has_rdoc: true
178
182
  homepage: http://serverspec.org/
179
- licenses:
183
+ licenses:
180
184
  - MIT
181
185
  post_install_message:
182
186
  rdoc_options: []
183
- require_paths:
187
+
188
+ require_paths:
184
189
  - lib
185
- required_ruby_version: !ruby/object:Gem::Requirement
190
+ required_ruby_version: !ruby/object:Gem::Requirement
186
191
  none: false
187
- requirements:
188
- - - ! '>='
189
- - !ruby/object:Gem::Version
190
- version: '0'
191
- required_rubygems_version: !ruby/object:Gem::Requirement
192
+ requirements:
193
+ - - ">="
194
+ - !ruby/object:Gem::Version
195
+ hash: 3
196
+ segments:
197
+ - 0
198
+ version: "0"
199
+ required_rubygems_version: !ruby/object:Gem::Requirement
192
200
  none: false
193
- requirements:
194
- - - ! '>='
195
- - !ruby/object:Gem::Version
196
- version: '0'
201
+ requirements:
202
+ - - ">="
203
+ - !ruby/object:Gem::Version
204
+ hash: 3
205
+ segments:
206
+ - 0
207
+ version: "0"
197
208
  requirements: []
209
+
198
210
  rubyforge_project:
199
- rubygems_version: 1.8.25
211
+ rubygems_version: 1.3.7
200
212
  signing_key:
201
213
  specification_version: 3
202
214
  summary: RSpec tests for your servers provisioned by Puppet, Chef or anything else
203
- test_files:
215
+ test_files:
204
216
  - spec/debian/commands_spec.rb
205
217
  - spec/debian/matchers_spec.rb
206
218
  - spec/gentoo/commands_spec.rb