unobtainium 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +1 -0
- data/.rubocop.yml +3 -0
- data/Gemfile.lock +2 -2
- data/README.md +1 -1
- data/Rakefile +2 -0
- data/lib/unobtainium/drivers/phantom.rb +8 -1
- data/lib/unobtainium/support/port_scanner.rb +57 -13
- data/lib/unobtainium/support/runner.rb +11 -3
- data/lib/unobtainium/version.rb +1 -1
- data/spec/port_scanner_spec.rb +13 -12
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b7101f0e169ee18822dea81ce744bf8b86bab64a
|
4
|
+
data.tar.gz: 500258b36f1090ec08f3c51c23f40818e555c394
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a372094b13fa1d4faaa78e5478aee58df00bafff7a6efd3b05ae8f7371d309128eb4c486c44d8ba4b9a7c36ec83b63d22d8a4d36176cd3608ec3fcd160e154c4
|
7
|
+
data.tar.gz: 5e5a94cf7577499a32af36fd6e0115b3fecd39d880ec3e97c1d11ae746274c5331e38a1daad919faa0904e497157c001d2b4491cd9bc2e94e5572ef4cfbf957a
|
data/.codeclimate.yml
CHANGED
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
unobtainium (0.
|
4
|
+
unobtainium (0.5.0)
|
5
5
|
sys-proctable (~> 1.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -37,7 +37,7 @@ GEM
|
|
37
37
|
gherkin (3.2.0)
|
38
38
|
json (1.8.3)
|
39
39
|
mini_portile2 (2.0.0)
|
40
|
-
multi_json (1.
|
40
|
+
multi_json (1.12.0)
|
41
41
|
multi_test (0.1.2)
|
42
42
|
nokogiri (1.6.7.2)
|
43
43
|
mini_portile2 (~> 2.0.0.rc2)
|
data/README.md
CHANGED
@@ -92,7 +92,7 @@ details.
|
|
92
92
|
- [unobtainium-faraday](https://github.com/jfinkhaeuser/unobtainium-faraday) is
|
93
93
|
a faraday-based driver for dealing with RESTish APIs.
|
94
94
|
- [unobtainium-kramdown](https://github.com/jfinkhaeuser/unobtainium-kramdown) is
|
95
|
-
|
95
|
+
an open-uri-based driver for dealing with Markdown structured text.
|
96
96
|
|
97
97
|
# Credits
|
98
98
|
This gem is inspired by [LapisLazuli](https://github.com/spriteCloud/lapis-lazuli),
|
data/Rakefile
CHANGED
@@ -125,7 +125,14 @@ module Unobtainium
|
|
125
125
|
timeout -= 1
|
126
126
|
end
|
127
127
|
if timeout <= 0
|
128
|
-
|
128
|
+
runner.kill
|
129
|
+
out = runner.stdout.read
|
130
|
+
err = runner.stderr.read
|
131
|
+
runner.reset
|
132
|
+
|
133
|
+
raise "Timeout waiting to connect to PhantomJS!\n"\
|
134
|
+
"STDOUT: #{out}\n"\
|
135
|
+
"STDERR: #{err}"
|
129
136
|
end
|
130
137
|
|
131
138
|
# Run Selenium against server
|
@@ -57,22 +57,18 @@ module Unobtainium
|
|
57
57
|
end
|
58
58
|
|
59
59
|
# Test a socket for each domain
|
60
|
-
addr = Socket.sockaddr_in(port, host)
|
61
|
-
|
62
60
|
test_domains.each do |domain|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
return
|
70
|
-
ensure
|
71
|
-
if not sock.nil?
|
72
|
-
sock.close
|
73
|
-
end
|
61
|
+
addr = get_addr(host, port, domain)
|
62
|
+
if addr.nil?
|
63
|
+
next
|
64
|
+
end
|
65
|
+
|
66
|
+
if test_sockaddr(addr, domain)
|
67
|
+
return true
|
74
68
|
end
|
75
69
|
end
|
70
|
+
|
71
|
+
return false
|
76
72
|
end
|
77
73
|
|
78
74
|
##
|
@@ -155,6 +151,54 @@ module Unobtainium
|
|
155
151
|
|
156
152
|
return false
|
157
153
|
end
|
154
|
+
|
155
|
+
# Create an address for the domain. That's a little convoluted, but it
|
156
|
+
# avoids errors with trying to use INET addresses with INET6 and vice versa.
|
157
|
+
def get_addr(host, port, domain)
|
158
|
+
begin
|
159
|
+
infos = Addrinfo.getaddrinfo(host, port, domain, :STREAM)
|
160
|
+
infos.each do |info|
|
161
|
+
if info.pfamily == Socket.const_get('PF_' + domain.to_s)
|
162
|
+
return info.to_sockaddr
|
163
|
+
end
|
164
|
+
end
|
165
|
+
rescue SocketError
|
166
|
+
# Host does not resolve in this domain
|
167
|
+
return nil
|
168
|
+
end
|
169
|
+
|
170
|
+
return nil
|
171
|
+
end
|
172
|
+
|
173
|
+
# Test a particular sockaddr
|
174
|
+
def test_sockaddr(addr, domain)
|
175
|
+
sock = Socket.new(domain, :STREAM)
|
176
|
+
|
177
|
+
connected = false
|
178
|
+
loop do
|
179
|
+
begin
|
180
|
+
sock.connect_nonblock(addr)
|
181
|
+
rescue Errno::EINPROGRESS
|
182
|
+
if not IO.select(nil, [sock], nil, 1)
|
183
|
+
# Timed out, retry?
|
184
|
+
next
|
185
|
+
end
|
186
|
+
rescue Errno::EISCONN
|
187
|
+
connected = true
|
188
|
+
break
|
189
|
+
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
|
190
|
+
# Could not connect
|
191
|
+
break
|
192
|
+
rescue Errno::EINVAL, Errno::EAFNOSUPPORT
|
193
|
+
# Unsupported protocol
|
194
|
+
break
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
sock.close
|
199
|
+
|
200
|
+
return connected
|
201
|
+
end
|
158
202
|
end # module PortScanner
|
159
203
|
end # module Support
|
160
204
|
end # module Unobtainium
|
@@ -65,6 +65,9 @@ module Unobtainium
|
|
65
65
|
raise "Command already running!"
|
66
66
|
end
|
67
67
|
|
68
|
+
# Reset everything
|
69
|
+
reset
|
70
|
+
|
68
71
|
# Capture options; pipes for stdout and stderr
|
69
72
|
@stdout, @wout = IO.pipe
|
70
73
|
@stderr, @werr = IO.pipe
|
@@ -77,6 +80,13 @@ module Unobtainium
|
|
77
80
|
return @pid
|
78
81
|
end
|
79
82
|
|
83
|
+
##
|
84
|
+
# Resets stdout, stderr, etc. - does not kill a process, see #kill
|
85
|
+
# instead.
|
86
|
+
def reset
|
87
|
+
cleanup(true)
|
88
|
+
end
|
89
|
+
|
80
90
|
##
|
81
91
|
# Wait for the command to exit.
|
82
92
|
# @return [Process::Status] exit status of the command.
|
@@ -135,9 +145,6 @@ module Unobtainium
|
|
135
145
|
end
|
136
146
|
# rubocop:enable Lint/HandleExceptions
|
137
147
|
end
|
138
|
-
|
139
|
-
# Clean up everything
|
140
|
-
cleanup(true)
|
141
148
|
end
|
142
149
|
|
143
150
|
##
|
@@ -145,6 +152,7 @@ module Unobtainium
|
|
145
152
|
# Use together with Runtime class to clean up any commands at exit.
|
146
153
|
def destroy
|
147
154
|
kill
|
155
|
+
reset
|
148
156
|
end
|
149
157
|
|
150
158
|
private
|
data/lib/unobtainium/version.rb
CHANGED
data/spec/port_scanner_spec.rb
CHANGED
@@ -8,31 +8,32 @@ describe ::Unobtainium::Support::PortScanner do
|
|
8
8
|
def connect_mock(_, addr)
|
9
9
|
port, = Socket.unpack_sockaddr_in(addr)
|
10
10
|
if port == 1234 or port == 4321
|
11
|
-
|
11
|
+
raise Errno::EISCONN
|
12
12
|
end
|
13
13
|
raise Errno::ECONNREFUSED
|
14
14
|
end
|
15
15
|
|
16
16
|
describe "port_open?" do
|
17
17
|
it "detects an open port correctly" do
|
18
|
-
allow_any_instance_of(Socket).to receive(:
|
18
|
+
allow_any_instance_of(Socket).to receive(:connect_nonblock).and_raise(
|
19
|
+
Errno::EISCONN)
|
19
20
|
expect(tester.port_open?('localhost', 1234)).to be_truthy
|
20
21
|
end
|
21
22
|
|
22
23
|
it "detects a closed port correctly" do
|
23
|
-
allow_any_instance_of(Socket).to receive(:
|
24
|
+
allow_any_instance_of(Socket).to receive(:connect_nonblock).and_raise(
|
24
25
|
Errno::ECONNREFUSED)
|
25
26
|
expect(tester.port_open?('localhost', 1234)).to be_falsy
|
26
27
|
end
|
27
28
|
|
28
29
|
it "handles a single domain parameter" do
|
29
|
-
allow_any_instance_of(Socket).to receive(:
|
30
|
+
allow_any_instance_of(Socket).to receive(:connect_nonblock).and_raise(
|
30
31
|
Errno::ECONNREFUSED)
|
31
32
|
expect(tester.port_open?('localhost', 1234, :INET)).to be_falsy
|
32
33
|
end
|
33
34
|
|
34
35
|
it "handles many domain parameters" do
|
35
|
-
allow_any_instance_of(Socket).to receive(:
|
36
|
+
allow_any_instance_of(Socket).to receive(:connect_nonblock).and_raise(
|
36
37
|
Errno::ECONNREFUSED)
|
37
38
|
expect(tester.port_open?('localhost', 1234, [:INET, :INET6])).to be_falsy
|
38
39
|
end
|
@@ -53,7 +54,7 @@ describe ::Unobtainium::Support::PortScanner do
|
|
53
54
|
end
|
54
55
|
|
55
56
|
it "finds an open port in a range" do
|
56
|
-
allow_any_instance_of(Socket).to receive(:
|
57
|
+
allow_any_instance_of(Socket).to receive(:connect_nonblock) do |sock, addr|
|
57
58
|
connect_mock(sock, addr)
|
58
59
|
end
|
59
60
|
|
@@ -61,7 +62,7 @@ describe ::Unobtainium::Support::PortScanner do
|
|
61
62
|
end
|
62
63
|
|
63
64
|
it "finds an open port in an array" do
|
64
|
-
allow_any_instance_of(Socket).to receive(:
|
65
|
+
allow_any_instance_of(Socket).to receive(:connect_nonblock) do |sock, addr|
|
65
66
|
connect_mock(sock, addr)
|
66
67
|
end
|
67
68
|
|
@@ -69,7 +70,7 @@ describe ::Unobtainium::Support::PortScanner do
|
|
69
70
|
end
|
70
71
|
|
71
72
|
it "doesn't find an open port in a range" do
|
72
|
-
allow_any_instance_of(Socket).to receive(:
|
73
|
+
allow_any_instance_of(Socket).to receive(:connect_nonblock) do |sock, addr|
|
73
74
|
connect_mock(sock, addr)
|
74
75
|
end
|
75
76
|
|
@@ -77,7 +78,7 @@ describe ::Unobtainium::Support::PortScanner do
|
|
77
78
|
end
|
78
79
|
|
79
80
|
it "doesn't find an open port in an array" do
|
80
|
-
allow_any_instance_of(Socket).to receive(:
|
81
|
+
allow_any_instance_of(Socket).to receive(:connect_nonblock) do |sock, addr|
|
81
82
|
connect_mock(sock, addr)
|
82
83
|
end
|
83
84
|
|
@@ -85,7 +86,7 @@ describe ::Unobtainium::Support::PortScanner do
|
|
85
86
|
end
|
86
87
|
|
87
88
|
it "finds an open port in mixed arguments" do
|
88
|
-
allow_any_instance_of(Socket).to receive(:
|
89
|
+
allow_any_instance_of(Socket).to receive(:connect_nonblock) do |sock, addr|
|
89
90
|
connect_mock(sock, addr)
|
90
91
|
end
|
91
92
|
|
@@ -101,7 +102,7 @@ describe ::Unobtainium::Support::PortScanner do
|
|
101
102
|
end
|
102
103
|
|
103
104
|
it "can abort after the first find" do
|
104
|
-
allow_any_instance_of(Socket).to receive(:
|
105
|
+
allow_any_instance_of(Socket).to receive(:connect_nonblock) do |sock, addr|
|
105
106
|
connect_mock(sock, addr)
|
106
107
|
end
|
107
108
|
|
@@ -109,7 +110,7 @@ describe ::Unobtainium::Support::PortScanner do
|
|
109
110
|
end
|
110
111
|
|
111
112
|
it "can scan for closed/available ports" do
|
112
|
-
allow_any_instance_of(Socket).to receive(:
|
113
|
+
allow_any_instance_of(Socket).to receive(:connect_nonblock) do |sock, addr|
|
113
114
|
connect_mock(sock, addr)
|
114
115
|
end
|
115
116
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unobtainium
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jens Finkhaeuser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|