cucumber-sshd 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ /Gemfile-custom.rb
2
+ /Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ eval File.read('Gemfile-custom.rb') if File.exist?('Gemfile-custom.rb')
@@ -0,0 +1,16 @@
1
+ require File.expand_path('../lib/cucumber/sshd/version', __FILE__)
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'cucumber-sshd'
5
+ s.version = Cucumber::SSHD::VERSION.dup
6
+ s.summary = 'Cucumber sshd helpers'
7
+ s.description = 'Run an sshd server for scenarios tagged with @sshd'
8
+ s.homepage = 'https://rubygems.org/gems/cucumber-sshd'
9
+
10
+ s.authors = 'Thibault Jouan'
11
+ s.email = 'tj@a13.fr'
12
+
13
+ s.files = `git ls-files`.split $/
14
+
15
+ s.add_dependency 'aruba', '~> 0.5'
16
+ end
@@ -0,0 +1 @@
1
+ require 'cucumber/sshd/version'
@@ -0,0 +1,20 @@
1
+ require 'cucumber/sshd/server'
2
+
3
+ Before('@sshd') do
4
+ start_server = proc do
5
+ Cucumber::SSHD::Server.start(current_dir, wait_ready: @_sshd_wait_ready)
6
+ end
7
+
8
+ if @_sshd_fast && !@_sshd
9
+ @_sshd = start_server.call
10
+ at_exit { @_sshd.stop }
11
+ else
12
+ @_sshd = start_server.call
13
+ end
14
+
15
+ ENV['HOME'] = File.expand_path current_dir
16
+ end
17
+
18
+ After('@sshd') do
19
+ @_sshd.stop unless @_sshd_fast
20
+ end
@@ -0,0 +1,122 @@
1
+ module Cucumber
2
+ module SSHD
3
+ class Server
4
+ include Aruba::Api
5
+
6
+ HOST = 'some_host.test'
7
+ PORT = 2222
8
+ COMMAND = '/usr/sbin/sshd'
9
+ COMMAND_ARGS = '-Deq'
10
+ KEY_PATH = 'etc/ssh_host_rsa_key'
11
+ KEY_PUB_PATH = KEY_PATH.dup << '.pub'
12
+ SSHD_CONFIG_PATH = 'etc/sshd_config'
13
+ SSH_CONFIG_PATH = '.ssh/config'
14
+
15
+ class << self
16
+ def start(*args)
17
+ server = new(args.shift, *args)
18
+ server.make_env
19
+ server.start
20
+ server
21
+ end
22
+ end
23
+
24
+ attr_accessor :base_path, :host, :port, :pid
25
+
26
+ def initialize(base_path, wait_ready: false)
27
+ @base_path = base_path
28
+ @host = ENV['SSHD_TEST_HOST'] ? ENV['SSHD_TEST_HOST'] : HOST
29
+ @port = ENV['SSHD_TEST_PORT'] ? ENV['SSHD_TEST_PORT'] : PORT
30
+ @pid = nil
31
+ @wait_ready = wait_ready
32
+ end
33
+
34
+ def command
35
+ "#{COMMAND} -f #{SSHD_CONFIG_PATH} #{COMMAND_ARGS}"
36
+ end
37
+
38
+ def wait_ready?
39
+ !!@wait_ready
40
+ end
41
+
42
+ def start
43
+ in_current_dir do
44
+ @pid = fork do
45
+ $stderr.reopen '/dev/null'
46
+ exec command
47
+ end
48
+ end
49
+
50
+ wait_ready! if wait_ready?
51
+ end
52
+
53
+ def wait_ready!
54
+ TCPSocket.new 'localhost', port
55
+ rescue Errno::ECONNREFUSED
56
+ sleep 0.05
57
+ retry
58
+ end
59
+
60
+ def stop
61
+ Process.kill('TERM', pid)
62
+ Process.wait(pid)
63
+ end
64
+
65
+ def make_env
66
+ %w[etc .ssh].map { |e| create_dir e }
67
+
68
+ write_file KEY_PATH, <<-eoh
69
+ -----BEGIN RSA PRIVATE KEY-----
70
+ MIIEpAIBAAKCAQEA7EVDKeM7NYCGGVJw0wWLGCoptMFSR7DobhbEx2bAQbWDLFBF
71
+ 7S9bXpW/ddebFA4GBkHVriNPwu/IGjIgO3tivVcy6iguNKdYRABlSfpeAs+OdCzK
72
+ hyEWhmKnFMZs2MhPiJg/KUep2gFZLoEcs9vkk37+cLcuUVkXVOSPXlYCuHjgkwaN
73
+ 9ij/KvCcLP4tw83H3Pyh1Wn/Y4k1+3nWN2S3RgRHF9RjEx7nm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fxRUCgYEA7m06NhWejhAHc/zwpsZtO/VUE3e3rknqiIUl
90
+ zIc71D3G3+JOZunQA1xVOhSb+SrgHYBibu6Ej3a/MqeBRXkZ6gm6r7AsF9LU0SLl
91
+ 2fsMKzA9vVgfbNwaMmS6yQ+WjUbb7hghJlmtQ+So6N5n2AaJHKaADmJuZmJGwAg6
92
+ k1ZexGECgYAFc+GjjFOPxC+Qg6z8261PnDffBK0o+0/EIq3cGA7Cp5pEo/hhMjDl
93
+ W7CLjAGkok9W+rr9XwwXWCBuJmPh2jYeNaQljrHt9hIAOAxoYdbweb9oSo5SkcHv
94
+ iDjcFK8S1e5vnlZAh9xH1WMCEsaz1WNqWm7CZOayN2LFn6Ed9seYYg==
95
+ -----END RSA PRIVATE KEY-----
96
+ eoh
97
+
98
+ write_file KEY_PUB_PATH, <<-eoh
99
+ ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDsRUMp4zs1gIYZUnDTBYsYKim0wVJHsOhuFsTHZsBBtYMsUEXtL1telb9115sUDgYGQdWuI0/C78gaMiA7e2K9VzLqKC40p1hEAGVJ+l4Cz450LMqHIRaGYqcUxmzYyE+ImD8pR6naAVkugRyz2+STfv5wty5RWRdU5I9eVgK4eOCTBo32KP8q8Jws/i3Dzcfc/KHVaf9jiTX7edY3ZLdGBEcX1GMTHuebYWZdxmrXDKA97kbZtA29krKQv7CUogfAqIzgBalUKVzM6KWM2/0pE6EZZqchk00EgNOeKTEW9jQXKg/Wq9GsTwGWrE17Ib+9g2Zey/zGk7Qw4XrnPd3Z
100
+ eoh
101
+
102
+ write_file SSHD_CONFIG_PATH, <<-eoh
103
+ Port #{port}
104
+ ListenAddress ::1
105
+
106
+ Protocol 2
107
+ HostKey #{File.expand_path base_path}/#{KEY_PATH}
108
+ PidFile /dev/null
109
+ UsePrivilegeSeparation no
110
+ Subsystem sftp /usr/libexec/sftp-server
111
+ ForceCommand HOME=#{File.expand_path base_path} sh -c "cd ~; $SSH_ORIGINAL_COMMAND"
112
+ eoh
113
+
114
+ write_file SSH_CONFIG_PATH, <<-eoh
115
+ Host #{host}
116
+ HostName localhost
117
+ Port #{port}
118
+ eoh
119
+ end
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,5 @@
1
+ module Cucumber
2
+ module SSHD
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cucumber-sshd
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Thibault Jouan
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-04-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: aruba
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - "~>"
20
+ - !ruby/object:Gem::Version
21
+ version: '0.5'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '0.5'
30
+ description: Run an sshd server for scenarios tagged with @sshd
31
+ email: tj@a13.fr
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - ".gitignore"
37
+ - Gemfile
38
+ - cucumber-sshd.gemspec
39
+ - lib/cucumber/sshd.rb
40
+ - lib/cucumber/sshd/cucumber.rb
41
+ - lib/cucumber/sshd/server.rb
42
+ - lib/cucumber/sshd/version.rb
43
+ homepage: https://rubygems.org/gems/cucumber-sshd
44
+ licenses: []
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubyforge_project:
63
+ rubygems_version: 1.8.29
64
+ signing_key:
65
+ specification_version: 3
66
+ summary: Cucumber sshd helpers
67
+ test_files: []