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.
Files changed (194) hide show
  1. checksums.yaml +7 -0
  2. data/.editorconfig +11 -0
  3. data/.github/workflows/ruby.yml +28 -0
  4. data/.ruby-version +1 -0
  5. data/.yardopts +1 -1
  6. data/ChangeLog.md +28 -0
  7. data/Gemfile +6 -7
  8. data/README.md +53 -32
  9. data/Rakefile +1 -2
  10. data/gemspec.yml +16 -7
  11. data/lib/ronin/binary.rb +5 -5
  12. data/lib/ronin/binary/hexdump.rb +5 -5
  13. data/lib/ronin/binary/hexdump/parser.rb +5 -5
  14. data/lib/ronin/binary/struct.rb +5 -5
  15. data/lib/ronin/binary/template.rb +7 -7
  16. data/lib/ronin/extensions.rb +5 -5
  17. data/lib/ronin/extensions/enumerable.rb +5 -5
  18. data/lib/ronin/extensions/file.rb +37 -31
  19. data/lib/ronin/extensions/ip_addr.rb +6 -7
  20. data/lib/ronin/extensions/kernel.rb +5 -5
  21. data/lib/ronin/extensions/meta.rb +5 -5
  22. data/lib/ronin/extensions/regexp.rb +5 -5
  23. data/lib/ronin/extensions/resolv.rb +5 -5
  24. data/lib/ronin/extensions/string.rb +5 -5
  25. data/lib/ronin/formatting.rb +5 -5
  26. data/lib/ronin/formatting/binary.rb +5 -5
  27. data/lib/ronin/formatting/digest.rb +5 -5
  28. data/lib/ronin/formatting/extensions.rb +5 -5
  29. data/lib/ronin/formatting/extensions/binary.rb +5 -5
  30. data/lib/ronin/formatting/extensions/binary/array.rb +6 -6
  31. data/lib/ronin/formatting/extensions/binary/base64.rb +5 -5
  32. data/lib/ronin/formatting/extensions/binary/file.rb +5 -5
  33. data/lib/ronin/formatting/extensions/binary/float.rb +6 -6
  34. data/lib/ronin/formatting/extensions/binary/integer.rb +6 -6
  35. data/lib/ronin/formatting/extensions/binary/string.rb +6 -6
  36. data/lib/ronin/formatting/extensions/digest.rb +5 -5
  37. data/lib/ronin/formatting/extensions/digest/file.rb +5 -5
  38. data/lib/ronin/formatting/extensions/digest/string.rb +5 -5
  39. data/lib/ronin/formatting/extensions/html.rb +5 -5
  40. data/lib/ronin/formatting/extensions/html/integer.rb +5 -5
  41. data/lib/ronin/formatting/extensions/html/string.rb +7 -7
  42. data/lib/ronin/formatting/extensions/http.rb +5 -5
  43. data/lib/ronin/formatting/extensions/http/integer.rb +6 -6
  44. data/lib/ronin/formatting/extensions/http/string.rb +7 -7
  45. data/lib/ronin/formatting/extensions/sql.rb +5 -5
  46. data/lib/ronin/formatting/extensions/sql/string.rb +15 -13
  47. data/lib/ronin/formatting/extensions/text.rb +5 -5
  48. data/lib/ronin/formatting/extensions/text/array.rb +5 -5
  49. data/lib/ronin/formatting/extensions/text/string.rb +5 -5
  50. data/lib/ronin/formatting/html.rb +5 -5
  51. data/lib/ronin/formatting/http.rb +5 -5
  52. data/lib/ronin/formatting/sql.rb +5 -5
  53. data/lib/ronin/formatting/text.rb +5 -5
  54. data/lib/ronin/fuzzing.rb +5 -5
  55. data/lib/ronin/fuzzing/extensions.rb +5 -5
  56. data/lib/ronin/fuzzing/extensions/string.rb +5 -5
  57. data/lib/ronin/fuzzing/fuzzer.rb +5 -5
  58. data/lib/ronin/fuzzing/fuzzing.rb +7 -7
  59. data/lib/ronin/fuzzing/mutator.rb +5 -5
  60. data/lib/ronin/fuzzing/repeater.rb +5 -5
  61. data/lib/ronin/fuzzing/template.rb +5 -5
  62. data/lib/ronin/mixin.rb +2 -2
  63. data/lib/ronin/network.rb +5 -5
  64. data/lib/ronin/network/dns.rb +5 -5
  65. data/lib/ronin/network/esmtp.rb +5 -5
  66. data/lib/ronin/network/extensions.rb +5 -5
  67. data/lib/ronin/network/extensions/dns.rb +5 -5
  68. data/lib/ronin/network/extensions/dns/net.rb +5 -5
  69. data/lib/ronin/network/extensions/esmtp.rb +5 -5
  70. data/lib/ronin/network/extensions/esmtp/net.rb +5 -5
  71. data/lib/ronin/network/extensions/http.rb +5 -5
  72. data/lib/ronin/network/extensions/http/net.rb +5 -5
  73. data/lib/ronin/network/extensions/http/uri/http.rb +5 -5
  74. data/lib/ronin/network/extensions/imap.rb +5 -5
  75. data/lib/ronin/network/extensions/imap/net.rb +5 -5
  76. data/lib/ronin/network/extensions/pop3.rb +5 -5
  77. data/lib/ronin/network/extensions/pop3/net.rb +5 -5
  78. data/lib/ronin/network/extensions/smtp.rb +5 -5
  79. data/lib/ronin/network/extensions/smtp/net.rb +5 -5
  80. data/lib/ronin/network/extensions/ssl.rb +5 -5
  81. data/lib/ronin/network/extensions/ssl/net.rb +5 -5
  82. data/lib/ronin/network/extensions/tcp.rb +5 -5
  83. data/lib/ronin/network/extensions/tcp/net.rb +5 -5
  84. data/lib/ronin/network/extensions/telnet.rb +5 -5
  85. data/lib/ronin/network/extensions/telnet/net.rb +5 -5
  86. data/lib/ronin/network/extensions/udp.rb +5 -5
  87. data/lib/ronin/network/extensions/udp/net.rb +5 -5
  88. data/lib/ronin/network/ftp.rb +5 -5
  89. data/lib/ronin/network/http.rb +5 -5
  90. data/lib/ronin/network/http/exceptions.rb +5 -5
  91. data/lib/ronin/network/http/exceptions/unknown_request.rb +5 -5
  92. data/lib/ronin/network/http/http.rb +52 -57
  93. data/lib/ronin/network/http/proxy.rb +5 -5
  94. data/lib/ronin/network/imap.rb +5 -5
  95. data/lib/ronin/network/mixins.rb +5 -5
  96. data/lib/ronin/network/mixins/dns.rb +5 -5
  97. data/lib/ronin/network/mixins/esmtp.rb +5 -5
  98. data/lib/ronin/network/mixins/ftp.rb +5 -5
  99. data/lib/ronin/network/mixins/http.rb +7 -7
  100. data/lib/ronin/network/mixins/imap.rb +5 -5
  101. data/lib/ronin/network/mixins/mixin.rb +5 -5
  102. data/lib/ronin/network/mixins/pop3.rb +5 -5
  103. data/lib/ronin/network/mixins/smtp.rb +5 -5
  104. data/lib/ronin/network/mixins/ssl.rb +5 -5
  105. data/lib/ronin/network/mixins/tcp.rb +5 -5
  106. data/lib/ronin/network/mixins/telnet.rb +5 -5
  107. data/lib/ronin/network/mixins/udp.rb +5 -5
  108. data/lib/ronin/network/mixins/unix.rb +5 -5
  109. data/lib/ronin/network/network.rb +5 -5
  110. data/lib/ronin/network/pop3.rb +5 -5
  111. data/lib/ronin/network/proxy.rb +5 -5
  112. data/lib/ronin/network/smtp.rb +5 -5
  113. data/lib/ronin/network/smtp/email.rb +6 -6
  114. data/lib/ronin/network/smtp/smtp.rb +5 -5
  115. data/lib/ronin/network/ssl.rb +7 -7
  116. data/lib/ronin/network/tcp.rb +5 -5
  117. data/lib/ronin/network/tcp/proxy.rb +5 -5
  118. data/lib/ronin/network/tcp/tcp.rb +32 -23
  119. data/lib/ronin/network/telnet.rb +7 -5
  120. data/lib/ronin/network/udp.rb +5 -5
  121. data/lib/ronin/network/udp/proxy.rb +5 -5
  122. data/lib/ronin/network/udp/udp.rb +28 -26
  123. data/lib/ronin/network/unix.rb +7 -7
  124. data/lib/ronin/path.rb +32 -36
  125. data/lib/ronin/spec/ui/output.rb +5 -5
  126. data/lib/ronin/support.rb +5 -5
  127. data/lib/ronin/support/inflector.rb +5 -5
  128. data/lib/ronin/support/support.rb +5 -5
  129. data/lib/ronin/support/version.rb +6 -6
  130. data/lib/ronin/templates.rb +5 -5
  131. data/lib/ronin/templates/erb.rb +5 -5
  132. data/lib/ronin/templates/template.rb +5 -5
  133. data/lib/ronin/ui/output.rb +5 -5
  134. data/lib/ronin/ui/output/helpers.rb +5 -5
  135. data/lib/ronin/ui/output/output.rb +17 -21
  136. data/lib/ronin/ui/output/terminal.rb +5 -5
  137. data/lib/ronin/ui/output/terminal/color.rb +5 -5
  138. data/lib/ronin/ui/output/terminal/raw.rb +5 -5
  139. data/lib/ronin/ui/shell.rb +5 -5
  140. data/lib/ronin/wordlist.rb +7 -7
  141. data/ronin-support.gemspec +1 -0
  142. data/spec/binary/hexdump/parser_spec.rb +22 -22
  143. data/spec/binary/struct_spec.rb +56 -56
  144. data/spec/binary/template_spec.rb +106 -104
  145. data/spec/extensions/enumerable_spec.rb +4 -4
  146. data/spec/extensions/file_spec.rb +12 -14
  147. data/spec/extensions/ip_addr_spec.rb +30 -30
  148. data/spec/extensions/kernel_spec.rb +7 -7
  149. data/spec/extensions/regexp_spec.rb +69 -69
  150. data/spec/extensions/resolv_spec.rb +2 -2
  151. data/spec/extensions/string_spec.rb +30 -29
  152. data/spec/formatting/binary/array_spec.rb +2 -2
  153. data/spec/formatting/binary/base64_spec.rb +8 -8
  154. data/spec/formatting/binary/float_spec.rb +6 -4
  155. data/spec/formatting/binary/integer_spec.rb +25 -25
  156. data/spec/formatting/binary/string_spec.rb +32 -30
  157. data/spec/formatting/digest/string_spec.rb +5 -5
  158. data/spec/formatting/html/integer_spec.rb +6 -6
  159. data/spec/formatting/html/string_spec.rb +10 -10
  160. data/spec/formatting/http/integer_spec.rb +3 -3
  161. data/spec/formatting/http/string_spec.rb +5 -5
  162. data/spec/formatting/sql/string_spec.rb +21 -19
  163. data/spec/formatting/text/array_spec.rb +15 -15
  164. data/spec/formatting/text/string_spec.rb +33 -33
  165. data/spec/fuzzing/extensions/string_spec.rb +11 -11
  166. data/spec/fuzzing/fuzzer_spec.rb +15 -15
  167. data/spec/fuzzing/fuzzing_spec.rb +5 -5
  168. data/spec/fuzzing/mutator_spec.rb +15 -15
  169. data/spec/fuzzing/repeater_spec.rb +7 -7
  170. data/spec/fuzzing/template_spec.rb +11 -11
  171. data/spec/mixin_spec.rb +10 -12
  172. data/spec/network/dns_spec.rb +34 -32
  173. data/spec/network/ftp_spec.rb +9 -9
  174. data/spec/network/http/http_spec.rb +237 -144
  175. data/spec/network/http/proxy_spec.rb +37 -37
  176. data/spec/network/network_spec.rb +1 -1
  177. data/spec/network/proxy_spec.rb +19 -19
  178. data/spec/network/smtp/email_spec.rb +14 -14
  179. data/spec/network/ssl_spec.rb +9 -9
  180. data/spec/network/tcp/proxy_spec.rb +9 -7
  181. data/spec/network/tcp/tcp_spec.rb +161 -118
  182. data/spec/network/telnet_spec.rb +5 -5
  183. data/spec/network/udp/udp_spec.rb +123 -96
  184. data/spec/network/unix_spec.rb +24 -25
  185. data/spec/path_spec.rb +43 -18
  186. data/spec/spec_helper.rb +0 -1
  187. data/spec/support/inflector_spec.rb +4 -4
  188. data/spec/support_spec.rb +1 -1
  189. data/spec/templates/erb_spec.rb +3 -3
  190. data/spec/templates/template_spec.rb +10 -10
  191. data/spec/ui/shell_spec.rb +15 -15
  192. data/spec/wordlist_spec.rb +19 -19
  193. metadata +408 -366
  194. 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) { 25 }
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
- let(:host) { 'example.com' }
22
- let(:port) { 80 }
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).should == true
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?('localhost',rand(1024) + 1).should == false
42
+ expect(subject.tcp_open?(host,closed_port)).to be(false)
30
43
  end
