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
@@ -8,7 +8,7 @@ describe Network::DNS do
8
8
 
9
9
  describe "nameserver" do
10
10
  it "should be nil by default" do
11
- subject.nameserver.should be_nil
11
+ expect(subject.nameserver).to be_nil
12
12
  end
13
13
  end
14
14
 
@@ -16,20 +16,20 @@ describe Network::DNS do
16
16
  it "should accept Strings" do
17
17
  subject.nameserver = server
18
18
 
19
- subject.nameserver.should == server
19
+ expect(subject.nameserver).to eq(server)
20
20
  end
21
21
 
22
22
  it "should accept nil" do
23
23
  subject.nameserver = server
24
24
  subject.nameserver = nil
25
25
 
26
- subject.nameserver.should be_nil
26
+ expect(subject.nameserver).to be_nil
27
27
  end
28
28
 
29
29
  it "should convert non-nil values to Strings" do
30
30
  subject.nameserver = IPAddr.new(server)
31
31
 
32
- subject.nameserver.should == server
32
+ expect(subject.nameserver).to eq(server)
33
33
  end
34
34
  end
35
35
 
@@ -41,19 +41,21 @@ describe Network::DNS do
41
41
  end
42
42
 
43
43
  it "should return Resolv when passed no nameserver" do
44
- subject.dns_resolver(nil).should == Resolv
44
+ expect(subject.dns_resolver(nil)).to eq(Resolv)
45
45
  end
46
46
 
47
47
  it "should return Resolv::DNS when passed a nameserver" do
48
- subject.dns_resolver(server).should be_kind_of(Resolv::DNS)
48
+ expect(subject.dns_resolver(server)).to be_kind_of(Resolv::DNS)
49
49
  end
50
50
  end
51
51
 
52
52
  describe "helper methods", :network do
53
53
  let(:hostname) { 'example.com' }
54
54
  let(:bad_hostname) { 'foo.bar' }
55
- let(:address) { '192.0.43.10' }
55
+ let(:address) { '93.184.216.34' }
56
56
  let(:bad_address) { '0.0.0.0' }
57
+ let(:reverse_address) { '192.0.43.10' }
58
+ let(:reverse_ipaddr) { IPAddr.new(reverse_address) }
57
59
  let(:reverse_hostname) { '43-10.any.icann.org' }
58
60
 
59
61
  subject do
@@ -64,19 +66,19 @@ describe Network::DNS do
64
66
 
65
67
  describe "#dns_lookup" do
66
68
  it "should lookup the address for a hostname" do
67
- subject.dns_lookup(hostname).should == address
69
+ expect(subject.dns_lookup(hostname)).to eq(address)
68
70
  end
69
71
 
70
72
  it "should return nil for unknown hostnames" do
71
- subject.dns_lookup(bad_hostname).should be_nil
73
+ expect(subject.dns_lookup(bad_hostname)).to be_nil
72
74
  end
73
75
 
74
76
  it "should accept non-String hostnames" do
75
- subject.dns_lookup(hostname.to_sym).should == address
77
+ expect(subject.dns_lookup(hostname.to_sym)).to eq(address)
76
78
  end
77
79
 
78
80
  it "should accept an additional nameserver argument" do
79
- subject.dns_lookup(hostname,server).should == address
81
+ expect(subject.dns_lookup(hostname,server)).to eq(address)
80
82
  end
81
83
 
82
84
  context "when given a block" do
@@ -87,7 +89,7 @@ describe Network::DNS do
87
89
  resolved_address = address
88
90
  end
89
91
 
90
- resolved_address.should == address
92
+ expect(resolved_address).to eq(address)
91
93
  end
92
94
 
93
95
  it "should not yield unresolved addresses" do
@@ -97,65 +99,65 @@ describe Network::DNS do
97
99
  resolved_address = address
98
100
  end
99
101
 
100
- resolved_address.should be_nil
102
+ expect(resolved_address).to be_nil
101
103
  end
102
104
  end
103
105
  end
104
106
 
105
107
  describe "#dns_lookup_all" do
106
108
  it "should lookup all addresses for a hostname" do
107
- subject.dns_lookup_all(hostname).should include(address)
109
+ expect(subject.dns_lookup_all(hostname)).to include(address)
108
110
  end
109
111
 
110
112
  it "should return an empty Array for unknown hostnames" do
111
- subject.dns_lookup_all(bad_hostname).should == []
113
+ expect(subject.dns_lookup_all(bad_hostname)).to eq([])
112
114
  end
113
115
 
114
116
  it "should accept non-String hostnames" do
