ronin-support 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.editorconfig +11 -0
- data/.github/workflows/ruby.yml +28 -0
- data/.ruby-version +1 -0
- data/.yardopts +1 -1
- data/ChangeLog.md +28 -0
- data/Gemfile +6 -7
- data/README.md +53 -32
- data/Rakefile +1 -2
- data/gemspec.yml +16 -7
- data/lib/ronin/binary.rb +5 -5
- data/lib/ronin/binary/hexdump.rb +5 -5
- data/lib/ronin/binary/hexdump/parser.rb +5 -5
- data/lib/ronin/binary/struct.rb +5 -5
- data/lib/ronin/binary/template.rb +7 -7
- data/lib/ronin/extensions.rb +5 -5
- data/lib/ronin/extensions/enumerable.rb +5 -5
- data/lib/ronin/extensions/file.rb +37 -31
- data/lib/ronin/extensions/ip_addr.rb +6 -7
- data/lib/ronin/extensions/kernel.rb +5 -5
- data/lib/ronin/extensions/meta.rb +5 -5
- data/lib/ronin/extensions/regexp.rb +5 -5
- data/lib/ronin/extensions/resolv.rb +5 -5
- data/lib/ronin/extensions/string.rb +5 -5
- data/lib/ronin/formatting.rb +5 -5
- data/lib/ronin/formatting/binary.rb +5 -5
- data/lib/ronin/formatting/digest.rb +5 -5
- data/lib/ronin/formatting/extensions.rb +5 -5
- data/lib/ronin/formatting/extensions/binary.rb +5 -5
- data/lib/ronin/formatting/extensions/binary/array.rb +6 -6
- data/lib/ronin/formatting/extensions/binary/base64.rb +5 -5
- data/lib/ronin/formatting/extensions/binary/file.rb +5 -5
- data/lib/ronin/formatting/extensions/binary/float.rb +6 -6
- data/lib/ronin/formatting/extensions/binary/integer.rb +6 -6
- data/lib/ronin/formatting/extensions/binary/string.rb +6 -6
- data/lib/ronin/formatting/extensions/digest.rb +5 -5
- data/lib/ronin/formatting/extensions/digest/file.rb +5 -5
- data/lib/ronin/formatting/extensions/digest/string.rb +5 -5
- data/lib/ronin/formatting/extensions/html.rb +5 -5
- data/lib/ronin/formatting/extensions/html/integer.rb +5 -5
- data/lib/ronin/formatting/extensions/html/string.rb +7 -7
- data/lib/ronin/formatting/extensions/http.rb +5 -5
- data/lib/ronin/formatting/extensions/http/integer.rb +6 -6
- data/lib/ronin/formatting/extensions/http/string.rb +7 -7
- data/lib/ronin/formatting/extensions/sql.rb +5 -5
- data/lib/ronin/formatting/extensions/sql/string.rb +15 -13
- data/lib/ronin/formatting/extensions/text.rb +5 -5
- data/lib/ronin/formatting/extensions/text/array.rb +5 -5
- data/lib/ronin/formatting/extensions/text/string.rb +5 -5
- data/lib/ronin/formatting/html.rb +5 -5
- data/lib/ronin/formatting/http.rb +5 -5
- data/lib/ronin/formatting/sql.rb +5 -5
- data/lib/ronin/formatting/text.rb +5 -5
- data/lib/ronin/fuzzing.rb +5 -5
- data/lib/ronin/fuzzing/extensions.rb +5 -5
- data/lib/ronin/fuzzing/extensions/string.rb +5 -5
- data/lib/ronin/fuzzing/fuzzer.rb +5 -5
- data/lib/ronin/fuzzing/fuzzing.rb +7 -7
- data/lib/ronin/fuzzing/mutator.rb +5 -5
- data/lib/ronin/fuzzing/repeater.rb +5 -5
- data/lib/ronin/fuzzing/template.rb +5 -5
- data/lib/ronin/mixin.rb +2 -2
- data/lib/ronin/network.rb +5 -5
- data/lib/ronin/network/dns.rb +5 -5
- data/lib/ronin/network/esmtp.rb +5 -5
- data/lib/ronin/network/extensions.rb +5 -5
- data/lib/ronin/network/extensions/dns.rb +5 -5
- data/lib/ronin/network/extensions/dns/net.rb +5 -5
- data/lib/ronin/network/extensions/esmtp.rb +5 -5
- data/lib/ronin/network/extensions/esmtp/net.rb +5 -5
- data/lib/ronin/network/extensions/http.rb +5 -5
- data/lib/ronin/network/extensions/http/net.rb +5 -5
- data/lib/ronin/network/extensions/http/uri/http.rb +5 -5
- data/lib/ronin/network/extensions/imap.rb +5 -5
- data/lib/ronin/network/extensions/imap/net.rb +5 -5
- data/lib/ronin/network/extensions/pop3.rb +5 -5
- data/lib/ronin/network/extensions/pop3/net.rb +5 -5
- data/lib/ronin/network/extensions/smtp.rb +5 -5
- data/lib/ronin/network/extensions/smtp/net.rb +5 -5
- data/lib/ronin/network/extensions/ssl.rb +5 -5
- data/lib/ronin/network/extensions/ssl/net.rb +5 -5
- data/lib/ronin/network/extensions/tcp.rb +5 -5
- data/lib/ronin/network/extensions/tcp/net.rb +5 -5
- data/lib/ronin/network/extensions/telnet.rb +5 -5
- data/lib/ronin/network/extensions/telnet/net.rb +5 -5
- data/lib/ronin/network/extensions/udp.rb +5 -5
- data/lib/ronin/network/extensions/udp/net.rb +5 -5
- data/lib/ronin/network/ftp.rb +5 -5
- data/lib/ronin/network/http.rb +5 -5
- data/lib/ronin/network/http/exceptions.rb +5 -5
- data/lib/ronin/network/http/exceptions/unknown_request.rb +5 -5
- data/lib/ronin/network/http/http.rb +52 -57
- data/lib/ronin/network/http/proxy.rb +5 -5
- data/lib/ronin/network/imap.rb +5 -5
- data/lib/ronin/network/mixins.rb +5 -5
- data/lib/ronin/network/mixins/dns.rb +5 -5
- data/lib/ronin/network/mixins/esmtp.rb +5 -5
- data/lib/ronin/network/mixins/ftp.rb +5 -5
- data/lib/ronin/network/mixins/http.rb +7 -7
- data/lib/ronin/network/mixins/imap.rb +5 -5
- data/lib/ronin/network/mixins/mixin.rb +5 -5
- data/lib/ronin/network/mixins/pop3.rb +5 -5
- data/lib/ronin/network/mixins/smtp.rb +5 -5
- data/lib/ronin/network/mixins/ssl.rb +5 -5
- data/lib/ronin/network/mixins/tcp.rb +5 -5
- data/lib/ronin/network/mixins/telnet.rb +5 -5
- data/lib/ronin/network/mixins/udp.rb +5 -5
- data/lib/ronin/network/mixins/unix.rb +5 -5
- data/lib/ronin/network/network.rb +5 -5
- data/lib/ronin/network/pop3.rb +5 -5
- data/lib/ronin/network/proxy.rb +5 -5
- data/lib/ronin/network/smtp.rb +5 -5
- data/lib/ronin/network/smtp/email.rb +6 -6
- data/lib/ronin/network/smtp/smtp.rb +5 -5
- data/lib/ronin/network/ssl.rb +7 -7
- data/lib/ronin/network/tcp.rb +5 -5
- data/lib/ronin/network/tcp/proxy.rb +5 -5
- data/lib/ronin/network/tcp/tcp.rb +32 -23
- data/lib/ronin/network/telnet.rb +7 -5
- data/lib/ronin/network/udp.rb +5 -5
- data/lib/ronin/network/udp/proxy.rb +5 -5
- data/lib/ronin/network/udp/udp.rb +28 -26
- data/lib/ronin/network/unix.rb +7 -7
- data/lib/ronin/path.rb +32 -36
- data/lib/ronin/spec/ui/output.rb +5 -5
- data/lib/ronin/support.rb +5 -5
- data/lib/ronin/support/inflector.rb +5 -5
- data/lib/ronin/support/support.rb +5 -5
- data/lib/ronin/support/version.rb +6 -6
- data/lib/ronin/templates.rb +5 -5
- data/lib/ronin/templates/erb.rb +5 -5
- data/lib/ronin/templates/template.rb +5 -5
- data/lib/ronin/ui/output.rb +5 -5
- data/lib/ronin/ui/output/helpers.rb +5 -5
- data/lib/ronin/ui/output/output.rb +17 -21
- data/lib/ronin/ui/output/terminal.rb +5 -5
- data/lib/ronin/ui/output/terminal/color.rb +5 -5
- data/lib/ronin/ui/output/terminal/raw.rb +5 -5
- data/lib/ronin/ui/shell.rb +5 -5
- data/lib/ronin/wordlist.rb +7 -7
- data/ronin-support.gemspec +1 -0
- data/spec/binary/hexdump/parser_spec.rb +22 -22
- data/spec/binary/struct_spec.rb +56 -56
- data/spec/binary/template_spec.rb +106 -104
- data/spec/extensions/enumerable_spec.rb +4 -4
- data/spec/extensions/file_spec.rb +12 -14
- data/spec/extensions/ip_addr_spec.rb +30 -30
- data/spec/extensions/kernel_spec.rb +7 -7
- data/spec/extensions/regexp_spec.rb +69 -69
- data/spec/extensions/resolv_spec.rb +2 -2
- data/spec/extensions/string_spec.rb +30 -29
- data/spec/formatting/binary/array_spec.rb +2 -2
- data/spec/formatting/binary/base64_spec.rb +8 -8
- data/spec/formatting/binary/float_spec.rb +6 -4
- data/spec/formatting/binary/integer_spec.rb +25 -25
- data/spec/formatting/binary/string_spec.rb +32 -30
- data/spec/formatting/digest/string_spec.rb +5 -5
- data/spec/formatting/html/integer_spec.rb +6 -6
- data/spec/formatting/html/string_spec.rb +10 -10
- data/spec/formatting/http/integer_spec.rb +3 -3
- data/spec/formatting/http/string_spec.rb +5 -5
- data/spec/formatting/sql/string_spec.rb +21 -19
- data/spec/formatting/text/array_spec.rb +15 -15
- data/spec/formatting/text/string_spec.rb +33 -33
- data/spec/fuzzing/extensions/string_spec.rb +11 -11
- data/spec/fuzzing/fuzzer_spec.rb +15 -15
- data/spec/fuzzing/fuzzing_spec.rb +5 -5
- data/spec/fuzzing/mutator_spec.rb +15 -15
- data/spec/fuzzing/repeater_spec.rb +7 -7
- data/spec/fuzzing/template_spec.rb +11 -11
- data/spec/mixin_spec.rb +10 -12
- data/spec/network/dns_spec.rb +34 -32
- data/spec/network/ftp_spec.rb +9 -9
- data/spec/network/http/http_spec.rb +237 -144
- data/spec/network/http/proxy_spec.rb +37 -37
- data/spec/network/network_spec.rb +1 -1
- data/spec/network/proxy_spec.rb +19 -19
- data/spec/network/smtp/email_spec.rb +14 -14
- data/spec/network/ssl_spec.rb +9 -9
- data/spec/network/tcp/proxy_spec.rb +9 -7
- data/spec/network/tcp/tcp_spec.rb +161 -118
- data/spec/network/telnet_spec.rb +5 -5
- data/spec/network/udp/udp_spec.rb +123 -96
- data/spec/network/unix_spec.rb +24 -25
- data/spec/path_spec.rb +43 -18
- data/spec/spec_helper.rb +0 -1
- data/spec/support/inflector_spec.rb +4 -4
- data/spec/support_spec.rb +1 -1
- data/spec/templates/erb_spec.rb +3 -3
- data/spec/templates/template_spec.rb +10 -10
- data/spec/ui/shell_spec.rb +15 -15
- data/spec/wordlist_spec.rb +19 -19
- metadata +408 -366
- data/.gemtest +0 -0
@@ -6,10 +6,7 @@ require 'resolv'
|
|
6
6
|
describe Network::TCP do
|
7
7
|
describe "helper methods", :network do
|
8
8
|
let(:host) { 'smtp.gmail.com' }
|
9
|
-
let(:port) {
|
10
|
-
|
11
|
-
let(:server_host) { 'localhost' }
|
12
|
-
let(:server_ip) { Resolv.getaddress(server_host) }
|
9
|
+
let(:port) { 587 }
|
13
10
|
|
14
11
|
subject do
|
15
12
|
obj = Object.new
|
@@ -17,104 +14,132 @@ describe Network::TCP do
|
|
17
14
|
obj
|
18
15
|
end
|
19
16
|
|
17
|
+
shared_examples "TCP Server" do
|
18
|
+
let(:server_host) { 'localhost' }
|
19
|
+
let(:server_port) { 1024 + rand(65535 - 1024) }
|
20
|
+
let(:server_ip) { Resolv.getaddress(server_host) }
|
21
|
+
let(:server) { TCPServer.new(server_host,server_port) }
|
22
|
+
let(:server_bind_ip) { server.addr[3] }
|
23
|
+
let(:server_bind_port) { server.addr[1] }
|
24
|
+
|
25
|
+
before(:each) { server.listen(1) }
|
26
|
+
after(:each) { server.close }
|
27
|
+
end
|
28
|
+
|
20
29
|
describe "#tcp_open?" do
|
21
|
-
|
22
|
-
|
30
|
+
include_examples "TCP Server"
|
31
|
+
|
32
|
+
let(:host) { server_bind_ip }
|
33
|
+
let(:port) { server_bind_port }
|
23
34
|
|
24
35
|
it "should return true for open ports" do
|
25
|
-
subject.tcp_open?(host,port).
|
36
|
+
expect(subject.tcp_open?(host,port)).to be(true)
|
26
37
|
end
|
27
38
|
|
39
|
+
let(:closed_port) { port + 1 }
|
40
|
+
|
28
41
|
it "should return false for closed ports" do
|
29
|
-
subject.tcp_open?(
|
42
|
+
expect(subject.tcp_open?(host,closed_port)).to be(false)
|
30
43
|
end
|
31
44
|
|
32
|
-
|
33
|
-
timeout
|
45
|
+
context "when given a timeout" do
|
46
|
+
it "should have a timeout for firewalled ports" do
|
47
|
+
timeout = 2
|
34
48
|
|
35
|
-
|
36
|
-
|
37
|
-
|
49
|
+
t1 = Time.now
|
50
|
+
subject.tcp_open?(host,port+1,nil,nil,timeout)
|
51
|
+
t2 = Time.now
|
38
52
|
|
39
|
-
|
53
|
+
expect((t2 - t1).to_i).to be <= timeout
|
54
|
+
end
|
40
55
|
end
|
41
56
|
end
|
42
57
|
|
43
58
|
describe "#tcp_connect" do
|
44
|
-
let(:
|
59
|
+
let(:host) { 'example.com' }
|
60
|
+
let(:port) { 80 }
|
45
61
|
|
46
62
|
it "should open a TCPSocket" do
|
47
63
|
socket = subject.tcp_connect(host,port)
|
48
64
|
|
49
|
-
socket.
|
50
|
-
socket.
|
65
|
+
expect(socket).to be_kind_of(TCPSocket)
|
66
|
+
expect(socket).not_to be_closed
|
51
67
|
|
52
68
|
socket.close
|
53
69
|
end
|
54
70
|
|
55
|
-
|
56
|
-
|
57
|
-
bound_port = socket.addr[1]
|
71
|
+
context "when given a local host and port" do
|
72
|
+
let(:local_port) { 1024 + rand(65535 - 1024) }
|
58
73
|
|
59
|
-
|
74
|
+
it "should bind to a local host and port" do
|
75
|
+
socket = subject.tcp_connect(host,port,nil,local_port)
|
76
|
+
bound_port = socket.addr[1]
|
60
77
|
|
61
|
-
|
78
|
+
expect(bound_port).to eq(local_port)
|
79
|
+
|
80
|
+
socket.close
|
81
|
+
end
|
62
82
|
end
|
63
83
|
|
64
|
-
|
65
|
-
|
84
|
+
context "when given a block" do
|
85
|
+
it "should yield the new TCPSocket" do
|
86
|
+
socket = nil
|
66
87
|
|
67
|
-
|
68
|
-
|
69
|
-
|
88
|
+
subject.tcp_connect(host,port) do |yielded_socket|
|
89
|
+
socket = yielded_socket
|
90
|
+
end
|
70
91
|
|
71
|
-
|
72
|
-
|
92
|
+
expect(socket).not_to be_closed
|
93
|
+
socket.close
|
94
|
+
end
|
73
95
|
end
|
74
96
|
end
|
75
97
|
|
76
98
|
describe "#tcp_connect_and_send" do
|
77
|
-
let(:data) { "HELO ronin\n" }
|
78
|
-
let(:local_port) { 1024 + rand(65535 - 1024) }
|
99
|
+
let(:data) { "HELO ronin-support\n" }
|
79
100
|
|
80
|
-
let(:expected_response) { "250
|
101
|
+
let(:expected_response) { "250 #{host} at your service\r\n" }
|
81
102
|
|
82
103
|
it "should connect and then send data" do
|
83
104
|
socket = subject.tcp_connect_and_send(data,host,port)
|
84
105
|
banner = socket.readline
|
85
106
|
response = socket.readline
|
86
107
|
|
87
|
-
response.
|
108
|
+
expect(response).to eq(expected_response)
|
88
109
|
|
89
110
|
socket.close
|
90
111
|
end
|
91
112
|
|
92
|
-
|
93
|
-
|
94
|
-
|
113
|
+
context "when given a local host and port" do
|
114
|
+
let(:local_port) { 1024 + rand(65535 - 1024) }
|
115
|
+
|
116
|
+
it "should bind to a local host and port" do
|
117
|
+
socket = subject.tcp_connect_and_send(data,host,port,nil,local_port)
|
118
|
+
bound_port = socket.addr[1]
|
95
119
|
|
96
|
-
|
120
|
+
expect(bound_port).to eq(local_port)
|
97
121
|
|
98
|
-
|
122
|
+
socket.close
|
123
|
+
end
|
99
124
|
end
|
100
125
|
|
101
|
-
|
102
|
-
|
126
|
+
context "when given a block" do
|
127
|
+
it "should yield the TCPSocket" do
|
128
|
+
response = nil
|
103
129
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
130
|
+
socket = subject.tcp_connect_and_send(data,host,port) do |socket|
|
131
|
+
banner = socket.readline
|
132
|
+
response = socket.readline
|
133
|
+
end
|
108
134
|
|
109
|
-
|
135
|
+
expect(response).to eq(expected_response)
|
110
136
|
|
111
|
-
|
137
|
+
socket.close
|
138
|
+
end
|
112
139
|
end
|
113
140
|
end
|
114
141
|
|
115
142
|
describe "#tcp_session" do
|
116
|
-
let(:local_port) { 1024 + rand(65535 - 1024) }
|
117
|
-
|
118
143
|
it "should open then close a TCPSocket" do
|
119
144
|
socket = nil
|
120
145
|
|
@@ -122,123 +147,137 @@ describe Network::TCP do
|
|
122
147
|
socket = yielded_socket
|
123
148
|
end
|
124
149
|
|
125
|
-
socket.
|
126
|
-
socket.
|
150
|
+
expect(socket).to be_kind_of(TCPSocket)
|
151
|
+
expect(socket).to be_closed
|
127
152
|
end
|
128
153
|
|
129
|
-
|
130
|
-
|
154
|
+
context "when given a local host and port" do
|
155
|
+
let(:local_port) { 1024 + rand(65535 - 1024) }
|
131
156
|
|
132
|
-
|
133
|
-
bound_port =
|
134
|
-
|
157
|
+
it "should bind to a local host and port" do
|
158
|
+
bound_port = nil
|
159
|
+
|
160
|
+
subject.tcp_session(host,port,nil,local_port) do |socket|
|
161
|
+
bound_port = socket.addr[1]
|
162
|
+
end
|
135
163
|
|
136
|
-
|
164
|
+
expect(bound_port).to eq(local_port)
|
165
|
+
end
|
137
166
|
end
|
138
167
|
end
|
139
168
|
|
140
169
|
describe "#tcp_banner" do
|
141
170
|
let(:host) { 'smtp.gmail.com' }
|
142
|
-
let(:port) {
|
143
|
-
let(:local_port) { 1024 + rand(65535 - 1024) }
|
171
|
+
let(:port) { 587 }
|
144
172
|
|
145
|
-
let(:expected_banner) { /^220
|
173
|
+
let(:expected_banner) { /^220 #{Regexp.escape(host)} ESMTP [^\s]+ - gsmtp$/ }
|
146
174
|
|
147
175
|
it "should return the read service banner" do
|
148
176
|
banner = subject.tcp_banner(host,port)
|
149
177
|
|
150
|
-
banner.
|
178
|
+
expect(banner).to match(expected_banner)
|
151
179
|
end
|
152
180
|
|
153
|
-
|
154
|
-
|
181
|
+
context "when given a local host and port" do
|
182
|
+
let(:local_port) { 1024 + rand(65535 - 1024) }
|
155
183
|
|
156
|
-
|
157
|
-
|
184
|
+
it "should bind to a local host and port" do
|
185
|
+
banner = subject.tcp_banner(host,port,nil,local_port)
|
158
186
|
|
159
|
-
|
160
|
-
banner = nil
|
161
|
-
|
162
|
-
subject.tcp_banner(host,port) do |yielded_banner|
|
163
|
-
banner = yielded_banner
|
187
|
+
expect(banner).to match(expected_banner)
|
164
188
|
end
|
189
|
+
end
|
165
190
|
|
166
|
-
|
191
|
+
context "when given a block" do
|
192
|
+
it "should yield the banner" do
|
193
|
+
banner = nil
|
194
|
+
|
195
|
+
subject.tcp_banner(host,port) do |yielded_banner|
|
196
|
+
banner = yielded_banner
|
197
|
+
end
|
198
|
+
|
199
|
+
expect(banner).to match(expected_banner)
|
200
|
+
end
|
167
201
|
end
|
168
202
|
end
|
169
203
|
|
170
|
-
|
171
|
-
|
172
|
-
let(:server_port) { server.addr[1] }
|
204
|
+
let(:local_host) { 'localhost' }
|
205
|
+
let(:local_ip) { Resolv.getaddress(local_host) }
|
173
206
|
|
174
|
-
|
175
|
-
|
207
|
+
describe "#tcp_send" do
|
208
|
+
include_context "TCP Server"
|
176
209
|
|
177
|
-
|
210
|
+
let(:data) { "hello\n" }
|
178
211
|
|
179
212
|
it "should send data to a service" do
|
180
|
-
subject.tcp_send(data,
|
213
|
+
subject.tcp_send(data,server_bind_ip,server_bind_port)
|
181
214
|
|
182
215
|
client = server.accept
|
183
216
|
sent = client.readline
|
184
217
|
|
185
218
|
client.close
|
186
219
|
|
187
|
-
sent.
|
220
|
+
expect(sent).to eq(data)
|
188
221
|
end
|
189
222
|
|
190
|
-
|
191
|
-
|
223
|
+
context "when given a local host and port" do
|
224
|
+
let(:local_port) { 1024 + rand(65535 - 1024) }
|
192
225
|
|
193
|
-
|
194
|
-
|
226
|
+
it "should bind to a local host and port" do
|
227
|
+
subject.tcp_send(data,server_bind_ip,server_bind_port,server_bind_ip,local_port)
|
195
228
|
|
196
|
-
|
229
|
+
client = server.accept
|
230
|
+
client_port = client.peeraddr[1]
|
197
231
|
|
198
|
-
|
232
|
+
expect(client_port).to eq(local_port)
|
233
|
+
|
234
|
+
client.close
|
235
|
+
end
|
199
236
|
end
|
200
237
|
end
|
201
238
|
|
202
239
|
describe "#tcp_server" do
|
203
|
-
let(:server_port) { 1024 + rand(65535 - 1024) }
|
204
|
-
|
205
240
|
it "should create a new TCPServer" do
|
206
241
|
server = subject.tcp_server
|
207
242
|
|
208
|
-
server.
|
209
|
-
server.
|
243
|
+
expect(server).to be_kind_of(TCPServer)
|
244
|
+
expect(server).not_to be_closed
|
210
245
|
|
211
246
|
server.close
|
212
247
|
end
|
213
248
|
|
214
|
-
|
215
|
-
|
216
|
-
bound_host = server.addr[3]
|
217
|
-
bound_port = server.addr[1]
|
249
|
+
context "when given a local host and port" do
|
250
|
+
let(:local_port) { 1024 + rand(65535 - 1024) }
|
218
251
|
|
219
|
-
|
220
|
-
|
252
|
+
it "should bind to a specific port and host" do
|
253
|
+
server = subject.tcp_server(local_port,local_host)
|
254
|
+
bound_host = server.addr[3]
|
255
|
+
bound_port = server.addr[1]
|
221
256
|
|
222
|
-
|
223
|
-
|
257
|
+
expect(bound_host).to eq(local_ip)
|
258
|
+
expect(bound_port).to eq(local_port)
|
224
259
|
|
225
|
-
|
226
|
-
server = nil
|
227
|
-
|
228
|
-
subject.tcp_server do |yielded_server|
|
229
|
-
server = yielded_server
|
260
|
+
server.close
|
230
261
|
end
|
262
|
+
end
|
231
263
|
|
232
|
-
|
233
|
-
|
264
|
+
context "when given a block" do
|
265
|
+
it "should yield the new TCPServer" do
|
266
|
+
server = nil
|
234
267
|
|
235
|
-
|
268
|
+
subject.tcp_server do |yielded_server|
|
269
|
+
server = yielded_server
|
270
|
+
end
|
271
|
+
|
272
|
+
expect(server).to be_kind_of(TCPServer)
|
273
|
+
expect(server).not_to be_closed
|
274
|
+
|
275
|
+
server.close
|
276
|
+
end
|
236
277
|
end
|
237
278
|
end
|
238
279
|
|
239
280
|
describe "#tcp_server_session" do
|
240
|
-
let(:server_port) { 1024 + rand(65535 - 1024) }
|
241
|
-
|
242
281
|
it "should create a temporary TCPServer" do
|
243
282
|
server = nil
|
244
283
|
|
@@ -246,21 +285,25 @@ describe Network::TCP do
|
|
246
285
|
server = yielded_server
|
247
286
|
end
|
248
287
|
|
249
|
-
server.
|
250
|
-
server.
|
288
|
+
expect(server).to be_kind_of(TCPServer)
|
289
|
+
expect(server).to be_closed
|
251
290
|
end
|
252
291
|
|
253
|
-
|
254
|
-
|
255
|
-
bound_port = nil
|
256
|
-
|
257
|
-
subject.tcp_server_session(server_port,server_host) do |yielded_server|
|
258
|
-
bound_host = yielded_server.addr[3]
|
259
|
-
bound_port = yielded_server.addr[1]
|
260
|
-
end
|
292
|
+
context "when given a block" do
|
293
|
+
let(:local_port) { 1024 + rand(65535 - 1024) }
|
261
294
|
|
262
|
-
|
263
|
-
|
295
|
+
it "should bind to a specific port and host" do
|
296
|
+
bound_host = nil
|
297
|
+
bound_port = nil
|
298
|
+
|
299
|
+
subject.tcp_server_session(local_port,local_host) do |server|
|
300
|
+
bound_host = server.addr[3]
|
301
|
+
bound_port = server.addr[1]
|
302
|
+
end
|
303
|
+
|
304
|
+
expect(bound_host).to eq(local_ip)
|
305
|
+
expect(bound_port).to eq(local_port)
|
306
|
+
end
|
264
307
|
end
|
265
308
|
end
|
266
309
|
|
data/spec/network/telnet_spec.rb
CHANGED
@@ -15,7 +15,7 @@ describe Network::Telnet do
|
|
15
15
|
it "should return a Net::Telnet object" do
|
16
16
|
telnet = subject.telnet_connect(host)
|
17
17
|
|
18
|
-
telnet.
|
18
|
+
expect(telnet).to be_kind_of(Net::Telnet)
|
19
19
|
telnet.close
|
20
20
|
end
|
21
21
|
|
@@ -33,7 +33,7 @@ describe Network::Telnet do
|
|
33
33
|
telnet = telnet_object
|
34
34
|
end
|
35
35
|
|
36
|
-
telnet.
|
36
|
+
expect(telnet).to be_kind_of(Net::Telnet)
|
37
37
|
telnet.close
|
38
38
|
end
|
39
39
|
end
|
@@ -47,7 +47,7 @@ describe Network::Telnet do
|
|
47
47
|
yielded_telnet = telnet
|
48
48
|
end
|
49
49
|
|
50
|
-
yielded_telnet.
|
50
|
+
expect(yielded_telnet).to be_kind_of(Net::Telnet)
|
51
51
|
end
|
52
52
|
|
53
53
|
it "should close the Telnet session after yielding it" do
|
@@ -59,8 +59,8 @@ describe Network::Telnet do
|
|
59
59
|
was_open = !telnet.sock.closed?
|
60
60
|
end
|
61
61
|
|
62
|
-
was_open.
|
63
|
-
session.sock.
|
62
|
+
expect(was_open).to be(true)
|
63
|
+
expect(session.sock).to be_closed
|
64
64
|
end
|
65
65
|
end
|
66
66
|
end
|