31
44
 
32
- it "should have a timeout for firewalled ports" do
33
- timeout = 2
45
+ context "when given a timeout" do
46
+ it "should have a timeout for firewalled ports" do
47
+ timeout = 2
34
48
 
35
- t1 = Time.now
36
- subject.tcp_open?(host,1337,nil,nil,timeout)
37
- t2 = Time.now
49
+ t1 = Time.now
50
+ subject.tcp_open?(host,port+1,nil,nil,timeout)
51
+ t2 = Time.now
38
52
 
39
- (t2 - t1).to_i.should <= timeout
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(:local_port) { 1024 + rand(65535 - 1024) }
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.should be_kind_of(TCPSocket)
50
- socket.should_not be_closed
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
- it "should bind to a local host and port" do
56
- socket = subject.tcp_connect(host,port,nil,local_port)
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
- bound_port.should == local_port
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
- socket.close
78
+ expect(bound_port).to eq(local_port)
79
+
80
+ socket.close
81
+ end
62
82
  end
63
83
 
64
- it "should yield the new TCPSocket" do
65
- socket = nil
84
+ context "when given a block" do
85
+ it "should yield the new TCPSocket" do
86
+ socket = nil
66
87
 
67
- subject.tcp_connect(host,port) do |yielded_socket|
68
- socket = yielded_socket
69
- end
88
+ subject.tcp_connect(host,port) do |yielded_socket|
89
+ socket = yielded_socket
90
+ end
70
91
 