115
- subject.dns_lookup_all(hostname.to_sym).should include(address)
117
+ expect(subject.dns_lookup_all(hostname.to_sym)).to include(address)
116
118
  end
117
119
 
118
120
  it "should accept an additional nameserver argument" do
119
- subject.dns_lookup_all(hostname,server).should include(address)
121
+ expect(subject.dns_lookup_all(hostname,server)).to include(address)
120
122
  end
121
123
 
122
124
  context "when given a block" do
123
125
  it "should yield the resolved address" do
124
- subject.enum_for(:dns_lookup,hostname).to_a.should == [address]
126
+ expect(subject.enum_for(:dns_lookup,hostname).to_a).to eq([address])
125
127
  end
126
128
 
127
129
  it "should not yield unresolved addresses" do
128
- subject.enum_for(:dns_lookup,bad_hostname).to_a.should == []
130
+ expect(subject.enum_for(:dns_lookup,bad_hostname).to_a).to eq([])
129
131
  end
130
132
  end
131
133
  end
132
134
 
133
135
  describe "#dns_reverse_lookup" do
134
136
  it "should lookup the address for a hostname" do
135
- subject.dns_reverse_lookup(address).should == reverse_hostname
137
+ expect(subject.dns_reverse_lookup(reverse_address)).to eq(reverse_hostname)
136
138
  end
137
139
 
138
140
  it "should return nil for unknown hostnames" do
139
- subject.dns_reverse_lookup(bad_address).should be_nil
141
+ expect(subject.dns_reverse_lookup(bad_address)).to be_nil
140
142
  end
141
143
 
142
144
  it "should accept non-String addresses" do
143
- subject.dns_reverse_lookup(IPAddr.new(address)).should == reverse_hostname
145
+ expect(subject.dns_reverse_lookup(reverse_ipaddr)).to eq(reverse_hostname)
144
146
  end
145
147
 
146
148
  it "should accept an additional nameserver argument" do
147
- subject.dns_reverse_lookup(address,server).should == reverse_hostname
149
+ expect(subject.dns_reverse_lookup(reverse_address,server)).to eq(reverse_hostname)
148
150
  end
149
151
 
150
152
  context "when given a block" do
151
153
  it "should yield the resolved hostname" do
152
154
  resolved_hostname = nil
153
155
 
154
- subject.dns_reverse_lookup(address) do |hostname|
156
+ subject.dns_reverse_lookup(reverse_address) do |hostname|
155
157
  resolved_hostname = hostname
156
158
  end
157
159
 
158
- resolved_hostname.should == reverse_hostname
160
+ expect(resolved_hostname).to eq(reverse_hostname)
159
161
  end
160
162
 
161
163
  it "should not yield unresolved hostnames" do
@@ -165,35 +167,35 @@ describe Network::DNS do
165
167
  resolved_hostname = hostname
166
168
  end
167
169
 
168
- resolved_hostname.should be_nil
170
+ expect(resolved_hostname).to be_nil
169
171
  end
170
172
  end
171
173
  end
172
174
 
173
175
  describe "#dns_reverse_lookup_all" do
174
176
  it "should lookup all addresses for a hostname" do
175
- subject.dns_reverse_lookup_all(address).should include(reverse_hostname)
177
+ expect(subject.dns_reverse_lookup_all(reverse_address)).to include(reverse_hostname)
176
178
  end
177
179
 
178
180
  it "should return an empty Array for unknown hostnames" do
179
- subject.dns_reverse_lookup_all(bad_address).should == []
181
+ expect(subject.dns_reverse_lookup_all(bad_address)).to eq([])
180
182
  end
181
183
 
182
184
  it "should accept non-String addresses" do
183
- subject.dns_reverse_lookup_all(IPAddr.new(address)).should include(reverse_hostname)
185
+ expect(subject.dns_reverse_lookup_all(reverse_ipaddr)).to include(reverse_hostname)
184
186
  end
185
187
 
186
188
  it "should accept an additional nameserver argument" do
187
- subject.dns_reverse_lookup_all(address,server).should include(reverse_hostname)
189
+ expect(subject.dns_reverse_lookup_all(reverse_address,server)).to include(reverse_hostname)
188
190
  end
189
191
 
190
192
  context "when given a block" do
191
193
  it "should yield the resolved hostnames" do
192
- subject.enum_for(:dns_reverse_lookup_all,address).to_a.should == [reverse_hostname]
194
+ expect(subject.enum_for(:dns_reverse_lookup_all,reverse_address).to_a).to eq([reverse_hostname])
193
195
  end
194
196
 
195
197
  it "should not yield unresolved hostnames" do
