train 1.5.11 → 1.6.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/lib/train/transports/winrm.rb +16 -4
  3. data/lib/train/version.rb +1 -1
  4. metadata +3 -165
  5. data/.rubocop.yml +0 -77
  6. data/CHANGELOG.md +0 -900
  7. data/Gemfile +0 -41
  8. data/README.md +0 -212
  9. data/Rakefile +0 -73
  10. data/test/fixtures/plugins/train-test-fixture/LICENSE +0 -201
  11. data/test/fixtures/plugins/train-test-fixture/README.md +0 -5
  12. data/test/fixtures/plugins/train-test-fixture/lib/train-test-fixture/connection.rb +0 -35
  13. data/test/fixtures/plugins/train-test-fixture/lib/train-test-fixture/platform.rb +0 -18
  14. data/test/fixtures/plugins/train-test-fixture/lib/train-test-fixture/transport.rb +0 -14
  15. data/test/fixtures/plugins/train-test-fixture/lib/train-test-fixture/version.rb +0 -5
  16. data/test/fixtures/plugins/train-test-fixture/lib/train-test-fixture.rb +0 -4
  17. data/test/fixtures/plugins/train-test-fixture/pkg/train-test-fixture-0.1.0.gem +0 -0
  18. data/test/fixtures/plugins/train-test-fixture/train-test-fixture.gemspec +0 -35
  19. data/test/integration/.kitchen.yml +0 -43
  20. data/test/integration/Berksfile +0 -3
  21. data/test/integration/bootstrap.sh +0 -22
  22. data/test/integration/chefignore +0 -1
  23. data/test/integration/cookbooks/test/metadata.rb +0 -1
  24. data/test/integration/cookbooks/test/recipes/default.rb +0 -100
  25. data/test/integration/cookbooks/test/recipes/prep_files.rb +0 -56
  26. data/test/integration/docker_run.rb +0 -153
  27. data/test/integration/docker_test.rb +0 -24
  28. data/test/integration/docker_test_container.rb +0 -24
  29. data/test/integration/helper.rb +0 -61
  30. data/test/integration/sudo/customcommand.rb +0 -15
  31. data/test/integration/sudo/nopasswd.rb +0 -16
  32. data/test/integration/sudo/passwd.rb +0 -21
  33. data/test/integration/sudo/reqtty.rb +0 -17
  34. data/test/integration/sudo/run_as.rb +0 -12
  35. data/test/integration/test-travis-centos.yml +0 -6
  36. data/test/integration/test-travis-debian.yml +0 -6
  37. data/test/integration/test-travis-fedora.yml +0 -8
  38. data/test/integration/test-travis-oel.yml +0 -6
  39. data/test/integration/test-travis-ubuntu.yml +0 -8
  40. data/test/integration/test_local.rb +0 -19
  41. data/test/integration/test_ssh.rb +0 -39
  42. data/test/integration/tests/path_block_device_test.rb +0 -74
  43. data/test/integration/tests/path_character_device_test.rb +0 -74
  44. data/test/integration/tests/path_file_test.rb +0 -99
  45. data/test/integration/tests/path_folder_test.rb +0 -90
  46. data/test/integration/tests/path_missing_test.rb +0 -76
  47. data/test/integration/tests/path_pipe_test.rb +0 -62
  48. data/test/integration/tests/path_symlink_test.rb +0 -95
  49. data/test/integration/tests/run_command_test.rb +0 -35
  50. data/test/unit/extras/command_wrapper_test.rb +0 -110
  51. data/test/unit/extras/stat_test.rb +0 -210
  52. data/test/unit/file/local/unix_test.rb +0 -224
  53. data/test/unit/file/local/windows_test.rb +0 -101
  54. data/test/unit/file/local_test.rb +0 -121
  55. data/test/unit/file/remote/aix_test.rb +0 -81
  56. data/test/unit/file/remote/linux_test.rb +0 -221
  57. data/test/unit/file/remote/qnx_test.rb +0 -80
  58. data/test/unit/file/remote/unix_test.rb +0 -119
  59. data/test/unit/file/remote/windows_test.rb +0 -72
  60. data/test/unit/file/remote_test.rb +0 -62
  61. data/test/unit/file_test.rb +0 -129
  62. data/test/unit/helper.rb +0 -7
  63. data/test/unit/platforms/detect/os_common_test.rb +0 -85
  64. data/test/unit/platforms/detect/os_linux_test.rb +0 -132
  65. data/test/unit/platforms/detect/os_windows_test.rb +0 -107
  66. data/test/unit/platforms/detect/scanner_test.rb +0 -61
  67. data/test/unit/platforms/detect/uuid_test.rb +0 -133
  68. data/test/unit/platforms/family_test.rb +0 -32
  69. data/test/unit/platforms/os_detect_test.rb +0 -249
  70. data/test/unit/platforms/platform_test.rb +0 -405
  71. data/test/unit/platforms/platforms_test.rb +0 -52
  72. data/test/unit/plugins/connection_test.rb +0 -219
  73. data/test/unit/plugins/transport_test.rb +0 -111
  74. data/test/unit/plugins_test.rb +0 -22
  75. data/test/unit/train_test.rb +0 -247
  76. data/test/unit/transports/aws_test.rb +0 -120
  77. data/test/unit/transports/azure_test.rb +0 -145
  78. data/test/unit/transports/cisco_ios_connection.rb +0 -92
  79. data/test/unit/transports/gcp_test.rb +0 -266
  80. data/test/unit/transports/helpers/azure/file_credentials_test.rb +0 -129
  81. data/test/unit/transports/local_test.rb +0 -183
  82. data/test/unit/transports/mock_test.rb +0 -150
  83. data/test/unit/transports/ssh_test.rb +0 -330
  84. data/test/unit/transports/vmware_test.rb +0 -159
  85. data/test/unit/version_test.rb +0 -8
  86. data/test/windows/local_test.rb +0 -243
  87. data/test/windows/winrm_test.rb +0 -187
  88. data/train.gemspec +0 -45
