serverspec 0.8.1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/Rakefile +6 -8
  4. data/WindowsSupport.md +88 -0
  5. data/bin/serverspec-init +75 -0
  6. data/lib/serverspec/backend/base.rb +31 -0
  7. data/lib/serverspec/backend/cmd.rb +35 -0
  8. data/lib/serverspec/backend/exec.rb +1 -24
  9. data/lib/serverspec/backend/powershell/command.rb +36 -0
  10. data/lib/serverspec/backend/powershell/script_helper.rb +69 -0
  11. data/lib/serverspec/backend/powershell/support/check_file_access_rules.ps1 +12 -0
  12. data/lib/serverspec/backend/powershell/support/crop_text.ps1 +11 -0
  13. data/lib/serverspec/backend/powershell/support/find_group.ps1 +8 -0
  14. data/lib/serverspec/backend/powershell/support/find_installed_application.ps1 +7 -0
  15. data/lib/serverspec/backend/powershell/support/find_service.ps1 +5 -0
  16. data/lib/serverspec/backend/powershell/support/find_user.ps1 +8 -0
  17. data/lib/serverspec/backend/powershell/support/find_usergroup.ps1 +9 -0
  18. data/lib/serverspec/backend/powershell/support/is_port_listening.ps1 +13 -0
  19. data/lib/serverspec/backend/winrm.rb +26 -0
  20. data/lib/serverspec/backend.rb +5 -0
  21. data/lib/serverspec/commands/windows.rb +211 -0
  22. data/lib/serverspec/helper/cmd.rb +15 -0
  23. data/lib/serverspec/helper/type.rb +1 -1
  24. data/lib/serverspec/helper/windows.rb +9 -0
  25. data/lib/serverspec/helper/winrm.rb +15 -0
  26. data/lib/serverspec/helper.rb +3 -0
  27. data/lib/serverspec/setup.rb +59 -83
  28. data/lib/serverspec/type/windows_registry_key.rb +21 -0
  29. data/lib/serverspec/version.rb +1 -1
  30. data/lib/serverspec.rb +3 -0
  31. data/spec/backend/cmd/configuration_spec.rb +9 -0
  32. data/spec/backend/powershell/script_helper_spec.rb +77 -0
  33. data/spec/backend/winrm/configuration_spec.rb +9 -0
  34. data/spec/spec_helper.rb +18 -26
  35. data/spec/support/powershell_command_runner.rb +52 -0
  36. data/spec/windows/file_spec.rb +161 -0
  37. data/spec/windows/group_spec.rb +29 -0
  38. data/spec/windows/port_spec.rb +31 -0
  39. data/spec/windows/user_spec.rb +44 -0
  40. metadata +37 -2