196
- subject.enum_for(:dns_reverse_lookup_all,bad_address).to_a.should == []
198
+ expect(subject.enum_for(:dns_reverse_lookup_all,bad_address).to_a).to eq([])
197
199
  end
198
200
  end
199
201
  end
@@ -9,20 +9,20 @@ describe Network::FTP do
9
9
  obj
10
10
  end
11
11
 
12
- let(:host) { 'ftp.kernel.org' }
12
+ let(:host) { 'ftp.osuosl.org' }
13
13
 
14
14
  describe "#ftp_connect" do
15
15
  it "should return a Net::FTP object" do
16
16
  ftp = subject.ftp_connect(host)
17
17
 
18
- ftp.should be_kind_of(Net::FTP)
18
+ expect(ftp).to be_kind_of(Net::FTP)
19
19
  ftp.close
20
20
  end
21
21
 
22
22
  it "should connect to an FTP service" do
23
23
  ftp = subject.ftp_connect(host)
24
24
 
25
- ftp.should_not be_closed
25
+ expect(ftp).not_to be_closed
26
26
  ftp.close
27
27
  end
28
28
 
@@ -30,14 +30,14 @@ describe Network::FTP do
30
30
  it "should set passive mode by default" do
31
31
  ftp = subject.ftp_connect(host)
32
32
 
33
- ftp.passive.should be_true
33
+ expect(ftp.passive).to be(true)
34
34
  ftp.close
35
35
  end
36
36
 
37
37
  it "should allow disabling passive mode" do
38
38
  ftp = subject.ftp_connect(host, :passive => false)
39
39
 
40
- ftp.passive.should be_false
40
+ expect(ftp.passive).to be(false)
41
41
  ftp.close
42
42
  end
43
43
  end
@@ -45,7 +45,7 @@ describe Network::FTP do
45
45
  context "when given a block" do
46
46
  it "should yield the new Net::FTP object" do
47
47
  ftp = subject.ftp_connect(host) do |ftp|
48
- ftp.should be_kind_of(Net::FTP)
48
+ expect(ftp).to be_kind_of(Net::FTP)
49
49
  end
50
50
 
51
51
  ftp.close
@@ -61,7 +61,7 @@ describe Network::FTP do
61
61
  yielded_ftp = ftp
62
62
  end
63
63
 
64
- yielded_ftp.should be_kind_of(Net::FTP)
64
+ expect(yielded_ftp).to be_kind_of(Net::FTP)
65
65
  end
66
66
 
67
67
  it "should close the FTP session after yielding it" do
@@ -73,8 +73,8 @@ describe Network::FTP do
73
73
  was_open = !ftp.closed?
74
74
  end
75
75
 
76
- was_open.should == true
77
- session.should be_closed
76
+ expect(was_open).to be(true)
77
+ expect(session).to be_closed
78
78
  end
79
79
  end
80
80
  end
@@ -4,7 +4,7 @@ require 'ronin/network/http'
4
4
  describe Network::HTTP do
5
5
  describe "proxy" do
6
6
  it "should be disabled by default" do
7
- subject.proxy.should_not be_enabled
7
+ expect(subject.proxy).not_to be_enabled
8
8
  end
9
9
  end
10
10
 
@@ -14,7 +14,7 @@ describe Network::HTTP do
14
14
  it "should accept URI objects" do
15
15
  options = subject.expand_url(url)
16
16
 
17
- options[:host].should == url.host
17
+ expect(options[:host]).to eq(url.host)
18
18
  end
19
19
 
20
20
  it "should accept Hashes" do
@@ -24,33 +24,61 @@ describe Network::HTTP do
24
24
  }
25
25
  options = subject.expand_url(hash)
26
26
 
27
- options[:host].should == url.host
28
- options[:port].should == url.port
27
+ expect(options[:host]).to eq(url.host)
28
+ expect(options[:port]).to eq(url.port)
29
29
  end
30
30
 
31
31
  it "should accept Strings" do
32
32
  options = subject.expand_url(url.to_s)
33
33
 
34
- options[:host].should == url.host
35
- options[:port].should == url.port
34
+ expect(options[:host]).to eq(url.host)
35
+ expect(options[:port]).to eq(url.port)
36
36
  end
37
37
 
38
- it "should default :path to '/'" do
39
- options = subject.expand_url(URI('http://example.com'))
38
+ describe ":path" do
39
+ it "should filter out empty URL paths" do
40
+ options = subject.expand_url(URI('http://example.com'))
40
41
 
41
- options[:path].should == '/'
42
+ expect(options[:path]).to be_nil
43
+ end
44
+
45
+ context "when the path is empty" do
46
+ it "should not be set" do
47
+ options = subject.expand_url(URI('http://example.com'))
48
+
49
+ expect(options).not_to have_key(:path)
50
+ end
51
+ end
42
52
  end
