train 1.4.25 → 1.4.29

Sign up to get free protection for your applications and to get access to all the features.
@@ -18,11 +18,6 @@ describe 'file interface' do
18
18
  file.type.must_equal(:pipe)
19
19
  end
20
20
 
21
- # # TODO add back content
22
- # it 'has no content' do
23
- # file.content.must_be_nil
24
- # end
25
-
26
21
  it 'has owner name root' do
27
22
  file.owner.must_equal('root')
28
23
  end
@@ -43,16 +38,6 @@ describe 'file interface' do
43
38
  file.link_path.must_be_nil
44
39
  end
45
40
 
46
- # # TODO add back content
47
- # it 'has no md5sum' do
48
- # file.md5sum.must_be_nil
49
- # end
50
- #
51
- # # TODO add back content
52
- # it 'has no sha256sum' do
53
- # file.sha256sum.must_be_nil
54
- # end
55
-
56
41
  it 'has a modified time' do
57
42
  file.mtime.must_be_close_to(Time.now.to_i - Test.mtime/2, Test.mtime)
58
43
  end
@@ -143,4 +143,82 @@ describe Train::File::Local::Unix do
143
143
  file_tester.unix_mode_mask('all', 'r').must_equal 0444
144
144
  end
145
145
  end
146
- 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
@@ -38,4 +38,64 @@ describe 'file common' do
38
38
  backend.mock_command('Get-Acl "path" | select -expand Owner', out)
39
39
  cls.new(backend, 'path').owner.must_equal out
40
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
41
101
  end
@@ -30,4 +30,52 @@ describe Train::File::Remote::Aix do
30
30
  backend.mock_command("perl -e 'print readlink shift' path", 'our_link_path')
31
31
  file.link_path.must_equal 'our_link_path'
32
32
  end
33
+
34
+ describe '#md5sum' do
35
+ let(:md5_checksum) { '57d4c6f9d15313fd5651317e588c035d' }
36
+
37
+ let(:ruby_md5_mock) do
38
+ checksum_mock = mock
39
+ checksum_mock.expects(:update).returns('')
40
+ checksum_mock.expects(:hexdigest).returns(md5_checksum)
41
+ checksum_mock
42
+ end
43
+
44
+ it 'defaults to a Ruby based checksum if other methods fail' do
45
+ backend.mock_command('md5sum /tmp/testfile', '', '', 1)
46
+ Digest::MD5.expects(:new).returns(ruby_md5_mock)
47
+ cls.new(backend, '/tmp/testfile').md5sum.must_equal md5_checksum
48
+ end
49
+
50
+ it 'calculates the correct md5sum on the `aix` platform family' do
51
+ output = "#{md5_checksum} /tmp/testfile"
52
+ backend.mock_command('md5sum /tmp/testfile', output)
53
+ cls.new(backend, '/tmp/testfile').md5sum.must_equal md5_checksum
54
+ end
55
+ end
56
+
57
+ describe '#sha256sum' do
58
+ let(:sha256_checksum) {
59
+ '491260aaa6638d4a64c714a17828c3d82bad6ca600c9149b3b3350e91bcd283d'
60
+ }
61
+
62
+ let(:ruby_sha256_mock) do
63
+ checksum_mock = mock
64
+ checksum_mock.expects(:update).returns('')
65
+ checksum_mock.expects(:hexdigest).returns(sha256_checksum)
66
+ checksum_mock
67
+ end
68
+
69
+ it 'defaults to a Ruby based checksum if other methods fail' do
70
+ backend.mock_command('sha256sum /tmp/testfile', '', '', 1)
71
+ Digest::SHA256.expects(:new).returns(ruby_sha256_mock)
72
+ cls.new(backend, '/tmp/testfile').sha256sum.must_equal sha256_checksum
73
+ end
74
+
75
+ it 'calculates the correct sha256sum on the `aix` platform family' do
76
+ output = "#{sha256_checksum} /tmp/testfile"
77
+ backend.mock_command('sha256sum /tmp/testfile', output)
78
+ cls.new(backend, '/tmp/testfile').sha256sum.must_equal sha256_checksum
79
+ end
80
+ end
33
81
  end
@@ -9,7 +9,7 @@ describe Train::File::Remote::Linux do
9
9
  backend = Train::Transports::Mock.new.connection
