cucumber-sshd 1.1.1 → 2.0.0.pre

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: 321a4a141c1314bef669e2deafa3204f4eb34c42
4
- data.tar.gz: 8f60fe0b843ac59113362ac7acb8f4bea807dfa2
3
+ metadata.gz: cc37a65b387332778989833f88297ebc5de1d15d
4
+ data.tar.gz: 8d4b5945eb138b9720e1b8fb41037afd9c023856
5
5
  SHA512:
6
- metadata.gz: 7cb263a11ea35d808abcb98f7ffd7bd79f9fa67bbb378556e8db8752595f22ce359d39d46fcae4e3b4a9454bc7e8b8eb3410afe4f15a198e455f0c250c11c4a2
7
- data.tar.gz: ddb13966299aee8cf69c790c5b0628a58f951a486a7814b6aa38c180289a61c3cf382e354ee7241c0fff7c0275a82888cc2b967fbe8e4f5fe1ae5f2f5fe1af56
6
+ metadata.gz: d8f34e74f453dfc253501894d3fe1d1bd61dd7bc6ed4cca2faf3aebc667031b568af0ca7ff7ec81d74f596f8eb87f20bb7adc9d4e64d63c9b5467b410f68fa27
7
+ data.tar.gz: e59c9c431835c47046aaeb371f28af948bb71ff6e4a5cad06e102b0c15120f24151fc50b388ec809651998aa7b58ca09f1672f5779a4614c00dbaa60c373d633
@@ -1,21 +1,21 @@
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 = -> home do
5
+ Cucumber::SSHD::Server.start home, wait_ready: @_sshd_wait_ready
6
6
  end
7
7
 
8
8
  if @_sshd_fast && !$_sshd
9
9
  unless $_sshd
10
- $_sshd = start_server.call
10
+ $_sshd = start_server.call @_sshd_home
11
11
  at_exit { $_sshd.stop }
12
12
  end
13
13
  @_sshd = $_sshd
14
14
  else
15
- @_sshd = start_server.call
15
+ @_sshd = start_server.call @_sshd_home
16
16
  end
17
17
  end
18
18
 
19
- After('@sshd') do
19
+ After '@sshd' do
20
20
  @_sshd.stop unless @_sshd_fast
21
21
  end
@@ -1,114 +1,108 @@
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'
4
+ BASE_PATH = 'tmp/home'.freeze
5
+ HOST = 'some_host.test'.freeze
6
+ HOSTNAME = 'localhost'.freeze
7
+ LISTEN_ADDR = '::1'.freeze
9
8
  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'
9
+ COMMAND = '/usr/sbin/sshd'.freeze
10
+ COMMAND_ARGS = '-Deq'.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_host'.freeze
17
16
  SFTP_SERVER_PATHS = %w[
18
17
  /usr/libexec/sftp-server
19
18
  /usr/lib/openssh/sftp-server
20
- ]
19
+ ].freeze
20
+
21
+ KEY = <<-eoh.freeze
22
+ -----BEGIN EC PRIVATE KEY-----
23
+ MHcCAQEEIJbQy3yg9iU4xFvia9DWKWuhMzI5QGncR6OUldAOSIe7oAoGCCqGSM49
24
+ AwEHoUQDQgAEJpS8Sknl2X6PNurToQCNu5lX/scaJLr3FkiufD+p67epbwIjiyzo
25
+ qnLMVQddVitzQP7LEhXbNUuUAzEMfA6rAA==
26
+ -----END EC PRIVATE KEY-----
27
+ eoh
28
+ KEY_PUB =
29
+ 'ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNT' \
30
+ 'YAAABBBCaUvEpJ5dl+jzbq06EAjbuZV/7HGiS69xZIrnw/qeu3qW8CI4ss6KpyzFUH' \
31
+ 'XVYrc0D+yxIV2zVLlAMxDHwOqwA='
32
+
21
33
  class << self
22
- def start(*args)
23
- server = new(args.shift, *args)
24
- server.make_env
34
+ def start *args
35
+ server = new args.shift, *args
36
+ server.configure
25
37
  server.start
26
38
  server
27
39
  end
28
40
  end
29
41
 
30
- attr_accessor :base_path, :host, :port, :pid
42
+ attr_accessor :base_path, :host, :addr, :port, :pid
31
43
 
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
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
36
49
  @pid = nil
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 base_path do
50
61
  @pid = fork do
51
- $stderr.reopen '/dev/null'
62
+ $stderr.reopen '/dev/null' unless ENV.key? 'CUCUMBER_SSHD_DEBUG'
52
63
  exec command
53
64
  end
65
+ if ENV.key? 'CUCUMBER_SSHD_DEBUG'
66
+ sleep 0.05
67
+ fail "`#{command}` failed" if Process.waitpid pid, Process::WNOHANG
68
+ end
54
69
  end
