r-train 0.9.6 → 0.9.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7575ec657025aa3a654b3027981d2ced614549be
4
- data.tar.gz: 667d45c23b863cc86fa69c9adc364af790c320ca
3
+ metadata.gz: 4ecdabc0165badec2fd8ff58e1fa04bb12dcd0ca
4
+ data.tar.gz: 7d3100e5f0f9ad7c35087010f34e7027c5d6ced2
5
5
  SHA512:
6
- metadata.gz: e6b12280fcd7d238ed3c0fb7ae9716b4752b07ddcfbadb77bc0d8b2c9fbd7d721caef426e1f37c99a68d119c8b3d1f7e1ae395ef776a72a47419a24d2ebf8508
7
- data.tar.gz: 589e2fa5193099b0d5f0f4146e3f0a6c19c677607387e01984d1febbeee6a643e6970407dea8e1f7c9caea5fb45c4476c878df772a5a47f05d94f1052f761432
6
+ metadata.gz: 9d5ca60694e074a0e75358b37f13481a9e1c548d097270e1457f92f14e32bae154360fffb08828527d15d4153c3ba21f9da91668de139962eb2e597cc8f5a91a
7
+ data.tar.gz: d5690275ba08a1a50bfa1348746f92eb2d8d06e27b8e97569dc31479fd01dce3c06f2118a659358a4aff15a24ebf879318ba5393745a13f24864ba27019cfb0d
data/CHANGELOG.md CHANGED
@@ -1,10 +1,23 @@
1
1
  # Change Log
2
2
 