10
10
  backend.mock_os({ name: 'linux', family: 'unix' })
11
11
  backend
12
- }
12
+ }
13
13
 
14
14
  def mock_stat(args, out, err = '', code = 0)
15
15
  backend.mock_command(
@@ -170,4 +170,52 @@ describe Train::File::Remote::Linux do
170
170
  f.selinux_label.must_equal 'labels'
171
171
  end
172
172
  end
173
+
174
+ describe '#md5sum' do
175
+ let(:md5_checksum) { '57d4c6f9d15313fd5651317e588c035d' }
176
+
177
+ let(:ruby_md5_mock) do
178
+ checksum_mock = mock
179
+ checksum_mock.expects(:update).returns('')
180
+ checksum_mock.expects(:hexdigest).returns(md5_checksum)
181
+ checksum_mock
182
+ end
183
+
184
+ it 'defaults to a Ruby based checksum if other methods fail' do
185
+ backend.mock_command('md5sum /tmp/testfile', '', '', 1)
186
+ Digest::MD5.expects(:new).returns(ruby_md5_mock)
187
+ cls.new(backend, '/tmp/testfile').md5sum.must_equal md5_checksum
188
+ end
189
+
190
+ it 'calculates the correct md5sum on the `linux` platform family' do
191
+ output = "#{md5_checksum} /tmp/testfile"
192
+ backend.mock_command('md5sum /tmp/testfile', output)
193
+ cls.new(backend, '/tmp/testfile').md5sum.must_equal md5_checksum
194
+ end
195
+ end
196
+
197
+ describe '#sha256sum' do
198
+ let(:sha256_checksum) {
199
+ '491260aaa6638d4a64c714a17828c3d82bad6ca600c9149b3b3350e91bcd283d'
200
+ }
201
+
202
+ let(:ruby_sha256_mock) do
203
+ checksum_mock = mock
204
+ checksum_mock.expects(:update).returns('')
205
+ checksum_mock.expects(:hexdigest).returns(sha256_checksum)
206
+ checksum_mock
207
+ end
208
+
209
+ it 'defaults to a Ruby based checksum if other methods fail' do
210
+ backend.mock_command('sha256sum /tmp/testfile', '', '', 1)
211
+ Digest::SHA256.expects(:new).returns(ruby_sha256_mock)
212
+ cls.new(backend, '/tmp/testfile').sha256sum.must_equal sha256_checksum
213
+ end
214
+
215
+ it 'calculates the correct sha256sum on the `linux` platform family' do
216
+ output = "#{sha256_checksum} /tmp/testfile"
217
+ backend.mock_command('sha256sum /tmp/testfile', output)
218
+ cls.new(backend, '/tmp/testfile').sha256sum.must_equal sha256_checksum
219
+ end
220
+ end
173
221
  end
@@ -7,7 +7,7 @@ describe Train::File::Remote::Qnx do
7
7
  let(:cls) { Train::File::Remote::Qnx }
8
8
  let(:backend) {
9
9
  backend = Train::Transports::Mock.new.connection
10
- backend.mock_os({ name: 'qnx', family: 'unix' })
10
+ backend.mock_os({ family: 'qnx' })
11
11
  backend
12
12
  }
13
13
 
@@ -41,4 +41,40 @@ describe Train::File::Remote::Qnx do
41
41
  proc { file.send(m) }.must_raise NotImplementedError
42
42
  end
43
43
  end
44
+
45
+ describe '#md5sum' do
46
+ let(:md5_checksum) { '17404a596cbd0d1e6c7d23fcd845ab82' }
47
+
48
+ let(:ruby_md5_mock) do
49
+ checksum_mock = mock
50
+ checksum_mock.expects(:update).returns('')
51
+ checksum_mock.expects(:hexdigest).returns(md5_checksum)
52
+ checksum_mock
53
+ end
54
+
55
+ it 'defaults to a Ruby based checksum if other methods fail' do
56
+ backend.mock_command('md5sum /tmp/testfile', '', '', 1)
57
+ Digest::MD5.expects(:new).returns(ruby_md5_mock)
58
+ cls.new(backend, '/tmp/testfile').md5sum.must_equal md5_checksum
59
+ end
60
+ end
61
+
62
+ describe '#sha256sum' do
63
+ let(:sha256_checksum) {
64
+ 'ec864fe99b539704b8872ac591067ef22d836a8d942087f2dba274b301ebe6e5'
65
+ }
66
+
67
+ let(:ruby_sha256_mock) do
68
+ checksum_mock = mock
69
+ checksum_mock.expects(:update).returns('')
70
+ checksum_mock.expects(:hexdigest).returns(sha256_checksum)
71
+ checksum_mock
72
+ end
73
+
74
+ it 'defaults to a Ruby based checksum if other methods fail' do
75
+ backend.mock_command('sha256sum /tmp/testfile', '', '', 1)
76
+ Digest::SHA256.expects(:new).returns(ruby_sha256_mock)
77
+ cls.new(backend, '/tmp/testfile').sha256sum.must_equal sha256_checksum
78
+ end
79
+ end
44
80
  end
@@ -1,8 +1,15 @@
1
1
  require 'helper'
2
+ require 'train/transports/mock'
2
3
  require 'train/file/remote/unix'
3
4
 
4
5
  describe Train::File::Remote::Unix do
5
- let(:cls) { Train::File::Remote::Unix }
6
+ let(:cls) { Train::File::Remote::Unix }
7
+
8
+ let(:backend) {
9
+ backend = Train::Transports::Mock.new.connection
10
+ backend.mock_os({ family: 'linux' })
11
+ backend
12
+ }
6
13
 
7
14
  def mockup(stubs)
8
15
  Class.new(cls) do
@@ -41,4 +48,72 @@ describe Train::File::Remote::Unix do
41
48
  fc.unix_mode_mask('all', 'r').must_equal 0444
42
49
  end
43
50
  end
44
- end
51
+
52
+ describe '#md5sum' do
53
+ let(:md5_checksum) { '57d4c6f9d15313fd5651317e588c035d' }
54
+
55
+ let(:ruby_md5_mock) do
56
+ checksum_mock = mock
57
+ checksum_mock.expects(:update).returns('')
58
+ checksum_mock.expects(:hexdigest).returns(md5_checksum)
59
+ checksum_mock
60
+ end
61
+
62
+ it 'defaults to a Ruby based checksum if other methods fail' do
63
+ backend.mock_command('md5 -r /tmp/testfile', '', '', 1)
64
+ Digest::MD5.expects(:new).returns(ruby_md5_mock)
65
+ cls.new(backend, '/tmp/testfile').md5sum.must_equal md5_checksum
66
+ end
67
+
68
+
69
+ it 'calculates the correct md5sum on the `darwin` platform family' do
70
+ output = "#{md5_checksum} /tmp/testfile"
71
+ backend.mock_os(family: 'darwin')
72
+ backend.mock_command('md5 -r /tmp/testfile', output)
73
+ cls.new(backend, '/tmp/testfile').md5sum.must_equal md5_checksum
74
+ end
75
+
76
+ it 'calculates the correct md5sum on the `solaris` platform family' do
77
+ # The `digest` command doesn't output the filename by default
78
+ output = "#{md5_checksum}"
79
+ backend.mock_os(family: 'solaris')
80
+ backend.mock_command('digest -a md5 /tmp/testfile', output)
81
+ cls.new(backend, '/tmp/testfile').md5sum.must_equal md5_checksum
82
+ end
83
+ end
84
+
85
+ describe '#sha256sum' do
86
+ let(:sha256_checksum) {
87
+ '491260aaa6638d4a64c714a17828c3d82bad6ca600c9149b3b3350e91bcd283d'
88
+ }
89
+
90
+ let(:ruby_sha256_mock) do
91
+ checksum_mock = mock
92
+ checksum_mock.expects(:update).returns('')
93
+ checksum_mock.expects(:hexdigest).returns(sha256_checksum)
94
+ checksum_mock
95
+ end
96
+
97
+ it 'defaults to a Ruby based checksum if other methods fail' do
98
+ backend.mock_command('shasum -a 256 /tmp/testfile', '', '', 1)
99
+ Digest::SHA256.expects(:new).returns(ruby_sha256_mock)
100
+ cls.new(backend, '/tmp/testfile').sha256sum.must_equal sha256_checksum
101
+ end
102
+
103
+
104
+ it 'calculates the correct sha256sum on the `darwin` platform family' do
105
+ output = "#{sha256_checksum} /tmp/testfile"
106
+ backend.mock_os(family: 'darwin')
107
+ backend.mock_command('shasum -a 256 /tmp/testfile', output)
108
+ cls.new(backend, '/tmp/testfile').sha256sum.must_equal sha256_checksum
109
+ end
110
+
111
+ it 'calculates the correct sha256sum on the `solaris` platform family' do
112
+ # The `digest` command doesn't output the filename by default
113
+ output = "#{sha256_checksum}"
114
+ backend.mock_os(family: 'solaris')
115
+ backend.mock_command('digest -a sha256 /tmp/testfile', output)
116
+ cls.new(backend, '/tmp/testfile').sha256sum.must_equal sha256_checksum
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,72 @@
1
+ require 'helper'
2
+ require 'train/transports/mock'
3
+ require 'train/file/remote/windows'
4
+
5
+ describe Train::File::Remote::Windows do
6
+ let(:cls) { Train::File::Remote::Windows }
7
+ let(:backend) {
8
+ backend = Train::Transports::Mock.new.connection
9
+ backend.mock_os({ family: 'windows' })
10
+ backend
11
+ }
12
+
13
+ describe '#md5sum' do
14
+ let(:md5_checksum) { '4ce0c733cdcf1d2f78532bbd9ce3441d' }
15
+ let(:filepath) { 'C:\Windows\explorer.exe' }
16
+
17
+ let(:ruby_md5_mock) do
18
+ checksum_mock = mock
19
+ checksum_mock.expects(:update).returns('')
20
+ checksum_mock.expects(:hexdigest).returns(md5_checksum)
21
+ checksum_mock
22
+ end
23
+
24
+ it 'defaults to a Ruby based checksum if other methods fail' do
25
+ backend.mock_command("CertUtil -hashfile #{filepath} MD5", '', '', 1)
26
+ Digest::MD5.expects(:new).returns(ruby_md5_mock)
27
+ cls.new(backend, '/tmp/testfile').md5sum.must_equal md5_checksum
28
+ end
29
+
30
+ it 'calculates the correct md5sum on the `windows` platform family' do
31
+ output = <<-EOC
32
+ MD5 hash of file C:\\Windows\\explorer.exe:\r
33
+ 4c e0 c7 33 cd cf 1d 2f 78 53 2b bd 9c e3 44 1d\r
34
+ CertUtil: -hashfile command completed successfully.\r
35
+ EOC
36
+
37
+ backend.mock_command("CertUtil -hashfile #{filepath} MD5", output)
38
+ cls.new(backend, filepath).md5sum.must_equal md5_checksum
39
+ end
40
+ end
41
+
42
+ describe '#sha256sum' do
43
+ let(:sha256_checksum) {
44
+ '85270240a5fd51934f0627c92b2282749d071fdc9ac351b81039ced5b10f798b'
45
+ }
46
+ let(:filepath) { 'C:\Windows\explorer.exe' }
47
+
48
+ let(:ruby_sha256_mock) do
49
+ checksum_mock = mock
50
+ checksum_mock.expects(:update).returns('')
51
+ checksum_mock.expects(:hexdigest).returns(sha256_checksum)
52
+ checksum_mock
53
+ end
54
+
55
+ it 'defaults to a Ruby based checksum if other methods fail' do
56
+ backend.mock_command("CertUtil -hashfile #{filepath} SHA256", '', '', 1)
57
+ Digest::SHA256.expects(:new).returns(ruby_sha256_mock)
58
+ cls.new(backend, '/tmp/testfile').sha256sum.must_equal sha256_checksum
59
+ end
60
+
61
+ it 'calculates the correct sha256sum on the `windows` platform family' do
62
+ output = <<-EOC
63
+ SHA256 hash of file C:\\Windows\\explorer.exe:\r
64
+ 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
65
+ CertUtil: -hashfile command completed successfully.\r
66
+ EOC
67
+
68
+ backend.mock_command("CertUtil -hashfile #{filepath} SHA256", output)
69
+ cls.new(backend, filepath).sha256sum.must_equal sha256_checksum
70
+ end
71
+ end
72
+ end