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,32 +18,6 @@ describe Train::File do
18
18
  new_cls.type.must_equal :unknown
19
19
  end
20
20
 
21
- it 'calculates md5sum from content' do
22
- content = 'hello world'
23
- new_cls.stub :content, content do |i|
24
- i.md5sum.must_equal '5eb63bbbe01eeed093cb22bb8f5acdc3'
25
- end
26
- end
27
-
28
- it 'sets md5sum of nil content to nil' do
29
- new_cls.stub :content, nil do |i|
30
- i.md5sum.must_be_nil
31
- end
32
- end
33
-
34
- it 'calculates sha256sum from content' do
35
- content = 'hello world'
36
- new_cls.stub :content, content do |i|
37
- i.sha256sum.must_equal 'b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9'
38
- end
39
- end
40
-
41
- it 'sets sha256sum of nil content to nil' do
42
- new_cls.stub :content, nil do |i|
43
- i.sha256sum.must_be_nil
44
- end
45
- end
46
-
47
21
  it 'throws Not implemented error for exist?' do
48
22
  # proc { Train.validate_backend({ host: rand }) }.must_raise Train::UserError
49
23
  proc { new_cls.exist?}.must_raise NotImplementedError
@@ -91,13 +65,12 @@ describe Train::File do
91
65
 
92
66
  it 'set product_version to nil' do
93
67
  new_cls.product_version.must_be_nil
94
- end
68
+ end
95
69
 
96
70
  it 'set product_version to nil' do
97
71
  new_cls.file_version.must_be_nil
98
72
  end
99
73
 
100
-
101
74
  describe 'type' do
102
75
  it 'recognized type == file' do
103
76
  fc = mockup(type: :file)
@@ -153,4 +126,4 @@ describe Train::File do
153
126
  fc.version?(x).must_equal true
154
127
  end
155
128
  end
156
- end
129
+ end
@@ -122,59 +122,4 @@ describe 'azure transport' do
122
122
  connection.unique_identifier.must_equal 'test_tenant_id'
123
123
  end
124
124
  end
125
-
126
- describe 'parse_credentials_file' do
127
- let(:cred_file) do
128
- require 'tempfile'
129
- file = Tempfile.new('cred_file')
130
- info = <<-INFO
131
- [my_subscription_id]
132
- client_id = "my_client_id"
133
- client_secret = "my_client_secret"
134
- tenant_id = "my_tenant_id"
135
-
136
- [my_subscription_id2]
137
- client_id = "my_client_id2"
138
- client_secret = "my_client_secret2"
139
- tenant_id = "my_tenant_id2"
140
- INFO
141
- file.write(info)
142
- file.close
143
- file
144
- end
145
-
146
- it 'validate credentials from file' do
147
- options[:credentials_file] = cred_file.path
148
- options[:subscription_id] = 'my_subscription_id'
149
- connection.send(:parse_credentials_file)
150
-
151
- options[:tenant_id].must_equal 'my_tenant_id'
152
- options[:client_id].must_equal 'my_client_id'
153
- options[:client_secret].must_equal 'my_client_secret'
154
- options[:subscription_id].must_equal 'my_subscription_id'
155
- end
156
-
157
- it 'validate credentials from file subscription override' do
158
- options[:credentials_file] = cred_file.path
159
- options[:subscription_id] = 'my_subscription_id2'
160
- connection.send(:parse_credentials_file)
161
-
162
- options[:tenant_id].must_equal 'my_tenant_id2'
163
- options[:client_id].must_equal 'my_client_id2'
164
- options[:client_secret].must_equal 'my_client_secret2'
165
- options[:subscription_id].must_equal 'my_subscription_id2'
166
- end
167
-
168
- it 'validate credentials from file subscription index' do
169
- options[:credentials_file] = cred_file.path
170
- options[:subscription_id] = nil
171
- ENV['AZURE_SUBSCRIPTION_NUMBER'] = '2'
172
- connection.send(:parse_credentials_file)
173
-
174
- options[:tenant_id].must_equal 'my_tenant_id2'
175
- options[:client_id].must_equal 'my_client_id2'
176
- options[:client_secret].must_equal 'my_client_secret2'
177
- options[:subscription_id].must_equal 'my_subscription_id2'
178
- end
179
- end
180
125
  end