3
- ## [0.9.5](https://github.com/chef/train/tree/0.9.5) (2016-01-29)
4
- [Full Changelog](https://github.com/chef/train/compare/v0.9.5...0.9.5)
3
+ ## [0.9.7](https://github.com/chef/train/tree/0.9.7) (2016-02-05)
4
+ [Full Changelog](https://github.com/chef/train/compare/v0.9.6...0.9.7)
5
+
6
+ **Implemented enhancements:**
7
+
8
+ - add `requiretty` workaround measures [\#63](https://github.com/chef/train/pull/63) ([srenatus](https://github.com/srenatus))
9
+
10
+ **Merged pull requests:**
11
+
12
+ - ensure bundler is installed on travis [\#66](https://github.com/chef/train/pull/66) ([chris-rock](https://github.com/chris-rock))
13
+ - feature: add file.basename [\#64](https://github.com/chef/train/pull/64) ([arlimus](https://github.com/arlimus))
14
+
15
+ ## [v0.9.6](https://github.com/chef/train/tree/v0.9.6) (2016-01-29)
16
+ [Full Changelog](https://github.com/chef/train/compare/v0.9.5...v0.9.6)
5
17
 
6
18
  **Merged pull requests:**
7
19
 
20
+ - 0.9.6 [\#62](https://github.com/chef/train/pull/62) ([chris-rock](https://github.com/chris-rock))
8
21
  - add solaris support [\#61](https://github.com/chef/train/pull/61) ([chris-rock](https://github.com/chris-rock))
9
22
 
10
23
  ## [v0.9.5](https://github.com/chef/train/tree/v0.9.5) (2016-01-25)
@@ -50,13 +50,18 @@ module Train::Extras
50
50
  return nil if res.exit_status == 0
51
51
  rawerr = res.stdout + ' ' + res.stderr
52
52
 
53
- rawerr = 'Wrong sudo password.' if rawerr.include? 'Sorry, try again'
54
- if rawerr.include? 'sudo: no tty present and no askpass program specified'
55
- rawerr = 'Sudo requires a password, please configure it.'
56
- end
57
- if rawerr.include? 'sudo: command not found'
58
- rawerr = "Can't find sudo command. Please either install and "\
59
- 'configure it on the target or deactivate sudo.'
53
+ {
54
+ 'Sorry, try again' => 'Wrong sudo password.',
55
+ 'sudo: no tty present and no askpass program specified' =>
56
+ 'Sudo requires a password, please configure it.',
57
+ 'sudo: command not found' =>
58
+ "Can't find sudo command. Please either install and "\
59
+ 'configure it on the target or deactivate sudo.',
60
+ 'sudo: sorry, you must have a tty to run sudo' =>
61
+ 'Sudo requires a TTY. Please see the README on how to configure '\
62
+ 'sudo to allow for non-interactive usage.',
63
+ }.each do |sudo, human|
64
+ rawerr = human if rawerr.include? sudo
60
65
  end
61
66
 
62
67
  rawerr
@@ -6,7 +6,7 @@ require 'digest/sha2'
6
6
  require 'digest/md5'
7
7
 
8
8
  module Train::Extras
9
- class FileCommon
9
+ class FileCommon # rubocop:disable Metrics/ClassLength
10
10
  # interface methods: these fields should be implemented by every
11
11
  # backend File
12
12
  %w{
@@ -106,10 +106,23 @@ module Train::Extras
106
106
  !mounted.nil? && !mounted.stdout.nil? && !mounted.stdout.empty?
107
107
  end
108
108
 
109
+ def basename(suffix = nil, sep = '/')
110
+ fail 'Not yet supported: Suffix in file.basename' unless suffix.nil?
111
+ @basename ||= detect_filename(path, sep || '/')
112
+ end
113
+
109
114
  # helper methods provided to any implementing class
110
115
 
111
116
  private
112
117
 
118
+ def detect_filename(path, sep)
119
+ idx = path.rindex(sep)
120
+ return path if idx.nil?
121
+ idx += 1
122
+ return detect_filename(path[0..-2], sep) if idx == path.length
123
+ path[idx..-1]
124
+ end
125
+
113
126
  def target_type
114
127
  # Just return the type unless this is a symlink
115
128
  return type unless type == :symlink
@@ -2,6 +2,7 @@
2
2
  # author: Dominik Richter
3
3
  # author: Christoph Hartmann
4
4
 
5
+ require 'shellwords'
5
6
  require 'train/extras/stat'
6
7
 
7
8
  # PS C:\Users\Administrator> Get-Item -Path C:\test.txt | Select-Object -Property BaseName, FullName, IsReadOnly, Exists,
@@ -16,6 +17,10 @@ module Train::Extras
16
17
  @spath = Shellwords.escape(@path)
17
18
  end
18
19
 
20
+ def basename(suffix = nil, sep = '\\')
21
+ super(suffix, sep)
22
+ end
23
+
19
24
  def content
20
25
  return @content if defined?(@content)
21
26
  @content = @backend.run_command(
data/lib/train/version.rb CHANGED
@@ -3,5 +3,5 @@
3
3
  # Author:: Dominik Richter (<dominik.richter@gmail.com>)
4
4
 
5
5
  module Train
6
- VERSION = '0.9.6'
6
+ VERSION = '0.9.7'
7
7
  end
@@ -26,7 +26,7 @@ execute 'test ssh connection' do
26
26
  end
27
27
 
28
28
  # prepare a few users
29
- %w{ nopasswd passwd nosudo }.each do |name|
29
+ %w{ nopasswd passwd nosudo reqtty }.each do |name|
30
30
  user name do
31
31
  password '$1$7MCNTXPI$r./jqCEoVlLlByYKSL3sZ.'
32
32
  manage_home true
@@ -37,12 +37,20 @@ end
37
37
  sudo name do
38
38
  user '%'+name
39
39
  nopasswd true
40
+ defaults ['!requiretty']
40
41
  end
41
42
  end
42
43
 
43
44
  sudo 'passwd' do
44
45
  user 'passwd'
45
46
  nopasswd false
47
+ defaults ['!requiretty']
48
+ end
49
+
50
+ sudo 'reqtty' do
51
+ user 'reqtty'
52
+ nopasswd true
53
+ defaults ['requiretty']
46
54
  end
47
55
 
48
56
  # execute tests
@@ -61,10 +69,26 @@ execute 'run ssh tests' do
61
69
  cwd '/tmp/kitchen/data'
62
70
  end
63
71
 
64
- %w{passwd nopasswd}.each do |name|
72
+ %w{passwd nopasswd reqtty}.each do |name|
65
73
  execute "run local sudo tests as #{name}" do
66
74
  command "/opt/chef/embedded/bin/ruby -I lib test/integration/sudo/#{name}.rb"
67
75
  cwd '/tmp/kitchen/data'
68
76
  user name
69
77
  end
70
78
  end
79
+
80
+ execute 'fix sudoers for reqtty' do
81
+ command 'chef-apply contrib/fixup_requiretty.rb'
82
+ cwd '/tmp/kitchen/data'
83
+ environment(
84
+ 'TRAIN_SUDO_USER' => 'reqtty',
85
+ 'TRAIN_SUDO_VERY_MUCH' => 'yes',
86
+ )
87
+ end
88
+
89
+ # if it's fixed, it should behave like user 'nopasswd'
90
+ execute "run local sudo tests as reqtty, no longer requiring a tty" do
91
+ command "/opt/chef/embedded/bin/ruby -I lib test/integration/sudo/nopasswd.rb"
92
+ cwd '/tmp/kitchen/data'
93
+ user 'reqtty'
94
+ end
@@ -0,0 +1,17 @@
1
+ # encoding: utf-8
2
+ # author: Dominik Richter
3
+ # author: Christoph Hartmann
4
+ # author: Stephan Renatus
5
+
6
+ require_relative 'run_as'
7
+
8
+ describe 'run_command' do
9
+ it 'is running as non-root without sudo' do
10
+ run_as('whoami').stdout.wont_match /root/i
11
+ end
12
+
13
+ it 'is throwing an error trying to use sudo' do
14
+ err = ->{ run_as('whoami', { sudo: true }) }.must_raise Train::UserError
15
+ err.message.must_match /Sudo failed: Sudo requires a TTY. Please see the README/i
16
+ end
17
+ end
@@ -130,4 +130,50 @@ describe 'file common' do
130
130
  fc.unix_mode_mask('all', 'r').must_equal 0444
131
131
  end
132
132
  end
133
+
134
+ describe 'basename helper' do
135
+ def fc(path)
136
+ mockup(type: :file, path: path)
137
+ end
138
+
139
+ it 'works with an empty path' do
140
+ fc('').basename.must_equal ''
141
+ end
142
+
143
+ it 'separates a simple path (defaults to unix mode)' do
144
+ fc('/dir/file').basename.must_equal 'file'
145
+ end
146
+
147
+ it 'separates a simple path (Unix mode)' do
148
+ fc('/dir/file').basename(nil, '/').must_equal 'file'
149
+ end
150
+
151
+ it 'separates a simple path (Windows mode)' do
152
+ fc('C:\dir\file').basename(nil, '\\').must_equal 'file'
153
+ end
154
+
155
+ it 'identifies a folder name (Unix mode)' do
156
+ fc('/dir/file/').basename(nil, '/').must_equal 'file'
157
+ end
158
+
159
+ it 'identifies a folder name (Windows mode)' do
160
+ fc('C:\dir\file\\').basename(nil, '\\').must_equal 'file'
161
+ end
162
+
163
+ it 'ignores tailing separators (Unix mode)' do
164
+ fc('/dir/file///').basename(nil, '/').must_equal 'file'
165
+ end
166
+
167
+ it 'ignores tailing separators (Windows mode)' do
168
+ fc('C:\dir\file\\\\\\').basename(nil, '\\').must_equal 'file'
169
+ end
170
+
171
+ it 'doesnt work with backward slashes (Unix mode)' do
172
+ fc('C:\dir\file').basename(nil, '/').must_equal 'C:\\dir\file'
173
+ end
174
+
175
+ it 'doesnt work with forward slashes (Windows mode)' do
176
+ fc('/dir/file').basename(nil, '\\').must_equal '/dir/file'
177
+ end
178
+ end
133
179
  end
@@ -18,6 +18,14 @@ describe 'file common' do
18
18
  )
19
19
  end
20
20
 
21
+ it 'provides the full path' do
22
+ cls.new(backend, '/dir/file').path.must_equal '/dir/file'
23
+ end
24
+
25
+ it 'provides the basename to a unix path' do
26
+ cls.new(backend, '/dir/file').basename.must_equal 'file'
27
+ end
28
+
21
29
  it 'reads file contents' do
22
30
  out = rand.to_s
23
31
  backend.mock_command('cat path || echo -n', out)
@@ -0,0 +1,29 @@
1
+ # encoding: utf-8
2
+ require 'helper'
3
+ require 'train/transports/mock'
4
+ require 'train/extras'
5
+
6
+ describe 'file common' do
7
+ let(:cls) { Train::Extras::WindowsFile }
8
+ let(:backend) {
9
+ backend = Train::Transports::Mock.new.connection
10
+ backend.mock_os({ family: 'windows' })
11
+ backend
12
+ }
13
+
14
+ it 'provides the full path' do
15
+ cls.new(backend, 'C:\dir\file').path.must_equal 'C:\dir\file'
16
+ end
17
+
18
+ it 'provides the basename to a unix path' do
19
+ cls.new(backend, 'C:\dir\file').basename.must_equal 'file'
20
+ end
21
+
22
+ it 'reads file contents' do
23
+ out = rand.to_s
24
+ backend.mock_command('Get-Content("path") | Out-String', out)
25
+ cls.new(backend, 'path').content.must_equal out
26
+ end
27
+
28
+ # TODO: add all missing file tests!!
29
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: r-train
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.6
4
+ version: 0.9.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dominik Richter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-29 00:00:00.000000000 Z
11
+ date: 2016-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -276,6 +276,7 @@ files:
276
276
  - test/integration/helper.rb
277
277
  - test/integration/sudo/nopasswd.rb
278
278
  - test/integration/sudo/passwd.rb
279
+ - test/integration/sudo/reqtty.rb
279
280
  - test/integration/sudo/run_as.rb
280
281
  - test/integration/test-runner.yaml
281
282
  - test/integration/test_local.rb
@@ -295,6 +296,7 @@ files:
295
296
  - test/unit/extras/os_common_test.rb
296
297
  - test/unit/extras/os_detect_linux_test.rb
297
298
  - test/unit/extras/stat_test.rb
299
+ - test/unit/extras/windows_file_test.rb
298
300
  - test/unit/helper.rb
299
301
  - test/unit/plugins/connection_test.rb
300
302
  - test/unit/plugins/transport_test.rb
@@ -396,6 +398,7 @@ test_files:
396
398
  - test/integration/helper.rb
397
399
  - test/integration/sudo/nopasswd.rb
398
400
  - test/integration/sudo/passwd.rb
401
+ - test/integration/sudo/reqtty.rb
399
402
  - test/integration/sudo/run_as.rb
400
403
  - test/integration/test-runner.yaml
401
404
  - test/integration/test_local.rb
@@ -415,6 +418,7 @@ test_files:
415
418
  - test/unit/extras/os_common_test.rb
416
419
  - test/unit/extras/os_detect_linux_test.rb
417
420
  - test/unit/extras/stat_test.rb
421
+ - test/unit/extras/windows_file_test.rb
418
422
  - test/unit/helper.rb
419
423
  - test/unit/plugins/connection_test.rb
420
424
  - test/unit/plugins/transport_test.rb