cucumber-sshd 2.0.0.pre4 → 2.1.0

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
  SHA256:
3
- metadata.gz: 8e13ed3049d6552756a9416a4ea6273b152045a0685cc47c8e571301dbd65676
4
- data.tar.gz: dbdd82943fc074916e47a1863c889cf8169185c42658026ee5f43cade2b99337
3
+ metadata.gz: bdf66c3017c8748e8500c2afd205d4933a6e4620effbb8a52c1016fad5e81371
4
+ data.tar.gz: 46a7249f56a23a5c22a6803edc2ed721bd09795b2d13e26ee94236113baa74a2
5
5
  SHA512:
6
- metadata.gz: c88bdb30b7fa9d598bc325e3e220217b187e498d523960a3b424afa83feec0285c45db317082654d62adbb6ef25e01ebe1c09cca40ea51d17c9dc3bcf433049c
7
- data.tar.gz: 3056bf120c760512aca97f1d2f038f4e16180d1fef2de886d257994046e23ad96db0584c2619f983ab4917cb45b527b90a3bdb46327d9130db7344473c9f82e4
6
+ metadata.gz: ae3978de0a18792dfb0fe0721e967eff7b30064eae2ea945e2b0c642999e15a5c992a54e8777b28a664d6a56a8f2d7679a06015da17d65e793e7429d78b243f8
7
+ data.tar.gz: 4f4389002a3ab1378595397e77c1b1c015334f505653284f596f55809c0423629bdf510ee4fabd96fbd23972644ece6c0deb906da2e6a423a9ed0c3cf2b66b42
@@ -3,12 +3,11 @@ require 'cucumber/sshd/server'
3
3
  Before '@sshd' do
4
4
  start_server = -> do
5
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
+ 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')
12
11
  end
13
12
 
14
13
  if !$_sshd && ENV.key?('CUCUMBER_SSHD_PERSIST')
@@ -1,27 +1,29 @@
1
1
  module Cucumber
2
2
  module SSHD
3
3
  class Server
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
14
- SFTP_SERVER_PATHS = %w[
4
+ HOST = 'some_host.test'.freeze
5
+ HOSTNAME = 'localhost'.freeze
6
+ COMMAND = '/usr/sbin/sshd'.freeze
7
+ COMMAND_ARGS = '-De'.freeze
8
+ TMP_FILE_PREFIX = 'cucumber_sshd_'.freeze
9
+ WAIT_READY_DELAY = 0.005
10
+ WAIT_READY_TRIGGER = 'Server listening'.freeze
11
+ KEY_PATH = 'etc/ssh_host_rsa_key'.freeze
12
+ KEY_PUB_PATH = [KEY_PATH, '.pub'].join.freeze
13
+ SSHD_CONFIG_PATH = 'etc/sshd_config'.freeze
14
+ SSH_CONFIG_PATH = '.ssh/config'.freeze
15
+ SSH_KNOWN_HOSTS_PATH = '.ssh/known_hosts'.freeze
16
+ SFTP_SERVER_PATHS = %w[
15
17
  /usr/libexec/sftp-server
16
18
  /usr/lib/openssh/sftp-server
17
19
  ].freeze
18
20
 
19
- KEY = <<-eoh.freeze
20
- -----BEGIN EC PRIVATE KEY-----
21
- MHcCAQEEIJbQy3yg9iU4xFvia9DWKWuhMzI5QGncR6OUldAOSIe7oAoGCCqGSM49
22
- AwEHoUQDQgAEJpS8Sknl2X6PNurToQCNu5lX/scaJLr3FkiufD+p67epbwIjiyzo
23
- qnLMVQddVitzQP7LEhXbNUuUAzEMfA6rAA==
24
- -----END EC PRIVATE KEY-----
21
+ KEY = <<~eoh.freeze
22
+ -----BEGIN EC PRIVATE KEY-----
23
+ MHcCAQEEIJbQy3yg9iU4xFvia9DWKWuhMzI5QGncR6OUldAOSIe7oAoGCCqGSM49
24
+ AwEHoUQDQgAEJpS8Sknl2X6PNurToQCNu5lX/scaJLr3FkiufD+p67epbwIjiyzo
25
+ qnLMVQddVitzQP7LEhXbNUuUAzEMfA6rAA==
26
+ -----END EC PRIVATE KEY-----
25
27
  eoh
26
28
  KEY_PUB =
27
29
  'ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNT' \
@@ -29,8 +31,8 @@ qnLMVQddVitzQP7LEhXbNUuUAzEMfA6rAA==
29
31
  'XVYrc0D+yxIV2zVLlAMxDHwOqwA='
30
32
 
31
33
  class << self
32
- def start *args
33
- server = new args.shift, *args
34
+ def start options
35
+ server = new **options
34
36
  server.configure
35
37
  server.start
36
38
  server
@@ -40,14 +42,14 @@ qnLMVQddVitzQP7LEhXbNUuUAzEMfA6rAA==
40
42
  attr_reader :home
41
43
 
42
44
  def initialize(
43
- home:, addr:, port:, debug: false, persist: false, wait_ready: false
45
+ home:, addr:, port:, debug: false, persist: false
44
46
  )
45
- @home = home
46
- @addr = addr
47
- @port = port
48
- @debug = debug
49
- @persist = persist
50
- @wait_ready = wait_ready
47
+ @home = home
48
+ @addr = addr
49
+ @port = port
50
+ @debug = debug
51
+ @persist = persist
52
+ @stderr = Tempfile.new TMP_FILE_PREFIX
51
53
  end
52
54
 
53
55
  def configure
@@ -57,18 +59,11 @@ qnLMVQddVitzQP7LEhXbNUuUAzEMfA6rAA==
57
59
  end
58
60
 
59
61
  def start
62
+ print_server_info if debug?
60
63
  Dir.chdir home do
61
- @pid = fork do
62
- $stderr.reopen '/dev/null' unless debug?
63
- exec command
64
- end
65
- if debug?
66
- sleep 0.05
67
- fail "`#{command}` failed" if Process.waitpid pid, Process::WNOHANG
68
- end
64
+ @pid = spawn *command, err: @stderr
69
65
  end
70
- print_server_info if debug?
71
- wait_ready! if wait_ready?
66
+ wait_ready
72
67
  end
73
68
 
74
69
  def stop
@@ -78,23 +73,23 @@ qnLMVQddVitzQP7LEhXbNUuUAzEMfA6rAA==
78
73
 
79
74
  private
80
75
 
81
- attr_reader :addr, :port, :debug, :persist, :wait_ready, :pid
76
+ attr_reader :addr, :port, :debug, :persist, :pid
82
77
 
83
78
  def command
84
79
  [
85
80
  COMMAND,
86
81
  '-f',
87
82
  SSHD_CONFIG_PATH,
88
- (debug? ? COMMAND_ARGS_DEBUG : COMMAND_ARGS)
89
- ].join ' '
83
+ COMMAND_ARGS
84
+ ]
90
85
  end