@@ -0,0 +1,121 @@
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 'returns empty hash when no credentials file detected' do
42
+ result = Train::Transports::Helpers::Azure::FileCredentials.parse({})
43
+
44
+ assert_empty(result)
45
+ end
46
+
47
+ it 'loads only entry from file when no subscription id given' do
48
+ options[:credentials_file] = cred_file_single_entry.path
49
+
50
+ result = Train::Transports::Helpers::Azure::FileCredentials.parse(options)
51
+
52
+ assert_equal('my_tenant_id', result[:tenant_id])
53
+ assert_equal('my_client_id', result[:client_id])
54
+ assert_equal('my_client_secret', result[:client_secret])
55
+ assert_equal('my_subscription_id', result[:subscription_id])
56
+ end
57
+
58
+ it 'raises an error when no subscription id given and multiple entries' do
59
+ error = assert_raises RuntimeError do
60
+ Train::Transports::Helpers::Azure::FileCredentials.parse(options)
61
+ end
62
+
63
+ 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)
64
+ end
65
+
66
+ it 'loads entry when subscription id is given' do
67
+ options[:subscription_id] = 'my_subscription_id'
68
+
69
+ result = Train::Transports::Helpers::Azure::FileCredentials.parse(options)
70
+
71
+ assert_equal('my_tenant_id', result[:tenant_id])
72
+ assert_equal('my_client_id', result[:client_id])
73
+ assert_equal('my_client_secret', result[:client_secret])
74
+ assert_equal('my_subscription_id', result[:subscription_id])
75
+ end
76
+
77
+ it 'raises an error when subscription id not found' do
78
+ options[:subscription_id] = 'missing_subscription_id'
79
+
80
+ error = assert_raises RuntimeError do
81
+ Train::Transports::Helpers::Azure::FileCredentials.parse(options)
82
+ end
83
+
84
+ assert_equal('No credentials found for subscription number missing_subscription_id', error.message)
85
+ end
86
+
87
+ it 'loads entry based on index' do
88
+ ENV['AZURE_SUBSCRIPTION_NUMBER'] = '2'
89
+
90
+ result = Train::Transports::Helpers::Azure::FileCredentials.parse(options)
91
+
92
+ ENV.delete('AZURE_SUBSCRIPTION_NUMBER')
93
+
94
+ assert_equal('my_tenant_id2', result[:tenant_id])
95
+ assert_equal('my_client_id2', result[:client_id])
96
+ assert_equal('my_client_secret2', result[:client_secret])
97
+ assert_equal('my_subscription_id2', result[:subscription_id])
98
+ end
99
+
100
+ it 'raises an error when index is out of bounds' do
101
+ ENV['AZURE_SUBSCRIPTION_NUMBER'] = '3'
102
+
103
+ error = assert_raises RuntimeError do
104
+ Train::Transports::Helpers::Azure::FileCredentials.parse(options)
105
+ end
106
+ ENV.delete('AZURE_SUBSCRIPTION_NUMBER')
107
+
108
+ assert_equal('Your credentials file only contains 2 subscriptions. You specified number 3.', error.message)
109
+ end
110
+
111
+ it 'raises an error when index 0 is given' do
112
+ ENV['AZURE_SUBSCRIPTION_NUMBER'] = '0'
113
+
114
+ error = assert_raises RuntimeError do
115
+ Train::Transports::Helpers::Azure::FileCredentials.parse(options)
116
+ end
117
+ ENV.delete('AZURE_SUBSCRIPTION_NUMBER')
118
+
119
+ assert_equal('Index must be greater than 0.', error.message)
120
+ end
121
+ end
@@ -55,6 +55,18 @@ describe 'ssh transport' do
55
55
  end
56
56
  end
57
57
 
58
+ describe 'ssh options' do
59
+ let(:ssh) { cls.new(conf) }
60
+ let(:connection) { ssh.connection }
61
+ it 'includes BatchMode when :non_interactive is set' do
62
+ conf[:non_interactive] = true
63
+ connection.ssh_opts.include?("BatchMode=yes").must_equal true
64
+ end
65
+ it 'excludes BatchMode when :non_interactive is not set' do
66
+ connection.ssh_opts.include?("BatchMode=yes").must_equal false
67
+ end
68
+ end
69
+
58
70
  describe 'opening a connection' do
59
71
  let(:ssh) { cls.new(conf) }
60
72
  let(:connection) { ssh.connection }
@@ -84,12 +84,22 @@ describe 'windows winrm command' do
84
84
  file.mode.must_be_nil
85
85
  end
86
86
 
87
- it 'has an md5sum' do
88
- file.md5sum.wont_be_nil
89
- end
90
-
91
- it 'has an sha256sum' do
92
- file.sha256sum.wont_be_nil
87
+ it 'has the correct md5sum' do
88
+ # Must create unique file to prevent `ERROR_SHARING_VIOLATION`
89
+ tempfile = Tempfile.new('tempfile')
90
+ tempfile.write('easy to hash')
91
+ tempfile.close
92
+ conn.file(tempfile.path).md5sum.must_equal 'c15b41ade1221a532a38d89671ffaa20'
93
+ tempfile.unlink
94
+ end
95
+
96
+ it 'has the correct sha256sum' do
97
+ # Must create unique file to prevent `ERROR_SHARING_VIOLATION`
98
+ tempfile = Tempfile.new('tempfile')
99
+ tempfile.write('easy to hash')
100
+ tempfile.close
101
+ conn.file(tempfile.path).sha256sum.must_equal '24ae25354d5f697566e715cd46e1df2f490d0b8367c21447962dbf03bf7225ba'
102
+ tempfile.unlink
93
103
  end
