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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f66c6692ec00c796550a364e5979acb85e9543c1
4
- data.tar.gz: 07bbd717fa000609bc99079929ed82aced1fa9ef
3
+ metadata.gz: 0ff66620e157ca71c03a36183c8471d5433beb12
4
+ data.tar.gz: 7881a2de96cb1a4eda8c0d3f8b3823fb40a1393b
5
5
  SHA512:
6
- metadata.gz: 7b6c63aaada973bbd9f65b7d76bc612d61c4be85f12a586ea4a8d3ee37bbc223e76a91a09c8a8815da24c0ed3d8ead4b2991aadbabf7cb761383a65643816d72
7
- data.tar.gz: ac924a78406ec0ddbe5f6a6080e7073343ee35cd2621415bd4c1aeb30d304e99457a499fb2e8be1e541eb764272bfe92173fa19ea3ac5a91195849f82844dbbd
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 = -> home do
5
- Cucumber::SSHD::Server.start home, wait_ready: @_sshd_wait_ready
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 @_sshd_fast && !$_sshd
9
- unless $_sshd
10
- $_sshd = start_server.call @_sshd_home
11
- at_exit { $_sshd.stop }
12
- end
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
- @_sshd = start_server.call @_sshd_home
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
- @_sshd.stop unless @_sshd_fast
26
+ $_sshd.stop unless ENV.key? 'CUCUMBER_SSHD_PERSIST'
21
27
  end
@@ -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
- attr_accessor :base_path, :host, :addr, :port, :pid
40
+ attr_reader :home
43
41
 
44
- def initialize base_path, wait_ready: false
45
- @base_path = base_path || BASE_PATH
46
- @host = HOST
47
- @addr = ENV.fetch 'CUCUMBER_SSHD_LISTEN', LISTEN_ADDR
48
- @port = ENV.fetch 'CUCUMBER_SSHD_PORT', PORT
49
- @pid = nil
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 base_path do
60
+ Dir.chdir home do
61
61
  @pid = fork do
62
- $stderr.reopen '/dev/null' unless ENV.key? 'CUCUMBER_SSHD_DEBUG'
62
+ $stderr.reopen '/dev/null' unless debug?
63
63
  exec command
64
64
  end
65
- if ENV.key? 'CUCUMBER_SSHD_DEBUG'
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 #{host}
94
+ Host #{HOST}
93
95
  HostName #{HOSTNAME}
94
96
  Port #{port}
95
- UserKnownHostsFile #{File.expand_path base_path}/#{SSH_KNOWN_HOSTS_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 base_path}/#{KEY_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 base_path} sh -c "cd ~; [ -f .ssh/rc ] && . .ssh/rc; $SSH_ORIGINAL_COMMAND"
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(base_path, path), mode: 0700
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
- !!@wait_ready
152
+ !!wait_ready
132
153
  end
133
154
 
134
155
  def write_file_secure path, content
135
- File.open File.join(base_path, path), ?w, 0600 do |file|
156
+ File.open File.join(home, path), ?w, 0600 do |file|
136
157
  file.write content
137
158
  end
138
159
  end
@@ -1,5 +1,5 @@
1
1
  module Cucumber
2
2
  module SSHD
3
- VERSION = '2.0.0.pre1'.freeze
3
+ VERSION = '2.0.0.pre2'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cucumber-sshd
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.pre1
4
+ version: 2.0.0.pre2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thibault Jouan