43
53
 
44
- it "should append the query-string to the :path options" do
45
- options = subject.expand_url(url)
54
+ describe ":query" do
55
+ it "should set :query to the query string" do
56
+ options = subject.expand_url(url)
57
+
58
+ expect(options[:query]).to eq(url.query)
59
+ end
60
+
61
+ context "when query is nil" do
62
+ it "should not be set" do
63
+ options = subject.expand_url(URI('http://example.com/path'))
46
64
 
47
- options[:path].should == "#{url.path}?#{url.query}"
65
+ expect(options).not_to have_key(:query)
66
+ end
67
+ end
68
+
69
+ context "when query is empty" do
70
+ it "should be set" do
71
+ options = subject.expand_url(URI('http://example.com/path?'))
72
+
73
+ expect(options[:query]).to be_empty
74
+ end
75
+ end
48
76
  end
49
77
 
50
78
  it "should set :ssl if the URI scheme is 'https'" do
51
79
  options = subject.expand_url(URI('https://example.com'))
52
80
 
53
- options[:ssl].should == {}
81
+ expect(options[:ssl]).to eq({})
54
82
  end
55
83
  end
56
84
 
@@ -59,30 +87,30 @@ describe Network::HTTP do
59
87
  options = {:ssl => true}
60
88
  expanded_options = subject.expand_options(options)
61
89
 
62
- expanded_options[:ssl].should == {}
90
+ expect(expanded_options[:ssl]).to eq({})
63
91
  end
64
92
 
65
93
  it "should added a default port and path" do
66
94
  options = {:host => 'example.com'}
67
95
  expanded_options = subject.expand_options(options)
68
96
 
69
- expanded_options[:port].should == 80
70
- expanded_options[:path].should == '/'
97
+ expect(expanded_options[:port]).to eq(80)
98
+ expect(expanded_options[:path]).to eq('/')
71
99
  end
72
100
 
73
101
  it "should add the default proxy settings" do
74
102
  options = {:host => 'example.com'}
75
103
  expanded_options = subject.expand_options(options)
76
104
 
77
- expanded_options[:proxy].should == subject.proxy
105
+ expect(expanded_options[:proxy]).to eq(subject.proxy)
78
106
  end
79
107
 
80
108
  it "should disable the proxy settings if :proxy is nil" do
81
109
  options = {:host => 'example.com', :proxy => nil}
82
110
  expanded_options = subject.expand_options(options)
83
111
 
84
- expanded_options[:proxy][:host].should be_nil
85
- expanded_options[:proxy][:port].should be_nil
112
+ expect(expanded_options[:proxy][:host]).to be_nil
113
+ expect(expanded_options[:proxy][:port]).to be_nil
86
114
  end
87
115
 
88
116
  it "should not modify :proxy if it is a HTTP::Proxy object" do
@@ -90,184 +118,249 @@ describe Network::HTTP do
90
118
  options = {:host => 'example.com', :proxy => proxy}
91
119
  expanded_options = subject.expand_options(options)
92
120
 
93
- expanded_options[:proxy].should == proxy
121
+ expect(expanded_options[:proxy]).to eq(proxy)
94
122
  end
95
123
 
96
124
  it "should parse the :proxy option" do
97
125
  options = {:host => 'example.com', :proxy => 'http://proxy.com:8181'}
98
126
  expanded_options = subject.expand_options(options)
99
127
 
100
- expanded_options[:proxy][:host].should == 'proxy.com'
101
- expanded_options[:proxy][:port].should == 8181
128
+ expect(expanded_options[:proxy][:host]).to eq('proxy.com')
129
+ expect(expanded_options[:proxy][:port]).to eq(8181)
102
130
  end
103
131
 
104
132
  it "should expand the :url option" do
105
133
  options = {:url => 'http://joe:secret@example.com:8080/bla?var'}
106
134
  expanded_options = subject.expand_options(options)
107
135
 
108
- expanded_options[:url].should be_nil
109
- expanded_options[:host].should == 'example.com'
110
- expanded_options[:port].should == 8080
111
- expanded_options[:user].should == 'joe'
112
- expanded_options[:password].should == 'secret'
113
- expanded_options[:path].should == '/bla?var'
136
+ expect(expanded_options[:url]).to be_nil
137
+ expect(expanded_options[:host]).to eq('example.com')
138
+ expect(expanded_options[:port]).to eq(8080)
139
+ expect(expanded_options[:user]).to eq('joe')
140
+ expect(expanded_options[:password]).to eq('secret')
141
+ expect(expanded_options[:path]).to eq('/bla')
142
+ expect(expanded_options[:query]).to eq('var')
114
143
  end
