cucumber-sshd 1.1.1 → 2.0.0.pre4

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
- SHA1:
3
- metadata.gz: 321a4a141c1314bef669e2deafa3204f4eb34c42
4
- data.tar.gz: 8f60fe0b843ac59113362ac7acb8f4bea807dfa2
2
+ SHA256:
3
+ metadata.gz: 8e13ed3049d6552756a9416a4ea6273b152045a0685cc47c8e571301dbd65676
4
+ data.tar.gz: dbdd82943fc074916e47a1863c889cf8169185c42658026ee5f43cade2b99337
5
5
  SHA512:
6
- metadata.gz: 7cb263a11ea35d808abcb98f7ffd7bd79f9fa67bbb378556e8db8752595f22ce359d39d46fcae4e3b4a9454bc7e8b8eb3410afe4f15a198e455f0c250c11c4a2
7
- data.tar.gz: ddb13966299aee8cf69c790c5b0628a58f951a486a7814b6aa38c180289a61c3cf382e354ee7241c0fff7c0275a82888cc2b967fbe8e4f5fe1ae5f2f5fe1af56
6
+ metadata.gz: c88bdb30b7fa9d598bc325e3e220217b187e498d523960a3b424afa83feec0285c45db317082654d62adbb6ef25e01ebe1c09cca40ea51d17c9dc3bcf433049c
7
+ data.tar.gz: 3056bf120c760512aca97f1d2f038f4e16180d1fef2de886d257994046e23ad96db0584c2619f983ab4917cb45b527b90a3bdb46327d9130db7344473c9f82e4
@@ -1,21 +1,27 @@
1
1
  require 'cucumber/sshd/server'
2
2
 
3
- Before('@sshd') do
4
- start_server = proc do
5
- Cucumber::SSHD::Server.start(expand_path('.'), wait_ready: @_sshd_wait_ready)
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 @_sshd_fast && !$_sshd
9
- unless $_sshd
10
- $_sshd = start_server.call
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
20
+ $_sshd.configure
21
+ $_sshd.start unless ENV.key? 'CUCUMBER_SSHD_PERSIST'
16
22
  end
17
23
  end
18
24
 
19
- After('@sshd') do
20
- @_sshd.stop unless @_sshd_fast
25
+ After '@sshd' do
26
+ $_sshd.stop unless ENV.key? 'CUCUMBER_SSHD_PERSIST'
21
27
  end
@@ -1,149 +1,161 @@
1
- require 'aruba/api'
2
-
3
1
  module Cucumber
4
2
  module SSHD
5
3
  class Server
6
- include Aruba::Api
7
-
8
- HOST = 'some_host.test'
9
- PORT = 2222
10
- COMMAND = '/usr/sbin/sshd'
11
- COMMAND_ARGS = '-Deq'
12
- KEY_PATH = 'etc/ssh_host_rsa_key'
13
- KEY_PUB_PATH = KEY_PATH.dup << '.pub'
14
- SSHD_CONFIG_PATH = 'etc/sshd_config'
15
- SSH_CONFIG_PATH = '.ssh/config'
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(*args)
23
- server = new(args.shift, *args)
24
- server.make_env
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
- attr_accessor :base_path, :host, :port, :pid
40
+ attr_reader :home
31
41
 
32
- def initialize(base_path, wait_ready: false)
33
- @base_path = base_path
34
- @host = ENV['SSHD_TEST_HOST'] ? ENV['SSHD_TEST_HOST'] : HOST
35
- @port = ENV['SSHD_TEST_PORT'] ? ENV['SSHD_TEST_PORT'] : PORT
36
- @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
37
50
  @wait_ready = wait_ready
38
51
  end
39
52
 
40
- def command
41
- "#{COMMAND} -f #{SSHD_CONFIG_PATH} #{COMMAND_ARGS}"
42
- end
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
- cd '.' do
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('TERM', pid)
68
- Process.wait(pid)
75
+ Process.kill 'TERM', pid
76
+ Process.wait pid
69
77
  end
70
78
 
71
- def make_env
72
- %w[etc .ssh].map { |e| create_dir_secure e }
79
+ private
73
80
 