71
- socket.should_not be_closed
72
- socket.close
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 mx.google.com at your service\r\n" }
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.should == expected_response
108
+ expect(response).to eq(expected_response)
88
109
 
89
110
  socket.close
90
111
  end
91
112
 
92
- it "should bind to a local host and port" do
93
- socket = subject.tcp_connect_and_send(data,host,port,nil,local_port)
94
- bound_port = socket.addr[1]
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
- bound_port.should == local_port
120
+ expect(bound_port).to eq(local_port)
97
121
 
98
- socket.close
122
+ socket.close
123
+ end
99
124
  end
100
125
 
101
- it "should yield the TCPSocket" do
102
- response = nil
126
+ context "when given a block" do
127
+ it "should yield the TCPSocket" do
128
+ response = nil
103
129
 
104
- socket = subject.tcp_connect_and_send(data,host,port) do |socket|
105
- banner = socket.readline
106
- response = socket.readline
107
- end
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
- response.should == expected_response
135
+ expect(response).to eq(expected_response)
110
136
 
111
- socket.close
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.should be_kind_of(TCPSocket)
126
- socket.should be_closed
150
+ expect(socket).to be_kind_of(TCPSocket)
151
+ expect(socket).to be_closed
127
152
  end
128
153
 
129
- it "should bind to a local host and port" do
130
- bound_port = nil
154
+ context "when given a local host and port" do
155
+ let(:local_port) { 1024 + rand(65535 - 1024) }
131
156
 