@@ -1,243 +0,0 @@
1
- # encoding: utf-8
2
- # author: Christoph Hartmann
3
- # author: Dominik Richter
4
-
5
- require 'minitest/autorun'
6
- require 'minitest/spec'
7
- require 'mocha/setup'
8
- require 'train'
9
- require 'tempfile'
10
-
11
- # Loading here to ensure methods exist to be stubbed
12
- require 'train/transports/local'
13
-
14
- describe 'windows local command' do
15
- let(:backend) do
16
- # get final config
17
- target_config = Train.target_config({})
18
- # initialize train
19
- backend = Train.create('local', target_config)
20
- end
21
- let(:conn) { backend.connection }
22
-
23
- it 'verify os' do
24
- os = conn.os
25
- os[:name].must_equal 'windows_server_2012_r2_datacenter'
26
- os[:family].must_equal "windows"
27
- os[:release].must_equal '6.3.9600'
28
- os[:arch].must_equal 'x86_64'
29
- end
30
-
31
- it 'run echo test' do
32
- cmd = conn.run_command('Write-Output "test"')
33
- cmd.stdout.must_equal "test\r\n"
34
- cmd.stderr.must_equal ''
35
- end
36
-
37
- describe 'force 64 bit powershell command' do
38
- let(:runner) { conn.instance_variable_get(:@runner) }
39
- let(:powershell) { runner.instance_variable_get(:@powershell_cmd) }
40
- RUBY_PLATFORM_DUP = RUBY_PLATFORM.dup
41
-
42
- def override_platform(platform)
43
- ::Object.send(:remove_const, :RUBY_PLATFORM)
44
- ::Object.const_set(:RUBY_PLATFORM, platform)
45
- end
46
-
47
- after do
48
- backend.instance_variable_set(:@connection, nil)
49
- ::Object.send(:remove_const, :RUBY_PLATFORM)
50
- ::Object.const_set(:RUBY_PLATFORM, RUBY_PLATFORM_DUP)
51
- end
52
-
53
- it 'use normal powershell with PipeRunner' do
54
- Train::Transports::Local::Connection::WindowsPipeRunner
55
- .any_instance
56
- .expects(:acquire_pipe)
57
- .returns('acquired')
58
-
59
- override_platform('x64-mingw32')
60
- powershell.must_equal 'powershell'
61
- end
62
-
63
- it 'use 64bit powershell with PipeRunner' do
64
- Train::Transports::Local::Connection::WindowsPipeRunner
65
- .any_instance
66
- .expects(:acquire_pipe)
67
- .returns('acquired')
68
-
69
- override_platform('i386-mingw32')
70
- powershell.must_equal "#{ENV['SystemRoot']}\\sysnative\\WindowsPowerShell\\v1.0\\powershell.exe"
71
- end
72
-
73
- it 'use normal powershell with ShellRunner' do
74
- Train::Transports::Local::Connection::WindowsPipeRunner
75
- .any_instance
76
- .expects(:acquire_pipe)
77
- .returns(nil)
78
-
79
- override_platform('x64-mingw32')
80
- runner.class.must_equal Train::Transports::Local::Connection::WindowsShellRunner
81
- powershell.must_equal 'powershell'
82
- end
83
-
84
- it 'use 64bit powershell with ShellRunner' do
85
- Train::Transports::Local::Connection::WindowsPipeRunner
86
- .any_instance
87
- .expects(:acquire_pipe)
88
- .returns(nil)
89
-
90
- override_platform('i386-mingw32')
91
- runner.class.must_equal Train::Transports::Local::Connection::WindowsShellRunner
92
- powershell.must_equal "#{ENV['SystemRoot']}\\sysnative\\WindowsPowerShell\\v1.0\\powershell.exe"
93
- end
94
- end
95
-
96
- it 'use powershell piping' do
97
- cmd = conn.run_command("New-Object -Type PSObject | Add-Member -MemberType NoteProperty -Name A -Value (Write-Output 'PropertyA') -PassThru | Add-Member -MemberType NoteProperty -Name B -Value (Write-Output 'PropertyB') -PassThru | ConvertTo-Json")
98
- cmd.stdout.must_equal "{\r\n \"A\": \"PropertyA\",\r\n \"B\": \"PropertyB\"\r\n}\r\n"
99
- cmd.stderr.must_equal ''
100
- end
101
-
102
- it 'can execute a command using a named pipe' do
103
- SecureRandom.expects(:hex).returns('via_pipe')
104
-
105
- Train::Transports::Local::Connection::WindowsShellRunner
106
- .any_instance
107
- .expects(:new)
108
- .never
109
-
110
- cmd = conn.run_command('Write-Output "Create pipe"')
111
- File.exist?('//./pipe/inspec_via_pipe').must_equal true
112
- cmd.stdout.must_equal "Create pipe\r\n"
113
- cmd.stderr.must_equal ''
114
- end
115
-
116
- it 'can execute a command via ShellRunner if pipe creation fails' do
117
- # By forcing `acquire_pipe` to fail to return a pipe, any attempts to create
118
- # a `WindowsPipeRunner` object should fail. If we can still run a command,
119
- # then we know that it was successfully executed by `Mixlib::ShellOut`.
120
- Train::Transports::Local::Connection::WindowsPipeRunner
121
- .any_instance
122
- .expects(:acquire_pipe)
123
- .at_least_once
124
- .returns(nil)
125
-
126
- proc { Train::Transports::Local::Connection::WindowsPipeRunner.new }
127
- .must_raise(Train::Transports::Local::PipeError)
128
-
129
- cmd = conn.run_command('Write-Output "test"')
130
- cmd.stdout.must_equal "test\r\n"
131
- cmd.stderr.must_equal ''
132
- end
133
-
134
- describe 'file' do
135
- before do
136
- @temp = Tempfile.new('foo')
137
- @temp.write("hello world")
138
- @temp.rewind
139
- end
140
-
141
- let(:file) { conn.file(@temp.path) }
142
-
143
- it 'exists' do
144
- file.exist?.must_equal(true)
145
- end
146
-
147
- it 'is a file' do
148
- file.file?.must_equal(true)
149
- end
150
-
151
- it 'has type :file' do
152
- file.type.must_equal(:file)
153
- end
154
-
155
- it 'has content' do
156
- file.content.must_equal("hello world")
157
- end
158
-
159
- it 'returns basename of file' do
160
- file_name = ::File.basename(@temp)
161
- file.basename.must_equal(file_name)
162
- end
163
-
164
- it 'has owner name' do
165
- file.owner.wont_be_nil
166
- end
167
-
168
- it 'has no group name' do
169
- file.group.must_be_nil
170
- end
171
-
172
- it 'has no mode' do
173
- file.mode.wont_be_nil
174
- end
175
-
176
- it 'has an md5sum' do
177
- file.md5sum.wont_be_nil
178
- end
179
-
180
- it 'has an sha256sum' do
181
- file.sha256sum.wont_be_nil
182
- end
183
-
184
- it 'has no modified time' do
185
- file.mtime.wont_be_nil
186
- end
187
-
188
- it 'has no size' do
189
- file.size.wont_be_nil
190
- end
191
-
192
- it 'has size 11' do
193
- size = ::File.size(@temp)
194
- file.size.must_equal size
195
- end
196
-
197
- it 'has no selinux_label handling' do
198
- file.selinux_label.must_be_nil
199
- end
200
-
201
- it 'has product_version' do
202
- file.product_version.wont_be_nil
203
- end
204
-
205
- it 'has file_version' do
206
- file.file_version.wont_be_nil
207
- end
208
-
209
- it 'provides a json representation' do
210
- j = file.to_json
211
- j.must_be_kind_of Hash
212
- j['type'].must_equal :file
213
- end
214
-
215
- after do
216
- @temp.close
217
- @temp.unlink
218
- end
219
- end
220
-
221
- describe 'file' do
222
- before do
223
- @temp = Tempfile.new('foo bar')
224
- @temp.rewind
225
- end
226
-
227
- let(:file) { conn.file(@temp.path) }
228
-
229
- it 'provides the full path with whitespace for path #{@temp.path}' do
230
- file.path.must_equal @temp.path
231
- end
232
-
233
- after do
234
- @temp.close
235
- @temp.unlink
236
- end
237
- end
238
-
239
- after do
240
- # close the connection
241
- conn.close
242
- end
243
- end
@@ -1,187 +0,0 @@
1
- # encoding: utf-8
2
- # author: Christoph Hartmann
3
- # author: Dominik Richter
4
-
5
- require 'minitest/autorun'
6
- require 'minitest/spec'
7
- require 'mocha/setup'
8
- require 'train'
9
-
10
- describe 'windows winrm command' do
11
- let(:conn) {
12
- # get final config
13
- target_config = Train.target_config({
14
- target: ENV['train_target'],
15
- password: ENV['winrm_pass'],
16
- ssl: ENV['train_ssl'],
17
- self_signed: true,
18
- })
19
-
20
- # initialize train
21
- backend = Train.create('winrm', target_config)
22
-
23
- # start or reuse a connection
24
- conn = backend.connection
25
- conn
26
- }
27
-
28
- it 'verify os' do
29
- os = conn.os
30
- os[:name].must_equal 'windows_server_2012_r2_datacenter'
31
- os[:family].must_equal 'windows'
32
- os[:release].must_equal '6.3.9600'
33
- os[:arch].must_equal 'x86_64'
34
- end
35
-
36
- it 'run echo test' do
37
- cmd = conn.run_command('Write-Output "test"')
38
- cmd.stdout.must_equal "test\r\n"
39
- cmd.stderr.must_equal ''
40
- end
41
-
42
- it 'use powershell piping' do
43
- cmd = conn.run_command("New-Object -Type PSObject | Add-Member -MemberType NoteProperty -Name A -Value (Write-Output 'PropertyA') -PassThru | Add-Member -MemberType NoteProperty -Name B -Value (Write-Output 'PropertyB') -PassThru | ConvertTo-Json")
44
- cmd.stdout.must_equal "{\r\n \"A\": \"PropertyA\",\r\n \"B\": \"PropertyB\"\r\n}\r\n"
45
- cmd.stderr.must_equal ''
46
- end
47
-
48
-
49
- describe 'file' do
50
- before do
51
- @temp = Tempfile.new('foo')
52
- @temp.write("hello world")
53
- @temp.rewind
54
- end
55
-
56
- let(:file) { conn.file(@temp.path) }
57
-
58
- it 'exists' do
59
- file.exist?.must_equal(true)
60
- end
61
-
62
- it 'is a file' do
63
- file.file?.must_equal(true)
64
- end
65
-
66
- it 'has type :file' do
67
- file.type.must_equal(:file)
68
- end
69
-
70
- it 'has content' do
71
- # TODO: this shouldn't include newlines that aren't in the original file
72
- file.content.must_equal("hello world\r\n")
73
- end
74
-
75
- it 'has owner name' do
76
- file.owner.wont_be_nil
77
- end
78
-
79
- it 'has no group name' do
80
- file.group.must_be_nil
81
- end
82
-
83
- it 'has no mode' do
84
- file.mode.must_be_nil
85
- end
86
-
87
- it 'has the correct md5sum' do
88
- # Must create unique file to prevent `ERROR_SHARING_VIOLATION`
89
- tempfile = Tempfile.new('tempfile')
90
- tempfile.write('easy to hash')
91
- tempfile.close
92
- conn.file(tempfile.path).md5sum.must_equal 'c15b41ade1221a532a38d89671ffaa20'
93
- tempfile.unlink
94
- end
95
-
96
- it 'has the correct sha256sum' do
97
- # Must create unique file to prevent `ERROR_SHARING_VIOLATION`
98
- tempfile = Tempfile.new('tempfile')
99
- tempfile.write('easy to hash')
100
- tempfile.close
101
- conn.file(tempfile.path).sha256sum.must_equal '24ae25354d5f697566e715cd46e1df2f490d0b8367c21447962dbf03bf7225ba'
102
- tempfile.unlink
103
- end
104
-
105
- it 'has no modified time' do
106
- file.mtime.must_be_nil
107
- end
108
-
109
- it 'has no size' do
110
- file.size.wont_be_nil
111
- end
112
-
113
- it 'has size 11' do
114
- size = ::File.size(@temp)
115
- file.size.must_equal size
116
- end
117
-
118
- it 'has no selinux_label handling' do
119
- file.selinux_label.must_be_nil
120
- end
121
-
122
- it 'has product_version' do
123
- file.product_version.wont_be_nil
124
- end
125
-
126
- # TODO: This is not failing in manual testing
127
- # it 'returns basname of file' do
128
- # basename = ::File.basename(@temp)
129
- # file.basename.must_equal basename
130
- # end
131
-
132
- it 'has file_version' do
133
- file.file_version.wont_be_nil
134
- end
135
-
136
- it 'returns nil for mounted' do
137
- file.mounted.must_be_nil
138
- end
139
-
140
- it 'has no link_path' do
141
- file.link_path.must_be_nil
142
- end
143
-
144
- it 'has no uid' do
145
- file.uid.must_be_nil
146
- end
147
-
148
- it 'has no gid' do
149
- file.gid.must_be_nil
150
- end
151
-
152
- it 'provides a json representation' do
153
- j = file.to_json
154
- j.must_be_kind_of Hash
155
- j['type'].must_equal :file
156
- end
157
-
158
- after do
159
- @temp.close
160
- @temp.unlink
161
- end
162
- end
163
-
164
- describe 'file' do
165
- before do
166
- @temp = Tempfile.new('foo bar')
167
- @temp.write("hello world")
168
- @temp.rewind
169
- end
170
-
171
- let(:file) { conn.file(@temp.path) }
172
-
173
- it 'provides the full path with whitespace for path #{@temp.path}' do
174
- file.path.must_equal @temp.path
175
- end
176
-
177
- after do
178
- @temp.close
179
- @temp.unlink
180
- end
181
- end
182
-
183
- after do
184
- # close the connection
185
- conn.close
186
- end
187
- end
data/train.gemspec DELETED
@@ -1,45 +0,0 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'train/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = 'train'
8
- spec.version = Train::VERSION
9
- spec.authors = ['Dominik Richter']
10
- spec.email = ['drichter@chef.io']
11
- spec.summary = 'Transport interface to talk to different backends.'
12
- spec.description = 'Transport interface to talk to different backends.'
13
- spec.homepage = 'https://github.com/inspec/train/'
14
- spec.license = 'Apache-2.0'
15
-
16
- spec.files = %w{
17
- train.gemspec README.md Rakefile LICENSE Gemfile CHANGELOG.md .rubocop.yml
18
- } + Dir.glob(
19
- '{lib,test}/**/*', File::FNM_DOTMATCH
20
- ).reject { |f| File.directory?(f) }
21
-
22
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
23
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
24
- spec.require_paths = ['lib']
25
-
26
- spec.required_ruby_version = '>= 2.0'
27
-
28
- spec.add_dependency 'json', '>= 1.8', '< 3.0'
29
- # chef-client < 12.4.1 require mixlib-shellout-2.0.1
30
- spec.add_dependency 'mixlib-shellout', '~> 2.0'
31
- spec.add_dependency 'net-ssh', '>= 2.9', '< 6.0'
32
- spec.add_dependency 'net-scp', '~> 1.2'
33
- spec.add_dependency 'winrm', '~> 2.0'
34
- spec.add_dependency 'winrm-fs', '~> 1.0'
35
- spec.add_dependency 'docker-api', '~> 1.26'
36
- spec.add_dependency 'aws-sdk', '~> 2'
37
- spec.add_dependency 'azure_mgmt_resources', '~> 0.15'
38
- spec.add_dependency 'azure_graph_rbac', '~> 0.16'
39
- spec.add_dependency 'azure_mgmt_key_vault', '~> 0.17'
40
- spec.add_dependency 'google-api-client', '~> 0.23.9'
41
- spec.add_dependency 'googleauth', '~> 0.6.6'
42
- spec.add_dependency 'inifile'
43
-
44
- spec.add_development_dependency 'mocha', '~> 1.1'
45
- end