ronin-support 0.4.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (224) 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 +121 -33
  7. data/Gemfile +17 -18
  8. data/README.md +57 -33
  9. data/Rakefile +10 -3
  10. data/gemspec.yml +16 -7
  11. data/lib/ronin/binary.rb +21 -0
  12. data/lib/ronin/binary/hexdump.rb +20 -0
  13. data/lib/ronin/binary/hexdump/parser.rb +403 -0
  14. data/lib/ronin/binary/struct.rb +567 -0
  15. data/lib/ronin/binary/template.rb +454 -0
  16. data/lib/ronin/extensions.rb +5 -5
  17. data/lib/ronin/extensions/enumerable.rb +5 -5
  18. data/lib/ronin/extensions/file.rb +39 -33
  19. data/lib/ronin/extensions/ip_addr.rb +29 -31
  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 +50 -5
  23. data/lib/ronin/extensions/resolv.rb +7 -9
  24. data/lib/ronin/extensions/string.rb +10 -10
  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 +7 -5
  30. data/lib/ronin/formatting/extensions/binary/array.rb +61 -0
  31. data/lib/ronin/formatting/extensions/binary/base64.rb +106 -0
  32. data/lib/ronin/formatting/extensions/binary/file.rb +44 -11
  33. data/lib/ronin/formatting/extensions/binary/float.rb +65 -0
  34. data/lib/ronin/formatting/extensions/binary/integer.rb +66 -50
  35. data/lib/ronin/formatting/extensions/binary/string.rb +81 -205
  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 +9 -13
  41. data/lib/ronin/formatting/extensions/html/string.rb +31 -39
  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 +22 -24
  47. data/lib/ronin/formatting/extensions/text.rb +5 -5
  48. data/lib/ronin/formatting/extensions/text/array.rb +13 -11
  49. data/lib/ronin/formatting/extensions/text/string.rb +70 -13
  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 +42 -213
  57. data/lib/ronin/fuzzing/fuzzer.rb +110 -0
  58. data/lib/ronin/fuzzing/fuzzing.rb +33 -26
  59. data/lib/ronin/fuzzing/mutator.rb +161 -0
  60. data/lib/ronin/fuzzing/repeater.rb +81 -0
  61. data/lib/ronin/fuzzing/template.rb +133 -0
  62. data/lib/ronin/mixin.rb +2 -2
  63. data/lib/ronin/network.rb +7 -5
  64. data/lib/ronin/network/dns.rb +64 -24
  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 +149 -0
  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 +65 -70
  93. data/lib/ronin/network/http/proxy.rb +5 -5
  94. data/lib/ronin/network/imap.rb +16 -15
  95. data/lib/ronin/network/mixins.rb +6 -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 +155 -0
  99. data/lib/ronin/network/mixins/http.rb +58 -587
  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 +43 -10
  106. data/lib/ronin/network/mixins/telnet.rb +5 -5
  107. data/lib/ronin/network/mixins/udp.rb +126 -6
  108. data/lib/ronin/network/mixins/unix.rb +279 -0
  109. data/lib/ronin/network/network.rb +5 -5
  110. data/lib/ronin/network/pop3.rb +10 -10
  111. data/lib/ronin/network/proxy.rb +578 -0
  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 +12 -13
  115. data/lib/ronin/network/ssl.rb +16 -17
  116. data/lib/ronin/network/tcp.rb +7 -310
  117. data/lib/ronin/network/tcp/proxy.rb +417 -0
  118. data/lib/ronin/network/tcp/tcp.rb +452 -0
  119. data/lib/ronin/network/telnet.rb +34 -28
  120. data/lib/ronin/network/udp.rb +7 -271
  121. data/lib/ronin/network/udp/proxy.rb +191 -0
  122. data/lib/ronin/network/udp/udp.rb +452 -0
  123. data/lib/ronin/network/unix.rb +286 -0
  124. data/lib/ronin/path.rb +35 -39
  125. data/lib/ronin/spec/ui/output.rb +6 -12
  126. data/lib/ronin/support.rb +6 -5
  127. data/lib/ronin/support/inflector.rb +8 -12
  128. data/lib/ronin/support/support.rb +7 -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 +42 -28
  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 +15 -9
  138. data/lib/ronin/ui/output/terminal/raw.rb +5 -5
  139. data/lib/ronin/ui/shell.rb +8 -11
  140. data/lib/ronin/wordlist.rb +110 -30
  141. data/ronin-support.gemspec +39 -109
  142. data/spec/binary/hexdump/helpers/hexdumps.rb +13 -0
  143. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/ascii.bin +0 -0
  144. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/hexdump_decimal_shorts.txt +0 -0
  145. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/hexdump_hex_bytes.txt +0 -0
  146. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/hexdump_hex_shorts.txt +0 -0
  147. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/hexdump_octal_bytes.txt +0 -0
  148. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/hexdump_octal_shorts.txt +0 -0
  149. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/hexdump_repeated.txt +0 -0
  150. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_decimal_bytes.txt +0 -0
  151. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_decimal_ints.txt +0 -0
  152. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_decimal_quads.txt +0 -0
  153. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_decimal_shorts.txt +0 -0
  154. data/spec/binary/hexdump/helpers/hexdumps/od_doubles.txt +17 -0
  155. data/spec/binary/hexdump/helpers/hexdumps/od_floats.txt +17 -0
  156. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_hex_bytes.txt +0 -0
  157. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_hex_ints.txt +0 -0
  158. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_hex_quads.txt +0 -0
  159. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_hex_shorts.txt +0 -0
  160. data/spec/binary/hexdump/helpers/hexdumps/od_named_chars.txt +17 -0
  161. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_octal_bytes.txt +0 -0
  162. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_octal_ints.txt +0 -0
  163. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_octal_quads.txt +0 -0
  164. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_octal_shorts.txt +0 -0
  165. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_repeated.txt +0 -0
  166. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/repeated.bin +0 -0
  167. data/spec/binary/hexdump/parser_spec.rb +302 -0
  168. data/spec/binary/struct_spec.rb +496 -0
  169. data/spec/binary/template_spec.rb +416 -0
  170. data/spec/extensions/enumerable_spec.rb +4 -4
  171. data/spec/extensions/file_spec.rb +12 -14
  172. data/spec/extensions/ip_addr_spec.rb +76 -50
  173. data/spec/extensions/kernel_spec.rb +7 -7
  174. data/spec/extensions/regexp_spec.rb +119 -59
  175. data/spec/extensions/resolv_spec.rb +2 -2
  176. data/spec/extensions/string_spec.rb +31 -30
  177. data/spec/formatting/binary/array_spec.rb +26 -0
  178. data/spec/formatting/binary/base64_spec.rb +50 -0
  179. data/spec/formatting/binary/float_spec.rb +36 -0
  180. data/spec/formatting/binary/integer_spec.rb +76 -50
  181. data/spec/formatting/binary/string_spec.rb +91 -198
  182. data/spec/formatting/digest/string_spec.rb +5 -5
  183. data/spec/formatting/html/integer_spec.rb +6 -6
  184. data/spec/formatting/html/string_spec.rb +10 -10
  185. data/spec/formatting/http/integer_spec.rb +3 -3
  186. data/spec/formatting/http/string_spec.rb +5 -5
  187. data/spec/formatting/sql/string_spec.rb +21 -19
  188. data/spec/formatting/text/array_spec.rb +15 -15
  189. data/spec/formatting/text/string_spec.rb +58 -28
  190. data/spec/fuzzing/extensions/string_spec.rb +87 -0
  191. data/spec/fuzzing/fuzzer_spec.rb +109 -0
  192. data/spec/fuzzing/fuzzing_spec.rb +24 -0
  193. data/spec/fuzzing/mutator_spec.rb +112 -0
  194. data/spec/fuzzing/repeater_spec.rb +57 -0
  195. data/spec/fuzzing/template_spec.rb +54 -0
  196. data/spec/mixin_spec.rb +10 -12
  197. data/spec/network/dns_spec.rb +89 -23
  198. data/spec/network/ftp_spec.rb +81 -0
  199. data/spec/network/http/http_spec.rb +237 -144
  200. data/spec/network/http/proxy_spec.rb +37 -37
  201. data/spec/network/network_spec.rb +2 -2
  202. data/spec/network/proxy_spec.rb +121 -0
  203. data/spec/network/shared/unix_server.rb +31 -0
  204. data/spec/network/smtp/email_spec.rb +14 -14
  205. data/spec/network/ssl_spec.rb +53 -3
  206. data/spec/network/tcp/proxy_spec.rb +118 -0
  207. data/spec/network/tcp/tcp_spec.rb +316 -0
  208. data/spec/network/telnet_spec.rb +67 -0
  209. data/spec/network/udp/udp_spec.rb +298 -0
  210. data/spec/network/unix_spec.rb +182 -0
  211. data/spec/path_spec.rb +43 -18
  212. data/spec/spec_helper.rb +2 -3
  213. data/spec/support/inflector_spec.rb +4 -4
  214. data/spec/support_spec.rb +1 -1
  215. data/spec/templates/erb_spec.rb +3 -3
  216. data/spec/templates/template_spec.rb +10 -10
  217. data/spec/ui/shell_spec.rb +15 -15
  218. data/spec/wordlist_spec.rb +80 -19
  219. metadata +176 -121
  220. data/.gemtest +0 -0
  221. data/spec/formatting/binary/helpers/hexdumps.rb +0 -16
  222. data/spec/fuzzing/string_spec.rb +0 -158
  223. data/spec/network/tcp_spec.rb +0 -247
  224. data/spec/network/udp_spec.rb +0 -248