132
- subject.tcp_session(host,port,nil,local_port) do |socket|
133
- bound_port = socket.addr[1]
134
- end
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
- bound_port.should == local_port
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) { 25 }
143
- let(:local_port) { 1024 + rand(65535 - 1024) }
171
+ let(:port) { 587 }
144
172
 
145
- let(:expected_banner) { /^220 mx\.google\.com ESMTP/ }
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.should =~ expected_banner
178
+ expect(banner).to match(expected_banner)
151
179
  end
152
180
 
153
- it "should bind to a local host and port" do
154
- banner = subject.tcp_banner(host,port,nil,local_port)
181
+ context "when given a local host and port" do
182
+ let(:local_port) { 1024 + rand(65535 - 1024) }
155
183
 
156
- banner.should =~ expected_banner
157
- end
184
+ it "should bind to a local host and port" do
185
+ banner = subject.tcp_banner(host,port,nil,local_port)
158
186
 
159
- it "should yield the banner" do
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
- banner.should =~ expected_banner
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
- describe "#tcp_send" do
171
- let(:server) { TCPServer.new(server_host,0) }
172
- let(:server_port) { server.addr[1] }
204
+ let(:local_host) { 'localhost' }
205
+ let(:local_ip) { Resolv.getaddress(local_host) }
173
206
 