55
70
 
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+Cr63l5m98YfoWJkWR
83
- dZxdPT22rWHGMk6PzuYxZxoszgoCJ2skzWAcW1EFvBjhROHwAr0Qk1Ssut4NX/DB
84
- B04FS2X5HS2QCOuwNymqnpejtmk+A2hv9bGVzj0X614gX3h5+0dImGrYE0Lu+Abf
85
- 5fvWhN5nxgK5CVlU7WM09WxyHj9lBXI+W2dgTl6w3QJfBBQTkarLmDpwIeErq9xc
86
- al2qHj60nYC+RdFopuLfJWKiObdKRFpuPFYKbTA9nJz9T61zAF+LaDZ1mvdTuQmz
87
- jJEJ0nECgYEA+o2uJcDOCD2LBp2LqeQcGk1PrFLpSQ5921B10SxDWhygs2+UlBCW
88
- 7t/qurqjEUZ91l3TAlUM7ViB/EkXk/xWJRJCzlmWRXfht9LPQTWlnDox/w8uSV2g
89
- 3VwPx1xpju2PHO7Vsk6dsQsyoro14qNhYa9m1lBHA1TtJ/RLWauvnmUCgYEA8WgZ
90
- MthPXi/clDg2DlROGOEWd7WgaErEz578HWnegcMrHb8RV/XW21CO2UegHykzUlxz
91
- vJxAqhQeKJbP7T8uzuCZnkZqBqPh5PJT1XqxZibTeQvqYLzbIiKqmDrZWuRJvbLL
92
- kPxwYEG8R8nl9Dk1tLHuTQWWa5Q49he1cDss4GUCgYEA7WMBRZnIW3xb1Xe9VMjg
93
- a3cmbqHbj7FgQ0OXbQigA6euBnRIdITHTCnxDtw4Fe0Q2uLoQoRsjA/YkDx8T2S8
94
- BcGodDPjMYxk2rKsVR9L+poUtpEejLpd6H0KIhwHkzi26HXNGHRt6ckvP4hn94RO
95
- hqwWJiXHMnvrenh2T85fxRUCgYEA7m06NhWejhAHc/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
+ def command
82
+ [
83
+ COMMAND,
84
+ '-f',
85
+ SSHD_CONFIG_PATH,
86
+ COMMAND_ARGS
87
+ ].join ' '
88
+ end
103
89
 
104
- write_file_secure KEY_PUB_PATH, <<-eoh
105
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDsRUMp4zs1gIYZUnDTBYsYKim0wVJHsOhuFsTHZsBBtYMsUEXtL1telb9115sUDgYGQdWuI0/C78gaMiA7e2K9VzLqKC40p1hEAGVJ+l4Cz450LMqHIRaGYqcUxmzYyE+ImD8pR6naAVkugRyz2+STfv5wty5RWRdU5I9eVgK4eOCTBo32KP8q8Jws/i3Dzcfc/KHVaf9jiTX7edY3ZLdGBEcX1GMTHuebYWZdxmrXDKA97kbZtA29krKQv7CUogfAqIzgBalUKVzM6KWM2/0pE6EZZqchk00EgNOeKTEW9jQXKg/Wq9GsTwGWrE17Ib+9g2Zey/zGk7Qw4XrnPd3Z
90
+ def configure_client
91
+ write_file_secure SSH_CONFIG_PATH, <<-eoh
92
+ Host #{host}
93
+ HostName #{HOSTNAME}
94
+ Port #{port}
95
+ UserKnownHostsFile #{File.expand_path base_path}/#{SSH_KNOWN_HOSTS_PATH}
106
96
  eoh
97
+ write_file_secure SSH_KNOWN_HOSTS_PATH, "[#{HOSTNAME}]:2222 #{KEY_PUB}"
98
+ end
107
99
 
100
+ def configure_server
101
+ write_file_secure KEY_PATH, KEY
102
+ write_file_secure KEY_PUB_PATH, KEY_PUB
108
103
  write_file_secure SSHD_CONFIG_PATH, <<-eoh
109
104
  Port #{port}
110
- ListenAddress ::1
111
-
105
+ ListenAddress #{addr}
112
106
  Protocol 2
113
107
  HostKey #{File.expand_path base_path}/#{KEY_PATH}
114
108
  PidFile /dev/null
@@ -116,34 +110,31 @@ UsePrivilegeSeparation no
116
110
  Subsystem sftp #{sftp_server_path}
117
111
  ForceCommand HOME=#{File.expand_path base_path} sh -c "cd ~; [ -f .ssh/rc ] && . .ssh/rc; $SSH_ORIGINAL_COMMAND"
118
112
  eoh
119
-
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
126
-
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
130
113
  end
131
114
 
115
+ def create_dir_secure path
116
+ FileUtils.mkdir_p File.join(base_path, path), mode: 0700
117
+ end
132
118
 
133
- private
119
+ def sftp_server_path
120
+ SFTP_SERVER_PATHS.detect { |e| File.exist? e }
121
+ end
134
122
 
135
- def write_file_secure(path, content)
136
- write_file path, content
137
- chmod 0600, path
123
+ def wait_ready!
124
+ TCPSocket.new HOSTNAME, port
125
+ rescue Errno::ECONNREFUSED
126
+ sleep 0.05
127
+ retry
138
128
  end
139
129
 
140
- def create_dir_secure(path)
141
- create_directory path
142
- chmod 0700, path
130
+ def wait_ready?
131
+ !!@wait_ready
143
132
  end
144
133
 
145
- def sftp_server_path
146
- SFTP_SERVER_PATHS.detect { |e| File.exist? e } or SFTP_SERVER_PATHS.first
134
+ def write_file_secure path, content
135
+ File.open File.join(base_path, path), ?w, 0600 do |file|
136
+ file.write content
137
+ end
147
138
  end
148
139
  end
149
140
  end
@@ -1,5 +1,5 @@
1
1
  module Cucumber
2
2
  module SSHD
3
- VERSION = '1.1.1'
3
+ VERSION = '2.0.0.pre'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,17 +1,17 @@
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.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thibault Jouan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-14 00:00:00.000000000 Z
11
+ date: 2017-10-20 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
  - - "~>"
@@ -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: []
@@ -77,12 +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
98
  rubyforge_project:
85
- rubygems_version: 2.4.5
99
+ rubygems_version: 2.6.14
86
100
  signing_key:
87
101
  specification_version: 4
88
102
  summary: Cucumber sshd helpers