@@ -32,7 +32,7 @@ describe String do
32
32
  let(:html_escaped) { "one & two" }
33
33
 
34
34
  it "should HTML escape itself" do
35
- subject.html_escape.should == html_escaped
35
+ expect(subject.html_escape).to eq(html_escaped)
36
36
  end
37
37
  end
38
38
 
@@ -40,7 +40,7 @@ describe String do
40
40
  let(:html_escaped) { "one & two" }
41
41
 
42
42
  it "should HTML unescape itself" do
43
- html_escaped.html_unescape.should == subject
43
+ expect(html_escaped.html_unescape).to eq(subject)
44
44
  end
45
45
  end
46
46
 
@@ -50,7 +50,7 @@ describe String do
50
50
  end
51
51
 
52
52
  it "should HTML format all chars" do
53
- subject.format_html.should == formatted_html
53
+ expect(subject.format_html).to eq(formatted_html)
54
54
  end
55
55
  end
56
56
 
@@ -61,11 +61,11 @@ describe String do
61
61
  let(:normal_chars) { "abc" }
62
62
 
63
63
  it "should escape special JavaScript characters" do
64
- special_chars.js_escape.should == escaped_special_chars
64
+ expect(special_chars.js_escape).to eq(escaped_special_chars)
65
65
  end