115
-
116
144
  end
117
145
 
118
146
  describe "headers" do
119
147
  it "should convert Symbol options to HTTP Headers" do
120
148
  options = {:user_agent => 'bla', :location => 'test'}
121
149
 
122
- subject.headers(options).should == {
150
+ expect(subject.headers(options)).to eq({
123
151
  'User-Agent' => 'bla',
124
- 'Location' => 'test'
125
- }
152
+ 'Location' => 'test'
153
+ })
126
154
  end
127
155
 
128
156
  it "should convert String options to HTTP Headers" do
129
157
  options = {'user_agent' => 'bla', 'x-powered-by' => 'PHP'}
130
158
 
131
- subject.headers(options).should == {
132
- 'User-Agent' => 'bla',
159
+ expect(subject.headers(options)).to eq({
160
+ 'User-Agent' => 'bla',
133
161
  'X-Powered-By' => 'PHP'
134
- }
162
+ })
135
163
  end
136
164
 
137
165
  it "should convert all values to Strings" do
138
166
  mtime = Time.now.to_i
139
167
  options = {:modified_by => mtime, :x_accept => :gzip}
140
168
 
141
- subject.headers(options).should == {
169
+ expect(subject.headers(options)).to eq({
142
170
  'Modified-By' => mtime.to_s,
143
- 'X-Accept' => 'gzip'
144
- }
171
+ 'X-Accept' => 'gzip'
172
+ })
145
173
  end
146
174
  end
147
175
 
148
176
  describe "request" do
149
177
  it "should handle Symbol names" do
150
- subject.request(
178
+ expect(subject.request(
151
179
  :method => :get, :path => '/'
152
- ).class.should == Net::HTTP::Get
180
+ ).class).to eq(Net::HTTP::Get)
153
181
  end
154
182
 
155
183
  it "should handle String names" do
156
- subject.request(
184
+ expect(subject.request(
157
185
  :method => 'GET', :path => '/'
158
- ).class.should == Net::HTTP::Get
186
+ ).class).to eq(Net::HTTP::Get)
159
187
  end
160
188
 
161
- it "should raise an UnknownRequest exception for invalid names" do
162
- lambda {
163
- subject.request(:method => :bla)
164
- }.should raise_error(subject::UnknownRequest)
165
- end
189
+ context "with :path" do
190
+ it "should use a default path" do
191
+ expect {
192
+ subject.request(:method => :get)
193
+ }.not_to raise_error
194
+ end
195
+
196
+ it "should set the path" do
197
+ req = subject.request(:method => :get, :path => '/foo')
166
198
 
167
- it "should use a default path" do
168
- lambda {
169
- subject.request(:method => :get)
170
- }.should_not raise_error(ArgumentError)
199
+ expect(req.path).to eq('/foo')
200
+ end
171
201
  end
172
202
 
173
- it "should accept the :user option for Basic-Auth" do
174
- req = subject.request(:method => :get, :user => 'joe')
203
+ context "with :query" do
204
+ let(:path) { '/foo' }
205
+ let(:query) { 'q=1' }
175
206
 
176
- req['authorization'].should == "Basic am9lOg=="
177
- end
207
+ it "should append the query-string to the path" do
208
+ req = subject.request(
209
+ :method => :get,
210
+ :path => path,
211
+ :query => query
212
+ )
178
213
 
179
- it "should accept the :user and :password options for Basic-Auth" do
180
- req = subject.request(
181
- :method => :get,
182
- :user => 'joe',
183
- :password => 'secret'
184
- )
214
+ expect(req.path).to eq("#{path}?#{query}")
215
+ end
185
216
 
186
- req['authorization'].should == "Basic am9lOnNlY3JldA=="
187
- end
217
+ context "when path already contains a query string" do
218
+ let(:additional_query) { 'x=2' }
188
219
 
189
- it "should create HTTP Copy requests" do
190
- req = subject.request(:method => :copy)
220
+ it "should append the query using a '&' character" do
221
+ req = subject.request(
222
+ :method => :get,
223
+ :path => "#{path}?#{query}",
224
+ :query => additional_query
225
+ )
191
226
 
192
- req.class.should == Net::HTTP::Copy
193
- end
227
+ expect(req.path).to eq("#{path}?#{query}&#{additional_query}")
228
+ end
194
229
 
195
- it "should create HTTP Delete requests" do
196
- req = subject.request(:method => :delete)
230
+ context "when :query is empty" do
231
+ it "should append an extra '&'" do
232
+ req = subject.request(
233
+ :method => :get,
234
+ :path => "#{path}?#{query}",
235
+ :query => ''
236
+ )
197
237
 