174
- let(:data) { "hello\n" }
175
- let(:local_port) { 1024 + rand(65535 - 1024) }
207
+ describe "#tcp_send" do
208
+ include_context "TCP Server"
176
209
 
177
- after(:all) { server.close }
210
+ let(:data) { "hello\n" }
178
211
 
179
212
  it "should send data to a service" do
180
- subject.tcp_send(data,server_host,server_port)
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.should == data
220
+ expect(sent).to eq(data)
188
221
  end
189
222
 
190
- it "should bind to a local host and port" do
191
- subject.tcp_send(data,server_host,server_port,nil,local_port)
223
+ context "when given a local host and port" do
224
+ let(:local_port) { 1024 + rand(65535 - 1024) }
192
225
 
193
- client = server.accept
194
- client_port = client.peeraddr[1]
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
- client_port.should == local_port
229
+ client = server.accept
230
+ client_port = client.peeraddr[1]
197
231
 
198
- client.close
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.should be_kind_of(TCPServer)
209
- server.should_not be_closed
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
- it "should bind to a specific port and host" do
215
- server = subject.tcp_server(server_port,server_host)
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
- bound_host.should == server_ip
220
- bound_port.should == server_port
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
- server.close
223
- end
257
+ expect(bound_host).to eq(local_ip)
258
+ expect(bound_port).to eq(local_port)
224
259
 
225
- it "should yield the new TCPServer" do
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
- server.should be_kind_of(TCPServer)
233
- server.should_not be_closed
264
+ context "when given a block" do
265
+ it "should yield the new TCPServer" do
266
+ server = nil
234
267
 
235
- server.close
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.should be_kind_of(TCPServer)
250
- server.should be_closed
288
+ expect(server).to be_kind_of(TCPServer)
289
+ expect(server).to be_closed
251
290
  end
252
291
 
253
- it "should bind to a specific port and host" do
254
- bound_host = nil
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
- bound_host.should == server_ip
263
- bound_port.should == server_port
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
 
@@ -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.should be_kind_of(Net::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.should be_kind_of(Net::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.should be_kind_of(Net::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.should == true
63
- session.sock.should be_closed
62
+ expect(was_open).to be(true)
63
+ expect(session.sock).to be_closed
64
64
  end
65
65
  end
66
66
  end