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,111 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'helper'
|
3
|
-
|
4
|
-
describe 'v1 Transport Plugin' do
|
5
|
-
describe 'empty v1 transport plugin' do
|
6
|
-
let(:plugin) { Class.new(Train.plugin(1)) }
|
7
|
-
|
8
|
-
it 'initializes an empty configuration' do
|
9
|
-
plugin.new.options.must_equal({})
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'saves the provided configuration' do
|
13
|
-
conf = { a: rand }
|
14
|
-
plugin.new(conf).options.must_equal(conf)
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'saves the provided configuration' do
|
18
|
-
conf = { a: rand }
|
19
|
-
plugin.new(conf).options.must_equal(conf)
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'provides a default logger' do
|
23
|
-
conf = { a: rand }
|
24
|
-
plugin.new(conf)
|
25
|
-
.method(:logger).call
|
26
|
-
.must_be_instance_of(Logger)
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'can configure custom loggers' do
|
30
|
-
l = rand
|
31
|
-
plugin.new({ logger: l })
|
32
|
-
.method(:logger).call
|
33
|
-
.must_equal(l)
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'provides a connection method' do
|
37
|
-
proc { plugin.new.connection }.must_raise Train::ClientError
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
describe 'registered with a name' do
|
42
|
-
before do
|
43
|
-
Train::Plugins.registry.clear
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'doesnt have any plugins in the registry if none were configured' do
|
47
|
-
Train::Plugins.registry.empty?.must_equal true
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'is is added to the plugins registry' do
|
51
|
-
plugin_name = rand
|
52
|
-
Train::Plugins.registry.wont_include(plugin_name)
|
53
|
-
|
54
|
-
plugin = Class.new(Train.plugin(1)) do
|
55
|
-
name plugin_name
|
56
|
-
end
|
57
|
-
|
58
|
-
Train::Plugins.registry[plugin_name].must_equal(plugin)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
describe 'with options' do
|
63
|
-
def train_class(opts = {})
|
64
|
-
name = rand.to_s
|
65
|
-
plugin = Class.new(Train.plugin(1)) do
|
66
|
-
option name, opts
|
67
|
-
end
|
68
|
-
[name, plugin]
|
69
|
-
end
|
70
|
-
|
71
|
-
it 'exposes the parameters via api' do
|
72
|
-
name, plugin = train_class
|
73
|
-
plugin.default_options.keys.must_equal [name]
|
74
|
-
end
|
75
|
-
|
76
|
-
it 'exposes the parameters via api' do
|
77
|
-
default = rand.to_s
|
78
|
-
name, plugin = train_class({ default: default })
|
79
|
-
plugin.default_options[name][:default].must_equal default
|
80
|
-
end
|
81
|
-
|
82
|
-
it 'option must be required' do
|
83
|
-
name, plugin = train_class(required: true)
|
84
|
-
plugin.default_options[name][:required].must_equal true
|
85
|
-
end
|
86
|
-
|
87
|
-
it 'default option must not be required' do
|
88
|
-
name, plugin = train_class
|
89
|
-
plugin.default_options[name][:required].must_be_nil
|
90
|
-
end
|
91
|
-
|
92
|
-
it 'can include options from another module' do
|
93
|
-
nameA, pluginA = train_class
|
94
|
-
b = Class.new(Train.plugin(1)) do
|
95
|
-
include_options(pluginA)
|
96
|
-
end
|
97
|
-
b.default_options[nameA].wont_be_nil
|
98
|
-
end
|
99
|
-
|
100
|
-
it 'overwrites existing options when including' do
|
101
|
-
old = rand.to_s
|
102
|
-
nu = rand.to_s
|
103
|
-
nameA, pluginA = train_class({ default: nu })
|
104
|
-
b = Class.new(Train.plugin(1)) do
|
105
|
-
option nameA, default: old
|
106
|
-
include_options(pluginA)
|
107
|
-
end
|
108
|
-
b.default_options[nameA][:default].must_equal nu
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
data/test/unit/plugins_test.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'helper'
|
3
|
-
|
4
|
-
describe Train::Plugins do
|
5
|
-
it 'provides a method to create new v1 transport plugins' do
|
6
|
-
Train.plugin(1).must_equal Train::Plugins::Transport
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'fails when called with an unsupported plugin version' do
|
10
|
-
proc {
|
11
|
-
Train.plugin(2)
|
12
|
-
}.must_raise Train::ClientError
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'defaults to v1 plugins' do
|
16
|
-
Train.plugin.must_equal Train::Plugins::Transport
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'provides a registry of plugins' do
|
20
|
-
Train::Plugins.registry.must_be_instance_of(Hash)
|
21
|
-
end
|
22
|
-
end
|
data/test/unit/train_test.rb
DELETED
@@ -1,247 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
#
|
3
|
-
# Author:: Dominik Richter (<dominik.richter@gmail.com>)
|
4
|
-
require_relative 'helper'
|
5
|
-
|
6
|
-
describe Train do
|
7
|
-
before do
|
8
|
-
Train::Plugins.registry.clear
|
9
|
-
end
|
10
|
-
|
11
|
-
describe '#create' do
|
12
|
-
it 'raises an error if the plugin isnt found' do
|
13
|
-
proc { Train.create('missing') }.must_raise Train::UserError
|
14
|
-
proc { Train.create('missing') }.must_raise Train::PluginLoadError
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'loads a core plugin if it isnt in the registry yet via symbol' do
|
18
|
-
Kernel.stub :require, true do
|
19
|
-
ex = Class.new(Train.plugin 1) { name 'existing' }
|
20
|
-
train = Train.create(:existing)
|
21
|
-
train.class.must_equal ex
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'loads a core plugin if it isnt in the registry yet via string' do
|
26
|
-
Kernel.stub :require, true do
|
27
|
-
ex = Class.new(Train.plugin 1) { name 'existing' }
|
28
|
-
train = Train.create('existing')
|
29
|
-
train.class.must_equal ex
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'loads a gem plugin if it isnt in the registry yet via string' do
|
34
|
-
# The 'train-test-fixture' gem is located in test/fixtures/plugins/train-test-fixture and is
|
35
|
-
# lib/train/trainsports, and Train will need to pre-pend 'train-' to the
|
36
|
-
# transport name to get the gem name.
|
37
|
-
transport = Train.create('test-fixture')
|
38
|
-
# Normally one would call transport.class.name, but that's been overridden to be a write-only DSL method
|
39
|
-
# So use to_s
|
40
|
-
transport.class.to_s.must_equal 'TrainPlugins::TestFixture::Transport'
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
describe '#options' do
|
45
|
-
it 'raises exception if a given transport plugin isnt found' do
|
46
|
-
proc { Train.options('missing') }.must_raise Train::UserError
|
47
|
-
proc { Train.options('missing') }.must_raise Train::PluginLoadError
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'provides empty options of a transport plugin' do
|
51
|
-
Class.new(Train.plugin 1) { name 'none' }
|
52
|
-
Train.options('none').must_equal({})
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'provides all options of a transport plugin' do
|
56
|
-
Class.new(Train.plugin 1) {
|
57
|
-
name 'one'
|
58
|
-
option :one, required: true, default: 123
|
59
|
-
}
|
60
|
-
Train.options('one').must_equal({
|
61
|
-
one: {
|
62
|
-
required: true,
|
63
|
-
default: 123,
|
64
|
-
}
|
65
|
-
})
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
describe '#target_config' do
|
70
|
-
it 'configures resolves target' do
|
71
|
-
org = {
|
72
|
-
target: 'ssh://user:pass@host.com:123/path',
|
73
|
-
}
|
74
|
-
res = Train.target_config(org)
|
75
|
-
res[:backend].must_equal 'ssh'
|
76
|
-
res[:host].must_equal 'host.com'
|
77
|
-
res[:user].must_equal 'user'
|
78
|
-
res[:password].must_equal 'pass'
|
79
|
-
res[:port].must_equal 123
|
80
|
-
res[:target].must_equal org[:target]
|
81
|
-
res[:path].must_equal '/path'
|
82
|
-
org.keys.must_equal [:target]
|
83
|
-
end
|
84
|
-
|
85
|
-
it 'resolves a target while keeping existing fields' do
|
86
|
-
org = {
|
87
|
-
target: 'ssh://user:pass@host.com:123/path',
|
88
|
-
backend: rand,
|
89
|
-
host: rand,
|
90
|
-
user: rand,
|
91
|
-
password: rand,
|
92
|
-
port: rand,
|
93
|
-
path: rand
|
94
|
-
}
|
95
|
-
res = Train.target_config(org)
|
96
|
-
res.must_equal org
|
97
|
-
end
|
98
|
-
|
99
|
-
it 'resolves a winrm target' do
|
100
|
-
org = {
|
101
|
-
target: 'winrm://Administrator@192.168.10.140',
|
102
|
-
backend: 'winrm',
|
103
|
-
host: '192.168.10.140',
|
104
|
-
user: 'Administrator',
|
105
|
-
password: nil,
|
106
|
-
port: nil,
|
107
|
-
path: nil
|
108
|
-
}
|
109
|
-
res = Train.target_config(org)
|
110
|
-
res.must_equal org
|
111
|
-
end
|
112
|
-
|
113
|
-
it 'keeps the configuration when incorrect target is supplied' do
|
114
|
-
org = {
|
115
|
-
target: 'wrong',
|
116
|
-
}
|
117
|
-
res = Train.target_config(org)
|
118
|
-
res[:backend].must_be_nil
|
119
|
-
res[:host].must_be_nil
|
120
|
-
res[:user].must_be_nil
|
121
|
-
res[:password].must_be_nil
|
122
|
-
res[:port].must_be_nil
|
123
|
-
res[:path].must_be_nil
|
124
|
-
res[:target].must_equal org[:target]
|
125
|
-
end
|
126
|
-
|
127
|
-
it 'always takes ruby sumbols as configuration fields' do
|
128
|
-
org = {
|
129
|
-
'target' => 'ssh://user:pass@host.com:123/path',
|
130
|
-
'backend' => rand,
|
131
|
-
'host' => rand,
|
132
|
-
'user' => rand,
|
133
|
-
'password' => rand,
|
134
|
-
'port' => rand,
|
135
|
-
'path' => rand
|
136
|
-
}
|
137
|
-
nu = org.each_with_object({}) { |(x, y), acc|
|
138
|
-
acc[x.to_sym] = y; acc
|
139
|
-
}
|
140
|
-
res = Train.target_config(org)
|
141
|
-
res.must_equal nu
|
142
|
-
end
|
143
|
-
|
144
|
-
it 'supports IPv4 URIs' do
|
145
|
-
org = { target: 'mock://1.2.3.4:123' }
|
146
|
-
res = Train.target_config(org)
|
147
|
-
res[:backend].must_equal 'mock'
|
148
|
-
res[:host].must_equal '1.2.3.4'
|
149
|
-
res[:user].must_be_nil
|
150
|
-
res[:password].must_be_nil
|
151
|
-
res[:port].must_equal 123
|
152
|
-
res[:path].must_be_nil
|
153
|
-
res[:target].must_equal org[:target]
|
154
|
-
end
|
155
|
-
|
156
|
-
it 'supports IPv6 URIs' do
|
157
|
-
org = { target: 'mock://[abc::def]:123' }
|
158
|
-
res = Train.target_config(org)
|
159
|
-
res[:backend].must_equal 'mock'
|
160
|
-
res[:host].must_equal 'abc::def'
|
161
|
-
res[:user].must_be_nil
|
162
|
-
res[:password].must_be_nil
|
163
|
-
res[:port].must_equal 123
|
164
|
-
res[:path].must_be_nil
|
165
|
-
res[:target].must_equal org[:target]
|
166
|
-
end
|
167
|
-
|
168
|
-
it 'supports empty URIs with schema://' do
|
169
|
-
org = { target: 'mock://' }
|
170
|
-
res = Train.target_config(org)
|
171
|
-
res[:backend].must_equal 'mock'
|
172
|
-
res[:host].must_be_nil
|
173
|
-
res[:user].must_be_nil
|
174
|
-
res[:password].must_be_nil
|
175
|
-
res[:port].must_be_nil
|
176
|
-
res[:path].must_be_nil
|
177
|
-
res[:target].must_equal org[:target]
|
178
|
-
end
|
179
|
-
|
180
|
-
it 'supports empty URIs with schema:' do
|
181
|
-
org = { target: 'mock:' }
|
182
|
-
res = Train.target_config(org)
|
183
|
-
res[:backend].must_equal 'mock'
|
184
|
-
res[:host].must_be_nil
|
185
|
-
res[:user].must_be_nil
|
186
|
-
res[:password].must_be_nil
|
187
|
-
res[:port].must_be_nil
|
188
|
-
res[:path].must_be_nil
|
189
|
-
res[:target].must_equal org[:target]
|
190
|
-
end
|
191
|
-
|
192
|
-
it 'supports www-form encoded passwords when the option is set' do
|
193
|
-
raw_password = '+!@#$%^&*()_-\';:"\\|/?.>,<][}{=`~'
|
194
|
-
encoded_password = URI.encode_www_form_component(raw_password)
|
195
|
-
org = { target: "mock://username:#{encoded_password}@1.2.3.4:100",
|
196
|
-
www_form_encoded_password: true}
|
197
|
-
res = Train.target_config(org)
|
198
|
-
res[:backend].must_equal 'mock'
|
199
|
-
res[:host].must_equal '1.2.3.4'
|
200
|
-
res[:user].must_equal 'username'
|
201
|
-
res[:password].must_equal raw_password
|
202
|
-
res[:port].must_equal 100
|
203
|
-
res[:target].must_equal org[:target]
|
204
|
-
end
|
205
|
-
|
206
|
-
it 'ignores www-form-encoded password value when there is no password' do
|
207
|
-
org = { target: "mock://username@1.2.3.4:100",
|
208
|
-
www_form_encoded_password: true}
|
209
|
-
res = Train.target_config(org)
|
210
|
-
res[:backend].must_equal 'mock'
|
211
|
-
res[:host].must_equal '1.2.3.4'
|
212
|
-
res[:user].must_equal 'username'
|
213
|
-
res[:password].must_be_nil
|
214
|
-
res[:port].must_equal 100
|
215
|
-
res[:target].must_equal org[:target]
|
216
|
-
end
|
217
|
-
|
218
|
-
it 'it raises UserError on invalid URIs' do
|
219
|
-
org = { target: 'mock world' }
|
220
|
-
proc { Train.target_config(org) }.must_raise Train::UserError
|
221
|
-
end
|
222
|
-
end
|
223
|
-
|
224
|
-
describe '#validate_backend' do
|
225
|
-
it 'just returns the backend if it is provided' do
|
226
|
-
x = rand
|
227
|
-
Train.validate_backend({ backend: x }).must_equal x
|
228
|
-
end
|
229
|
-
|
230
|
-
it 'returns the local backend if nothing was provided' do
|
231
|
-
Train.validate_backend({}).must_equal :local
|
232
|
-
end
|
233
|
-
|
234
|
-
it 'returns the default backend if nothing was provided' do
|
235
|
-
x = rand
|
236
|
-
Train.validate_backend({}, x).must_equal x
|
237
|
-
end
|
238
|
-
|
239
|
-
it 'fails if no backend was given but a target is provided' do
|
240
|
-
proc { Train.validate_backend({ target: rand }) }.must_raise Train::UserError
|
241
|
-
end
|
242
|
-
|
243
|
-
it 'fails if no backend was given but a host is provided' do
|
244
|
-
proc { Train.validate_backend({ host: rand }) }.must_raise Train::UserError
|
245
|
-
end
|
246
|
-
end
|
247
|
-
end
|
@@ -1,120 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'helper'
|
4
|
-
|
5
|
-
describe 'aws transport' do
|
6
|
-
def transport(options = nil)
|
7
|
-
ENV['AWS_REGION'] = 'test_region'
|
8
|
-
ENV['AWS_ACCESS_KEY_ID'] = 'test_key_id'
|
9
|
-
ENV['AWS_SECRET_ACCESS_KEY'] = 'test_access_key'
|
10
|
-
ENV['AWS_SESSION_TOKEN'] = 'test_session_token'
|
11
|
-
|
12
|
-
# need to require this at here as it captures the envs on load
|
13
|
-
require 'train/transports/aws'
|
14
|
-
Train::Transports::Aws.new(options)
|
15
|
-
end
|
16
|
-
let(:connection) { transport.connection }
|
17
|
-
let(:options) { connection.instance_variable_get(:@options) }
|
18
|
-
let(:cache) { connection.instance_variable_get(:@cache) }
|
19
|
-
|
20
|
-
describe 'options' do
|
21
|
-
it 'defaults to env options' do
|
22
|
-
options[:region].must_equal 'test_region'
|
23
|
-
options[:access_key_id].must_equal 'test_key_id'
|
24
|
-
options[:secret_access_key].must_equal 'test_access_key'
|
25
|
-
options[:session_token].must_equal 'test_session_token'
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'test options override' do
|
29
|
-
transport = transport(region: 'us-east-2', access_key_id: '8')
|
30
|
-
options = transport.connection.instance_variable_get(:@options)
|
31
|
-
options[:region].must_equal 'us-east-2'
|
32
|
-
options[:access_key_id].must_equal '8'
|
33
|
-
options[:secret_access_key].must_equal 'test_access_key'
|
34
|
-
options[:session_token].must_equal 'test_session_token'
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'test url parse override' do
|
38
|
-
transport = transport(host: 'us-east-2')
|
39
|
-
options = transport.connection.instance_variable_get(:@options)
|
40
|
-
options[:region].must_equal 'us-east-2'
|
41
|
-
options[:session_token].must_equal 'test_session_token'
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
describe 'platform' do
|
46
|
-
it 'returns platform' do
|
47
|
-
plat = connection.platform
|
48
|
-
plat.name.must_equal 'aws'
|
49
|
-
plat.family_hierarchy.must_equal ['cloud', 'api']
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
describe 'aws_client' do
|
54
|
-
it 'test aws_client with caching' do
|
55
|
-
client = connection.aws_client(Object)
|
56
|
-
client.is_a?(Object).must_equal true
|
57
|
-
cache[:api_call].count.must_equal 1
|
58
|
-
end
|
59
|
-
|
60
|
-
it 'test aws_client without caching' do
|
61
|
-
connection.disable_cache(:api_call)
|
62
|
-
client = connection.aws_client(Object)
|
63
|
-
client.is_a?(Object).must_equal true
|
64
|
-
cache[:api_call].count.must_equal 0
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
describe 'aws_resource' do
|
69
|
-
class AwsResource
|
70
|
-
attr_reader :hash
|
71
|
-
def initialize(hash)
|
72
|
-
@hash = hash
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
it 'test aws_resource with arguments' do
|
77
|
-
hash = { user: 1, name: 'test_user' }
|
78
|
-
resource = connection.aws_resource(AwsResource, hash)
|
79
|
-
resource.hash.must_equal hash
|
80
|
-
cache[:api_call].count.must_equal 0
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
describe 'connect' do
|
85
|
-
it 'validate aws connection with profile' do
|
86
|
-
options[:profile] = 'xyz'
|
87
|
-
ENV['AWS_PROFILE'].must_be_nil
|
88
|
-
connection.connect
|
89
|
-
ENV['AWS_PROFILE'].must_equal 'xyz'
|
90
|
-
end
|
91
|
-
|
92
|
-
it 'validate aws connection with region' do
|
93
|
-
options[:region] = 'xyz'
|
94
|
-
ENV['AWS_REGION'].must_equal 'test_region'
|
95
|
-
connection.connect
|
96
|
-
ENV['AWS_REGION'].must_equal 'xyz'
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
describe 'unique_identifier' do
|
101
|
-
|
102
|
-
class AwsCallerId
|
103
|
-
def account
|
104
|
-
"123456789012"
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
class StsClient
|
109
|
-
def get_caller_identity
|
110
|
-
AwsCallerId.new
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
it 'returns an account id' do
|
115
|
-
connection.stubs(:aws_client).returns(StsClient.new)
|
116
|
-
connection.unique_identifier.must_equal '123456789012'
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
end
|
@@ -1,145 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'helper'
|
4
|
-
|
5
|
-
describe 'azure transport' do
|
6
|
-
def transport(options = nil)
|
7
|
-
ENV['AZURE_TENANT_ID'] = 'test_tenant_id'
|
8
|
-
ENV['AZURE_CLIENT_ID'] = 'test_client_id'
|
9
|
-
ENV['AZURE_CLIENT_SECRET'] = 'test_client_secret'
|
10
|
-
ENV['AZURE_SUBSCRIPTION_ID'] = 'test_subscription_id'
|
11
|
-
|
12
|
-
# need to require this at here as it captures the envs on load
|
13
|
-
require 'train/transports/azure'
|
14
|
-
Train::Transports::Azure.new(options)
|
15
|
-
end
|
16
|
-
let(:connection) { transport.connection }
|
17
|
-
let(:options) { connection.instance_variable_get(:@options) }
|
18
|
-
let(:cache) { connection.instance_variable_get(:@cache) }
|
19
|
-
let(:credentials) { connection.instance_variable_get(:@credentials) }
|
20
|
-
|
21
|
-
describe 'options' do
|
22
|
-
it 'defaults to env options' do
|
23
|
-
options[:tenant_id].must_equal 'test_tenant_id'
|
24
|
-
options[:client_id].must_equal 'test_client_id'
|
25
|
-
options[:client_secret].must_equal 'test_client_secret'
|
26
|
-
options[:subscription_id].must_equal 'test_subscription_id'
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'allows for options override' do
|
30
|
-
transport = transport(subscription_id: '102', client_id: '717')
|
31
|
-
options = transport.connection.instance_variable_get(:@options)
|
32
|
-
options[:tenant_id].must_equal 'test_tenant_id'
|
33
|
-
options[:client_id].must_equal '717'
|
34
|
-
options[:client_secret].must_equal 'test_client_secret'
|
35
|
-
options[:subscription_id].must_equal '102'
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'allows uri parse override' do
|
39
|
-
transport = transport(host: '999')
|
40
|
-
options = transport.connection.instance_variable_get(:@options)
|
41
|
-
options[:tenant_id].must_equal 'test_tenant_id'
|
42
|
-
options[:subscription_id].must_equal '999'
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
describe 'platform' do
|
47
|
-
it 'returns platform' do
|
48
|
-
plat = connection.platform
|
49
|
-
plat.name.must_equal 'azure'
|
50
|
-
plat.family_hierarchy.must_equal ['cloud', 'api']
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
describe 'azure_client' do
|
55
|
-
class AzureResource
|
56
|
-
attr_reader :hash
|
57
|
-
def initialize(hash)
|
58
|
-
@hash = hash
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'can use azure_client with caching' do
|
63
|
-
connection.instance_variable_set(:@credentials, {})
|
64
|
-
client = connection.azure_client(AzureResource)
|
65
|
-
client.is_a?(AzureResource).must_equal true
|
66
|
-
cache[:api_call].count.must_equal 1
|
67
|
-
end
|
68
|
-
|
69
|
-
it 'can use azure_client without caching' do
|
70
|
-
connection.instance_variable_set(:@credentials, {})
|
71
|
-
connection.disable_cache(:api_call)
|
72
|
-
client = connection.azure_client(AzureResource)
|
73
|
-
client.is_a?(AzureResource).must_equal true
|
74
|
-
cache[:api_call].count.must_equal 0
|
75
|
-
end
|
76
|
-
|
77
|
-
it 'can use azure_client default client' do
|
78
|
-
MANAGEMENT_API_CLIENT = Azure::Resources::Profiles::Latest::Mgmt::Client
|
79
|
-
client = connection.azure_client
|
80
|
-
client.class.must_equal MANAGEMENT_API_CLIENT
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'can use azure_client graph client' do
|
84
|
-
GRAPH_API_CLIENT = Azure::GraphRbac::Profiles::Latest::Client
|
85
|
-
client = connection.azure_client(GRAPH_API_CLIENT)
|
86
|
-
client.class.must_equal GRAPH_API_CLIENT
|
87
|
-
end
|
88
|
-
|
89
|
-
it 'can use azure_client vault client' do
|
90
|
-
VAULT_API_CLIENT = ::Azure::KeyVault::Profiles::Latest::Mgmt::Client
|
91
|
-
client = connection.azure_client(VAULT_API_CLIENT, vault_name: 'Test Vault')
|
92
|
-
client.class.must_equal VAULT_API_CLIENT
|
93
|
-
end
|
94
|
-
|
95
|
-
it 'cannot instantiate azure_client vault client without a vault name' do
|
96
|
-
VAULT_API_CLIENT = ::Azure::KeyVault::Profiles::Latest::Mgmt::Client
|
97
|
-
assert_raises(Train::UserError) do
|
98
|
-
connection.azure_client(VAULT_API_CLIENT)
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
describe 'connect' do
|
104
|
-
it 'validate credentials' do
|
105
|
-
connection.connect
|
106
|
-
token = credentials[:credentials].instance_variable_get(:@token_provider)
|
107
|
-
token.class.must_equal MsRestAzure::ApplicationTokenProvider
|
108
|
-
|
109
|
-
credentials[:credentials].class.must_equal MsRest::TokenCredentials
|
110
|
-
credentials[:tenant_id].must_equal 'test_tenant_id'
|
111
|
-
credentials[:client_id].must_equal 'test_client_id'
|
112
|
-
credentials[:client_secret].must_equal 'test_client_secret'
|
113
|
-
credentials[:subscription_id].must_equal 'test_subscription_id'
|
114
|
-
end
|
115
|
-
|
116
|
-
it 'validate msi credentials' do
|
117
|
-
options[:client_id] = nil
|
118
|
-
options[:client_secret] = nil
|
119
|
-
Train::Transports::Azure::Connection.any_instance.stubs(:port_open?).returns(true)
|
120
|
-
|
121
|
-
connection.connect
|
122
|
-
token = credentials[:credentials].instance_variable_get(:@token_provider)
|
123
|
-
token.class.must_equal MsRestAzure::MSITokenProvider
|
124
|
-
|
125
|
-
credentials[:credentials].class.must_equal MsRest::TokenCredentials
|
126
|
-
credentials[:tenant_id].must_equal 'test_tenant_id'
|
127
|
-
credentials[:subscription_id].must_equal 'test_subscription_id'
|
128
|
-
credentials[:client_id].must_be_nil
|
129
|
-
credentials[:client_secret].must_be_nil
|
130
|
-
options[:msi_port].must_equal 50342
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
describe 'unique_identifier' do
|
135
|
-
it 'returns a subscription id' do
|
136
|
-
connection.unique_identifier.must_equal 'test_subscription_id'
|
137
|
-
end
|
138
|
-
|
139
|
-
it 'returns a tenant id' do
|
140
|
-
options = connection.instance_variable_get(:@options)
|
141
|
-
options[:subscription_id] = nil
|
142
|
-
connection.unique_identifier.must_equal 'test_tenant_id'
|
143
|
-
end
|
144
|
-
end
|
145
|
-
end
|