74
- write_file_secure KEY_PATH, <<-eoh
75
- -----BEGIN RSA PRIVATE KEY-----
76
- MIIEpAIBAAKCAQEA7EVDKeM7NYCGGVJw0wWLGCoptMFSR7DobhbEx2bAQbWDLFBF
77
- 7S9bXpW/ddebFA4GBkHVriNPwu/IGjIgO3tivVcy6iguNKdYRABlSfpeAs+OdCzK
78
- hyEWhmKnFMZs2MhPiJg/KUep2gFZLoEcs9vkk37+cLcuUVkXVOSPXlYCuHjgkwaN
79
- 9ij/KvCcLP4tw83H3Pyh1Wn/Y4k1+3nWN2S3RgRHF9RjEx7nm2FmXcZq1wygPe5G
80
- 2bQNvZKykL+wlKIHwKiM4AWpVClczOiljNv9KROhGWanIZNNBIDTnikxFvY0FyoP
81
- 1qvRrE8BlqxNeyG/vYNmXsv8xpO0MOF65z3d2QIDAQABAoIBAHL8dmZxX0R3i0vR
82
- knUwsnQNOQTuPPQFBelmDViaCiEwjGlJm+6F6KrMqERarO+Cr63l5m98Y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BK0o+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
- write_file_secure KEY_PUB_PATH, <<-eoh
105
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDsRUMp4zs1gIYZUnDTBYsYKim0wVJHsOhuFsTHZsBBtYMsUEXtL1telb9115sUDgYGQdWuI0/C78gaMiA7e2K9VzLqKC40p1hEAGVJ+l4Cz450LMqHIRaGYqcUxmzYyE+ImD8pR6naAVkugRyz2+STfv5wty5RWRdU5I9eVgK4eOCTBo32KP8q8Jws/i3Dzcfc/KHVaf9jiTX7edY3ZLdGBEcX1GMTHuebYWZdxmrXDKA97kbZtA29krKQv7CUogfAqIzgBalUKVzM6KWM2/0pE6EZZqchk00EgNOeKTEW9jQXKg/Wq9GsTwGWrE17Ib+9g2Zey/zGk7Qw4XrnPd3Z
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 ::1
111
-
107
+ ListenAddress #{addr}
112
108
  Protocol 2
113
- HostKey #{File.expand_path base_path}/#{KEY_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 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"
118
114
  eoh
115
+ end
119
116
 
120
- write_file_secure SSH_CONFIG_PATH, <<-eoh
121
- Host #{host}
122
- HostName localhost
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
- write_file_secure SSH_KNOWN_HOSTS_PATH, <<-eoh
128
- [localhost]:2222 ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDsRUMp4zs1gIYZUnDTBYsYKim0wVJHsOhuFsTHZsBBtYMsUEXtL1telb9115sUDgYGQdWuI0/C78gaMiA7e2K9VzLqKC40p1hEAGVJ+l4Cz450LMqHIRaGYqcUxmzYyE+ImD8pR6naAVkugRyz2+STfv5wty5RWRdU5I9eVgK4eOCTBo32KP8q8Jws/i3Dzcfc/KHVaf9jiTX7edY3ZLdGBEcX1GMTHuebYWZdxmrXDKA97kbZtA29krKQv7CUogfAqIzgBalUKVzM6KWM2/0pE6EZZqchk00EgNOeKTEW9jQXKg/Wq9GsTwGWrE17Ib+9g2Zey/zGk7Qw4XrnPd3Z
129
- eoh
121
+ def debug?
122
+ !!debug
130
123
  end
131
124
 
125
+ def persist?
126
+ !!persist
127
+ end
132
128
 
133
- private
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 write_file_secure(path, content)
136
- write_file path, content
137
- chmod 0600, path
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 create_dir_secure(path)
141
- create_directory path
142
- chmod 0700, path
151
+ def wait_ready?
152
+ !!wait_ready
143
153
  end
144
154
 
145
- def sftp_server_path
146
- SFTP_SERVER_PATHS.detect { |e| File.exist? e } or SFTP_SERVER_PATHS.first
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
@@ -1,5 +1,5 @@
1
1
  module Cucumber
2
2
  module SSHD
3
- VERSION = '1.1.1'
3
+ VERSION = '2.0.0.pre4'.freeze
4
4
  end
5
5
  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: 1.1.1
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: 2015-07-14 00:00:00.000000000 Z
11
+ date: 2021-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: aruba
14
+ name: childprocess
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0.8'
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.8'
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: '0'
96
+ version: 1.3.1
83
97
  requirements: []
84
- rubyforge_project:
85
- rubygems_version: 2.4.5
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: []