train 1.5.11 → 1.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/train/transports/winrm.rb +16 -4
- data/lib/train/version.rb +1 -1
- metadata +3 -165
- data/.rubocop.yml +0 -77
- data/CHANGELOG.md +0 -900
- data/Gemfile +0 -41
- data/README.md +0 -212
- data/Rakefile +0 -73
- data/test/fixtures/plugins/train-test-fixture/LICENSE +0 -201
- data/test/fixtures/plugins/train-test-fixture/README.md +0 -5
- data/test/fixtures/plugins/train-test-fixture/lib/train-test-fixture/connection.rb +0 -35
- data/test/fixtures/plugins/train-test-fixture/lib/train-test-fixture/platform.rb +0 -18
- data/test/fixtures/plugins/train-test-fixture/lib/train-test-fixture/transport.rb +0 -14
- data/test/fixtures/plugins/train-test-fixture/lib/train-test-fixture/version.rb +0 -5
- data/test/fixtures/plugins/train-test-fixture/lib/train-test-fixture.rb +0 -4
- data/test/fixtures/plugins/train-test-fixture/pkg/train-test-fixture-0.1.0.gem +0 -0
- data/test/fixtures/plugins/train-test-fixture/train-test-fixture.gemspec +0 -35
- data/test/integration/.kitchen.yml +0 -43
- data/test/integration/Berksfile +0 -3
- data/test/integration/bootstrap.sh +0 -22
- data/test/integration/chefignore +0 -1
- data/test/integration/cookbooks/test/metadata.rb +0 -1
- data/test/integration/cookbooks/test/recipes/default.rb +0 -100
- data/test/integration/cookbooks/test/recipes/prep_files.rb +0 -56
- data/test/integration/docker_run.rb +0 -153
- data/test/integration/docker_test.rb +0 -24
- data/test/integration/docker_test_container.rb +0 -24
- data/test/integration/helper.rb +0 -61
- data/test/integration/sudo/customcommand.rb +0 -15
- data/test/integration/sudo/nopasswd.rb +0 -16
- data/test/integration/sudo/passwd.rb +0 -21
- data/test/integration/sudo/reqtty.rb +0 -17
- data/test/integration/sudo/run_as.rb +0 -12
- data/test/integration/test-travis-centos.yml +0 -6
- data/test/integration/test-travis-debian.yml +0 -6
- data/test/integration/test-travis-fedora.yml +0 -8
- data/test/integration/test-travis-oel.yml +0 -6
- data/test/integration/test-travis-ubuntu.yml +0 -8
- data/test/integration/test_local.rb +0 -19
- data/test/integration/test_ssh.rb +0 -39
- data/test/integration/tests/path_block_device_test.rb +0 -74
- data/test/integration/tests/path_character_device_test.rb +0 -74
- data/test/integration/tests/path_file_test.rb +0 -99
- data/test/integration/tests/path_folder_test.rb +0 -90
- data/test/integration/tests/path_missing_test.rb +0 -76
- data/test/integration/tests/path_pipe_test.rb +0 -62
- data/test/integration/tests/path_symlink_test.rb +0 -95
- data/test/integration/tests/run_command_test.rb +0 -35
- data/test/unit/extras/command_wrapper_test.rb +0 -110
- data/test/unit/extras/stat_test.rb +0 -210
- data/test/unit/file/local/unix_test.rb +0 -224
- data/test/unit/file/local/windows_test.rb +0 -101
- data/test/unit/file/local_test.rb +0 -121
- data/test/unit/file/remote/aix_test.rb +0 -81
- data/test/unit/file/remote/linux_test.rb +0 -221
- data/test/unit/file/remote/qnx_test.rb +0 -80
- data/test/unit/file/remote/unix_test.rb +0 -119
- data/test/unit/file/remote/windows_test.rb +0 -72
- data/test/unit/file/remote_test.rb +0 -62
- data/test/unit/file_test.rb +0 -129
- data/test/unit/helper.rb +0 -7
- data/test/unit/platforms/detect/os_common_test.rb +0 -85
- data/test/unit/platforms/detect/os_linux_test.rb +0 -132
- data/test/unit/platforms/detect/os_windows_test.rb +0 -107
- data/test/unit/platforms/detect/scanner_test.rb +0 -61
- data/test/unit/platforms/detect/uuid_test.rb +0 -133
- data/test/unit/platforms/family_test.rb +0 -32
- data/test/unit/platforms/os_detect_test.rb +0 -249
- data/test/unit/platforms/platform_test.rb +0 -405
- data/test/unit/platforms/platforms_test.rb +0 -52
- data/test/unit/plugins/connection_test.rb +0 -219
- data/test/unit/plugins/transport_test.rb +0 -111
- data/test/unit/plugins_test.rb +0 -22
- data/test/unit/train_test.rb +0 -247
- data/test/unit/transports/aws_test.rb +0 -120
- data/test/unit/transports/azure_test.rb +0 -145
- data/test/unit/transports/cisco_ios_connection.rb +0 -92
- data/test/unit/transports/gcp_test.rb +0 -266
- data/test/unit/transports/helpers/azure/file_credentials_test.rb +0 -129
- data/test/unit/transports/local_test.rb +0 -183
- data/test/unit/transports/mock_test.rb +0 -150
- data/test/unit/transports/ssh_test.rb +0 -330
- data/test/unit/transports/vmware_test.rb +0 -159
- data/test/unit/version_test.rb +0 -8
- data/test/windows/local_test.rb +0 -243
- data/test/windows/winrm_test.rb +0 -187
- data/train.gemspec +0 -45
@@ -1,121 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
require 'train/transports/local'
|
3
|
-
|
4
|
-
describe Train::File::Local do
|
5
|
-
let(:transport) { Train::Transports::Local.new }
|
6
|
-
let(:connection) { transport.connection }
|
7
|
-
|
8
|
-
it 'gets file contents' do
|
9
|
-
res = rand.to_s
|
10
|
-
File.stub :read, res do
|
11
|
-
connection.file(rand.to_s).content.must_equal(res)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
{
|
16
|
-
exist?: :exist?,
|
17
|
-
file?: :file?,
|
18
|
-
socket?: :socket?,
|
19
|
-
directory?: :directory?,
|
20
|
-
symlink?: :symlink?,
|
21
|
-
pipe?: :pipe?,
|
22
|
-
character_device?: :chardev?,
|
23
|
-
block_device?: :blockdev?,
|
24
|
-
}.each do |method, file_method|
|
25
|
-
it "checks if file is a #{method}" do
|
26
|
-
File.stub file_method.to_sym, true do
|
27
|
-
connection.file(rand.to_s).method(method.to_sym).call.must_equal(true)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
describe '#type' do
|
33
|
-
it 'returns the type block_device if it is block device' do
|
34
|
-
File.stub :ftype, "blockSpecial" do
|
35
|
-
connection.file(rand.to_s).type.must_equal :block_device
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'returns the type character_device if it is character device' do
|
40
|
-
File.stub :ftype, "characterSpecial" do
|
41
|
-
connection.file(rand.to_s).type.must_equal :character_device
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'returns the type symlink if it is symlink' do
|
46
|
-
File.stub :ftype, "link" do
|
47
|
-
connection.file(rand.to_s).type.must_equal :symlink
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'returns the type file if it is file' do
|
52
|
-
File.stub :ftype, "file" do
|
53
|
-
connection.file(rand.to_s).type.must_equal :file
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
it 'returns the type directory if it is block directory' do
|
58
|
-
File.stub :ftype, "directory" do
|
59
|
-
connection.file(rand.to_s).type.must_equal :directory
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
it 'returns the type pipe if it is pipe' do
|
64
|
-
File.stub :ftype, "fifo" do
|
65
|
-
connection.file(rand.to_s).type.must_equal :pipe
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
it 'returns the type socket if it is socket' do
|
70
|
-
File.stub :ftype, "socket" do
|
71
|
-
connection.file(rand.to_s).type.must_equal :socket
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'returns the unknown if not known' do
|
76
|
-
File.stub :ftype, "unknown" do
|
77
|
-
connection.file(rand.to_s).type.must_equal :unknown
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
describe '#path' do
|
83
|
-
it 'returns the path if it is not a symlink' do
|
84
|
-
File.stub :symlink?, false do
|
85
|
-
filename = rand.to_s
|
86
|
-
connection.file(filename).path.must_equal filename
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
it 'returns the link_path if it is a symlink' do
|
91
|
-
File.stub :symlink?, true do
|
92
|
-
file_obj = connection.file(rand.to_s)
|
93
|
-
file_obj.stub :link_path, '/path/to/resolved_link' do
|
94
|
-
file_obj.path.must_equal '/path/to/resolved_link'
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
describe '#link_path' do
|
101
|
-
it 'returns file\'s link path' do
|
102
|
-
out = rand.to_s
|
103
|
-
File.stub :realpath, out do
|
104
|
-
File.stub :symlink?, true do
|
105
|
-
connection.file(rand.to_s).link_path.must_equal out
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
describe '#shallow_shlink_path' do
|
112
|
-
it 'returns file\'s direct link path' do
|
113
|
-
out = rand.to_s
|
114
|
-
File.stub :readlink, out do
|
115
|
-
File.stub :symlink?, true do
|
116
|
-
connection.file(rand.to_s).shallow_link_path.must_equal out
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|
@@ -1,81 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
require 'train/transports/local'
|
3
|
-
require 'train/file/remote/aix'
|
4
|
-
require 'train/transports/mock'
|
5
|
-
|
6
|
-
describe Train::File::Remote::Aix do
|
7
|
-
let(:cls) { Train::File::Remote::Aix }
|
8
|
-
let(:backend) {
|
9
|
-
backend = Train::Transports::Mock.new.connection
|
10
|
-
backend.mock_os({ name: 'aix', family: 'unix' })
|
11
|
-
backend
|
12
|
-
}
|
13
|
-
|
14
|
-
it 'returns a nil link_path if the object is not a symlink' do
|
15
|
-
file = cls.new(backend, 'path')
|
16
|
-
file.stubs(:symlink?).returns(false)
|
17
|
-
file.link_path.must_be_nil
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'returns a correct link_path' do
|
21
|
-
file = cls.new(backend, 'path')
|
22
|
-
file.stubs(:symlink?).returns(true)
|
23
|
-
backend.mock_command("perl -e 'print readlink shift' path", 'our_link_path')
|
24
|
-
file.link_path.must_equal 'our_link_path'
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'returns a correct shallow_link_path' do
|
28
|
-
file = cls.new(backend, 'path')
|
29
|
-
file.stubs(:symlink?).returns(true)
|
30
|
-
backend.mock_command("perl -e 'print readlink shift' path", 'our_link_path')
|
31
|
-
file.link_path.must_equal 'our_link_path'
|
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
|
81
|
-
end
|
@@ -1,221 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
require 'train/transports/local'
|
3
|
-
require 'train/file/remote/linux'
|
4
|
-
require 'train/transports/mock'
|
5
|
-
|
6
|
-
describe Train::File::Remote::Linux do
|
7
|
-
let(:cls) { Train::File::Remote::Linux }
|
8
|
-
let(:backend) {
|
9
|
-
backend = Train::Transports::Mock.new.connection
|
10
|
-
backend.mock_os({ name: 'linux', family: 'unix' })
|
11
|
-
backend
|
12
|
-
}
|
13
|
-
|
14
|
-
def mock_stat(args, out, err = '', code = 0)
|
15
|
-
backend.mock_command(
|
16
|
-
"stat #{args} 2>/dev/null --printf '%s\n%f\n%U\n%u\n%G\n%g\n%X\n%Y\n%C'",
|
17
|
-
out, err, code
|
18
|
-
)
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'works on nil path' do
|
22
|
-
cls.new(backend, nil).path.must_equal ''
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'provides the full path' do
|
26
|
-
cls.new(backend, '/dir/file').path.must_equal '/dir/file'
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'provides the basename to a unix path' do
|
30
|
-
cls.new(backend, '/dir/file').basename.must_equal 'file'
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'reads file contents' do
|
34
|
-
out = rand.to_s
|
35
|
-
backend.mock_command('cat path || echo -n', out)
|
36
|
-
cls.new(backend, 'path').content.must_equal out
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'reads file contents' do
|
40
|
-
backend.mock_command('cat path || echo -n', '')
|
41
|
-
mock_stat('-L path', '', 'some error...', 1)
|
42
|
-
cls.new(backend, 'path').content.must_be_nil
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'reads file contents' do
|
46
|
-
out = rand.to_s
|
47
|
-
backend.mock_command('cat /spaced\\ path || echo -n', out)
|
48
|
-
cls.new(backend, '/spaced path').content.must_equal out
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'checks for file existance' do
|
52
|
-
backend.mock_command('test -e path', true)
|
53
|
-
cls.new(backend, 'path').exist?.must_equal true
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'checks for file existance' do
|
57
|
-
backend.mock_command('test -e path', nil, nil, 1)
|
58
|
-
cls.new(backend, 'path').exist?.must_equal false
|
59
|
-
end
|
60
|
-
|
61
|
-
it 'retrieves the link path via #path()' do
|
62
|
-
out = rand.to_s
|
63
|
-
mock_stat('path', "13\na1ff\nz\n1001\nz\n1001\n1444573475\n1444573475\n?")
|
64
|
-
backend.mock_command('readlink -n path -f', out)
|
65
|
-
cls.new(backend, 'path').path.must_equal File.join(Dir.pwd, out)
|
66
|
-
end
|
67
|
-
|
68
|
-
it 'retrieves the link path' do
|
69
|
-
out = rand.to_s
|
70
|
-
mock_stat('path', "13\na1ff\nz\n1001\nz\n1001\n1444573475\n1444573475\n?")
|
71
|
-
backend.mock_command('readlink -n path -f', out)
|
72
|
-
cls.new(backend, 'path').link_path.must_equal File.join(Dir.pwd, out)
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'provide the source path' do
|
76
|
-
cls.new(backend, 'path').source_path.must_equal 'path'
|
77
|
-
end
|
78
|
-
|
79
|
-
it 'checks a mounted path' do
|
80
|
-
backend.mock_command("mount | grep -- ' on /mount/path '", rand.to_s)
|
81
|
-
cls.new(backend, '/mount/path').mounted?.must_equal true
|
82
|
-
end
|
83
|
-
|
84
|
-
it 'has nil product version' do
|
85
|
-
cls.new(backend, 'path').product_version.must_be_nil
|
86
|
-
end
|
87
|
-
|
88
|
-
it 'has nil file version' do
|
89
|
-
cls.new(backend, 'path').file_version.must_be_nil
|
90
|
-
end
|
91
|
-
|
92
|
-
describe 'stat on a file' do
|
93
|
-
before { mock_stat('-L path', "13\na1ff\nz\n1001\nz2\n1002\n1444573475\n1444573475\nlabels") }
|
94
|
-
let(:f) { cls.new(backend, 'path') }
|
95
|
-
|
96
|
-
it 'retrieves the file type' do
|
97
|
-
f.type.must_equal :symlink
|
98
|
-
end
|
99
|
-
|
100
|
-
it 'retrieves the file mode' do
|
101
|
-
f.mode.must_equal 00777
|
102
|
-
end
|
103
|
-
|
104
|
-
it 'retrieves the file owner' do
|
105
|
-
f.owner.must_equal 'z'
|
106
|
-
end
|
107
|
-
|
108
|
-
it 'retrieves the file uid' do
|
109
|
-
f.uid.must_equal 1001
|
110
|
-
end
|
111
|
-
|
112
|
-
it 'retrieves the file group' do
|
113
|
-
f.group.must_equal 'z2'
|
114
|
-
end
|
115
|
-
|
116
|
-
it 'retrieves the file gid' do
|
117
|
-
f.gid.must_equal 1002
|
118
|
-
end
|
119
|
-
|
120
|
-
it 'retrieves the file mtime' do
|
121
|
-
f.mtime.must_equal 1444573475
|
122
|
-
end
|
123
|
-
|
124
|
-
it 'retrieves the file size' do
|
125
|
-
f.size.must_equal 13
|
126
|
-
end
|
127
|
-
|
128
|
-
it 'retrieves the file selinux_label' do
|
129
|
-
f.selinux_label.must_equal 'labels'
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
describe 'stat on the source file' do
|
134
|
-
before { mock_stat('path', "13\na1ff\nz\n1001\nz2\n1002\n1444573475\n1444573475\nlabels") }
|
135
|
-
let(:f) { cls.new(backend, 'path').source }
|
136
|
-
|
137
|
-
it 'retrieves the file type' do
|
138
|
-
f.type.must_equal :symlink
|
139
|
-
end
|
140
|
-
|
141
|
-
it 'retrieves the file mode' do
|
142
|
-
f.mode.must_equal 00777
|
143
|
-
end
|
144
|
-
|
145
|
-
it 'retrieves the file owner' do
|
146
|
-
f.owner.must_equal 'z'
|
147
|
-
end
|
148
|
-
|
149
|
-
it 'retrieves the file uid' do
|
150
|
-
f.uid.must_equal 1001
|
151
|
-
end
|
152
|
-
|
153
|
-
it 'retrieves the file group' do
|
154
|
-
f.group.must_equal 'z2'
|
155
|
-
end
|
156
|
-
|
157
|
-
it 'retrieves the file gid' do
|
158
|
-
f.gid.must_equal 1002
|
159
|
-
end
|
160
|
-
|
161
|
-
it 'retrieves the file mtime' do
|
162
|
-
f.mtime.must_equal 1444573475
|
163
|
-
end
|
164
|
-
|
165
|
-
it 'retrieves the file size' do
|
166
|
-
f.size.must_equal 13
|
167
|
-
end
|
168
|
-
|
169
|
-
it 'retrieves the file selinux_label' do
|
170
|
-
f.selinux_label.must_equal 'labels'
|
171
|
-
end
|
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
|
221
|
-
end
|
@@ -1,80 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
require 'train/transports/local'
|
3
|
-
require 'train/file/remote/qnx'
|
4
|
-
require 'train/transports/mock'
|
5
|
-
|
6
|
-
describe Train::File::Remote::Qnx do
|
7
|
-
let(:cls) { Train::File::Remote::Qnx }
|
8
|
-
let(:backend) {
|
9
|
-
backend = Train::Transports::Mock.new.connection
|
10
|
-
backend.mock_os({ family: 'qnx' })
|
11
|
-
backend
|
12
|
-
}
|
13
|
-
|
14
|
-
it 'returns file contents when the file exists' do
|
15
|
-
out = rand.to_s
|
16
|
-
backend.mock_command('cat path', out)
|
17
|
-
file = cls.new(backend, 'path')
|
18
|
-
file.stubs(:exist?).returns(true)
|
19
|
-
file.content.must_equal out
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'returns nil contents when the file does not exist' do
|
23
|
-
file = cls.new(backend, 'path')
|
24
|
-
file.stubs(:exist?).returns(false)
|
25
|
-
file.content.must_be_nil
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'returns a file type' do
|
29
|
-
backend.mock_command('file path', 'blah directory blah')
|
30
|
-
cls.new(backend, 'path').type.must_equal :directory
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'returns a directory type' do
|
34
|
-
backend.mock_command('file path', 'blah regular file blah')
|
35
|
-
cls.new(backend, 'path').type.must_equal :file
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'raises exception for unimplemented methods' do
|
39
|
-
file = cls.new(backend, 'path')
|
40
|
-
%w{mode owner group uid gid mtime size selinux_label link_path mounted stat}.each do |m|
|
41
|
-
proc { file.send(m) }.must_raise NotImplementedError
|
42
|
-
end
|
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
|
80
|
-
end
|
@@ -1,119 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
require 'train/transports/mock'
|
3
|
-
require 'train/file/remote/unix'
|
4
|
-
|
5
|
-
describe Train::File::Remote::Unix do
|
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
|
-
}
|
13
|
-
|
14
|
-
def mockup(stubs)
|
15
|
-
Class.new(cls) do
|
16
|
-
stubs.each do |k,v|
|
17
|
-
define_method k.to_sym do
|
18
|
-
v
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end.new(nil, nil, false)
|
22
|
-
end
|
23
|
-
|
24
|
-
describe 'unix_mode_mask' do
|
25
|
-
let(:fc) { mockup(type: :file) }
|
26
|
-
|
27
|
-
it 'check owner mode calculation' do
|
28
|
-
fc.unix_mode_mask('owner', 'x').must_equal 0100
|
29
|
-
fc.unix_mode_mask('owner', 'w').must_equal 0200
|
30
|
-
fc.unix_mode_mask('owner', 'r').must_equal 0400
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'check group mode calculation' do
|
34
|
-
fc.unix_mode_mask('group', 'x').must_equal 0010
|
35
|
-
fc.unix_mode_mask('group', 'w').must_equal 0020
|
36
|
-
fc.unix_mode_mask('group', 'r').must_equal 0040
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'check other mode calculation' do
|
40
|
-
fc.unix_mode_mask('other', 'x').must_equal 0001
|
41
|
-
fc.unix_mode_mask('other', 'w').must_equal 0002
|
42
|
-
fc.unix_mode_mask('other', 'r').must_equal 0004
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'check all mode calculation' do
|
46
|
-
fc.unix_mode_mask('all', 'x').must_equal 0111
|
47
|
-
fc.unix_mode_mask('all', 'w').must_equal 0222
|
48
|
-
fc.unix_mode_mask('all', 'r').must_equal 0444
|
49
|
-
end
|
50
|
-
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
|
@@ -1,72 +0,0 @@
|
|
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
|