66
66
 
67
67
  it "should ignore normal characters" do
68
- normal_chars.js_escape.should == normal_chars
68
+ expect(normal_chars.js_escape).to eq(normal_chars)
69
69
  end
70
70
  end
71
71
 
@@ -77,19 +77,19 @@ describe String do
77
77
  let(:js_mixed) { "%u6F%u6E%u65 %26 two" }
78
78
 
79
79
  it "should unescape JavaScript unicode characters" do
80
- js_unicode.js_unescape.should == subject
80
+ expect(js_unicode.js_unescape).to eq(subject)
81
81
  end
82
82
 
83
83
  it "should unescape JavaScript hex characters" do
84
- js_hex.js_unescape.should == subject
84
+ expect(js_hex.js_unescape).to eq(subject)
85
85
  end
86
86
 
87
87
  it "should unescape backslash-escaped characters" do
88
- "\\b\\t\\n\\f\\r\\\"\\\\".js_unescape.should == "\b\t\n\f\r\"\\"
88
+ expect("\\b\\t\\n\\f\\r\\\"\\\\".js_unescape).to eq("\b\t\n\f\r\"\\")
89
89
  end
90
90
 
91
91
  it "should ignore non-escaped characters" do
92
- js_mixed.js_unescape.should == subject
92
+ expect(js_mixed.js_unescape).to eq(subject)
93
93
  end
94
94
  end
95
95
 
@@ -97,7 +97,7 @@ describe String do
97
97
  let(:js_formatted) { '\x6F\x6E\x65\x20\x26\x20\x74\x77\x6F' }
98
98
 
99
99
  it "should JavaScript escape all characters" do
100
- subject.format_js.should == js_formatted
100
+ expect(subject.format_js).to eq(js_formatted)
101
101
  end
102
102
  end
103
103
  end
@@ -20,7 +20,7 @@ describe Integer do
20
20
  let(:uri_encoded) { '%20' }
21
21
 
22
22
  it "should URI encode itself" do
