cucumber-sshd 1.1.1 → 2.0.0.pre4
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 +5 -5
- data/lib/cucumber/sshd/cucumber.rb +18 -12
- data/lib/cucumber/sshd/server.rb +108 -96
- data/lib/cucumber/sshd/version.rb +1 -1
- metadata +27 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8e13ed3049d6552756a9416a4ea6273b152045a0685cc47c8e571301dbd65676
|
4
|
+
data.tar.gz: dbdd82943fc074916e47a1863c889cf8169185c42658026ee5f43cade2b99337
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c88bdb30b7fa9d598bc325e3e220217b187e498d523960a3b424afa83feec0285c45db317082654d62adbb6ef25e01ebe1c09cca40ea51d17c9dc3bcf433049c
|
7
|
+
data.tar.gz: 3056bf120c760512aca97f1d2f038f4e16180d1fef2de886d257994046e23ad96db0584c2619f983ab4917cb45b527b90a3bdb46327d9130db7344473c9f82e4
|
@@ -1,21 +1,27 @@
|
|
1
1
|
require 'cucumber/sshd/server'
|
2
2
|
|
3
|
-
Before
|
4
|
-
start_server =
|
5
|
-
Cucumber::SSHD::Server.start
|
3
|
+
Before '@sshd' do
|
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
|
-
After
|
20
|
-
|
25
|
+
After '@sshd' do
|
26
|
+
$_sshd.stop unless ENV.key? 'CUCUMBER_SSHD_PERSIST'
|
21
27
|
end
|
data/lib/cucumber/sshd/server.rb
CHANGED
@@ -1,149 +1,161 @@
|
|
1
|
-
require 'aruba/api'
|
2
|
-
|
3
1
|
module Cucumber
|
4
2
|
module SSHD
|
5
3
|
class Server
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
SSH_KNOWN_HOSTS_PATH = '.ssh/known_host'
|
4
|
+
HOST = 'some_host.test'.freeze
|
5
|
+
HOSTNAME = 'localhost'.freeze
|
6
|
+
COMMAND = '/usr/sbin/sshd'.freeze
|
7
|
+
COMMAND_ARGS = '-Deq'.freeze
|
8
|
+
COMMAND_ARGS_DEBUG = '-De'.freeze
|
9
|
+
KEY_PATH = 'etc/ssh_host_rsa_key'.freeze
|
10
|
+
KEY_PUB_PATH = [KEY_PATH, '.pub'].join.freeze
|
11
|
+
SSHD_CONFIG_PATH = 'etc/sshd_config'.freeze
|
12
|
+
SSH_CONFIG_PATH = '.ssh/config'.freeze
|
13
|
+
SSH_KNOWN_HOSTS_PATH = '.ssh/known_hosts'.freeze
|
17
14
|
SFTP_SERVER_PATHS = %w[
|
18
15
|
/usr/libexec/sftp-server
|
19
16
|
/usr/lib/openssh/sftp-server
|
20
|
-
]
|
17
|
+
].freeze
|
18
|
+
|
19
|
+
KEY = <<-eoh.freeze
|
20
|
+
-----BEGIN EC PRIVATE KEY-----
|
21
|
+
MHcCAQEEIJbQy3yg9iU4xFvia9DWKWuhMzI5QGncR6OUldAOSIe7oAoGCCqGSM49
|
22
|
+
AwEHoUQDQgAEJpS8Sknl2X6PNurToQCNu5lX/scaJLr3FkiufD+p67epbwIjiyzo
|
23
|
+
qnLMVQddVitzQP7LEhXbNUuUAzEMfA6rAA==
|
24
|
+
-----END EC PRIVATE KEY-----
|
25
|
+
eoh
|
26
|
+
KEY_PUB =
|
27
|
+
'ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNT' \
|
28
|
+
'YAAABBBCaUvEpJ5dl+jzbq06EAjbuZV/7HGiS69xZIrnw/qeu3qW8CI4ss6KpyzFUH' \
|
29
|
+
'XVYrc0D+yxIV2zVLlAMxDHwOqwA='
|
30
|
+
|
21
31
|
class << self
|
22
|
-
def start
|
23
|
-
server = new
|
24
|
-
server.
|
32
|
+
def start *args
|
33
|
+
server = new args.shift, *args
|
34
|
+
server.configure
|
25
35
|
server.start
|
26
36
|
server
|
27
37
|
end
|
28
38
|
end
|
29
39
|
|
30
|
-
|
40
|
+
attr_reader :home
|
31
41
|
|
32
|
-
def initialize(
|
33
|
-
|
34
|
-
|
35
|
-
@
|
36
|
-
@
|
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
|
37
50
|
@wait_ready = wait_ready
|
38
51
|
end
|
39
52
|
|
40
|
-
def
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
def wait_ready?
|
45
|
-
!!@wait_ready
|
53
|
+
def configure
|
54
|
+
%w[etc .ssh].map { |e| create_dir_secure e }
|
55
|
+
configure_server
|
56
|
+
configure_client
|
46
57
|
end
|
47
58
|
|
48
59
|
def start
|
49
|
-
|
60
|
+
Dir.chdir home do
|
50
61
|
@pid = fork do
|
51
|
-
$stderr.reopen '/dev/null'
|
62
|
+
$stderr.reopen '/dev/null' unless debug?
|
52
63
|
exec command
|
53
64
|
end
|
65
|
+
if debug?
|
66
|
+
sleep 0.05
|
67
|
+
fail "`#{command}` failed" if Process.waitpid pid, Process::WNOHANG
|
68
|
+
end
|
54
69
|
end
|
55
|
-
|
70
|
+
print_server_info if debug?
|
56
71
|
wait_ready! if wait_ready?
|
57
72
|
end
|
58
73
|
|
59
|
-
def wait_ready!
|
60
|
-
TCPSocket.new 'localhost', port
|
61
|
-
rescue Errno::ECONNREFUSED
|
62
|
-
sleep 0.05
|
63
|
-
retry
|
64
|
-
end
|
65
|
-
|
66
74
|
def stop
|
67
|
-
Process.kill
|
68
|
-
Process.wait
|
75
|
+
Process.kill 'TERM', pid
|
76
|
+
Process.wait pid
|
69
77
|
end
|
70
78
|
|
71
|
-
|
72
|
-
%w[etc .ssh].map { |e| create_dir_secure e }
|
79
|
+
private
|
73
80
|
|
74
|
-
|
75
|
-
-----BEGIN RSA PRIVATE KEY-----
|
76
|
-
MIIEpAIBAAKCAQEA7EVDKeM7NYCGGVJw0wWLGCoptMFSR7DobhbEx2bAQbWDLFBF
|
77
|
-
7S9bXpW/ddebFA4GBkHVriNPwu/IGjIgO3tivVcy6iguNKdYRABlSfpeAs+OdCzK
|
78
|
-
hyEWhmKnFMZs2MhPiJg/KUep2gFZLoEcs9vkk37+cLcuUVkXVOSPXlYCuHjgkwaN
|
79
|
-
9ij/KvCcLP4tw83H3Pyh1Wn/Y4k1+3nWN2S3RgRHF9RjEx7nm2FmXcZq1wygPe5G
|
80
|
-
2bQNvZKykL+wlKIHwKiM4AWpVClczOiljNv9KROhGWanIZNNBIDTnikxFvY0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AHc/zwpsZtO/VUE3e3rknqiIUl
|
96
|
-
zIc71D3G3+JOZunQA1xVOhSb+SrgHYBibu6Ej3a/MqeBRXkZ6gm6r7AsF9LU0SLl
|
97
|
-
2fsMKzA9vVgfbNwaMmS6yQ+WjUbb7hghJlmtQ+So6N5n2AaJHKaADmJuZmJGwAg6
|
98
|
-
k1ZexGECgYAFc+GjjFOPxC+Qg6z8261PnDffBK0o+0/EIq3cGA7Cp5pEo/hhMjDl
|
99
|
-
W7CLjAGkok9W+rr9XwwXWCBuJmPh2jYeNaQljrHt9hIAOAxoYdbweb9oSo5SkcHv
|
100
|
-
iDjcFK8S1e5vnlZAh9xH1WMCEsaz1WNqWm7CZOayN2LFn6Ed9seYYg==
|
101
|
-
-----END RSA PRIVATE KEY-----
|
102
|
-
eoh
|
81
|
+
attr_reader :addr, :port, :debug, :persist, :wait_ready, :pid
|
103
82
|
|
104
|
-
|
105
|
-
|
83
|
+
def command
|
84
|
+
[
|
85
|
+
COMMAND,
|
86
|
+
'-f',
|
87
|
+
SSHD_CONFIG_PATH,
|
88
|
+
(debug? ? COMMAND_ARGS_DEBUG : COMMAND_ARGS)
|
89
|
+
].join ' '
|
90
|
+
end
|
91
|
+
|
92
|
+
def configure_client
|
93
|
+
write_file_secure SSH_CONFIG_PATH, <<-eoh
|
94
|
+
Host #{HOST}
|
95
|
+
HostName #{HOSTNAME}
|
96
|
+
Port #{port}
|
97
|
+
UserKnownHostsFile #{File.expand_path home}/#{SSH_KNOWN_HOSTS_PATH}
|
106
98
|
eoh
|
99
|
+
write_file_secure SSH_KNOWN_HOSTS_PATH, "[#{HOSTNAME}]:2222 #{KEY_PUB}"
|
100
|
+
end
|
107
101
|
|
102
|
+
def configure_server
|
103
|
+
write_file_secure KEY_PATH, KEY
|
104
|
+
write_file_secure KEY_PUB_PATH, KEY_PUB
|
108
105
|
write_file_secure SSHD_CONFIG_PATH, <<-eoh
|
109
106
|
Port #{port}
|
110
|
-
ListenAddress
|
111
|
-
|
107
|
+
ListenAddress #{addr}
|
112
108
|
Protocol 2
|
113
|
-
HostKey #{File.expand_path
|
109
|
+
HostKey #{File.expand_path home}/#{KEY_PATH}
|
114
110
|
PidFile /dev/null
|
115
111
|
UsePrivilegeSeparation no
|
116
112
|
Subsystem sftp #{sftp_server_path}
|
117
|
-
ForceCommand HOME=#{File.expand_path
|
113
|
+
ForceCommand HOME=#{File.expand_path home} sh -c "cd ~; [ -f .ssh/rc ] && . .ssh/rc; $SSH_ORIGINAL_COMMAND"
|
118
114
|
eoh
|
115
|
+
end
|
119
116
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
Port #{port}
|
124
|
-
UserKnownHostsFile #{File.expand_path base_path}/#{SSH_KNOWN_HOSTS_PATH}
|
125
|
-
eoh
|
117
|
+
def create_dir_secure path
|
118
|
+
FileUtils.mkdir_p File.join(home, path), mode: 0700
|
119
|
+
end
|
126
120
|
|
127
|
-
|
128
|
-
|
129
|
-
eoh
|
121
|
+
def debug?
|
122
|
+
!!debug
|
130
123
|
end
|
131
124
|
|
125
|
+
def persist?
|
126
|
+
!!persist
|
127
|
+
end
|
132
128
|
|
133
|
-
|
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
|
138
|
+
end
|
134
139
|
|
135
|
-
def
|
136
|
-
|
137
|
-
|
140
|
+
def sftp_server_path
|
141
|
+
SFTP_SERVER_PATHS.detect { |e| File.exist? e }
|
142
|
+
end
|
143
|
+
|
144
|
+
def wait_ready!
|
145
|
+
TCPSocket.new HOSTNAME, port
|
146
|
+
rescue Errno::ECONNREFUSED
|
147
|
+
sleep 0.05
|
148
|
+
retry
|
138
149
|
end
|
139
150
|
|
140
|
-
def
|
141
|
-
|
142
|
-
chmod 0700, path
|
151
|
+
def wait_ready?
|
152
|
+
!!wait_ready
|
143
153
|
end
|
144
154
|
|
145
|
-
def
|
146
|
-
|
155
|
+
def write_file_secure path, content
|
156
|
+
File.open File.join(home, path), ?w, 0600 do |file|
|
157
|
+
file.write content
|
158
|
+
end
|
147
159
|
end
|
148
160
|
end
|
149
161
|
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cucumber-sshd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0.pre4
|
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-04-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: childprocess
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0
|
19
|
+
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: cucumber
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '10.4'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec-expectations
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.7'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.7'
|
55
69
|
description: Run an sshd server for scenarios tagged with @sshd
|
56
70
|
email: tj@a13.fr
|
57
71
|
executables: []
|
@@ -66,7 +80,7 @@ homepage: https://rubygems.org/gems/cucumber-sshd
|
|
66
80
|
licenses:
|
67
81
|
- BSD-3-Clause
|
68
82
|
metadata: {}
|
69
|
-
post_install_message:
|
83
|
+
post_install_message:
|
70
84
|
rdoc_options: []
|
71
85
|
require_paths:
|
72
86
|
- lib
|
@@ -77,13 +91,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
77
91
|
version: '0'
|
78
92
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
93
|
requirements:
|
80
|
-
- - "
|
94
|
+
- - ">"
|
81
95
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
96
|
+
version: 1.3.1
|
83
97
|
requirements: []
|
84
|
-
|
85
|
-
|
86
|
-
signing_key:
|
98
|
+
rubygems_version: 3.0.8
|
99
|
+
signing_key:
|
87
100
|
specification_version: 4
|
88
101
|
summary: Cucumber sshd helpers
|
89
102
|
test_files: []
|