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,110 +0,0 @@
1
- # encoding: utf-8
2
- # author: Dominik Richter
3
- # author: Christoph Hartmann
4
-
5
- require 'helper'
6
- require 'train/transports/mock'
7
- require 'train/extras'
8
- require 'base64'
9
-
10
- describe 'linux command' do
11
- let(:cls) { Train::Extras::LinuxCommand }
12
- let(:cmd) { rand.to_s }
13
- let(:backend) {
14
- backend = Train::Transports::Mock.new.connection
15
- backend.mock_os({ family: 'linux' })
16
- backend
17
- }
18
-
19
- describe 'sudo wrapping' do
20
- it 'wraps commands in sudo' do
21
- lc = cls.new(backend, { sudo: true })
22
- lc.run(cmd).must_equal "sudo #{cmd}"
23
- end
24
-
25
- it 'doesnt wrap commands in sudo if user == root' do
26
- lc = cls.new(backend, { sudo: true, user: 'root' })
27
- lc.run(cmd).must_equal cmd
28
- end
29
-
30
- it 'wraps commands in sudo with all options' do
31
- opts = rand.to_s
32
- lc = cls.new(backend, { sudo: true, sudo_options: opts })
33
- lc.run(cmd).must_equal "sudo #{opts} #{cmd}"
34
- end
35
-
36
- it 'runs commands in sudo with password' do
37
- pw = rand.to_s
38
- lc = cls.new(backend, { sudo: true, sudo_password: pw })
39
- bpw = Base64.strict_encode64(pw + "\n")
40
- lc.run(cmd).must_equal "echo #{bpw} | base64 --decode | sudo -S #{cmd}"
41
- end
42
-
43
- it 'wraps commands in sudo_command instead of sudo' do
44
- sudo_command = rand.to_s
45
- lc = cls.new(backend, { sudo: true, sudo_command: sudo_command })
46
- lc.run(cmd).must_equal "#{sudo_command} #{cmd}"
47
- end
48
-
49
- it 'wraps commands in sudo_command with all options' do
50
- opts = rand.to_s
51
- sudo_command = rand.to_s
52
- lc = cls.new(backend, { sudo: true, sudo_command: sudo_command, sudo_options: opts })
53
- lc.run(cmd).must_equal "#{sudo_command} #{opts} #{cmd}"
54
- end
55
-
56
- it 'runs commands in sudo_command with password' do
57
- pw = rand.to_s
58
- sudo_command = rand.to_s
59
- lc = cls.new(backend, { sudo: true, sudo_command: sudo_command, sudo_password: pw })
60
- bpw = Base64.strict_encode64(pw + "\n")
61
- lc.run(cmd).must_equal "echo #{bpw} | base64 --decode | #{sudo_command} -S #{cmd}"
62
- end
63
- end
64
-
65
- describe 'shell wrapping' do
66
- it 'wraps commands in a default shell with login' do
67
- lc = cls.new(backend, { shell: true, shell_options: '--login' })
68
- bcmd = Base64.strict_encode64(cmd)
69
- lc.run(cmd).must_equal "echo #{bcmd} | base64 --decode | $SHELL --login"
70
- end
71
-
72
- it 'wraps sudo commands in a default shell with login' do
73
- lc = cls.new(backend, { sudo: true, shell: true, shell_options: '--login' })
74
- bcmd = Base64.strict_encode64("sudo #{cmd}")
75
- lc.run(cmd).must_equal "echo #{bcmd} | base64 --decode | $SHELL --login"
76
- end
77
-
78
- it 'wraps sudo commands and sudo passwords in a default shell with login' do
79
- pw = rand.to_s
80
- lc = cls.new(backend, { sudo: true, sudo_password: pw, shell: true, shell_options: '--login' })
81
- bpw = Base64.strict_encode64(pw + "\n")
82
- bcmd = Base64.strict_encode64("echo #{bpw} | base64 --decode | sudo -S #{cmd}")
83
- lc.run(cmd).must_equal "echo #{bcmd} | base64 --decode | $SHELL --login"
84
- p bcmd
85
- end
86
-
87
- it 'wraps commands in a default shell when shell is true' do
88
- lc = cls.new(backend, { shell: true })
89
- bcmd = Base64.strict_encode64(cmd)
90
- lc.run(cmd).must_equal "echo #{bcmd} | base64 --decode | $SHELL"
91
- end
92
-
93
- it 'doesnt wrap commands in a shell when shell is false' do
94
- lc = cls.new(backend, { shell: false })
95
- lc.run(cmd).must_equal cmd
96
- end
97
-
98
- it 'wraps commands in a `shell` instead of default shell' do
99
- lc = cls.new(backend, { shell: true, shell_command: '/bin/bash' })
100
- bcmd = Base64.strict_encode64(cmd)
101
- lc.run(cmd).must_equal "echo #{bcmd} | base64 --decode | /bin/bash"
102
- end
103
-
104
- it 'wraps commands in a default shell with login' do
105
- lc = cls.new(backend, { shell: true, shell_command: '/bin/bash', shell_options: '--login' })
106
- bcmd = Base64.strict_encode64(cmd)
107
- lc.run(cmd).must_equal "echo #{bcmd} | base64 --decode | /bin/bash --login"
108
- end
109
- end
110
- end
@@ -1,210 +0,0 @@
1
- # encoding: utf-8
2
- require 'helper'
3
- require 'train/extras'
4
- require 'train/transports/mock'
5
-
6
- describe 'stat' do
7
- let(:cls) { Train::Extras::Stat }
8
-
9
- describe 'find_type' do
10
- let (:random_mode) { (rand * 1000).to_i }
11
-
12
- it 'detects :unknown types' do
13
- cls.find_type(random_mode).must_equal :unknown
14
- end
15
-
16
- it 'detects sockets' do
17
- cls.find_type(00140755).must_equal :socket
18
- end
19
-
20
- it 'detects symlinks' do
21
- cls.find_type(00120755).must_equal :symlink
22
- end
23
-
24
- it 'detects files' do
25
- cls.find_type(00100755).must_equal :file
26
- end
27
-
28
- it 'detects block devices' do
29
- cls.find_type(00060755).must_equal :block_device
30
- end
31
-
32
- it 'detects directories' do
33
- cls.find_type(00040755).must_equal :directory
34
- end
35
-
36
- it 'detects character devices' do
37
- cls.find_type(00020755).must_equal :character_device
38
- end
39
-
40
- it 'detects pipes' do
41
- cls.find_type(00010755).must_equal :pipe
42
- end
43
- end
44
-
45
- describe 'linux stat' do
46
- let(:backend) {
47
- mock = Train::Transports::Mock.new(verbose: true).connection
48
- mock.mock_os({ name: 'ubuntu', family: 'debian', release: '15.04', arch: 'x86_64' })
49
- mock.commands = {
50
- "stat /path 2>/dev/null --printf '%s\n%f\n%U\n%u\n%G\n%g\n%X\n%Y\n%C'" => mock.mock_command('', '', '', 0),
51
- "stat /path-stat 2>/dev/null --printf '%s\n%f\n%U\n%u\n%G\n%g\n%X\n%Y\n%C'" => mock.mock_command('', "360\n43ff\nroot\n0\nrootz\n1\n1444520846\n1444522445\n?", '', 0),
52
- }
53
- mock
54
- }
55
-
56
- it 'ignores wrong stat results' do
57
- cls.linux_stat('/path', backend, false).must_equal({})
58
- end
59
-
60
- it 'reads correct stat results' do
61
- cls.linux_stat('/path-stat', backend, false).must_equal({
62
- type: :directory,
63
- mode: 01777,
64
- owner: 'root',
65
- uid: 0,
66
- group: 'rootz',
67
- gid: 1,
68
- mtime: 1444522445,
69
- size: 360,
70
- selinux_label: nil,
71
- })
72
- end
73
- end
74
-
75
- describe 'esx stat' do
76
- let(:backend) {
77
- mock = Train::Transports::Mock.new(verbose: true).connection
78
- mock.mock_os({ name: 'vmkernel', family: 'esx', release: '5' })
79
- mock.commands = {
80
- "stat /path 2>/dev/null -c '%s\n%f\n%U\n%u\n%G\n%g\n%X\n%Y\n%C'" => mock.mock_command('', '', '', 0),
81
- "stat /path-stat 2>/dev/null -c '%s\n%f\n%U\n%u\n%G\n%g\n%X\n%Y\n%C'" => mock.mock_command('', "360\n43ff\nroot\n0\nrootz\n1\n1444520846\n1444522445\n?", '', 0),
82
- }
83
- mock
84
- }
85
-
86
- it 'ignores wrong stat results' do
87
- cls.linux_stat('/path', backend, false).must_equal({})
88
- end
89
-
90
- it 'reads correct stat results' do
91
- cls.linux_stat('/path-stat', backend, false).must_equal({
92
- type: :directory,
93
- mode: 01777,
94
- owner: 'root',
95
- uid: 0,
96
- group: 'rootz',
97
- gid: 1,
98
- mtime: 1444522445,
99
- size: 360,
100
- selinux_label: nil,
101
- })
102
- end
103
- end
104
-
105
- describe 'alpine stat' do
106
- let(:backend) {
107
- mock = Train::Transports::Mock.new(verbose: true).connection
108
- mock.mock_os({ name: 'alpine', family: 'alpine', release: nil })
109
- mock.commands = {
110
- "stat /path 2>/dev/null -c '%s\n%f\n%U\n%u\n%G\n%g\n%X\n%Y\n%C'" => mock.mock_command('', '', '', 0),
111
- "stat /path-stat 2>/dev/null -c '%s\n%f\n%U\n%u\n%G\n%g\n%X\n%Y\n%C'" => mock.mock_command('', "360\n43ff\nroot\n0\nrootz\n1\n1444520846\n1444522445\n?", '', 0),
112
- }
113
- mock
114
- }
115
-
116
- it 'ignores wrong stat results' do
117
- cls.linux_stat('/path', backend, false).must_equal({})
118
- end
119
-
120
- it 'reads correct stat results' do
121
- cls.linux_stat('/path-stat', backend, false).must_equal({
122
- type: :directory,
123
- mode: 01777,
124
- owner: 'root',
125
- uid: 0,
126
- group: 'rootz',
127
- gid: 1,
128
- mtime: 1444522445,
129
- size: 360,
130
- selinux_label: nil,
131
- })
132
- end
133
- end
134
-
135
- describe 'bsd stat' do
136
- let(:backend) { Minitest::Mock.new }
137
-
138
- it 'ignores failed stat results' do
139
- res = Minitest::Mock.new
140
- res.expect :stdout, '.....'
141
- res.expect :exit_status, 1
142
- backend.expect :run_command, res, [String]
143
- cls.bsd_stat('/path', backend, false).must_equal({})
144
- end
145
-
146
- it 'ignores wrong stat results' do
147
- res = Minitest::Mock.new
148
- res.expect :stdout, ''
149
- res.expect :exit_status, 0
150
- backend.expect :run_command, res, [String]
151
- cls.bsd_stat('/path', backend, false).must_equal({})
152
- end
153
-
154
- it 'reads correct stat results' do
155
- res = Minitest::Mock.new
156
- res.expect :stdout, "360\n41777\nroot\n0\nrootz\n1\n1444520846\n1444522445"
157
- res.expect :exit_status, 0
158
- backend.expect :run_command, res, [String]
159
- cls.bsd_stat('/path', backend, false).must_equal({
160
- type: :directory,
161
- mode: 01777,
162
- owner: 'root',
163
- uid: 0,
164
- group: 'rootz',
165
- gid: 1,
166
- mtime: 1444522445,
167
- size: 360,
168
- selinux_label: nil,
169
- })
170
- end
171
- end
172
-
173
- describe 'aix stat' do
174
- let(:backend) { Minitest::Mock.new }
175
-
176
- it 'ignores failed stat results' do
177
- res = Minitest::Mock.new
178
- res.expect :stdout, '.....'
179
- res.expect :exit_status, 1
180
- backend.expect :run_command, res, [String]
181
- cls.aix_stat('/path', backend, false).must_equal({})
182
- end
183
-
184
- it 'ignores wrong stat results' do
185
- res = Minitest::Mock.new
186
- res.expect :stdout, ''
187
- res.expect :exit_status, 0
188
- backend.expect :run_command, res, [String]
189
- cls.aix_stat('/path', backend, false).must_equal({})
190
- end
191
-
192
- it 'reads correct stat results' do
193
- res = Minitest::Mock.new
194
- res.expect :stdout, "41777\nroot\n0\nrootz\n1\n1444522445\n360\n"
195
- res.expect :exit_status, 0
196
- backend.expect :run_command, res, [String]
197
- cls.aix_stat('/path', backend, false).must_equal({
198
- type: :directory,
199
- mode: 01777,
200
- owner: 'root',
201
- uid: 0,
202
- group: 'rootz',
203
- gid: 1,
204
- mtime: 1444522445,
205
- size: 360,
206
- selinux_label: nil,
207
- })
208
- end
209
- end
210
- end
@@ -1,224 +0,0 @@
1
- require 'helper'
2
- require 'train/file/local/unix'
3
- require 'train/transports/mock'
4
- require 'train/transports/local'
5
-
6
- describe Train::File::Local::Unix do
7
- let(:cls) { Train::File::Local::Unix }
8
-
9
- let(:backend) {
10
- backend = Train::Transports::Mock.new.connection
11
- backend.mock_os({ family: 'linux' })
12
- backend
13
- }
14
-
15
- it 'checks a mounted path' do
16
- backend.mock_command("mount | grep -- ' on /mount/path '", rand.to_s)
17
- cls.new(backend, '/mount/path').mounted?.must_equal true
18
- end
19
-
20
- describe 'file metadata' do
21
- let(:transport) { Train::Transports::Local.new }
22
- let(:connection) { transport.connection }
23
-
24
- let(:stat) { Struct.new(:mode, :size, :mtime, :uid, :gid) }
25
- let(:uid) { rand }
26
- let(:gid) { rand }
27
- let(:statres) { stat.new(00140755, rand, (rand*100).to_i, uid, gid) }
28
-
29
- def meta_stub(method, param, &block)
30
- pwres = Struct.new(:name)
31
- Etc.stub :getpwuid, pwres.new('owner') do
32
- Etc.stub :getgrgid, pwres.new('group') do
33
- File.stub method, param do; yield; end
34
- end
35
- end
36
- end
37
-
38
- it 'recognizes type' do
39
- meta_stub :stat, statres do
40
- connection.file(rand.to_s).stat[:type].must_equal :socket
41
- end
42
- end
43
-
44
- it 'recognizes mode' do
45
- meta_stub :stat, statres do
46
- connection.file(rand.to_s).stat[:mode].must_equal 00755
47
- end
48
- end
49
-
50
- it 'recognizes mtime' do
51
- meta_stub :stat, statres do
52
- connection.file(rand.to_s).stat[:mtime].must_equal statres.mtime
53
- end
54
- end
55
-
56
- it 'recognizes size' do
57
- meta_stub :stat, statres do
58
- connection.file(rand.to_s).stat[:size].must_equal statres.size
59
- end
60
- end
61
-
62
- it 'recognizes uid' do
63
- meta_stub :stat, statres do
64
- connection.file(rand.to_s).stat[:uid].must_equal uid
65
- end
66
- end
67
-
68
- it 'recognizes gid' do
69
- meta_stub :stat, statres do
70
- connection.file(rand.to_s).stat[:gid].must_equal gid
71
- end
72
- end
73
-
74
- it 'recognizes owner' do
75
- meta_stub :stat, statres do
76
- connection.file(rand.to_s).owner.must_equal 'owner'
77
- end
78
- end
79
-
80
- it 'recognizes group' do
81
- meta_stub :stat, statres do
82
- connection.file(rand.to_s).group.must_equal 'group'
83
- end
84
- end
85
-
86
- it 'grouped_into' do
87
- meta_stub :stat, statres do
88
- connection.file(rand.to_s).grouped_into?('group').must_equal true
89
- end
90
- end
91
-
92
- it 'recognizes selinux label' do
93
- meta_stub :stat, statres do
94
- label = rand.to_s
95
- res = Train::Extras::CommandResult.new(label, nil, 0)
96
- connection.stub :run_command, res do
97
- connection.file(rand.to_s).selinux_label.must_equal label
98
- end
99
- end
100
- end
101
-
102
- it 'recognizes source selinux label' do
103
- meta_stub :lstat, statres do
104
- label = rand.to_s
105
- res = Train::Extras::CommandResult.new(label, nil, 0)
106
- connection.stub :run_command, res do
107
- connection.file(rand.to_s).source.selinux_label.must_equal label
108
- end
109
- end
110
- end
111
- end
112
-
113
- describe '#unix_mode_mask' do
114
- let(:file_tester) do
115
- Class.new(cls) do
116
- define_method :type do
117
- :file
118
- end
119
- end.new(nil, nil, false)
120
- end
121
-
122
- it 'check owner mode calculation' do
123
- file_tester.unix_mode_mask('owner', 'x').must_equal 0100
124
- file_tester.unix_mode_mask('owner', 'w').must_equal 0200
125
- file_tester.unix_mode_mask('owner', 'r').must_equal 0400
126
- end
127
-
128
- it 'check group mode calculation' do
129
- file_tester.unix_mode_mask('group', 'x').must_equal 0010
130
- file_tester.unix_mode_mask('group', 'w').must_equal 0020
131
- file_tester.unix_mode_mask('group', 'r').must_equal 0040
132
- end
133
-
134
- it 'check other mode calculation' do
135
- file_tester.unix_mode_mask('other', 'x').must_equal 0001
136
- file_tester.unix_mode_mask('other', 'w').must_equal 0002
137
- file_tester.unix_mode_mask('other', 'r').must_equal 0004
138
- end
139
-
140
- it 'check all mode calculation' do
141
- file_tester.unix_mode_mask('all', 'x').must_equal 0111
142
- file_tester.unix_mode_mask('all', 'w').must_equal 0222
143
- file_tester.unix_mode_mask('all', 'r').must_equal 0444
144
- end
145
- end
146
-
147
- describe '#md5sum' do
148
- let(:md5_checksum) { '57d4c6f9d15313fd5651317e588c035d' }
149
-
150
- let(:ruby_md5_mock) do
151
- checksum_mock = mock
152
- checksum_mock.expects(:update).returns('')
153
- checksum_mock.expects(:hexdigest).returns(md5_checksum)
154
- checksum_mock
155
- end
156
-
157
- it 'defaults to a Ruby based checksum if other methods fail' do
158
- backend.mock_command('md5sum /tmp/testfile', '', '', 1)
159
- Digest::MD5.expects(:new).returns(ruby_md5_mock)
160
- cls.new(backend, '/tmp/testfile').md5sum.must_equal md5_checksum
161
- end
162
-
163
- it 'calculates the correct md5sum on the `linux` platform family' do
164
- output = "#{md5_checksum} /tmp/testfile"
165
- backend.mock_command('md5sum /tmp/testfile', output)
166
- cls.new(backend, '/tmp/testfile').md5sum.must_equal md5_checksum
167
- end
168
-
169
- it 'calculates the correct md5sum on the `darwin` platform family' do
170
- output = "#{md5_checksum} /tmp/testfile"
171
- backend.mock_os(family: 'darwin')
172
- backend.mock_command('md5 -r /tmp/testfile', output)
173
- cls.new(backend, '/tmp/testfile').md5sum.must_equal md5_checksum
174
- end
175
-
176
- it 'calculates the correct md5sum on the `solaris` platform family' do
177
- # The `digest` command doesn't output the filename by default
178
- output = "#{md5_checksum}"
179
- backend.mock_os(family: 'solaris')
180
- backend.mock_command('digest -a md5 /tmp/testfile', output)
181
- cls.new(backend, '/tmp/testfile').md5sum.must_equal md5_checksum
182
- end
183
- end
184
-
185
- describe '#sha256sum' do
186
- let(:sha256_checksum) {
187
- '491260aaa6638d4a64c714a17828c3d82bad6ca600c9149b3b3350e91bcd283d'
188
- }
189
-
190
- let(:ruby_sha256_mock) do
191
- checksum_mock = mock
192
- checksum_mock.expects(:update).returns('')
193
- checksum_mock.expects(:hexdigest).returns(sha256_checksum)
194
- checksum_mock
195
- end
196
-
197
- it 'defaults to a Ruby based checksum if other methods fail' do
198
- backend.mock_command('sha256sum /tmp/testfile', '', '', 1)
199
- Digest::SHA256.expects(:new).returns(ruby_sha256_mock)
200
- cls.new(backend, '/tmp/testfile').sha256sum.must_equal sha256_checksum
201
- end
202
-
203
- it 'calculates the correct sha256sum on the `linux` platform family' do
204
- output = "#{sha256_checksum} /tmp/testfile"
205
- backend.mock_command('sha256sum /tmp/testfile', output)
206
- cls.new(backend, '/tmp/testfile').sha256sum.must_equal sha256_checksum
207
- end
208
-
209
- it 'calculates the correct sha256sum on the `darwin` platform family' do
210
- output = "#{sha256_checksum} /tmp/testfile"
211
- backend.mock_os(family: 'darwin')
212
- backend.mock_command('shasum -a 256 /tmp/testfile', output)
213
- cls.new(backend, '/tmp/testfile').sha256sum.must_equal sha256_checksum
214
- end
215
-
216
- it 'calculates the correct sha256sum on the `solaris` platform family' do
217
- # The `digest` command doesn't output the filename by default
218
- output = "#{sha256_checksum}"
219
- backend.mock_os(family: 'solaris')
220
- backend.mock_command('digest -a sha256 /tmp/testfile', output)
221
- cls.new(backend, '/tmp/testfile').sha256sum.must_equal sha256_checksum
222
- end
223
- end
224
- end
@@ -1,101 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'helper'
4
- require 'train/transports/mock'
5
- require 'train/file/local/windows'
6
-
7
- describe 'file common' do
8
- let(:cls) { Train::File::Local::Windows }
9
- let(:backend) {
10
- backend = Train::Transports::Mock.new.connection
11
- backend.mock_os({ family: 'windows' })
12
- backend
13
- }
14
-
15
- it 'check escaping of invalid chars in path' do
16
- wf = cls.new(nil, nil)
17
- wf.sanitize_filename('c:/test') .must_equal 'c:/test'
18
- wf.sanitize_filename('c:/test directory') .must_equal 'c:/test directory'
19
- %w{ < > " * ?}.each do |char|
20
- wf.sanitize_filename("c:/test#{char}directory") .must_equal 'c:/testdirectory'
21
- end
22
- end
23
-
24
- it 'returns file version' do
25
- out = rand.to_s
26
- backend.mock_command('[System.Diagnostics.FileVersionInfo]::GetVersionInfo("path").FileVersion', out)
27
- cls.new(backend, 'path').file_version.must_equal out
28
- end
29
-
30
- it 'returns product version' do
31
- out = rand.to_s
32
- backend.mock_command('[System.Diagnostics.FileVersionInfo]::GetVersionInfo("path").FileVersion', out)
33
- cls.new(backend, 'path').file_version.must_equal out
34
- end
35
-
36
- it 'returns owner of file' do
37
- out = rand.to_s
38
- backend.mock_command('Get-Acl "path" | select -expand Owner', out)
39
- cls.new(backend, 'path').owner.must_equal out
40
- end
41
-
42
- describe '#md5sum' do
43
- let(:md5_checksum) { '4ce0c733cdcf1d2f78532bbd9ce3441d' }
44
- let(:filepath) { 'C:\Windows\explorer.exe' }
45
-
46
- let(:ruby_md5_mock) do
47
- checksum_mock = mock
48
- checksum_mock.expects(:update).returns('')
49
- checksum_mock.expects(:hexdigest).returns(md5_checksum)
50
- checksum_mock
51
- end
52
-
53
- it 'defaults to a Ruby based checksum if other methods fail' do
54
- backend.mock_command("CertUtil -hashfile #{filepath} MD5", '', '', 1)
55
- Digest::MD5.expects(:new).returns(ruby_md5_mock)
56
- cls.new(backend, '/tmp/testfile').md5sum.must_equal md5_checksum
57
- end
58
-
59
- it 'calculates the correct md5sum on the `windows` platform family' do
60
- output = <<-EOC
61
- MD5 hash of file C:\\Windows\\explorer.exe:\r
62
- 4c e0 c7 33 cd cf 1d 2f 78 53 2b bd 9c e3 44 1d\r
63
- CertUtil: -hashfile command completed successfully.\r
64
- EOC
65
-
66
- backend.mock_command("CertUtil -hashfile #{filepath} MD5", output)
67
- cls.new(backend, filepath).md5sum.must_equal md5_checksum
68
- end
69
- end
70
-
71
- describe '#sha256sum' do
72
- let(:sha256_checksum) {
73
- '85270240a5fd51934f0627c92b2282749d071fdc9ac351b81039ced5b10f798b'
74
- }
75
- let(:filepath) { 'C:\Windows\explorer.exe' }
76
-
77
- let(:ruby_sha256_mock) do
78
- checksum_mock = mock
79
- checksum_mock.expects(:update).returns('')
80
- checksum_mock.expects(:hexdigest).returns(sha256_checksum)
81
- checksum_mock
82
- end
83
-
84
- it 'defaults to a Ruby based checksum if other methods fail' do
85
- backend.mock_command('CertUtil -hashfile #{filepath} SHA256', '', '', 1)
86
- Digest::SHA256.expects(:new).returns(ruby_sha256_mock)
87
- cls.new(backend, '/tmp/testfile').sha256sum.must_equal sha256_checksum
88
- end
89
-
90
- it 'calculates the correct sha256sum on the `windows` platform family' do
91
- output = <<-EOC
92
- SHA256 hash of file C:\\Windows\\explorer.exe:\r
93
- 85 27 02 40 a5 fd 51 93 4f 06 27 c9 2b 22 82 74 9d 07 1f dc 9a c3 51 b8 10 39 ce d5 b1 0f 79 8b\r
94
- CertUtil: -hashfile command completed successfully.\r
95
- EOC
96
-
97
- backend.mock_command("CertUtil -hashfile #{filepath} SHA256", output)
98
- cls.new(backend, filepath).sha256sum.must_equal sha256_checksum
99
- end
100
- end
101
- end