23
- subject.uri_encode.should == uri_encoded
23
+ expect(subject.uri_encode).to eq(uri_encoded)
24
24
  end
25
25
  end
26
26
 
@@ -28,7 +28,7 @@ describe Integer do
28
28
  let(:uri_escaped) { '+' }
29
29
 
30
30
  it "should URI escape itself" do
31
- subject.uri_escape.should == uri_escaped
31
+ expect(subject.uri_escape).to eq(uri_escaped)
32
32
  end
33
33
  end
34
34
 
@@ -36,7 +36,7 @@ describe Integer do
36
36
  let(:http_formatted) { '%20' }
37
37
 
38
38
  it "should format the byte" do
39
- subject.format_http.should == http_formatted
39
+ expect(subject.format_http).to eq(http_formatted)
40
40
  end
41
41
  end
42
42
  end
@@ -30,7 +30,7 @@ describe String do
30
30
  let(:uri_encoded) { "mod%20%25%203" }
31
31
 
32
32
  it "should URI encode itself" do
33
- subject.uri_encode.should == uri_encoded
33
+ expect(subject.uri_encode).to eq(uri_encoded)
34
34
  end
35
35
  end
36
36
 
@@ -40,7 +40,7 @@ describe String do
40
40
  let(:uri_decoded) { "mod % 3" }
41
41
 
42
42
  it "should URI decode itself" do
43
- subject.uri_decode.should == uri_decoded
43
+ expect(subject.uri_decode).to eq(uri_decoded)
44
44
  end
45
45
  end
46
46
 
@@ -50,7 +50,7 @@ describe String do
50
50
  let(:uri_escaped) { "x+%2B+y" }
51
51
 
52
52
  it "should URI escape itself" do
53
- subject.uri_escape.should == uri_escaped
53
+ expect(subject.uri_escape).to eq(uri_escaped)
54
54
  end
55
55
  end
56
56
 
@@ -60,7 +60,7 @@ describe String do
60
60
  let(:uri_unescaped) { "x + y" }
61
61
 
62
62
  it "should URI unescape itself" do
63
- subject.uri_unescape.should == uri_unescaped
63
+ expect(subject.uri_unescape).to eq(uri_unescaped)
64
64
  end
65
65
  end
66
66
 
@@ -70,7 +70,7 @@ describe String do
70
70
  let(:http_formatted) { "%6D%6F%64%20%25%20%33" }
71
71
 
72
72
  it "should format each byte of the String" do
73
- subject.format_http.should == http_formatted
73
+ expect(subject.format_http).to eq(http_formatted)
74
74
  end
75
75
  end
76
76
  end
@@ -2,73 +2,75 @@ require 'spec_helper'
2
2
  require 'ronin/formatting/extensions/sql/string'
3
3
 
4
4
  describe String do
5
- before(:all) do
6
- @string = '/etc/passwd'
7
- @sql_encoded = '0x2f6574632f706173737764'
8
- @string_with_quotes = %{"O'Brian"}
9
- end
5
+ let(:string) {'/etc/passwd' }
6
+ let(:sql_encoded) { '0x2f6574632f706173737764' }
7
+ let(:string_with_quotes) { %{"O'Brian"} }
10
8
 
11
9
  it "should provide the #sql_escape method" do
12
- @string.should respond_to(:sql_escape)
10
+ expect(string).to respond_to(:sql_escape)
13
11
  end
14
12
 
15
13
  it "should provide the #sql_encode method" do
16
- @string.should respond_to(:sql_encode)
14
+ expect(string).to respond_to(:sql_encode)
17
15
  end
18
16
 
19
17
  it "should provide the #sql_decode method" do
20
- @string.should respond_to(:sql_decode)
18
+ expect(string).to respond_to(:sql_decode)
21
19
  end
22
20
 
23
21
  describe "#sql_escape" do
24
22
  it "should be able to single-quote escape" do
25
- @string_with_quotes.sql_escape(:single).should == %{'"O''Brian"'}
23
+ expect(string_with_quotes.sql_escape(:single)).to eq(%{'"O''Brian"'})
26
24
  end
27
25
 
28
26
  it "should be able to double-quote escape" do