198
- req.class.should == Net::HTTP::Delete
199
- end
238
+ expect(req.path).to be_end_with('&')
239
+ end
240
+ end
241
+ end
200
242
 
201
- it "should create HTTP Get requests" do
202
- req = subject.request(:method => :get)
243
+ context "when :query is empty" do
244
+ it "should append an extra '?'" do
245
+ req = subject.request(
246
+ :method => :get,
247
+ :path => path,
248
+ :query => ''
249
+ )
203
250
 
204
- req.class.should == Net::HTTP::Get
251
+ expect(req.path).to be_end_with('?')
252
+ end
253
+ end
205
254
  end
206
255
 
207
- it "should create HTTP Head requests" do
208
- req = subject.request(:method => :head)
256
+ context "with :user and :password" do
257
+ it "should accept the :user option for Basic-Auth" do
258
+ req = subject.request(:method => :get, :user => 'joe')
209
259
 
210
- req.class.should == Net::HTTP::Head
211
- end
260
+ expect(req['authorization']).to eq("Basic am9lOg==")
261
+ end
212
262
 
213
- it "should create HTTP Lock requests" do
214
- req = subject.request(:method => :lock)
263
+ it "should also accept the :password options for Basic-Auth" do
264
+ req = subject.request(
265
+ :method => :get,
266
+ :user => 'joe',
267
+ :password => 'secret'
268
+ )
215
269
 
216
- req.class.should == Net::HTTP::Lock
270
+ expect(req['authorization']).to eq("Basic am9lOnNlY3JldA==")
271
+ end
217
272
  end
218
273
 
219
- it "should create HTTP Mkcol requests" do
220
- req = subject.request(:method => :mkcol)
274
+ context "with :method" do
275
+ it "should create HTTP Copy requests" do
276
+ req = subject.request(:method => :copy)
221
277
 
222
- req.class.should == Net::HTTP::Mkcol
223
- end
278
+ expect(req.class).to eq(Net::HTTP::Copy)
279
+ end
224
280
 
225
- it "should create HTTP Move requests" do
226
- req = subject.request(:method => :move)
281
+ it "should create HTTP Delete requests" do
282
+ req = subject.request(:method => :delete)
227
283
 
228
- req.class.should == Net::HTTP::Move
229
- end
284
+ expect(req.class).to eq(Net::HTTP::Delete)
285
+ end
230
286
 
231
- it "should create HTTP Options requests" do
232
- req = subject.request(:method => :options)
287
+ it "should create HTTP Get requests" do
288
+ req = subject.request(:method => :get)
233
289
 
234
- req.class.should == Net::HTTP::Options
235
- end
290
+ expect(req.class).to eq(Net::HTTP::Get)
291
+ end
236
292
 
237
- it "should create HTTP Post requests" do
238
- req = subject.request(:method => :post)
293
+ it "should create HTTP Head requests" do
294
+ req = subject.request(:method => :head)
239
295
 
240
- req.class.should == Net::HTTP::Post
241
- end
296
+ expect(req.class).to eq(Net::HTTP::Head)
297
+ end
242
298
 
243
- it "should create HTTP Propfind requests" do
244
- req = subject.request(:method => :propfind)
299
+ it "should create HTTP Lock requests" do
300
+ req = subject.request(:method => :lock)
245
301
 
246
- req.class.should == Net::HTTP::Propfind
247
- end
302
+ expect(req.class).to eq(Net::HTTP::Lock)
303
+ end
248
304
 
249
- it "should create HTTP Proppatch requests" do
250
- req = subject.request(:method => :proppatch)
305
+ it "should create HTTP Mkcol requests" do
306
+ req = subject.request(:method => :mkcol)
251
307
 
252
- req.class.should == Net::HTTP::Proppatch
253
- end
308
+ expect(req.class).to eq(Net::HTTP::Mkcol)
309
+ end
254
310
 
255
- it "should create HTTP Trace requests" do
256
- req = subject.request(:method => :trace)
311
+ it "should create HTTP Move requests" do
312
+ req = subject.request(:method => :move)
257
313
 
258
- req.class.should == Net::HTTP::Trace
259
- end
314
+ expect(req.class).to eq(Net::HTTP::Move)
315
+ end
316
+
317
+ it "should create HTTP Options requests" do
318
+ req = subject.request(:method => :options)
260
319
 
