cucumber-sshd 2.0.0.pre1 → 2.0.0.pre5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/cucumber/sshd/cucumber.rb +16 -10
- data/lib/cucumber/sshd/server.rb +46 -25
- data/lib/cucumber/sshd/version.rb +1 -1
- metadata +6 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c4fc1f7d9977497a8e980b168f4fd208711ce56ffe64b32d276aeebc1b9baabb
|
4
|
+
data.tar.gz: 943a900e9f029576fe9d9954129c6926b8c5f893eda6ad6eee44f3b699d01517
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b32c97654027cbe8c7cebeacaf992d7a382a014c4c182e7adc1f2bc523ca999cc837dfb49addab9bd2090b7e4b5dff1bfb73ae0010dee4daa8414e6a5b821f16
|
7
|
+
data.tar.gz: 034c163a3488953f71227f5597dadf354992bcde25ab90523b3256a43a3c156ae40d38badfafdc43a9b78ce3cf3820070e9cd8fbad41a69aa0f34b4b8e92bc10
|
@@ -1,21 +1,27 @@
|
|
1
1
|
require 'cucumber/sshd/server'
|
2
2
|
|
3
3
|
Before '@sshd' do
|
4
|
-
start_server = ->
|
5
|
-
Cucumber::SSHD::Server.start
|
4
|
+
start_server = -> do
|
5
|
+
Cucumber::SSHD::Server.start \
|
6
|
+
home: ENV.fetch('CUCUMBER_SSHD_HOME', 'tmp/home'),
|
7
|
+
addr: ENV.fetch('CUCUMBER_SSHD_LISTEN', '::1'),
|
8
|
+
port: ENV.fetch('CUCUMBER_SSHD_PORT', 2222),
|
9
|
+
debug: ENV.key?('CUCUMBER_SSHD_DEBUG'),
|
10
|
+
persist: ENV.key?('CUCUMBER_SSHD_PERSIST'),
|
11
|
+
wait_ready: ENV.key?('CUCUMBER_SSHD_WAIT_READY')
|
6
12
|
end
|
7
13
|
|
8
|
-
if
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
@_sshd = $_sshd
|
14
|
+
if !$_sshd && ENV.key?('CUCUMBER_SSHD_PERSIST')
|
15
|
+
$_sshd = start_server.call
|
16
|
+
at_exit { $_sshd.stop }
|
17
|
+
elsif !$_sshd
|
18
|
+
$_sshd = start_server.call
|
14
19
|
else
|
15
|
-
|
20
|
+
$_sshd.configure
|
21
|
+
$_sshd.start unless ENV.key? 'CUCUMBER_SSHD_PERSIST'
|
16
22
|
end
|
17
23
|
end
|
18
24
|
|
19
25
|
After '@sshd' do
|
20
|
-
|
26
|
+
$_sshd.stop unless ENV.key? 'CUCUMBER_SSHD_PERSIST'
|
21
27
|
end
|
data/lib/cucumber/sshd/server.rb
CHANGED
@@ -1,18 +1,16 @@
|
|
1
1
|
module Cucumber
|
2
2
|
module SSHD
|
3
3
|
class Server
|
4
|
-
BASE_PATH = 'tmp/home'.freeze
|
5
4
|
HOST = 'some_host.test'.freeze
|
6
5
|
HOSTNAME = 'localhost'.freeze
|
7
|
-
LISTEN_ADDR = '::1'.freeze
|
8
|
-
PORT = 2222
|
9
6
|
COMMAND = '/usr/sbin/sshd'.freeze
|
10
7
|
COMMAND_ARGS = '-Deq'.freeze
|
8
|
+
COMMAND_ARGS_DEBUG = '-De'.freeze
|
11
9
|
KEY_PATH = 'etc/ssh_host_rsa_key'.freeze
|
12
10
|
KEY_PUB_PATH = [KEY_PATH, '.pub'].join.freeze
|
13
11
|
SSHD_CONFIG_PATH = 'etc/sshd_config'.freeze
|
14
12
|
SSH_CONFIG_PATH = '.ssh/config'.freeze
|
15
|
-
SSH_KNOWN_HOSTS_PATH = '.ssh/
|
13
|
+
SSH_KNOWN_HOSTS_PATH = '.ssh/known_hosts'.freeze
|
16
14
|
SFTP_SERVER_PATHS = %w[
|
17
15
|
/usr/libexec/sftp-server
|
18
16
|
/usr/lib/openssh/sftp-server
|
@@ -31,22 +29,24 @@ qnLMVQddVitzQP7LEhXbNUuUAzEMfA6rAA==
|
|
31
29
|
'XVYrc0D+yxIV2zVLlAMxDHwOqwA='
|
32
30
|
|
33
31
|
class << self
|
34
|
-
def start
|
35
|
-
server = new
|
32
|
+
def start options
|
33
|
+
server = new **options
|
36
34
|
server.configure
|
37
35
|
server.start
|
38
36
|
server
|
39
37
|
end
|
40
38
|
end
|
41
39
|
|
42
|
-
|
40
|
+
attr_reader :home
|
43
41
|
|
44
|
-
def initialize
|
45
|
-
|
46
|
-
|
47
|
-
@
|
48
|
-
@
|
49
|
-
@
|
42
|
+
def initialize(
|
43
|
+
home:, addr:, port:, debug: false, persist: false, wait_ready: false
|
44
|
+
)
|
45
|
+
@home = home
|
46
|
+
@addr = addr
|
47
|
+
@port = port
|
48
|
+
@debug = debug
|
49
|
+
@persist = persist
|
50
50
|
@wait_ready = wait_ready
|
51
51
|
end
|
52
52
|
|
@@ -57,17 +57,17 @@ qnLMVQddVitzQP7LEhXbNUuUAzEMfA6rAA==
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def start
|
60
|
-
Dir.chdir
|
60
|
+
Dir.chdir home do
|
61
61
|
@pid = fork do
|
62
|
-
$stderr.reopen '/dev/null' unless
|
62
|
+
$stderr.reopen '/dev/null' unless debug?
|
63
63
|
exec command
|
64
64
|
end
|
65
|
-
if
|
65
|
+
if debug?
|
66
66
|
sleep 0.05
|
67
67
|
fail "`#{command}` failed" if Process.waitpid pid, Process::WNOHANG
|
68
68
|
end
|
69
69
|
end
|
70
|
-
|
70
|
+
print_server_info if debug?
|
71
71
|
wait_ready! if wait_ready?
|
72
72
|
end
|
73
73
|
|
@@ -78,21 +78,23 @@ qnLMVQddVitzQP7LEhXbNUuUAzEMfA6rAA==
|
|
78
78
|
|
79
79
|
private
|
80
80
|
|
81
|
+
attr_reader :addr, :port, :debug, :persist, :wait_ready, :pid
|
82
|
+
|
81
83
|
def command
|
82
84
|
[
|
83
85
|
COMMAND,
|
84
86
|
'-f',
|
85
87
|
SSHD_CONFIG_PATH,
|
86
|
-
COMMAND_ARGS
|
88
|
+
(debug? ? COMMAND_ARGS_DEBUG : COMMAND_ARGS)
|
87
89
|
].join ' '
|
88
90
|
end
|
89
91
|
|
90
92
|
def configure_client
|
91
93
|
write_file_secure SSH_CONFIG_PATH, <<-eoh
|
92
|
-
Host #{
|
94
|
+
Host #{HOST}
|
93
95
|
HostName #{HOSTNAME}
|
94
96
|
Port #{port}
|
95
|
-
UserKnownHostsFile #{File.expand_path
|
97
|
+
UserKnownHostsFile #{File.expand_path home}/#{SSH_KNOWN_HOSTS_PATH}
|
96
98
|
eoh
|
97
99
|
write_file_secure SSH_KNOWN_HOSTS_PATH, "[#{HOSTNAME}]:2222 #{KEY_PUB}"
|
98
100
|
end
|
@@ -104,16 +106,35 @@ Host #{host}
|
|
104
106
|
Port #{port}
|
105
107
|
ListenAddress #{addr}
|
106
108
|
Protocol 2
|
107
|
-
HostKey #{File.expand_path
|
109
|
+
HostKey #{File.expand_path home}/#{KEY_PATH}
|
108
110
|
PidFile /dev/null
|
109
111
|
UsePrivilegeSeparation no
|
110
112
|
Subsystem sftp #{sftp_server_path}
|
111
|
-
ForceCommand HOME=#{File.expand_path
|
113
|
+
ForceCommand HOME=#{File.expand_path home} sh -c "cd ~; [ -f .ssh/rc ] && . .ssh/rc; $SSH_ORIGINAL_COMMAND"
|
112
114
|
eoh
|
113
115
|
end
|
114
116
|
|
115
117
|
def create_dir_secure path
|
116
|
-
FileUtils.mkdir_p File.join(
|
118
|
+
FileUtils.mkdir_p File.join(home, path), mode: 0700
|
119
|
+
end
|
120
|
+
|
121
|
+
def debug?
|
122
|
+
!!debug
|
123
|
+
end
|
124
|
+
|
125
|
+
def persist?
|
126
|
+
!!persist
|
127
|
+
end
|
128
|
+
|
129
|
+
def print_server_info
|
130
|
+
puts <<-eoh
|
131
|
+
CUCUMBER SSHD STARTING ---------------------------------------------------------
|
132
|
+
HOME: #{home}
|
133
|
+
LISTEN: #{addr}:#{port}
|
134
|
+
PERSIST: #{persist}
|
135
|
+
WAIT_READY: #{wait_ready}
|
136
|
+
--------------------------------------------------------------------------------
|
137
|
+
eoh
|
117
138
|
end
|
118
139
|
|
119
140
|
def sftp_server_path
|
@@ -128,11 +149,11 @@ ForceCommand HOME=#{File.expand_path base_path} sh -c "cd ~; [ -f .ssh/rc ] && .
|
|
128
149
|
end
|
129
150
|
|
130
151
|
def wait_ready?
|
131
|
-
|
152
|
+
!!wait_ready
|
132
153
|
end
|
133
154
|
|
134
155
|
def write_file_secure path, content
|
135
|
-
File.open File.join(
|
156
|
+
File.open File.join(home, path), ?w, 0600 do |file|
|
136
157
|
file.write content
|
137
158
|
end
|
138
159
|
end
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cucumber-sshd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.0.
|
4
|
+
version: 2.0.0.pre5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thibault Jouan
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-10-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: childprocess
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: cucumber
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,7 +66,7 @@ homepage: https://rubygems.org/gems/cucumber-sshd
|
|
80
66
|
licenses:
|
81
67
|
- BSD-3-Clause
|
82
68
|
metadata: {}
|
83
|
-
post_install_message:
|
69
|
+
post_install_message:
|
84
70
|
rdoc_options: []
|
85
71
|
require_paths:
|
86
72
|
- lib
|
@@ -95,9 +81,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
81
|
- !ruby/object:Gem::Version
|
96
82
|
version: 1.3.1
|
97
83
|
requirements: []
|
98
|
-
|
99
|
-
|
100
|
-
signing_key:
|
84
|
+
rubygems_version: 3.2.29
|
85
|
+
signing_key:
|
101
86
|
specification_version: 4
|
102
87
|
summary: Cucumber sshd helpers
|
103
88
|
test_files: []
|