29
- @string_with_quotes.sql_escape(:double).should == %{"""O'Brian"""}
27
+ expect(string_with_quotes.sql_escape(:double)).to eq(%{"""O'Brian"""})
28
+ end
29
+
30
+ it "should be able to tick-mark escape" do
31
+ expect(string_with_quotes.sql_escape(:tick)).to eq(%{`"O'Brian"`})
30
32
  end
31
33
  end
32
34
 
33
35
  describe "#sql_encode" do
34
36
  it "should be able to be SQL-hex encoded" do
35
- @string.sql_encode.should == @sql_encoded
37
+ expect(string.sql_encode).to eq(sql_encoded)
36
38
  end
37
39
 
38
40
  it "should return an empty String if empty" do
39
- ''.sql_encode.should == ''
41
+ expect(''.sql_encode).to eq('')
40
42
  end
41
43
  end
42
44
 
43
45
  describe "#sql_decode" do
44
46
  it "should be able to be SQL-hex decoded" do
45
- encoded = @string.sql_encode
47
+ encoded = string.sql_encode
46
48
 
47
- encoded.should == @sql_encoded
48
- encoded.sql_decode.should == @string
49
+ expect(encoded).to eq(sql_encoded)
50
+ expect(encoded.sql_decode).to eq(string)
49
51
  end
50
52
 
51
53
  it "should be able to decode SQL comma-escaping" do
52
- "'Conan O''Brian'".sql_decode.should == "Conan O'Brian"
54
+ expect("'Conan O''Brian'".sql_decode).to eq("Conan O'Brian")
53
55
  end
54
56
  end
55
57
 
56
58
  describe "#sql_inject" do
57
59
  context "when there is a leading quote character" do
58
60
  it "should remove the first and last quote character" do
59
- "'1' OR '1'='1'".sql_inject.should == "1' OR '1'='1"
61
+ expect("'1' OR '1'='1'".sql_inject).to eq("1' OR '1'='1")
60
62
  end
61
63
 
62
64
  context "when there is no matching leading/trailing quote characters" do
63
65
  it "should comment-terminate the String" do
64
- "'1' OR 1=1".sql_inject.should == "1' OR 1=1--"
66
+ expect("'1' OR 1=1".sql_inject).to eq("1' OR 1=1--")
65
67
  end
66
68
  end
67
69
  end
68
70
 
69
71
  context "when there is no leading quote character" do
70
72
  it "should not modify the String" do
71
- "1 OR 1=1".sql_inject.should == "1 OR 1=1"
73
+ expect("1 OR 1=1".sql_inject).to eq("1 OR 1=1")
72
74
  end
73
75
  end
74
76
  end
@@ -31,43 +31,43 @@ describe Array do
31
31
 
32
32
  describe "#bytes" do
33
33
  it "should convert an Array of bytes to an Array of bytes" do
34
- byte_array.bytes.should == byte_array
34
+ expect(byte_array.bytes).to eq(byte_array)
35
35
  end
36
36
 
37
37
  it "should convert an Array of chars to an Array of bytes" do
38
- char_array.bytes.should == byte_array
38
+ expect(char_array.bytes).to eq(byte_array)
39
39
  end
40
40
 
41
41
  it "should safely handle mixed byte/char/string Arrays" do
42
- mixed_array.bytes.should == byte_array
42
+ expect(mixed_array.bytes).to eq(byte_array)
43
43
  end
44
44
  end
45
45
 
46
46
  describe "#chars" do
47
47
  it "should convert an Array of bytes to an Array of chars" do
48
- byte_array.chars.should == char_array
48
+ expect(byte_array.chars).to eq(char_array)
49
49
  end
50
50
 
51
51
  it "should safely convert an Array of chars to an Array of chars" do
52
- char_array.chars.should == char_array
52
+ expect(char_array.chars).to eq(char_array)
53
53
  end
54
54
 
55
55
  it "should safely handle mixed byte/char/string Arrays" do
56
- mixed_array.chars.should == char_array
56
+ expect(mixed_array.chars).to eq(char_array)
57
57
  end
58
58
  end
59
59
 
60
60
  describe "#char_string" do
61
61
  it "should convert an Array of bytes to a String" do
62
- byte_array.char_string.should == string
62
+ expect(byte_array.char_string).to eq(string)
63
63
  end
64
64
 
65
65
  it "should convert an Array of chars to a String" do
66
- char_array.char_string.should == string
66
+ expect(char_array.char_string).to eq(string)
67
67
  end
68
68
 