261
- it "should create HTTP Unlock requests" do
262
- req = subject.request(:method => :unlock)
320
+ expect(req.class).to eq(Net::HTTP::Options)
321
+ end
322
+
323
+ it "should create HTTP Post requests" do
324
+ req = subject.request(:method => :post)
325
+
326
+ expect(req.class).to eq(Net::HTTP::Post)
327
+ end
328
+
329
+ it "should create HTTP Propfind requests" do
330
+ req = subject.request(:method => :propfind)
263
331
 
264
- req.class.should == Net::HTTP::Unlock
332
+ expect(req.class).to eq(Net::HTTP::Propfind)
333
+ end
334
+
335
+ it "should create HTTP Proppatch requests" do
336
+ req = subject.request(:method => :proppatch)
337
+
338
+ expect(req.class).to eq(Net::HTTP::Proppatch)
339
+ end
340
+
341
+ it "should create HTTP Trace requests" do
342
+ req = subject.request(:method => :trace)
343
+
344
+ expect(req.class).to eq(Net::HTTP::Trace)
345
+ end
346
+
347
+ it "should create HTTP Unlock requests" do
348
+ req = subject.request(:method => :unlock)
349
+
350
+ expect(req.class).to eq(Net::HTTP::Unlock)
351
+ end
352
+
353
+ it "should raise an UnknownRequest exception for invalid methods" do
354
+ expect {
355
+ subject.request(:method => :bla)
356
+ }.to raise_error(subject::UnknownRequest)
357
+ end
265
358
  end
266
359
 
267
360
  it "should raise an ArgumentError when :method is not specified" do
268
- lambda {
361
+ expect {
269
362
  subject.request()
270
- }.should raise_error(ArgumentError)
363
+ }.to raise_error(ArgumentError)
271
364
  end
272
365
  end
273
366
 
@@ -287,8 +380,8 @@ describe Network::HTTP do
287
380
  it "should create a Net::HTTP session" do
288
381
  http = subject.http_connect(:host => host, :port => port)
289
382
 
290
- http.should be_kind_of(Net::HTTP)
291
- http.should be_started
383
+ expect(http).to be_kind_of(Net::HTTP)
384
+ expect(http).to be_started
292
385
 
293
386
  http.finish
294
387
  end
@@ -300,7 +393,7 @@ describe Network::HTTP do
300
393
  http = session
301
394
  end
302
395
 
303
- http.should be_kind_of(Net::HTTP)
396
+ expect(http).to be_kind_of(Net::HTTP)
304
397
  end
305
398
 
306
399
  it "should allow yielding the expanded options" do
@@ -310,9 +403,9 @@ describe Network::HTTP do
310
403
  expanded_options = options
311
404
  end
312
405
 
313
- expanded_options[:host].should == host
314
- expanded_options[:port].should == port
315
- expanded_options[:path].should == path
406
+ expect(expanded_options[:host]).to eq(host)
407
+ expect(expanded_options[:port]).to eq(port)
408
+ expect(expanded_options[:path]).to eq(path)
316
409
  end
317
410
  end
318
411
 
@@ -324,8 +417,8 @@ describe Network::HTTP do
324
417
  http = session
325
418
  end
326
419
 
327
- http.should be_kind_of(Net::HTTP)
328
- http.should_not be_started
420
+ expect(http).to be_kind_of(Net::HTTP)
421
+ expect(http).not_to be_started
329
422
  end
330
423
 
331
424
  it "should allow yielding the Net::HTTP session" do
@@ -335,7 +428,7 @@ describe Network::HTTP do
335
428
  http = session
336
429
  end
337
430
 
338
- http.should be_kind_of(Net::HTTP)
431
+ expect(http).to be_kind_of(Net::HTTP)
339
432
  end
340
433
 
341
434
  it "should allow yielding the expanded options" do
@@ -345,9 +438,9 @@ describe Network::HTTP do
345
438
  expanded_options = options
346
439
  end
347
440
 
348
- expanded_options[:host].should == host
349
- expanded_options[:port].should == port
350
- expanded_options[:path].should == path
441
+ expect(expanded_options[:host]).to eq(host)
442
+ expect(expanded_options[:port]).to eq(port)
443
+ expect(expanded_options[:path]).to eq(path)
351
444
  end
352
445
  end
353
446
 
@@ -355,7 +448,7 @@ describe Network::HTTP do
355
448
  it "should send an arbitrary request and return the response" do
356
449
  response = subject.http_request(:url => uri, :method => :options)
357
450
 
358
- response.should be_kind_of(Net::HTTPMethodNotAllowed)
451
+ expect(response).to be_kind_of(Net::HTTPMethodNotAllowed)
359
452
  end
360
453
 
361
454
  it "should allow yielding the request" do
