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,92 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'helper'
|
4
|
-
require 'train/transports/ssh'
|
5
|
-
|
6
|
-
describe 'CiscoIOSConnection' do
|
7
|
-
let(:cls) do
|
8
|
-
Train::Platforms::Detect::Specifications::OS.load
|
9
|
-
plat = Train::Platforms.name('mock').in_family('cisco_ios')
|
10
|
-
plat.add_platform_methods
|
11
|
-
plat.stubs(:cisco_ios?).returns(true)
|
12
|
-
Train::Platforms::Detect.stubs(:scan).returns(plat)
|
13
|
-
Train::Transports::SSH
|
14
|
-
end
|
15
|
-
|
16
|
-
let(:opts) do
|
17
|
-
{
|
18
|
-
host: 'fakehost',
|
19
|
-
user: 'fakeuser',
|
20
|
-
password: 'fakepassword',
|
21
|
-
}
|
22
|
-
end
|
23
|
-
|
24
|
-
let(:connection) do
|
25
|
-
cls.new(opts).connection
|
26
|
-
end
|
27
|
-
|
28
|
-
describe '#initialize' do
|
29
|
-
it 'provides a uri' do
|
30
|
-
connection.uri.must_equal 'ssh://fakeuser@fakehost:22'
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
describe '#unique_identifier' do
|
35
|
-
it 'returns the correct identifier' do
|
36
|
-
output = "\r\nProcessor board ID 1111111111\r\n"
|
37
|
-
Train::Transports::SSH::CiscoIOSConnection.any_instance
|
38
|
-
.expects(:run_command_via_connection)
|
39
|
-
.with('show version | include Processor')
|
40
|
-
.returns(OpenStruct.new(stdout: output))
|
41
|
-
connection.unique_identifier.must_equal('1111111111')
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
describe '#format_result' do
|
46
|
-
it 'returns correctly when result is `good`' do
|
47
|
-
output = 'good'
|
48
|
-
Train::Extras::CommandResult.expects(:new).with(output, '', 0)
|
49
|
-
connection.send(:format_result, 'good')
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'returns correctly when result matches /Bad IP address/' do
|
53
|
-
output = "Translating \"nope\"\r\n\r\nTranslating \"nope\"\r\n\r\n% Bad IP address or host name\r\n% Unknown command or computer name, or unable to find computer address\r\n"
|
54
|
-
Train::Extras::CommandResult.expects(:new).with('', output, 1)
|
55
|
-
connection.send(:format_result, output)
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'returns correctly when result matches /Incomplete command/' do
|
59
|
-
output = "% Incomplete command.\r\n\r\n"
|
60
|
-
Train::Extras::CommandResult.expects(:new).with('', output, 1)
|
61
|
-
connection.send(:format_result, output)
|
62
|
-
end
|
63
|
-
|
64
|
-
it 'returns correctly when result matches /Invalid input detected/' do
|
65
|
-
output = " ^\r\n% Invalid input detected at '^' marker.\r\n\r\n"
|
66
|
-
Train::Extras::CommandResult.expects(:new).with('', output, 1)
|
67
|
-
connection.send(:format_result, output)
|
68
|
-
end
|
69
|
-
|
70
|
-
it 'returns correctly when result matches /Unrecognized host/' do
|
71
|
-
output = "Translating \"nope\"\r\n% Unrecognized host or address, or protocol not running.\r\n\r\n"
|
72
|
-
Train::Extras::CommandResult.expects(:new).with('', output, 1)
|
73
|
-
connection.send(:format_result, output)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
describe '#format_output' do
|
78
|
-
it 'returns the correct output' do
|
79
|
-
cmd = 'show calendar'
|
80
|
-
output = "show calendar\r\n10:35:50 UTC Fri Mar 23 2018\r\n7200_ios_12#\r\n7200_ios_12#"
|
81
|
-
result = connection.send(:format_output, output, cmd)
|
82
|
-
result.must_equal '10:35:50 UTC Fri Mar 23 2018'
|
83
|
-
end
|
84
|
-
|
85
|
-
it 'returns the correct output when a pipe is used' do
|
86
|
-
cmd = 'show running-config | section line con 0'
|
87
|
-
output = "show running-config | section line con 0\r\nline con 0\r\n exec-timeout 0 0\r\n privilege level 15\r\n logging synchronous\r\n stopbits 1\r\n7200_ios_12#\r\n7200_ios_12#"
|
88
|
-
result = connection.send(:format_output, output, cmd)
|
89
|
-
result.must_equal "line con 0\r\n exec-timeout 0 0\r\n privilege level 15\r\n logging synchronous\r\n stopbits 1"
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
@@ -1,266 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'helper'
|
4
|
-
|
5
|
-
describe 'gcp transport' do
|
6
|
-
|
7
|
-
let(:credentials_file) do
|
8
|
-
require 'tempfile'
|
9
|
-
file = Tempfile.new('application_default_credentials.json')
|
10
|
-
info = <<-INFO
|
11
|
-
{
|
12
|
-
"client_id": "asdfasf-asdfasdf.apps.googleusercontent.com",
|
13
|
-
"client_secret": "d-asdfasdf",
|
14
|
-
"refresh_token": "1/adsfasdf-lCkju3-yQmjr20xVZonrfkE48L",
|
15
|
-
"type": "authorized_user"
|
16
|
-
}
|
17
|
-
INFO
|
18
|
-
file.write(info)
|
19
|
-
file.close
|
20
|
-
file
|
21
|
-
end
|
22
|
-
|
23
|
-
let(:credentials_file_override) do
|
24
|
-
require 'tempfile'
|
25
|
-
file = Tempfile.new('application_default_credentials.json')
|
26
|
-
info = <<-INFO
|
27
|
-
{
|
28
|
-
"client_id": "asdfasf-asdfasdf.apps.googleusercontent.com",
|
29
|
-
"client_secret": "d-asdfasdf",
|
30
|
-
"refresh_token": "1/adsfasdf-lCkju3-yQmjr20xVZonrfkE48L",
|
31
|
-
"type": "authorized_user"
|
32
|
-
}
|
33
|
-
INFO
|
34
|
-
file.write(info)
|
35
|
-
file.close
|
36
|
-
file
|
37
|
-
end
|
38
|
-
|
39
|
-
def transport(options = nil)
|
40
|
-
ENV['GOOGLE_APPLICATION_CREDENTIALS'] = credentials_file.path
|
41
|
-
ENV['GOOGLE_CLOUD_PROJECT'] = 'test_project'
|
42
|
-
# need to require this at here as it captures the envs on load
|
43
|
-
require 'train/transports/gcp'
|
44
|
-
Train::Transports::Gcp.new(options)
|
45
|
-
end
|
46
|
-
|
47
|
-
let(:connection) { transport.connection }
|
48
|
-
let(:options) { connection.instance_variable_get(:@options) }
|
49
|
-
let(:cache) { connection.instance_variable_get(:@cache) }
|
50
|
-
|
51
|
-
describe 'options' do
|
52
|
-
it 'defaults to env options' do
|
53
|
-
options[:google_application_credentials] = credentials_file.path
|
54
|
-
options[:google_cloud_project].must_equal 'test_project'
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'allows for options override' do
|
59
|
-
transport = transport(google_application_credentials: credentials_file_override.path, google_cloud_project: "override_project")
|
60
|
-
options = transport.connection.instance_variable_get(:@options)
|
61
|
-
options[:google_application_credentials].must_equal credentials_file_override.path
|
62
|
-
options[:google_cloud_project].must_equal "override_project"
|
63
|
-
end
|
64
|
-
|
65
|
-
describe 'platform' do
|
66
|
-
it 'returns platform' do
|
67
|
-
platform = connection.platform
|
68
|
-
platform.name.must_equal 'gcp'
|
69
|
-
platform.family_hierarchy.must_equal ['cloud', 'api']
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
describe 'gcp_client' do
|
74
|
-
it 'test gcp_client with caching' do
|
75
|
-
client = connection.gcp_client(Object)
|
76
|
-
client.is_a?(Object).must_equal true
|
77
|
-
cache[:api_call].count.must_equal 1
|
78
|
-
end
|
79
|
-
|
80
|
-
it 'test gcp_client without caching' do
|
81
|
-
connection.disable_cache(:api_call)
|
82
|
-
client = connection.gcp_client(Object)
|
83
|
-
client.is_a?(Object).must_equal true
|
84
|
-
cache[:api_call].count.must_equal 0
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
|
89
|
-
describe 'gcp_compute_client' do
|
90
|
-
it 'test gcp_compute_client with caching' do
|
91
|
-
client = connection.gcp_compute_client
|
92
|
-
client.is_a?(Google::Apis::ComputeV1::ComputeService).must_equal true
|
93
|
-
cache[:api_call].count.must_equal 1
|
94
|
-
end
|
95
|
-
|
96
|
-
it 'test gcp_client without caching' do
|
97
|
-
connection.disable_cache(:api_call)
|
98
|
-
client = connection.gcp_compute_client
|
99
|
-
client.is_a?(Google::Apis::ComputeV1::ComputeService).must_equal true
|
100
|
-
cache[:api_call].count.must_equal 0
|
101
|
-
end
|
102
|
-
|
103
|
-
it 'test gcp_compute_client application name' do
|
104
|
-
client = connection.gcp_compute_client
|
105
|
-
client.is_a?(Google::Apis::ComputeV1::ComputeService).must_equal true
|
106
|
-
client.client_options.application_name.must_equal 'chef-inspec-train'
|
107
|
-
end
|
108
|
-
|
109
|
-
it 'test gcp_compute_client application version' do
|
110
|
-
client = connection.gcp_compute_client
|
111
|
-
client.is_a?(Google::Apis::ComputeV1::ComputeService).must_equal true
|
112
|
-
client.client_options.application_version.must_equal Train::VERSION
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
describe 'gcp_iam_client' do
|
117
|
-
it 'test gcp_iam_client with caching' do
|
118
|
-
client = connection.gcp_iam_client
|
119
|
-
client.is_a?(Google::Apis::IamV1::IamService).must_equal true
|
120
|
-
cache[:api_call].count.must_equal 1
|
121
|
-
end
|
122
|
-
|
123
|
-
it 'test gcp_iam_client without caching' do
|
124
|
-
connection.disable_cache(:api_call)
|
125
|
-
client = connection.gcp_iam_client
|
126
|
-
client.is_a?(Google::Apis::IamV1::IamService).must_equal true
|
127
|
-
cache[:api_call].count.must_equal 0
|
128
|
-
end
|
129
|
-
|
130
|
-
it 'test gcp_iam_client application name' do
|
131
|
-
client = connection.gcp_iam_client
|
132
|
-
client.is_a?(Google::Apis::IamV1::IamService).must_equal true
|
133
|
-
client.client_options.application_name.must_equal 'chef-inspec-train'
|
134
|
-
end
|
135
|
-
|
136
|
-
it 'test gcp_iam_client application version' do
|
137
|
-
client = connection.gcp_iam_client
|
138
|
-
client.is_a?(Google::Apis::IamV1::IamService).must_equal true
|
139
|
-
client.client_options.application_version.must_equal Train::VERSION
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
describe 'gcp_project_client' do
|
144
|
-
it 'test gcp_project_client with caching' do
|
145
|
-
client = connection.gcp_project_client
|
146
|
-
client.is_a?(Google::Apis::CloudresourcemanagerV1::CloudResourceManagerService).must_equal true
|
147
|
-
cache[:api_call].count.must_equal 1
|
148
|
-
end
|
149
|
-
|
150
|
-
it 'test gcp_project_client without caching' do
|
151
|
-
connection.disable_cache(:api_call)
|
152
|
-
client = connection.gcp_project_client
|
153
|
-
client.is_a?(Google::Apis::CloudresourcemanagerV1::CloudResourceManagerService).must_equal true
|
154
|
-
cache[:api_call].count.must_equal 0
|
155
|
-
end
|
156
|
-
|
157
|
-
it 'test gcp_project_client application name' do
|
158
|
-
client = connection.gcp_project_client
|
159
|
-
client.is_a?(Google::Apis::CloudresourcemanagerV1::CloudResourceManagerService).must_equal true
|
160
|
-
client.client_options.application_name.must_equal 'chef-inspec-train'
|
161
|
-
end
|
162
|
-
|
163
|
-
it 'test gcp_project_client application version' do
|
164
|
-
client = connection.gcp_project_client
|
165
|
-
client.is_a?(Google::Apis::CloudresourcemanagerV1::CloudResourceManagerService).must_equal true
|
166
|
-
client.client_options.application_version.must_equal Train::VERSION
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
describe 'gcp_storage_client' do
|
171
|
-
it 'test gcp_storage_client with caching' do
|
172
|
-
client = connection.gcp_storage_client
|
173
|
-
client.is_a?(Google::Apis::StorageV1::StorageService).must_equal true
|
174
|
-
cache[:api_call].count.must_equal 1
|
175
|
-
end
|
176
|
-
|
177
|
-
it 'test gcp_storage_client without caching' do
|
178
|
-
connection.disable_cache(:api_call)
|
179
|
-
client = connection.gcp_storage_client
|
180
|
-
client.is_a?(Google::Apis::StorageV1::StorageService).must_equal true
|
181
|
-
cache[:api_call].count.must_equal 0
|
182
|
-
end
|
183
|
-
|
184
|
-
it 'test gcp_storage_client application name' do
|
185
|
-
client = connection.gcp_storage_client
|
186
|
-
client.is_a?(Google::Apis::StorageV1::StorageService).must_equal true
|
187
|
-
client.client_options.application_name.must_equal 'chef-inspec-train'
|
188
|
-
end
|
189
|
-
|
190
|
-
it 'test gcp_storage_client application version' do
|
191
|
-
client = connection.gcp_storage_client
|
192
|
-
client.is_a?(Google::Apis::StorageV1::StorageService).must_equal true
|
193
|
-
client.client_options.application_version.must_equal Train::VERSION
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
|
-
describe 'gcp_admin_client' do
|
198
|
-
it 'test gcp_admin_client with caching' do
|
199
|
-
client = connection.gcp_admin_client
|
200
|
-
client.is_a?(Google::Apis::AdminDirectoryV1::DirectoryService).must_equal true
|
201
|
-
cache[:api_call].count.must_equal 1
|
202
|
-
end
|
203
|
-
|
204
|
-
it 'test gcp_admin_client without caching' do
|
205
|
-
connection.disable_cache(:api_call)
|
206
|
-
client = connection.gcp_admin_client
|
207
|
-
client.is_a?(Google::Apis::AdminDirectoryV1::DirectoryService).must_equal true
|
208
|
-
cache[:api_call].count.must_equal 0
|
209
|
-
end
|
210
|
-
|
211
|
-
it 'test gcp_admin_client application name' do
|
212
|
-
client = connection.gcp_admin_client
|
213
|
-
client.is_a?(Google::Apis::AdminDirectoryV1::DirectoryService).must_equal true
|
214
|
-
client.client_options.application_name.must_equal 'chef-inspec-train'
|
215
|
-
end
|
216
|
-
|
217
|
-
it 'test gcp_admin_client application version' do
|
218
|
-
client = connection.gcp_admin_client
|
219
|
-
client.is_a?(Google::Apis::AdminDirectoryV1::DirectoryService).must_equal true
|
220
|
-
client.client_options.application_version.must_equal Train::VERSION
|
221
|
-
end
|
222
|
-
end
|
223
|
-
|
224
|
-
# test options override of env vars in connect
|
225
|
-
describe 'connect' do
|
226
|
-
let(:creds) do
|
227
|
-
require 'tempfile'
|
228
|
-
file = Tempfile.new('creds')
|
229
|
-
info = <<-INFO
|
230
|
-
{
|
231
|
-
"client_id": "asdfasf-asdfasdf.apps.googleusercontent.com",
|
232
|
-
"client_secret": "d-asdfasdf",
|
233
|
-
"refresh_token": "1/adsfasdf-lCkju3-yQmjr20xVZonrfkE48L",
|
234
|
-
"type": "authorized_user"
|
235
|
-
}
|
236
|
-
INFO
|
237
|
-
file.write(info)
|
238
|
-
file.close
|
239
|
-
file
|
240
|
-
end
|
241
|
-
it 'validate gcp connection with credentials' do
|
242
|
-
options[:google_application_credentials] = creds.path
|
243
|
-
connection.connect
|
244
|
-
ENV['GOOGLE_APPLICATION_CREDENTIALS'].must_equal creds.path
|
245
|
-
end
|
246
|
-
it 'validate gcp connection with project' do
|
247
|
-
options[:google_cloud_project] = 'project'
|
248
|
-
connection.connect
|
249
|
-
ENV['GOOGLE_CLOUD_PROJECT'].must_equal 'project'
|
250
|
-
end
|
251
|
-
end
|
252
|
-
|
253
|
-
describe 'unique_identifier' do
|
254
|
-
it 'test connection unique identifier' do
|
255
|
-
client = connection
|
256
|
-
client.unique_identifier.must_equal 'asdfasf-asdfasdf.apps.googleusercontent.com'
|
257
|
-
end
|
258
|
-
end
|
259
|
-
|
260
|
-
describe 'uri' do
|
261
|
-
it 'test uri' do
|
262
|
-
client = connection
|
263
|
-
client.uri.must_equal 'gcp://asdfasf-asdfasdf.apps.googleusercontent.com'
|
264
|
-
end
|
265
|
-
end
|
266
|
-
end
|
@@ -1,129 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'helper'
|
4
|
-
require 'tempfile'
|
5
|
-
require 'train/transports/helpers/azure/file_credentials'
|
6
|
-
|
7
|
-
describe 'parse_credentials_file' do
|
8
|
-
let(:cred_file_single_entry) do
|
9
|
-
file = Tempfile.new('cred_file')
|
10
|
-
info = <<-INFO
|
11
|
-
[my_subscription_id]
|
12
|
-
client_id = "my_client_id"
|
13
|
-
client_secret = "my_client_secret"
|
14
|
-
tenant_id = "my_tenant_id"
|
15
|
-
INFO
|
16
|
-
file.write(info)
|
17
|
-
file.close
|
18
|
-
file
|
19
|
-
end
|
20
|
-
|
21
|
-
let(:cred_file_multiple_entries) do
|
22
|
-
file = Tempfile.new('cred_file')
|
23
|
-
info = <<-INFO
|
24
|
-
[my_subscription_id]
|
25
|
-
client_id = "my_client_id"
|
26
|
-
client_secret = "my_client_secret"
|
27
|
-
tenant_id = "my_tenant_id"
|
28
|
-
|
29
|
-
[my_subscription_id2]
|
30
|
-
client_id = "my_client_id2"
|
31
|
-
client_secret = "my_client_secret2"
|
32
|
-
tenant_id = "my_tenant_id2"
|
33
|
-
INFO
|
34
|
-
file.write(info)
|
35
|
-
file.close
|
36
|
-
file
|
37
|
-
end
|
38
|
-
|
39
|
-
let(:options) { { credentials_file: cred_file_multiple_entries.path } }
|
40
|
-
|
41
|
-
it 'handles a nil file' do
|
42
|
-
options[:credentials_file] = nil
|
43
|
-
|
44
|
-
result = Train::Transports::Helpers::Azure::FileCredentials.parse(options)
|
45
|
-
|
46
|
-
assert_empty(result)
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'returns empty hash when no credentials file detected' do
|
50
|
-
result = Train::Transports::Helpers::Azure::FileCredentials.parse({})
|
51
|
-
|
52
|
-
assert_empty(result)
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'loads only entry from file when no subscription id given' do
|
56
|
-
options[:credentials_file] = cred_file_single_entry.path
|
57
|
-
|
58
|
-
result = Train::Transports::Helpers::Azure::FileCredentials.parse(options)
|
59
|
-
|
60
|
-
assert_equal('my_tenant_id', result[:tenant_id])
|
61
|
-
assert_equal('my_client_id', result[:client_id])
|
62
|
-
assert_equal('my_client_secret', result[:client_secret])
|
63
|
-
assert_equal('my_subscription_id', result[:subscription_id])
|
64
|
-
end
|
65
|
-
|
66
|
-
it 'raises an error when no subscription id given and multiple entries' do
|
67
|
-
error = assert_raises RuntimeError do
|
68
|
-
Train::Transports::Helpers::Azure::FileCredentials.parse(options)
|
69
|
-
end
|
70
|
-
|
71
|
-
assert_equal('Credentials file must have one entry. Check your credentials file. If you have more than one entry set AZURE_SUBSCRIPTION_ID environment variable.', error.message)
|
72
|
-
end
|
73
|
-
|
74
|
-
it 'loads entry when subscription id is given' do
|
75
|
-
options[:subscription_id] = 'my_subscription_id'
|
76
|
-
|
77
|
-
result = Train::Transports::Helpers::Azure::FileCredentials.parse(options)
|
78
|
-
|
79
|
-
assert_equal('my_tenant_id', result[:tenant_id])
|
80
|
-
assert_equal('my_client_id', result[:client_id])
|
81
|
-
assert_equal('my_client_secret', result[:client_secret])
|
82
|
-
assert_equal('my_subscription_id', result[:subscription_id])
|
83
|
-
end
|
84
|
-
|
85
|
-
it 'raises an error when subscription id not found' do
|
86
|
-
options[:subscription_id] = 'missing_subscription_id'
|
87
|
-
|
88
|
-
error = assert_raises RuntimeError do
|
89
|
-
Train::Transports::Helpers::Azure::FileCredentials.parse(options)
|
90
|
-
end
|
91
|
-
|
92
|
-
assert_equal('No credentials found for subscription number missing_subscription_id', error.message)
|
93
|
-
end
|
94
|
-
|
95
|
-
it 'loads entry based on index' do
|
96
|
-
ENV['AZURE_SUBSCRIPTION_NUMBER'] = '2'
|
97
|
-
|
98
|
-
result = Train::Transports::Helpers::Azure::FileCredentials.parse(options)
|
99
|
-
|
100
|
-
ENV.delete('AZURE_SUBSCRIPTION_NUMBER')
|
101
|
-
|
102
|
-
assert_equal('my_tenant_id2', result[:tenant_id])
|
103
|
-
assert_equal('my_client_id2', result[:client_id])
|
104
|
-
assert_equal('my_client_secret2', result[:client_secret])
|
105
|
-
assert_equal('my_subscription_id2', result[:subscription_id])
|
106
|
-
end
|
107
|
-
|
108
|
-
it 'raises an error when index is out of bounds' do
|
109
|
-
ENV['AZURE_SUBSCRIPTION_NUMBER'] = '3'
|
110
|
-
|
111
|
-
error = assert_raises RuntimeError do
|
112
|
-
Train::Transports::Helpers::Azure::FileCredentials.parse(options)
|
113
|
-
end
|
114
|
-
ENV.delete('AZURE_SUBSCRIPTION_NUMBER')
|
115
|
-
|
116
|
-
assert_equal('Your credentials file only contains 2 subscriptions. You specified number 3.', error.message)
|
117
|
-
end
|
118
|
-
|
119
|
-
it 'raises an error when index 0 is given' do
|
120
|
-
ENV['AZURE_SUBSCRIPTION_NUMBER'] = '0'
|
121
|
-
|
122
|
-
error = assert_raises RuntimeError do
|
123
|
-
Train::Transports::Helpers::Azure::FileCredentials.parse(options)
|
124
|
-
end
|
125
|
-
ENV.delete('AZURE_SUBSCRIPTION_NUMBER')
|
126
|
-
|
127
|
-
assert_equal('Index must be greater than 0.', error.message)
|
128
|
-
end
|
129
|
-
end
|
@@ -1,183 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'helper'
|
4
|
-
require 'train/transports/local'
|
5
|
-
|
6
|
-
class TransportHelper
|
7
|
-
attr_accessor :transport
|
8
|
-
|
9
|
-
def initialize(user_opts = {})
|
10
|
-
opts = {platform_name: 'mock', family_hierarchy: ['mock']}.merge(user_opts)
|
11
|
-
Train::Platforms::Detect::Specifications::OS.load
|
12
|
-
plat = Train::Platforms.name(opts[:platform_name])
|
13
|
-
plat.family_hierarchy = opts[:family_hierarchy]
|
14
|
-
plat.add_platform_methods
|
15
|
-
Train::Platforms::Detect.stubs(:scan).returns(plat)
|
16
|
-
@transport = Train::Transports::Local.new(user_opts)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
describe 'local transport' do
|
21
|
-
let(:transport) { TransportHelper.new.transport }
|
22
|
-
let(:connection) { transport.connection }
|
23
|
-
|
24
|
-
it 'can be instantiated' do
|
25
|
-
transport.wont_be_nil
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'gets the connection' do
|
29
|
-
connection.must_be_kind_of Train::Transports::Local::Connection
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'provides a uri' do
|
33
|
-
connection.uri.must_equal 'local://'
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'doesnt wait to be read' do
|
37
|
-
connection.wait_until_ready.must_be_nil
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'can be closed' do
|
41
|
-
connection.close.must_be_nil
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'has no login command' do
|
45
|
-
connection.login_command.must_be_nil
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'provides a run_command_via_connection method' do
|
49
|
-
methods = connection.class.private_instance_methods(false)
|
50
|
-
methods.include?(:run_command_via_connection).must_equal true
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'provides a file_via_connection method' do
|
54
|
-
methods = connection.class.private_instance_methods(false)
|
55
|
-
methods.include?(:file_via_connection).must_equal true
|
56
|
-
end
|
57
|
-
|
58
|
-
describe 'when overriding runner selection' do
|
59
|
-
it 'can select the `GenericRunner`' do
|
60
|
-
Train::Transports::Local::Connection::GenericRunner
|
61
|
-
.expects(:new)
|
62
|
-
|
63
|
-
Train::Transports::Local::Connection::WindowsPipeRunner
|
64
|
-
.expects(:new)
|
65
|
-
.never
|
66
|
-
|
67
|
-
Train::Transports::Local::Connection::WindowsShellRunner
|
68
|
-
.expects(:new)
|
69
|
-
.never
|
70
|
-
|
71
|
-
Train::Transports::Local::Connection.new(command_runner: :generic)
|
72
|
-
end
|
73
|
-
|
74
|
-
it 'can select the `WindowsPipeRunner`' do
|
75
|
-
Train::Transports::Local::Connection::GenericRunner
|
76
|
-
.expects(:new)
|
77
|
-
.never
|
78
|
-
|
79
|
-
Train::Transports::Local::Connection::WindowsPipeRunner
|
80
|
-
.expects(:new)
|
81
|
-
|
82
|
-
Train::Transports::Local::Connection::WindowsShellRunner
|
83
|
-
.expects(:new)
|
84
|
-
.never
|
85
|
-
|
86
|
-
Train::Transports::Local::Connection.new(command_runner: :windows_pipe)
|
87
|
-
end
|
88
|
-
|
89
|
-
it 'can select the `WindowsShellRunner`' do
|
90
|
-
Train::Transports::Local::Connection::GenericRunner
|
91
|
-
.expects(:new)
|
92
|
-
.never
|
93
|
-
|
94
|
-
Train::Transports::Local::Connection::WindowsPipeRunner
|
95
|
-
.expects(:new)
|
96
|
-
.never
|
97
|
-
|
98
|
-
Train::Transports::Local::Connection::WindowsShellRunner
|
99
|
-
.expects(:new)
|
100
|
-
|
101
|
-
Train::Transports::Local::Connection.new(command_runner: :windows_shell)
|
102
|
-
end
|
103
|
-
|
104
|
-
it 'throws a RuntimeError when an invalid runner type is passed' do
|
105
|
-
proc { Train::Transports::Local::Connection.new(command_runner: :nope ) }
|
106
|
-
.must_raise(RuntimeError, "Runner type `:nope` not supported")
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
describe 'when running a local command' do
|
111
|
-
let(:cmd_runner) { Minitest::Mock.new }
|
112
|
-
|
113
|
-
def mock_run_cmd(cmd, &block)
|
114
|
-
cmd_runner.expect :run_command, nil
|
115
|
-
Mixlib::ShellOut.stub :new, cmd_runner do |*args|
|
116
|
-
block.call()
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
it 'gets stdout' do
|
121
|
-
mock_run_cmd(rand) do
|
122
|
-
x = rand
|
123
|
-
cmd_runner.expect :stdout, x
|
124
|
-
cmd_runner.expect :stderr, nil
|
125
|
-
cmd_runner.expect :exitstatus, nil
|
126
|
-
connection.run_command(rand).stdout.must_equal x
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
it 'gets stderr' do
|
131
|
-
mock_run_cmd(rand) do
|
132
|
-
x = rand
|
133
|
-
cmd_runner.expect :stdout, nil
|
134
|
-
cmd_runner.expect :stderr, x
|
135
|
-
cmd_runner.expect :exitstatus, nil
|
136
|
-
connection.run_command(rand).stderr.must_equal x
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
it 'gets exit_status' do
|
141
|
-
mock_run_cmd(rand) do
|
142
|
-
x = rand
|
143
|
-
cmd_runner.expect :stdout, nil
|
144
|
-
cmd_runner.expect :stderr, nil
|
145
|
-
cmd_runner.expect :exitstatus, x
|
146
|
-
connection.run_command(rand).exit_status.must_equal x
|
147
|
-
end
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
describe 'when running on Windows' do
|
152
|
-
let(:connection) do
|
153
|
-
TransportHelper.new(family_hierarchy: ['windows']).transport.connection
|
154
|
-
end
|
155
|
-
let(:runner) { mock }
|
156
|
-
|
157
|
-
it 'uses `WindowsPipeRunner` by default' do
|
158
|
-
Train::Transports::Local::Connection::WindowsPipeRunner
|
159
|
-
.expects(:new)
|
160
|
-
.returns(runner)
|
161
|
-
|
162
|
-
Train::Transports::Local::Connection::WindowsShellRunner
|
163
|
-
.expects(:new)
|
164
|
-
.never
|
165
|
-
|
166
|
-
runner.expects(:run_command).with('not actually executed')
|
167
|
-
connection.run_command('not actually executed')
|
168
|
-
end
|
169
|
-
|
170
|
-
it 'uses `WindowsShellRunner` when a named pipe is not available' do
|
171
|
-
Train::Transports::Local::Connection::WindowsPipeRunner
|
172
|
-
.expects(:new)
|
173
|
-
.raises(Train::Transports::Local::PipeError)
|
174
|
-
|
175
|
-
Train::Transports::Local::Connection::WindowsShellRunner
|
176
|
-
.expects(:new)
|
177
|
-
.returns(runner)
|
178
|
-
|
179
|
-
runner.expects(:run_command).with('not actually executed')
|
180
|
-
connection.run_command('not actually executed')
|
181
|
-
end
|
182
|
-
end
|
183
|
-
end
|