cucumber-sshd 2.0.0.pre1 → 2.0.0.pre2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cucumber/sshd/cucumber.rb +16 -10
- data/lib/cucumber/sshd/server.rb +43 -22
- data/lib/cucumber/sshd/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ff66620e157ca71c03a36183c8471d5433beb12
|
4
|
+
data.tar.gz: 7881a2de96cb1a4eda8c0d3f8b3823fb40a1393b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d86dc8a1dd4f6cfc28c62e24338fa71e8d27e9d679a51f88c48590e78572cda44b83bfae35a8f28e471a7468d6e5013b69121a74640036a6c58b3cf3ba6ff1e
|
7
|
+
data.tar.gz: 36541831f940b689afa89024747c2af1d8b2835b36ca50f22f8f92cea3cab68ef4431d1693e55a3531ea2ead7a9928f8396e427e43b0861fb82d7bfd56de74f9
|
@@ -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,13 +1,11 @@
|
|
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
|
@@ -39,14 +37,16 @@ qnLMVQddVitzQP7LEhXbNUuUAzEMfA6rAA==
|
|
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
|