@@ -365,7 +458,7 @@ describe Network::HTTP do
365
458
  request = req
366
459
  end
367
460
 
368
- request.should be_kind_of(Net::HTTP::Options)
461
+ expect(request).to be_kind_of(Net::HTTP::Options)
369
462
  end
370
463
 
371
464
  it "should allow yielding the expanded options" do
@@ -375,25 +468,25 @@ describe Network::HTTP do
375
468
  expanded_options = options
376
469
  end
377
470
 
378
- expanded_options[:host].should == host
379
- expanded_options[:port].should == port
380
- expanded_options[:path].should == path
471
+ expect(expanded_options[:host]).to eq(host)
472
+ expect(expanded_options[:port]).to eq(port)
473
+ expect(expanded_options[:path]).to eq(path)
381
474
  end
382
475
  end
383
476
 
384
477
  describe "#http_status" do
385
478
  it "should return an Integer" do
386
- subject.http_status(:url => uri).should be_kind_of(Integer)
479
+ expect(subject.http_status(:url => uri)).to be_kind_of(Integer)
387
480
  end
388
481
 
389
482
  it "should return the status-code of the Response" do
390
- subject.http_status(:url => uri).should == 200
483
+ expect(subject.http_status(:url => uri)).to eq(200)
391
484
  end
392
485
  end
393
486
 
394
487
  describe "#http_ok?" do
395
488
  it "should check if the Response has code 200" do
396
- subject.http_ok?(:url => uri).should == true
489
+ expect(subject.http_ok?(:url => uri)).to be(true)
397
490
  end
398
491
  end
399
492
 
@@ -402,7 +495,7 @@ describe Network::HTTP do
402
495
  let(:headers) { subject.http_get_headers(:url => url) }
403
496
 
404
497
  it "should return the 'Server' header" do
405
- subject.http_server(:url => url).should == headers['Server']
498
+ expect(subject.http_server(:url => url)).to eq(headers['Server'])
406
499
  end
407
500
  end
408
501
 
@@ -411,7 +504,7 @@ describe Network::HTTP do
411
504
  let(:headers) { subject.http_get_headers(:url => url) }
412
505
 
413
506
  it "should return the 'X-Powered-By' header" do
414
- subject.http_powered_by(:url => url).should == headers['X-Powered-By']
507
+ expect(subject.http_powered_by(:url => url)).to eq(headers['X-Powered-By'])
415
508
  end
416
509
  end
417
510
 
@@ -419,14 +512,14 @@ describe Network::HTTP do
419
512
  let(:headers) { subject.http_get_headers(:url => uri) }
420
513
 
421
514
  it "should return HTTP Headers" do
422
- headers.should_not be_empty
515
+ expect(headers).not_to be_empty
423
516
  end
424
517
 
425
518
  it "should format the HTTP Headers accordingly" do
426
519
  format = /^[A-Z][a-z0-9]*(-[A-Z][a-z0-9]*)*$/
427
520
  bad_headers = headers.keys.reject { |name| name =~ format }
428
521
 
429
- bad_headers.should == []
522
+ expect(bad_headers).to eq([])
430
523
  end
431
524
  end
432
525
 
@@ -434,8 +527,8 @@ describe Network::HTTP do
434
527
  it "should return the response body" do
435
528
  body = subject.http_get_body(:url => uri)
436
529
 
437
- body.should be_kind_of(String)
438
- body.should_not be_empty
530
+ expect(body).to be_kind_of(String)
531
+ expect(body).not_to be_empty
439
532
  end
440
533
  end
441
534
 
@@ -443,14 +536,14 @@ describe Network::HTTP do
443
536
  let(:headers) { subject.http_post_headers(:url => uri) }
444
537
 
445
538
  it "should return HTTP Headers" do
446
- headers.should_not be_empty
539
+ expect(headers).not_to be_empty
447
540
  end
448
541
 
449
542
  it "should format the HTTP Headers accordingly" do
450
543
  format = /^[A-Z][a-z0-9]*(-[A-Z][a-z0-9]*)*$/
451
544
  bad_headers = headers.keys.reject { |name| name =~ format }
452
545
 
453
- bad_headers.should == []
546
+ expect(bad_headers).to eq([])
454
547
  end
455
548
  end
456
549
 
@@ -458,8 +551,8 @@ describe Network::HTTP do
458
551
  it "should return the response body" do
459
552
  body = subject.http_post_body(:url => uri)
460
553
 
461
- body.should be_kind_of(String)
462
- body.should_not be_empty
554
+ expect(body).to be_kind_of(String)
555
+ expect(body).not_to be_empty
463
556
  end
464
557
  end
465
558
  end