sshkit-backends-netssh_global 0.1.1 → 0.2.0.pre.circleci20.20180622145523
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.circleci/config.yml +117 -0
- data/.gitignore +1 -0
- data/Brewfile +0 -3
- data/README.md +2 -0
- data/lib/sshkit/backends/netssh_global.rb +10 -14
- data/lib/sshkit/backends/version.rb +1 -1
- data/lib/sshkit/command_sudo_ssh_forward.rb +2 -10
- data/sshkit-backends-netssh_global.gemspec +1 -1
- data/test/functional/backends/test_netssh_global.rb +109 -21
- data/test/helper.rb +1 -1
- data/test/support/vagrant_wrapper.rb +5 -4
- data/test/unit/backends/test_netssh_global.rb +1 -1
- data/test/unit/test_command_sudo_ssh_forward.rb +70 -20
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c8e7804135495c932638591aaa07bac15b3b14ca2dc304037e305b505cc7578d
|
4
|
+
data.tar.gz: 30d99dfa5c8490f6afb0711e29c6b4e79900b9c7b2d4bdc6bded24290b54147c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2981248f2e792e4a41daac1c2b18b0be6075d998c3704b09f6ab7f15f6e31283eb152e690bdca1453b9bdf34ae7dcc10ee0d81ad63895212d699cda8d9f8caba
|
7
|
+
data.tar.gz: 0534a7474e214c748ac5642cafbb8f5719c37b912fb3ef731c6e29659eef8b957dc3dc4029944bc10fc830909fe6d22eddb9ff269f0492737d18d34e79b2de9b
|
@@ -0,0 +1,117 @@
|
|
1
|
+
version: 2
|
2
|
+
|
3
|
+
rubygems-login: &rubygems-login
|
4
|
+
run:
|
5
|
+
name: Login to RubyGems
|
6
|
+
command: |
|
7
|
+
mkdir ~/.gem
|
8
|
+
echo ":rubygems_api_key: $RUBYGEMS_API_KEY" > ~/.gem/credentials
|
9
|
+
chmod 0600 ~/.gem/credentials
|
10
|
+
|
11
|
+
install-git: &install-git
|
12
|
+
run: apk add --no-cache --no-progress git
|
13
|
+
|
14
|
+
defaults: &defaults
|
15
|
+
steps:
|
16
|
+
- *install-git
|
17
|
+
- checkout
|
18
|
+
- run: bundle check --path=vendor/bundle || bundle install --path=vendor/bundle
|
19
|
+
- run: bundle exec rake test
|
20
|
+
working_directory: ~/sshkit-backends-netssh_global
|
21
|
+
|
22
|
+
default-deploys: &default-deploys
|
23
|
+
docker:
|
24
|
+
- image: ruby:alpine
|
25
|
+
working_directory: ~/sshkit-backends-netssh_global
|
26
|
+
|
27
|
+
jobs:
|
28
|
+
deploy-gem:
|
29
|
+
<<: *default-deploys
|
30
|
+
steps:
|
31
|
+
- *install-git
|
32
|
+
- checkout
|
33
|
+
- *rubygems-login
|
34
|
+
- run:
|
35
|
+
name: Build gem
|
36
|
+
command: gem build "$CIRCLE_PROJECT_REPONAME".gemspec
|
37
|
+
- run:
|
38
|
+
name: Publish gem to RubyGems
|
39
|
+
command: |
|
40
|
+
package=$(ls -t1 "$CIRCLE_PROJECT_REPONAME"*.gem | head -1)
|
41
|
+
gem push "$CIRCLE_PROJECT_REPONAME"-"$(echo $CIRCLE_TAG | sed -e 's/v//')".gem
|
42
|
+
deploy-pre-release-gem:
|
43
|
+
<<: *default-deploys
|
44
|
+
steps:
|
45
|
+
- *install-git
|
46
|
+
- checkout
|
47
|
+
- *rubygems-login
|
48
|
+
- run:
|
49
|
+
name: Install gem-versioner
|
50
|
+
command: gem install gem-versioner
|
51
|
+
- run:
|
52
|
+
name: Build gem
|
53
|
+
command: PRE_RELEASE="$CIRCLE_BRANCH" gem build "$CIRCLE_PROJECT_REPONAME".gemspec
|
54
|
+
- run:
|
55
|
+
name: Push pre-release gem to RubyGems
|
56
|
+
command: |
|
57
|
+
package=$(ls -t1 "$CIRCLE_PROJECT_REPONAME"*.gem | head -1)
|
58
|
+
gem push "$package"
|
59
|
+
test-ruby-2.2:
|
60
|
+
<<: *defaults
|
61
|
+
docker:
|
62
|
+
- image: ruby:2.2-alpine
|
63
|
+
test-ruby-2.3:
|
64
|
+
<<: *defaults
|
65
|
+
docker:
|
66
|
+
- image: ruby:2.3-alpine
|
67
|
+
test-ruby-2.4:
|
68
|
+
<<: *defaults
|
69
|
+
docker:
|
70
|
+
- image: ruby:2.4-alpine
|
71
|
+
test-ruby-2.5:
|
72
|
+
<<: *defaults
|
73
|
+
docker:
|
74
|
+
- image: ruby:2.5-alpine
|
75
|
+
|
76
|
+
workflows:
|
77
|
+
version: 2
|
78
|
+
test-then-release-gem:
|
79
|
+
jobs:
|
80
|
+
- test-ruby-2.2:
|
81
|
+
filters:
|
82
|
+
tags:
|
83
|
+
only: /^v\d+\.\d+\.\d\+/
|
84
|
+
- test-ruby-2.3:
|
85
|
+
filters:
|
86
|
+
tags:
|
87
|
+
only: /^v\d+\.\d+\.\d\+/
|
88
|
+
- test-ruby-2.4:
|
89
|
+
filters:
|
90
|
+
tags:
|
91
|
+
only: /^v\d+\.\d+\.\d\+/
|
92
|
+
- test-ruby-2.5:
|
93
|
+
filters:
|
94
|
+
tags:
|
95
|
+
only: /^v\d+\.\d+\.\d\+/
|
96
|
+
- deploy-gem:
|
97
|
+
context: org-global
|
98
|
+
filters:
|
99
|
+
branches:
|
100
|
+
ignore: /.*/
|
101
|
+
tags:
|
102
|
+
only: /^v\d+\.\d+\.\d\+/
|
103
|
+
requires:
|
104
|
+
- test-ruby-2.2
|
105
|
+
- test-ruby-2.3
|
106
|
+
- test-ruby-2.4
|
107
|
+
- test-ruby-2.5
|
108
|
+
- deploy-pre-release-gem:
|
109
|
+
context: org-global
|
110
|
+
filters:
|
111
|
+
branches:
|
112
|
+
ignore: master
|
113
|
+
requires:
|
114
|
+
- test-ruby-2.2
|
115
|
+
- test-ruby-2.3
|
116
|
+
- test-ruby-2.4
|
117
|
+
- test-ruby-2.5
|
data/.gitignore
CHANGED
data/Brewfile
CHANGED
data/README.md
CHANGED
@@ -37,6 +37,8 @@ rake
|
|
37
37
|
```ruby
|
38
38
|
require 'sshkit/backends/netssh_global'
|
39
39
|
|
40
|
+
set :sshkit_backend, SSHKit::Backend::NetsshGlobal
|
41
|
+
|
40
42
|
SSHKit::Backend::NetsshGlobal.configure do |config|
|
41
43
|
config.owner = 'bob' # Which user to sudo as for every command
|
42
44
|
config.directory = '/home/bob' # Can be specified if it is important to default commands to run in a
|
@@ -8,7 +8,7 @@ module SSHKit
|
|
8
8
|
attr_writer :ssh_commands
|
9
9
|
|
10
10
|
def ssh_commands
|
11
|
-
@ssh_commands
|
11
|
+
@ssh_commands ||= [:ssh, :git, :'ssh-add', :bundle]
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
@@ -50,16 +50,13 @@ module SSHKit
|
|
50
50
|
|
51
51
|
def with_ssh
|
52
52
|
configure_host
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
)
|
59
|
-
|
60
|
-
yield conn.connection
|
61
|
-
ensure
|
62
|
-
self.class.pool.checkin conn
|
53
|
+
self.class.pool.with(
|
54
|
+
Net::SSH.method(:start),
|
55
|
+
String(host.hostname),
|
56
|
+
host.username,
|
57
|
+
host.netssh_options
|
58
|
+
) do |connection|
|
59
|
+
yield connection
|
63
60
|
end
|
64
61
|
end
|
65
62
|
|
@@ -69,8 +66,7 @@ module SSHKit
|
|
69
66
|
end
|
70
67
|
end
|
71
68
|
|
72
|
-
def command(
|
73
|
-
options = args.extract_options!
|
69
|
+
def command(args, options)
|
74
70
|
options.merge!(
|
75
71
|
in: pwd,
|
76
72
|
env: @env,
|
@@ -80,7 +76,7 @@ module SSHKit
|
|
80
76
|
ssh_commands: property(:ssh_commands),
|
81
77
|
shell: property(:shell)
|
82
78
|
)
|
83
|
-
SSHKit::CommandSudoSshForward.new(*[
|
79
|
+
SSHKit::CommandSudoSshForward.new(*args.concat([options]))
|
84
80
|
end
|
85
81
|
end
|
86
82
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'sshkit'
|
2
|
+
|
1
3
|
module SSHKit
|
2
4
|
class CommandSudoSshForward < SSHKit::Command
|
3
5
|
def to_command
|
@@ -20,16 +22,6 @@ module SSHKit
|
|
20
22
|
end
|
21
23
|
end
|
22
24
|
|
23
|
-
def environment_string
|
24
|
-
environment_hash.collect do |key,value|
|
25
|
-
if key.is_a? Symbol
|
26
|
-
"#{key.to_s.upcase}=#{value}"
|
27
|
-
else
|
28
|
-
"#{key.to_s}=#{value}"
|
29
|
-
end
|
30
|
-
end.join(' ')
|
31
|
-
end
|
32
|
-
|
33
25
|
def environment_hash
|
34
26
|
default_env.merge(options_env)
|
35
27
|
end
|
@@ -21,7 +21,7 @@ then need to sudo to a different identity for each command.}
|
|
21
21
|
|
22
22
|
gem.add_runtime_dependency('sshkit', '~> 1.11')
|
23
23
|
|
24
|
-
gem.add_development_dependency('minitest',
|
24
|
+
gem.add_development_dependency('minitest', '>= 2.11.3', '< 5.11.0')
|
25
25
|
gem.add_development_dependency('rake')
|
26
26
|
gem.add_development_dependency('turn')
|
27
27
|
gem.add_development_dependency('mocha')
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require_relative '../../helper'
|
2
2
|
require 'securerandom'
|
3
3
|
|
4
4
|
require 'sshkit/backends/netssh_global'
|
@@ -8,6 +8,10 @@ module SSHKit
|
|
8
8
|
class TestNetsshGlobalFunctional < FunctionalTest
|
9
9
|
def setup
|
10
10
|
super
|
11
|
+
@output = String.new
|
12
|
+
SSHKit.config.output_verbosity = :debug
|
13
|
+
SSHKit.config.output = SSHKit::Formatter::SimpleText.new(@output)
|
14
|
+
|
11
15
|
NetsshGlobal.configure do |config|
|
12
16
|
config.owner = a_user
|
13
17
|
config.directory = nil
|
@@ -32,18 +36,36 @@ module SSHKit
|
|
32
36
|
VagrantWrapper.hosts['one']
|
33
37
|
end
|
34
38
|
|
35
|
-
def
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
39
|
+
def test_simple_netssh
|
40
|
+
NetsshGlobal.new(a_host) do
|
41
|
+
execute 'date'
|
42
|
+
execute :ls, '-l'
|
43
|
+
with rails_env: :production do
|
44
|
+
within '/tmp' do
|
45
|
+
as :root do
|
46
|
+
execute :touch, 'restart.txt'
|
47
|
+
end
|
48
|
+
end
|
45
49
|
end
|
46
|
-
end
|
50
|
+
end.run
|
51
|
+
|
52
|
+
command_lines = @output.lines.select { |line| line.start_with?('Command:') }
|
53
|
+
assert_equal [
|
54
|
+
"Command: sudo -u owner -- sh -c '/usr/bin/env date'\n",
|
55
|
+
"Command: sudo -u owner -- sh -c '/usr/bin/env ls -l'\n",
|
56
|
+
"Command: if test ! -d /tmp; then echo \"Directory does not exist '/tmp'\" 1>&2; false; fi\n",
|
57
|
+
"Command: if ! sudo -u root whoami > /dev/null; then echo \"You cannot switch to user 'root' using sudo, please check the sudoers file\" 1>&2; false; fi\n",
|
58
|
+
"Command: cd /tmp && sudo -u root RAILS_ENV=\"production\" -- sh -c '/usr/bin/env touch restart.txt'\n"
|
59
|
+
], command_lines
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_capture
|
63
|
+
captured_command_result = nil
|
64
|
+
NetsshGlobal.new(a_host) do |_host|
|
65
|
+
captured_command_result = capture(:uname)
|
66
|
+
end.run
|
67
|
+
|
68
|
+
assert_includes %W(Linux Darwin), captured_command_result
|
47
69
|
end
|
48
70
|
|
49
71
|
def test_ssh_option_merge
|
@@ -54,7 +76,20 @@ module SSHKit
|
|
54
76
|
capture(:uname)
|
55
77
|
host_ssh_options = host.ssh_options
|
56
78
|
end.run
|
57
|
-
assert_equal
|
79
|
+
assert_equal [:forward_agent, :paranoid, :known_hosts, :logger, :password_prompt].sort, host_ssh_options.keys.sort
|
80
|
+
assert_equal false, host_ssh_options[:forward_agent]
|
81
|
+
assert_equal true, host_ssh_options[:paranoid]
|
82
|
+
assert_instance_of SSHKit::Backend::Netssh::KnownHosts, host_ssh_options[:known_hosts]
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_env_vars_substituion_in_subshell
|
86
|
+
captured_command_result = nil
|
87
|
+
NetsshGlobal.new(a_host) do |_host|
|
88
|
+
with some_env_var: :some_value do
|
89
|
+
captured_command_result = capture(:echo, '$SOME_ENV_VAR')
|
90
|
+
end
|
91
|
+
end.run
|
92
|
+
assert_equal "some_value", captured_command_result
|
58
93
|
end
|
59
94
|
|
60
95
|
def test_configure_owner_via_global_config
|
@@ -152,14 +187,6 @@ module SSHKit
|
|
152
187
|
assert(result, 'Expected test to execute as "owner", but it did not')
|
153
188
|
end
|
154
189
|
|
155
|
-
def test_test_executes_as_ssh_user_when_command_contains_spaces
|
156
|
-
result = NetsshGlobal.new(a_host) do
|
157
|
-
test 'test "$USER" = "vagrant"'
|
158
|
-
end.run
|
159
|
-
|
160
|
-
assert(result, 'Expected test to execute as "vagrant", but it did not')
|
161
|
-
end
|
162
|
-
|
163
190
|
def test_upload_file
|
164
191
|
file_contents = ""
|
165
192
|
file_owner = nil
|
@@ -225,6 +252,42 @@ module SSHKit
|
|
225
252
|
assert_equal a_user, file_owner
|
226
253
|
end
|
227
254
|
|
255
|
+
def test_upload_and_then_capture_file_contents
|
256
|
+
actual_file_contents = ""
|
257
|
+
actual_file_owner = nil
|
258
|
+
file_name = File.join("/tmp", SecureRandom.uuid)
|
259
|
+
File.open file_name, 'w+' do |f|
|
260
|
+
f.write "Some Content\nWith a newline and trailing spaces \n "
|
261
|
+
end
|
262
|
+
NetsshGlobal.new(a_host) do
|
263
|
+
upload!(file_name, file_name)
|
264
|
+
actual_file_contents = capture(:cat, file_name, strip: false)
|
265
|
+
actual_file_owner = capture(:stat, '-c', '%U', file_name)
|
266
|
+
end.run
|
267
|
+
assert_equal "Some Content\nWith a newline and trailing spaces \n ", actual_file_contents
|
268
|
+
assert_equal a_user, actual_file_owner
|
269
|
+
end
|
270
|
+
|
271
|
+
def test_upload_within
|
272
|
+
file_name = SecureRandom.uuid
|
273
|
+
file_contents = "Some Content"
|
274
|
+
dir_name = SecureRandom.uuid
|
275
|
+
actual_file_contents = ""
|
276
|
+
actual_file_owner = nil
|
277
|
+
NetsshGlobal.new(a_host) do |_host|
|
278
|
+
within("/tmp") do
|
279
|
+
execute :mkdir, "-p", dir_name
|
280
|
+
within(dir_name) do
|
281
|
+
upload!(StringIO.new(file_contents), file_name)
|
282
|
+
end
|
283
|
+
end
|
284
|
+
actual_file_contents = capture(:cat, "/tmp/#{dir_name}/#{file_name}", strip: false)
|
285
|
+
actual_file_owner = capture(:stat, '-c', '%U', "/tmp/#{dir_name}/#{file_name}")
|
286
|
+
end.run
|
287
|
+
assert_equal file_contents, actual_file_contents
|
288
|
+
assert_equal a_user, actual_file_owner
|
289
|
+
end
|
290
|
+
|
228
291
|
def test_upload_string_io
|
229
292
|
file_contents = ""
|
230
293
|
file_owner = nil
|
@@ -255,6 +318,31 @@ module SSHKit
|
|
255
318
|
assert_equal File.open(file_name).read, file_contents
|
256
319
|
end
|
257
320
|
|
321
|
+
def test_upload_via_pathname
|
322
|
+
file_contents = ""
|
323
|
+
file_owner = nil
|
324
|
+
NetsshGlobal.new(a_host) do |_host|
|
325
|
+
file_name = Pathname.new(File.join("/tmp", SecureRandom.uuid))
|
326
|
+
upload!(StringIO.new('example_io'), file_name)
|
327
|
+
file_owner = capture(:stat, '-c', '%U', file_name)
|
328
|
+
file_contents = download!(file_name)
|
329
|
+
end.run
|
330
|
+
assert_equal "example_io", file_contents
|
331
|
+
assert_equal a_user, file_owner
|
332
|
+
end
|
333
|
+
|
334
|
+
def test_interaction_handler
|
335
|
+
captured_command_result = nil
|
336
|
+
NetsshGlobal.new(a_host) do
|
337
|
+
command = 'echo Enter Data; read the_data; echo Captured $the_data;'
|
338
|
+
captured_command_result = capture(command, interaction_handler: {
|
339
|
+
"Enter Data\n" => "SOME DATA\n",
|
340
|
+
"Captured SOME DATA\n" => nil
|
341
|
+
})
|
342
|
+
end.run
|
343
|
+
assert_equal("Enter Data\nCaptured SOME DATA", captured_command_result)
|
344
|
+
end
|
345
|
+
|
258
346
|
def test_ssh_forwarded_when_command_is_ssh_command
|
259
347
|
remote_ssh_output = ''
|
260
348
|
local_ssh_output = `ssh-add -l 2>&1`.strip
|
data/test/helper.rb
CHANGED
@@ -19,7 +19,7 @@ end
|
|
19
19
|
class FunctionalTest < MiniTest::Unit::TestCase
|
20
20
|
def setup
|
21
21
|
unless VagrantWrapper.running?
|
22
|
-
|
22
|
+
skip "Vagrant VMs are not running. Please, start it manually with `vagrant up`"
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
@@ -31,10 +31,11 @@ class VagrantWrapper
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def running?
|
34
|
-
@running
|
35
|
-
|
36
|
-
|
37
|
-
|
34
|
+
return @running unless @running.nil?
|
35
|
+
|
36
|
+
status = `#{vagrant_binary} status || true`
|
37
|
+
|
38
|
+
@running = status.include?('running')
|
38
39
|
end
|
39
40
|
|
40
41
|
def boxes_list
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require_relative '../helper'
|
2
2
|
require 'sshkit/command_sudo_ssh_forward'
|
3
3
|
|
4
4
|
module SSHKit
|
@@ -19,7 +19,7 @@ module SSHKit
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
def
|
22
|
+
def test_multiple_lines_are_stripped_of_extra_space_and_joined_by_semicolons
|
23
23
|
c = CommandSudoSshForward.new <<-EOHEREDOC
|
24
24
|
if test ! -d /var/log; then
|
25
25
|
echo "Example"
|
@@ -28,51 +28,68 @@ module SSHKit
|
|
28
28
|
assert_equal "if test ! -d /var/log; then; echo \"Example\"; fi", c.to_command
|
29
29
|
end
|
30
30
|
|
31
|
+
def test_leading_and_trailing_space_is_stripped
|
32
|
+
c = CommandSudoSshForward.new(" echo hi ")
|
33
|
+
assert_equal "echo hi", c.to_command
|
34
|
+
end
|
35
|
+
|
31
36
|
def test_including_the_env
|
32
37
|
SSHKit.config = nil
|
33
38
|
c = CommandSudoSshForward.new(:rails, 'server', env: {rails_env: :production})
|
34
|
-
assert_equal
|
39
|
+
assert_equal '( RAILS_ENV="production" /usr/bin/env rails server )', c.to_command
|
35
40
|
end
|
36
41
|
|
37
42
|
def test_including_the_env_with_multiple_keys
|
38
43
|
SSHKit.config = nil
|
39
44
|
c = CommandSudoSshForward.new(:rails, 'server', env: {rails_env: :production, foo: 'bar'})
|
40
|
-
assert_equal
|
45
|
+
assert_equal '( RAILS_ENV="production" FOO="bar" /usr/bin/env rails server )', c.to_command
|
41
46
|
end
|
42
47
|
|
43
48
|
def test_including_the_env_with_string_keys
|
44
49
|
SSHKit.config = nil
|
45
50
|
c = CommandSudoSshForward.new(:rails, 'server', env: {'FACTER_env' => :production, foo: 'bar'})
|
46
|
-
assert_equal
|
51
|
+
assert_equal '( FACTER_env="production" FOO="bar" /usr/bin/env rails server )', c.to_command
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_double_quotes_are_escaped_in_env
|
55
|
+
SSHKit.config = nil
|
56
|
+
c = CommandSudoSshForward.new(:rails, 'server', env: {foo: 'asdf"hjkl'})
|
57
|
+
assert_equal %{( FOO="asdf\\\"hjkl" /usr/bin/env rails server )}, c.to_command
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_percentage_symbol_handled_in_env
|
61
|
+
SSHKit.config = nil
|
62
|
+
c = Command.new(:rails, 'server', env: {foo: 'asdf%hjkl'}, user: "anotheruser")
|
63
|
+
assert_equal %{( export FOO="asdf%hjkl" ; sudo -u anotheruser FOO=\"asdf%hjkl\" -- sh -c '/usr/bin/env rails server' )}, c.to_command
|
47
64
|
end
|
48
65
|
|
49
66
|
def test_including_the_env_doesnt_addressively_escape
|
50
67
|
SSHKit.config = nil
|
51
68
|
c = CommandSudoSshForward.new(:rails, 'server', env: {path: '/example:$PATH'})
|
52
|
-
assert_equal
|
69
|
+
assert_equal '( PATH="/example:$PATH" /usr/bin/env rails server )', c.to_command
|
53
70
|
end
|
54
71
|
|
55
72
|
def test_global_env
|
56
73
|
SSHKit.config = nil
|
57
74
|
SSHKit.config.default_env = { default: 'env' }
|
58
75
|
c = CommandSudoSshForward.new(:rails, 'server', env: {})
|
59
|
-
assert_equal
|
76
|
+
assert_equal '( DEFAULT="env" /usr/bin/env rails server )', c.to_command
|
60
77
|
end
|
61
78
|
|
62
79
|
def test_default_env_is_overwritten_with_locally_defined
|
63
80
|
SSHKit.config.default_env = { foo: 'bar', over: 'under' }
|
64
81
|
c = CommandSudoSshForward.new(:rails, 'server', env: { over: 'write'})
|
65
|
-
assert_equal
|
82
|
+
assert_equal '( FOO="bar" OVER="write" /usr/bin/env rails server )', c.to_command
|
66
83
|
end
|
67
84
|
|
68
85
|
def test_working_in_a_given_directory
|
69
86
|
c = CommandSudoSshForward.new(:ls, '-l', in: "/opt/sites")
|
70
|
-
assert_equal
|
87
|
+
assert_equal 'cd /opt/sites && /usr/bin/env ls -l', c.to_command
|
71
88
|
end
|
72
89
|
|
73
90
|
def test_working_in_a_given_directory_with_env
|
74
91
|
c = CommandSudoSshForward.new(:ls, '-l', in: "/opt/sites", env: {a: :b})
|
75
|
-
assert_equal
|
92
|
+
assert_equal 'cd /opt/sites && ( A="b" /usr/bin/env ls -l )', c.to_command
|
76
93
|
end
|
77
94
|
|
78
95
|
def test_having_a_host_passed
|
@@ -93,12 +110,12 @@ module SSHKit
|
|
93
110
|
|
94
111
|
def test_working_as_a_given_group
|
95
112
|
c = CommandSudoSshForward.new(:whoami, group: :devvers)
|
96
|
-
assert_equal
|
113
|
+
assert_equal %q[sg devvers -c "/usr/bin/env whoami"], c.to_command
|
97
114
|
end
|
98
115
|
|
99
116
|
def test_working_as_a_given_user_and_group
|
100
117
|
c = CommandSudoSshForward.new(:whoami, user: :anotheruser, group: :devvers)
|
101
|
-
assert_equal
|
118
|
+
assert_equal %q[sudo -u anotheruser -- sh -c 'sg devvers -c "/usr/bin/env whoami"'], c.to_command
|
102
119
|
end
|
103
120
|
|
104
121
|
def test_umask
|
@@ -122,7 +139,7 @@ module SSHKit
|
|
122
139
|
def test_umask_with_env_and_working_directory_and_user
|
123
140
|
SSHKit.config.umask = '007'
|
124
141
|
c = CommandSudoSshForward.new(:touch, 'somefile', user: 'bob', env: {a: 'b'}, in: '/var')
|
125
|
-
assert_equal
|
142
|
+
assert_equal 'cd /var && umask 007 && sudo -u bob A="b" -- sh -c \'/usr/bin/env touch somefile\'', c.to_command
|
126
143
|
end
|
127
144
|
|
128
145
|
def test_verbosity_defaults_to_logger_info
|
@@ -167,16 +184,49 @@ module SSHKit
|
|
167
184
|
assert c.failed?
|
168
185
|
end
|
169
186
|
|
170
|
-
def
|
187
|
+
def test_on_stdout
|
188
|
+
c = CommandSudoSshForward.new(:whoami)
|
189
|
+
c.on_stdout(nil, "test\n")
|
190
|
+
c.on_stdout(nil, 'test2')
|
191
|
+
c.on_stdout(nil, 'test3')
|
192
|
+
assert_equal "test\ntest2test3", c.full_stdout
|
193
|
+
end
|
194
|
+
|
195
|
+
def test_on_stderr
|
171
196
|
c = CommandSudoSshForward.new(:whoami)
|
172
|
-
|
173
|
-
assert_equal
|
197
|
+
c.on_stderr(nil, 'test')
|
198
|
+
assert_equal 'test', c.full_stderr
|
174
199
|
end
|
175
200
|
|
176
|
-
def
|
201
|
+
def test_deprecated_stdtream_accessors
|
202
|
+
deprecation_out = ''
|
203
|
+
SSHKit.config.deprecation_output = deprecation_out
|
204
|
+
|
177
205
|
c = CommandSudoSshForward.new(:whoami)
|
178
|
-
|
179
|
-
assert_equal
|
206
|
+
c.stdout='a test'
|
207
|
+
assert_equal('a test', c.stdout)
|
208
|
+
c.stderr='another test'
|
209
|
+
assert_equal('another test', c.stderr)
|
210
|
+
deprecation_lines = deprecation_out.lines.to_a
|
211
|
+
|
212
|
+
assert_equal 8, deprecation_lines.size
|
213
|
+
assert_equal(
|
214
|
+
'[Deprecated] The stdout= method on Command is deprecated. ' +
|
215
|
+
"The @stdout attribute will be removed in a future release.\n",
|
216
|
+
deprecation_lines[0])
|
217
|
+
assert_equal(
|
218
|
+
'[Deprecated] The stdout method on Command is deprecated. ' +
|
219
|
+
"The @stdout attribute will be removed in a future release. Use full_stdout() instead.\n",
|
220
|
+
deprecation_lines[2])
|
221
|
+
|
222
|
+
assert_equal(
|
223
|
+
'[Deprecated] The stderr= method on Command is deprecated. ' +
|
224
|
+
"The @stderr attribute will be removed in a future release.\n",
|
225
|
+
deprecation_lines[4])
|
226
|
+
assert_equal(
|
227
|
+
'[Deprecated] The stderr method on Command is deprecated. ' +
|
228
|
+
"The @stderr attribute will be removed in a future release. Use full_stderr() instead.\n",
|
229
|
+
deprecation_lines[6])
|
180
230
|
end
|
181
231
|
|
182
232
|
def test_setting_exit_status
|
@@ -224,7 +274,7 @@ module SSHKit
|
|
224
274
|
assert_equal(
|
225
275
|
'setfacl -m fred:x $(dirname $SSH_AUTH_SOCK) && '\
|
226
276
|
'setfacl -m fred:rw $SSH_AUTH_SOCK && '\
|
227
|
-
|
277
|
+
'sudo -u fred SSH_AUTH_SOCK="$SSH_AUTH_SOCK" -- sh -c \'/usr/bin/env whoami\'', c.to_command
|
228
278
|
)
|
229
279
|
end
|
230
280
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sshkit-backends-netssh_global
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0.pre.circleci20.20180622145523
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Theo Cushion
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2018-06-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sshkit
|
@@ -34,7 +34,7 @@ dependencies:
|
|
34
34
|
version: 2.11.3
|
35
35
|
- - "<"
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version:
|
37
|
+
version: 5.11.0
|
38
38
|
type: :development
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -44,7 +44,7 @@ dependencies:
|
|
44
44
|
version: 2.11.3
|
45
45
|
- - "<"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 5.11.0
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: rake
|
50
50
|
requirement: !ruby/object:Gem::Requirement
|
@@ -97,6 +97,7 @@ executables: []
|
|
97
97
|
extensions: []
|
98
98
|
extra_rdoc_files: []
|
99
99
|
files:
|
100
|
+
- ".circleci/config.yml"
|
100
101
|
- ".gitignore"
|
101
102
|
- Brewfile
|
102
103
|
- Gemfile
|
@@ -129,12 +130,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
129
130
|
version: '0'
|
130
131
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
132
|
requirements:
|
132
|
-
- - "
|
133
|
+
- - ">"
|
133
134
|
- !ruby/object:Gem::Version
|
134
|
-
version:
|
135
|
+
version: 1.3.1
|
135
136
|
requirements: []
|
136
137
|
rubyforge_project:
|
137
|
-
rubygems_version: 2.
|
138
|
+
rubygems_version: 2.7.7
|
138
139
|
signing_key:
|
139
140
|
specification_version: 4
|
140
141
|
summary: SSHKit backend for globally sudoing commands
|
@@ -145,4 +146,3 @@ test_files:
|
|
145
146
|
- test/support/vagrant_wrapper.rb
|
146
147
|
- test/unit/backends/test_netssh_global.rb
|
147
148
|
- test/unit/test_command_sudo_ssh_forward.rb
|
148
|
-
has_rdoc:
|