69
69
  it "should safely handle mixed byte/char/string Arrays" do
70
- mixed_array.char_string.should == string
70
+ expect(mixed_array.char_string).to eq(string)
71
71
  end
72
72
  end
73
73
 
@@ -75,15 +75,15 @@ describe Array do
75
75
  let(:hex_chars) { ['\x41', '\x41', '\x20'] }
76
76
 
77
77
  it "should convert an Array of bytes into hexadecimal chars" do
78
- byte_array.hex_chars.should == hex_chars
78
+ expect(byte_array.hex_chars).to eq(hex_chars)
79
79
  end
80
80
 
81
81
  it "should convert an Array of chars into hexadecimal chars" do
82
- char_array.hex_chars.should == hex_chars
82
+ expect(char_array.hex_chars).to eq(hex_chars)
83
83
  end
84
84
 
85
85
  it "should safely handle mixed byte/char/string Arrays" do
86
- mixed_array.hex_chars.should == hex_chars
86
+ expect(mixed_array.hex_chars).to eq(hex_chars)
87
87
  end
88
88
  end
89
89
 
@@ -91,15 +91,15 @@ describe Array do
91
91
  let(:hex_integers) { ['0x41', '0x41', '0x20'] }
92
92
 
93
93
  it "should convert an Array of bytes into hexadecimal integers" do
94
- byte_array.hex_integers.should == hex_integers
94
+ expect(byte_array.hex_integers).to eq(hex_integers)
95
95
  end
96
96
 
97
97
  it "should convert an Array of chars into hexadecimal integers" do
98
- char_array.hex_integers.should == hex_integers
98
+ expect(char_array.hex_integers).to eq(hex_integers)
99
99
  end
100
100
 
101
101
  it "should safely handle mixed byte/char/string Arrays" do
102
- mixed_array.hex_integers.should == hex_integers
102
+ expect(mixed_array.hex_integers).to eq(hex_integers)
103
103
  end
104
104
  end
105
105
  end
@@ -24,67 +24,75 @@ describe String do
24
24
  should respond_to(:insert_after)
25
25
  end
26
26
 
27
+ it "should provide String#escape" do
28
+ should respond_to(:escape)
29
+ end
30
+
31
+ it "should provide String#unescape" do
32
+ should respond_to(:unescape)
33
+ end
34
+
27
35
  describe "#format_bytes" do
28
36
  it "should format each byte in the String" do
29
- subject.format_bytes { |b|
37
+ expect(subject.format_bytes { |b|
30
38
  sprintf("%%%x",b)
31
- }.should == "%68%65%6c%6c%6f"
39
+ }).to eq("%68%65%6c%6c%6f")
32
40
  end
33
41
 
34
42
  it "should format specific bytes in a String" do
35
- subject.format_bytes(:include => [104, 108]) { |b|
43
+ expect(subject.format_bytes(:include => [104, 108]) { |b|
36
44
  b - 32
37
- }.should == 'HeLLo'
45
+ }).to eq('HeLLo')
38
46
  end
39
47
 
40
48
  it "should not format specific bytes in a String" do
41
- subject.format_bytes(:exclude => [101, 111]) { |b|
49
+ expect(subject.format_bytes(:exclude => [101, 111]) { |b|
42
50
  b - 32
43
- }.should == 'HeLLo'
51
+ }).to eq('HeLLo')
44
52
  end
45
53
 
46
54
  it "should format ranges of bytes in a String" do
47
- subject.format_bytes(:include => (104..108)) { |b|
55
+ expect(subject.format_bytes(:include => (104..108)) { |b|
48
56
  b - 32
49
- }.should == 'HeLLo'
57
+ }).to eq('HeLLo')
50
58
  end
51
59
 
52
60
  it "should not format ranges of bytes in a String" do
53
- subject.format_bytes(:exclude => (104..108)) { |b|
61
+ expect(subject.format_bytes(:exclude => (104..108)) { |b|
54
62
  b - 32
55
- }.should == 'hEllO'
63
+ }).to eq('hEllO')
56
64
  end
57
65
  end
58
66
 
59
67
  describe "#format_chars" do
60
68
  it "should format each character in the String" do
61
- subject.format_chars { |c|
69
+ expect(subject.format_chars { |c|
62
70
  "#{c}."
63
- }.should == "h.e.l.l.o."
71
+ }).to eq("h.e.l.l.o.")
64
72
  end