@@ -0,0 +1,52 @@
1
+ shared_examples "a powershell command runner" do
2
+ describe 'configurations are not set' do
3
+ context file('/some/file') do
4
+ it { should be_file }
5
+ its(:command) { should == "((Get-Item -Path '/some/file' -Force).attributes.ToString() -Split ', ') -contains 'Archive'" }
6
+ end
7
+ end
8
+
9
+ describe 'path is set' do
10
+ let(:path) { 'c:/path/bin' }
11
+ context file('/some/file') do
12
+ it { should be_file }
13
+ its(:command) {
14
+ should == <<-eof
15
+ $env:path = "c:/path/bin;$env:path"
16
+ ((Get-Item -Path '/some/file' -Force).attributes.ToString() -Split ', ') -contains 'Archive'
17
+ eof
18
+ }
19
+ end
20
+ end
21
+
22
+ describe 'pre_command is set' do
23
+ let(:pre_command) { 'some_other_command' }
24
+ context file('/some/file') do
25
+ it { should be_file }
26
+ its(:command) { should == <<-eof
27
+ if (some_other_command)
28
+ {
29
+ ((Get-Item -Path '/some/file' -Force).attributes.ToString() -Split ', ') -contains 'Archive'
30
+ }
31
+ eof
32
+ }
33
+ end
34
+ end
35
+
36
+ describe 'path and pre_command are set' do
37
+ let(:path) { 'c:/path/bin' }
38
+ let(:pre_command) { 'some_other_command' }
39
+ context file('/some/file') do
40
+ it { should be_file }
41
+ its(:command) { should == <<-eof
42
+ $env:path = "c:/path/bin;$env:path"
43
+ if (some_other_command)
44
+ {
45
+ $env:path = "c:/path/bin;$env:path"
46
+ ((Get-Item -Path '/some/file' -Force).attributes.ToString() -Split ', ') -contains 'Archive'
47
+ }
48
+ eof
49
+ }
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,161 @@
1
+ require 'spec_helper'
2
+
3
+ include Serverspec::Helper::Cmd
4
+ include Serverspec::Helper::Windows
5
+
6
+ describe file('/some/valid/file') do
7
+ it { should be_file }
8
+ its(:command) { should == "((Get-Item -Path '/some/valid/file' -Force).attributes.ToString() -Split ', ') -contains 'Archive'" }
9
+ end
10
+
11
+ describe file('/some/invalid/file') do
12
+ it { should_not be_file }
13
+ end
14
+
15
+ describe file('/some/valid/folder') do
16
+ it { should be_directory }
17
+ its(:command) { should == "((Get-Item -Path '/some/valid/folder' -Force).attributes.ToString() -Split ', ') -contains 'Directory'" }
18
+ end
19
+
20
+ describe file('/some/invalid/folder') do
21
+ it { should_not be_directory }
22
+ end
23
+
24
+ describe file('/some/file') do
25
+ it { should contain 'search text' }
26
+ its(:command) { should == "[Io.File]::ReadAllText('/some/file') -match 'search text'" }
27
+ end
28
+
29
+ describe file('/some/file') do
30
+ it { should contain /^search text/ }
31
+ its(:command) { should == "[Io.File]::ReadAllText('/some/file') -match '^search text'" }
32
+ end
33
+
34
+ describe file('/some/file') do
35
+ it { should_not contain 'This is invalid text!!' }
36
+ end
37
+
38
+ describe file('Gemfile') do
39
+ it { should contain('rspec').from(/^group :test do/).to(/^end/) }
40
+ its(:command) { should == "(CropText -text ([Io.File]::ReadAllText('Gemfile')) -fromPattern '^group :test do' -toPattern '^end') -match 'rspec'" }
41
+ end
42
+
43
+ describe file('/some/file') do
44
+ it { should_not contain('This is invalid text!!').from(/^group :test do/).to(/^end/) }
45
+ end
46
+
47
+ describe file('Gemfile') do
48
+ it { should contain('rspec').after(/^group :test do/) }
49
+ its(:command) { should == "(CropText -text ([Io.File]::ReadAllText('Gemfile')) -fromPattern '^group :test do' -toPattern '$') -match 'rspec'" }
50
+ end
51
+
52
+ describe file('Gemfile') do
53
+ it { should_not contain('This is invalid text!!').after(/^group :test do/) }
54
+ end
55
+
56
+ describe file('Gemfile') do
57
+ it { should contain('rspec').before(/end/) }
58
+ its(:command) { should == "(CropText -text ([Io.File]::ReadAllText('Gemfile')) -fromPattern '^' -toPattern 'end') -match 'rspec'" }
59
+ end
60
+
61
+ describe file('Gemfile') do
62
+ it { should_not contain('This is invalid text!!').before(/^end/) }
63
+ end
64
+
65
+ describe file('/some/file') do
66
+ it { should be_readable }
67
+ its(:command) { should eq "CheckFileAccessRules -path '/some/file' -identity 'Everyone' -rules @('FullControl', 'Modify', 'ReadAndExecute', 'Read', 'ListDirectory')" }
68
+ end
69
+
70
+ describe file('/some/invalid/file') do
71
+ it { should_not be_readable }
72
+ end
73
+
74
+ describe file('/some/file') do
75
+ it "should raise error if trying to check access by 'owner' or 'group' or 'others'" do
76
+ ['owner', 'group', 'others'].each do |access|
77
+ expect { should be_readable.by(access) }.to raise_error
78
+ end
79
+ end
80
+ end
81
+
82
+ describe file('/some/file') do
83
+ it { should be_readable.by('test.identity') }
84
+ its(:command) { should eq "CheckFileAccessRules -path '/some/file' -identity 'test.identity' -rules @('FullControl', 'Modify', 'ReadAndExecute', 'Read', 'ListDirectory')" }
85
+ end
86
+
87
+ describe file('/some/file') do
88
+ it { should be_readable.by_user('test.identity') }
89
+ its(:command) { should eq "CheckFileAccessRules -path '/some/file' -identity 'test.identity' -rules @('FullControl', 'Modify', 'ReadAndExecute', 'Read', 'ListDirectory')" }
90
+ end
91
+
92
+ describe file('/some/file') do
93
+ it { should be_writable }
94
+ its(:command) { should eq "CheckFileAccessRules -path '/some/file' -identity 'Everyone' -rules @('FullControl', 'Modify', 'Write')" }
95
+ end
96
+
97
+ describe file('/some/invalid/file') do
98
+ it { should_not be_writable }
99
+ end
100
+
101
+ describe file('/some/file') do
102
+ it "should raise error if trying to check access by 'owner' or 'group' or 'others'" do
103
+ ['owner', 'group', 'others'].each do |access|
104
+ expect { should be_writable.by(access) }.to raise_error
105
+ end
106
+ end
107
+ end
108
+
109
+ describe file('/some/file') do
110
+ it { should be_writable.by('test.identity') }
111
+ its(:command) { should eq "CheckFileAccessRules -path '/some/file' -identity 'test.identity' -rules @('FullControl', 'Modify', 'Write')" }
112
+ end
113
+
114
+ describe file('/some/file') do
115
+ it { should be_writable.by_user('test.identity') }
116
+ its(:command) { should eq "CheckFileAccessRules -path '/some/file' -identity 'test.identity' -rules @('FullControl', 'Modify', 'Write')" }
117
+ end
118
+
119
+ describe file('/some/file') do
120
+ it { should be_executable }
121
+ its(:command) { should eq "CheckFileAccessRules -path '/some/file' -identity 'Everyone' -rules @('FullControl', 'Modify', 'ReadAndExecute', 'ExecuteFile')" }
122
+ end
123
+
124
+ describe file('/some/invalid/file') do
125
+ it { should_not be_executable }
126
+ end
127
+
128
+ describe file('/some/file') do
129
+ it "should raise error if trying to check access by 'owner' or 'group' or 'others'" do
130
+ ['owner', 'group', 'others'].each do |access|
131
+ expect { should be_executable.by(access) }.to raise_error
132
+ end
133
+ end
134
+ end
135
+
136
+ describe file('/some/file') do
137
+ it { should be_executable.by('test.identity') }
138
+ its(:command) { should eq "CheckFileAccessRules -path '/some/file' -identity 'test.identity' -rules @('FullControl', 'Modify', 'ReadAndExecute', 'ExecuteFile')" }
139
+ end
140
+
141
+ describe file('/some/file') do
142
+ it { should be_executable.by_user('test.identity') }
143
+ its(:command) { should eq "CheckFileAccessRules -path '/some/file' -identity 'test.identity' -rules @('FullControl', 'Modify', 'ReadAndExecute', 'ExecuteFile')" }
144
+ end
145
+
146
+ describe file('/some/test/file') do
147
+ it "should raise error if command is not supported" do
148
+ {
149
+ :be_socket => [],
150
+ :be_mode => 644,
151
+ :be_owned_by => 'root',
152
+ :be_grouped_into => 'root',
153
+ :be_linked_to => '/some/other/file',
154
+ :be_mounted => [],
155
+ :match_md5checksum => '35435ea447c19f0ea5ef971837ab9ced',
156
+ :match_sha256checksum => '0c3feee1353a8459f8c7d84885e6bc602ef853751ffdbce3e3b6dfa1d345fc7a'
157
+ }.each do |method, args|
158
+ expect { should self.send(method, *args) }.to raise_error Serverspec::Commands::Windows::NotSupportedError
159
+ end
160
+ end
161
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ include Serverspec::Helper::Cmd
4
+ include Serverspec::Helper::Windows
5
+
6
+ describe group('test.group') do
7
+ it { should exist }
8
+ its(:command) { should eq "(FindGroup -groupName 'test.group') -ne $null" }
9
+ end
10
+
11
+ describe group('test.domain\test.group') do
12
+ it { should exist }
13
+ its(:command) { should eq "(FindGroup -groupName 'test.group' -domain 'test.domain') -ne $null" }
14
+ end
15
+
16
+ describe group('invalid-group') do
17
+ it { should_not exist }
18
+ end
19
+
20
+ describe group('test.group') do
21
+ it "should raise error if command is not supported" do
22
+ {
23
+ :have_gid => [nil],
24
+ }.each do |method, args|
25
+ expect { should self.send(method, *args) }.to raise_error Serverspec::Commands::Windows::NotSupportedError
26
+ end
27
+ end
28
+ end
29
+
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ include Serverspec::Helper::Cmd
4
+ include Serverspec::Helper::Windows
5
+
6
+ describe port(80) do
7
+ it { should be_listening }
8
+ its(:command) { should eq 'IsPortListening -portNumber 80' }
9
+ end
10
+
11
+ describe port('invalid') do
12
+ it { should_not be_listening }
13
+ end
14
+
15
+ describe port(80) do
16
+ it { should be_listening.with("tcp") }
17
+ its(:command) { should eq "IsPortListening -portNumber 80 -protocol 'tcp'" }
18
+ end
19
+
20
+ describe port(123) do
21
+ it { should be_listening.with("udp") }
22
+ its(:command) { should eq "IsPortListening -portNumber 123 -protocol 'udp'" }
23
+ end
24
+
25
+ describe port(80) do
26
+ it {
27
+ expect {
28
+ should be_listening.with('not implemented')
29
+ }.to raise_error(ArgumentError, %r/\A`be_listening` matcher doesn\'t support/)
30
+ }
31
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ include Serverspec::Helper::Cmd
4
+ include Serverspec::Helper::Windows
5
+
6
+ describe user('test.user') do
7
+ it { should exist }
8
+ its(:command) { should eq "(FindUser -userName 'test.user') -ne $null" }
9
+ end
10
+
11
+ describe user('test.domain\test.user') do
12
+ it { should exist }
13
+ its(:command) { should eq "(FindUser -userName 'test.user' -domain 'test.domain') -ne $null" }
14
+ end
15
+
16
+ describe user('invalid-user') do
17
+ it { should_not exist }
18
+ end
19
+
20
+ describe user('test.user') do
21
+ it { should belong_to_group 'test.group' }
22
+ its(:command) { should eq "(FindUserGroup -userName 'test.user' -groupName 'test.group') -ne $null" }
23
+ end
24
+
25
+ describe user('test.user.domain\test.user') do
26
+ it { should belong_to_group 'test.group.domain\test.group' }
27
+ its(:command) { should eq "(FindUserGroup -userName 'test.user' -userDomain 'test.user.domain' -groupName 'test.group' -groupDomain 'test.group.domain') -ne $null" }
28
+ end
29
+
30
+ describe user('test.user') do
31
+ it { should_not belong_to_group 'invalid-group' }
32
+ end
33
+
34
+ describe user('test.user') do
35
+ it "should raise error if command is not supported" do
36
+ {
37
+ :have_uid => [nil],
38
+ :have_login_shell => [nil],
39
+ :have_authorized_key => [nil],
40
+ }.each do |method, args|
41
+ expect { should self.send(method, *args) }.to raise_error Serverspec::Commands::Windows::NotSupportedError
42
+ end
43
+ end
44
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: serverspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gosuke Miyashita
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-13 00:00:00.000000000 Z
11
+ date: 2013-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-ssh
@@ -123,12 +123,26 @@ files:
123
123
  - LICENSE.txt
124
124
  - README.md
125
125
  - Rakefile
126
+ - WindowsSupport.md
126
127
  - bin/serverspec-init
127
128
  - lib/serverspec.rb
128
129
  - lib/serverspec/attributes.rb
129
130
  - lib/serverspec/backend.rb
131
+ - lib/serverspec/backend/base.rb
132
+ - lib/serverspec/backend/cmd.rb
130
133
  - lib/serverspec/backend/exec.rb
134
+ - lib/serverspec/backend/powershell/command.rb
135
+ - lib/serverspec/backend/powershell/script_helper.rb
136
+ - lib/serverspec/backend/powershell/support/check_file_access_rules.ps1
137
+ - lib/serverspec/backend/powershell/support/crop_text.ps1
138
+ - lib/serverspec/backend/powershell/support/find_group.ps1
139
+ - lib/serverspec/backend/powershell/support/find_installed_application.ps1
140
+ - lib/serverspec/backend/powershell/support/find_service.ps1
141
+ - lib/serverspec/backend/powershell/support/find_user.ps1
142
+ - lib/serverspec/backend/powershell/support/find_usergroup.ps1
143
+ - lib/serverspec/backend/powershell/support/is_port_listening.ps1
131
144
  - lib/serverspec/backend/ssh.rb
145
+ - lib/serverspec/backend/winrm.rb
132
146
  - lib/serverspec/commands/base.rb
133
147
  - lib/serverspec/commands/darwin.rb
134
148
  - lib/serverspec/commands/debian.rb
@@ -139,10 +153,12 @@ files:
139
153
  - lib/serverspec/commands/solaris.rb
140
154
  - lib/serverspec/commands/solaris10.rb
141
155
  - lib/serverspec/commands/solaris11.rb
156
+ - lib/serverspec/commands/windows.rb
142
157
  - lib/serverspec/configuration.rb
143
158
  - lib/serverspec/helper.rb
144
159
  - lib/serverspec/helper/attributes.rb
145
160
  - lib/serverspec/helper/base.rb
161
+ - lib/serverspec/helper/cmd.rb
146
162
  - lib/serverspec/helper/configuration.rb
147
163
  - lib/serverspec/helper/darwin.rb
148
164
  - lib/serverspec/helper/debian.rb
@@ -157,6 +173,8 @@ files:
157
173
  - lib/serverspec/helper/solaris11.rb
158
174
  - lib/serverspec/helper/ssh.rb
159
175
  - lib/serverspec/helper/type.rb
176
+ - lib/serverspec/helper/windows.rb
177
+ - lib/serverspec/helper/winrm.rb
160
178
  - lib/serverspec/matchers.rb
161
179
  - lib/serverspec/matchers/be_enabled.rb
162
180
  - lib/serverspec/matchers/be_executable.rb
@@ -200,14 +218,18 @@ files:
200
218
  - lib/serverspec/type/selinux.rb
201
219
  - lib/serverspec/type/service.rb
202
220
  - lib/serverspec/type/user.rb
221
+ - lib/serverspec/type/windows_registry_key.rb
203
222
  - lib/serverspec/type/yumrepo.rb
204
223
  - lib/serverspec/type/zfs.rb
205
224
  - lib/serverspec/version.rb
206
225
  - serverspec.gemspec
226
+ - spec/backend/cmd/configuration_spec.rb
207
227
  - spec/backend/exec/build_command_spec.rb
208
228
  - spec/backend/exec/configuration_spec.rb
229
+ - spec/backend/powershell/script_helper_spec.rb
209
230
  - spec/backend/ssh/build_command_spec.rb
210
231
  - spec/backend/ssh/configuration_spec.rb
232
+ - spec/backend/winrm/configuration_spec.rb
211
233
  - spec/darwin/command_spec.rb
212
234
  - spec/darwin/cron_spec.rb
213
235
  - spec/darwin/default_gateway_spec.rb
@@ -321,6 +343,11 @@ files:
321
343
  - spec/solaris11/user_spec.rb
322
344
  - spec/solaris11/zfs_spec.rb
323
345
  - spec/spec_helper.rb
346
+ - spec/support/powershell_command_runner.rb
347
+ - spec/windows/file_spec.rb
348
+ - spec/windows/group_spec.rb
349
+ - spec/windows/port_spec.rb
350
+ - spec/windows/user_spec.rb
324
351
  homepage: http://serverspec.org/
325
352
  licenses:
326
353
  - MIT
@@ -346,10 +373,13 @@ signing_key:
346
373
  specification_version: 4
347
374
  summary: RSpec tests for your servers configured by Puppet, Chef or anything else
348
375
  test_files:
376
+ - spec/backend/cmd/configuration_spec.rb
349
377
  - spec/backend/exec/build_command_spec.rb
350
378
  - spec/backend/exec/configuration_spec.rb
379
+ - spec/backend/powershell/script_helper_spec.rb
351
380
  - spec/backend/ssh/build_command_spec.rb
352
381
  - spec/backend/ssh/configuration_spec.rb
382
+ - spec/backend/winrm/configuration_spec.rb
353
383
  - spec/darwin/command_spec.rb
354
384
  - spec/darwin/cron_spec.rb
355
385
  - spec/darwin/default_gateway_spec.rb
@@ -463,3 +493,8 @@ test_files:
463
493
  - spec/solaris11/user_spec.rb
464
494
  - spec/solaris11/zfs_spec.rb
465
495
  - spec/spec_helper.rb
496
+ - spec/support/powershell_command_runner.rb
497
+ - spec/windows/file_spec.rb
498
+ - spec/windows/group_spec.rb
499
+ - spec/windows/port_spec.rb
500
+ - spec/windows/user_spec.rb