91
86
 
92
87
  def configure_client
93
88
  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}
89
+ Host #{HOST}
90
+ HostName #{HOSTNAME}
91
+ Port #{port}
92
+ UserKnownHostsFile #{File.expand_path home}/#{SSH_KNOWN_HOSTS_PATH}
98
93
  eoh
99
94
  write_file_secure SSH_KNOWN_HOSTS_PATH, "[#{HOSTNAME}]:2222 #{KEY_PUB}"
100
95
  end
@@ -108,7 +103,6 @@ ListenAddress #{addr}
108
103
  Protocol 2
109
104
  HostKey #{File.expand_path home}/#{KEY_PATH}
110
105
  PidFile /dev/null
111
- UsePrivilegeSeparation no
112
106
  Subsystem sftp #{sftp_server_path}
113
107
  ForceCommand HOME=#{File.expand_path home} sh -c "cd ~; [ -f .ssh/rc ] && . .ssh/rc; $SSH_ORIGINAL_COMMAND"
114
108
  eoh
@@ -132,7 +126,7 @@ CUCUMBER SSHD STARTING ---------------------------------------------------------
132
126
  HOME: #{home}
133
127
  LISTEN: #{addr}:#{port}
134
128
  PERSIST: #{persist}
135
- WAIT_READY: #{wait_ready}
129
+ COMMAND: #{command.join ' '}
136
130
  --------------------------------------------------------------------------------
137
131
  eoh
138
132
  end
@@ -141,15 +135,11 @@ WAIT_READY: #{wait_ready}
141
135
  SFTP_SERVER_PATHS.detect { |e| File.exist? e }
142
136
  end
143
137
 
144
- def wait_ready!
145
- TCPSocket.new HOSTNAME, port
146
- rescue Errno::ECONNREFUSED
147
- sleep 0.05
148
- retry
149
- end
150
-
151
- def wait_ready?
152
- !!wait_ready
138
+ def wait_ready
139
+ loop do
140
+ break if (IO.read @stderr.path).include? WAIT_READY_TRIGGER
141
+ sleep WAIT_READY_DELAY
142
+ end
153
143
  end
154
144
 
155
145
  def write_file_secure path, content
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.pre4
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thibault Jouan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-02 00:00:00.000000000 Z
11
+ date: 2022-06-14 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
@@ -75,7 +61,6 @@ files:
75
61
  - lib/cucumber/sshd.rb
76
62
  - lib/cucumber/sshd/cucumber.rb
77
63
  - lib/cucumber/sshd/server.rb
78
- - lib/cucumber/sshd/version.rb
79
64
  homepage: https://rubygems.org/gems/cucumber-sshd
80
65
  licenses:
81
66
  - BSD-3-Clause
@@ -91,11 +76,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
91
76
  version: '0'
92
77
  required_rubygems_version: !ruby/object:Gem::Requirement
93
78
  requirements:
94
- - - ">"
79
+ - - ">="
95
80
  - !ruby/object:Gem::Version
96
- version: 1.3.1
81
+ version: '0'
97
82
  requirements: []
98
- rubygems_version: 3.0.8
83
+ rubygems_version: 3.3.14
99
84
  signing_key:
100
85
  specification_version: 4
101
86
  summary: Cucumber sshd helpers
@@ -1,5 +0,0 @@
1
- module Cucumber
2
- module SSHD
3
- VERSION = '2.0.0.pre4'.freeze
4
- end
5
- end