65
73
 
66
74
  it "should format specific chars in a String" do
67
- subject.format_chars(:include => ['h', 'l']) { |c|
75
+ expect(subject.format_chars(:include => ['h', 'l']) { |c|
68
76
  c.upcase
69
- }.should == 'HeLLo'
77
+ }).to eq('HeLLo')
70
78
  end
71
79
 
72
80
  it "should not format specific chars in a String" do
73
- subject.format_chars(:exclude => ['h', 'l']) { |c|
81
+ expect(subject.format_chars(:exclude => ['h', 'l']) { |c|
74
82
  c.upcase
75
- }.should == 'hEllO'
83
+ }).to eq('hEllO')
76
84
  end
77
85
 
78
86
  it "should format ranges of chars in a String" do
79
- subject.format_chars(:include => /[h-l]/) { |c|
87
+ expect(subject.format_chars(:include => /[h-l]/) { |c|
80
88
  c.upcase
81
- }.should == 'HeLLo'
89
+ }).to eq('HeLLo')
82
90
  end
83
91
 
84
92
  it "should not format ranges of chars in a String" do
85
- subject.format_chars(:exclude => /[h-l]/) { |c|
93
+ expect(subject.format_chars(:exclude => /[h-l]/) { |c|
86
94
  c.upcase
87
- }.should == 'hEllO'
95
+ }).to eq('hEllO')
88
96
  end
89
97
  end
90
98
 
@@ -92,41 +100,63 @@ describe String do
92
100
  it "should capitalize each character when :probability is 1.0" do
93
101
  new_string = subject.random_case(:probability => 1.0)
94
102
 
95
- subject.upcase.should == new_string
103
+ expect(subject.upcase).to eq(new_string)
96
104
  end
97
105
 
98
106
  it "should not capitalize any characters when :probability is 0.0" do
99
107
  new_string = subject.random_case(:probability => 0.0)
100
108
 
101
- subject.should == new_string
109
+ expect(subject).to eq(new_string)
102
110
  end
103
111
  end
104
112
 
105
113
  describe "#insert_before" do
106
114
  it "should inject data before a matched String" do
107
- subject.insert_before('ll','x').should == "hexllo"
115
+ expect(subject.insert_before('ll','x')).to eq("hexllo")
108
116
  end
109
117
 
110
118
  it "should inject data before a matched Regexp" do
111
- subject.insert_before(/l+/,'x').should == "hexllo"
119
+ expect(subject.insert_before(/l+/,'x')).to eq("hexllo")
112
120
  end
113
121
 
114
122
  it "should not inject data if no matches are found" do
115
- subject.insert_before(/x/,'x').should == subject
123
+ expect(subject.insert_before(/x/,'x')).to eq(subject)
116
124
  end
117
125
  end
118
126
 
119
127
  describe "#insert_after" do
120
128
  it "should inject data after a matched String" do
121
- subject.insert_after('ll','x').should == "hellxo"
129
+ expect(subject.insert_after('ll','x')).to eq("hellxo")
122
130
  end
123
131
 
124
132
  it "should inject data after a matched Regexp" do
125
- subject.insert_after(/l+/,'x').should == "hellxo"
133
+ expect(subject.insert_after(/l+/,'x')).to eq("hellxo")
126
134
  end
127
135
 
128
136
  it "should not inject data if no matches are found" do
129
- subject.insert_after(/x/,'x').should == subject
137
+ expect(subject.insert_after(/x/,'x')).to eq(subject)
138
+ end
139
+ end
140
+
141
+ describe "#unescape" do
142
+ it "should not unescape a normal String" do
143
+ expect("hello".unescape).to eq("hello")
144
+ end
145
+
146
+ it "should unescape a hex String" do
147
+ expect("\\x68\\x65\\x6c\\x6c\\x6f\\x4e".unescape).to eq("hello\x4e")
148
+ end
149
+
150
+ it "should unescape an octal String" do
151
+ expect("hello\012".unescape).to eq("hello\n")
152
+ end
153
+
154
+ it "should unescape control characters" do
155
+ expect("hello\\n".unescape).to eq("hello\n")
156
+ end
157
+
158
+ it "should unescape normal characters" do
159
+ expect("hell\\o".unescape).to eq("hello")
130
160
  end
131
161
  end
132
162
  end