94
104
 
95
105
  it 'has no modified time' do
@@ -23,12 +23,12 @@ Gem::Specification.new do |spec|
23
23
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
24
24
  spec.require_paths = ['lib']
25
25
 
26
+ spec.required_ruby_version = '>= 2.0'
27
+
26
28
  spec.add_dependency 'json', '>= 1.8', '< 3.0'
27
29
  # chef-client < 12.4.1 require mixlib-shellout-2.0.1
28
30
  spec.add_dependency 'mixlib-shellout', '~> 2.0'
29
- # net-ssh 3.x drops Ruby 1.9 support, so this constraint could be raised when
30
- # 1.9 support is no longer needed here or for Inspec
31
- spec.add_dependency 'net-ssh', '>= 2.9', '< 5.0'
31
+ spec.add_dependency 'net-ssh', '>= 2.9', '< 6.0'
32
32
  spec.add_dependency 'net-scp', '~> 1.2'
33
33
  spec.add_dependency 'winrm', '~> 2.0'
34
34
  spec.add_dependency 'winrm-fs', '~> 1.0'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: train
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.25
4
+ version: 1.4.29
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dominik Richter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-01 00:00:00.000000000 Z
11
+ date: 2018-08-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -53,7 +53,7 @@ dependencies:
53
53
  version: '2.9'
54
54
  - - "<"
55
55
  - !ruby/object:Gem::Version
56
- version: '5.0'
56
+ version: '6.0'
57
57
  type: :runtime
58
58
  prerelease: false
59
59
  version_requirements: !ruby/object:Gem::Requirement
@@ -63,7 +63,7 @@ dependencies:
63
63
  version: '2.9'
64
64
  - - "<"
65
65
  - !ruby/object:Gem::Version
66
- version: '5.0'
66
+ version: '6.0'
67
67
  - !ruby/object:Gem::Dependency
68
68
  name: net-scp
69
69
  requirement: !ruby/object:Gem::Requirement
@@ -253,6 +253,10 @@ files:
253
253
  - lib/train/transports/cisco_ios_connection.rb
254
254
  - lib/train/transports/docker.rb
255
255
  - lib/train/transports/gcp.rb
256
+ - lib/train/transports/helpers/azure/file_credentials.rb
257
+ - lib/train/transports/helpers/azure/file_parser.rb
258
+ - lib/train/transports/helpers/azure/subscription_id_file_parser.rb
259
+ - lib/train/transports/helpers/azure/subscription_number_file_parser.rb
256
260
  - lib/train/transports/local.rb
257
261
  - lib/train/transports/mock.rb
258
262
  - lib/train/transports/ssh.rb
@@ -301,6 +305,7 @@ files:
301
305
  - test/unit/file/remote/linux_test.rb
302
306
  - test/unit/file/remote/qnx_test.rb
303
307
  - test/unit/file/remote/unix_test.rb
308
+ - test/unit/file/remote/windows_test.rb
304
309
  - test/unit/file/remote_test.rb
305
310
  - test/unit/file_test.rb
306
311
  - test/unit/helper.rb
@@ -321,6 +326,7 @@ files:
321
326
  - test/unit/transports/azure_test.rb
322
327
  - test/unit/transports/cisco_ios_connection.rb
323
328
  - test/unit/transports/gcp_test.rb
329
+ - test/unit/transports/helpers/azure/file_credentials_test.rb
324
330
  - test/unit/transports/local_test.rb
325
331
  - test/unit/transports/mock_test.rb
326
332
  - test/unit/transports/ssh_test.rb
@@ -341,7 +347,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
341
347
  requirements:
342
348
  - - ">="
343
349
  - !ruby/object:Gem::Version
344
- version: '0'
350
+ version: '2.0'
345
351
  required_rubygems_version: !ruby/object:Gem::Requirement
346
352
  requirements:
347
353
  - - ">="
@@ -394,6 +400,7 @@ test_files:
394
400
  - test/unit/file/remote/linux_test.rb
395
401
  - test/unit/file/remote/qnx_test.rb
396
402
  - test/unit/file/remote/unix_test.rb
403
+ - test/unit/file/remote/windows_test.rb
397
404
  - test/unit/file/remote_test.rb
398
405
  - test/unit/file_test.rb
399
406
  - test/unit/helper.rb
@@ -414,6 +421,7 @@ test_files:
414
421
  - test/unit/transports/azure_test.rb
415
422
  - test/unit/transports/cisco_ios_connection.rb
416
423
  - test/unit/transports/gcp_test.rb
424
+ - test/unit/transports/helpers/azure/file_credentials_test.rb
417
425
  - test/unit/transports/local_test.rb
418
426
  - test/unit/transports/mock_test.rb
419
427
  - test/unit/transports/ssh_test.rb