ronin-support 0.1.0 → 0.2.0.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. data/ChangeLog.md +24 -0
  2. data/Gemfile +9 -1
  3. data/README.md +6 -3
  4. data/gemspec.yml +3 -1
  5. data/lib/ronin/extensions.rb +2 -1
  6. data/lib/ronin/extensions/file.rb +4 -0
  7. data/lib/ronin/extensions/ip_addr.rb +8 -0
  8. data/lib/ronin/extensions/kernel.rb +2 -0
  9. data/lib/ronin/extensions/string.rb +50 -11
  10. data/lib/ronin/formatting/extensions/binary.rb +2 -0
  11. data/lib/ronin/formatting/extensions/binary/file.rb +12 -1
  12. data/lib/ronin/formatting/extensions/binary/integer.rb +6 -0
  13. data/lib/ronin/formatting/extensions/binary/string.rb +20 -0
  14. data/lib/ronin/formatting/extensions/digest/file.rb +14 -0
  15. data/lib/ronin/formatting/extensions/digest/string.rb +8 -0
  16. data/lib/ronin/formatting/extensions/html.rb +21 -0
  17. data/lib/ronin/formatting/extensions/html/integer.rb +126 -0
  18. data/lib/ronin/formatting/extensions/html/string.rb +184 -0
  19. data/lib/ronin/formatting/extensions/http/integer.rb +7 -1
  20. data/lib/ronin/formatting/extensions/http/string.rb +10 -0
  21. data/lib/ronin/formatting/extensions/text.rb +2 -0
  22. data/lib/ronin/formatting/extensions/text/array.rb +10 -0
  23. data/lib/ronin/formatting/extensions/text/string.rb +44 -12
  24. data/lib/ronin/formatting/html.rb +20 -0
  25. data/lib/ronin/mixin.rb +89 -0
  26. data/lib/ronin/network/extensions/esmtp/net.rb +6 -0
  27. data/lib/ronin/network/extensions/http/net.rb +124 -51
  28. data/lib/ronin/network/extensions/imap/net.rb +4 -0
  29. data/lib/ronin/network/extensions/pop3/net.rb +4 -0
  30. data/lib/ronin/network/extensions/smtp/net.rb +73 -2
  31. data/lib/ronin/network/extensions/ssl/net.rb +4 -0
  32. data/lib/ronin/network/extensions/tcp/net.rb +16 -0
  33. data/lib/ronin/network/extensions/telnet/net.rb +4 -0
  34. data/lib/ronin/network/extensions/udp/net.rb +12 -0
  35. data/lib/ronin/network/http/http.rb +50 -29
  36. data/lib/ronin/network/http/proxy.rb +26 -0
  37. data/lib/ronin/network/imap.rb +4 -0
  38. data/lib/ronin/network/network.rb +2 -0
  39. data/lib/ronin/network/pop3.rb +4 -0
  40. data/lib/ronin/network/smtp/email.rb +43 -14
  41. data/lib/ronin/network/smtp/smtp.rb +6 -0
  42. data/lib/ronin/network/ssl.rb +2 -0
  43. data/lib/ronin/network/telnet.rb +16 -0
  44. data/lib/ronin/path.rb +6 -0
  45. data/lib/ronin/support/inflector.rb +3 -1
  46. data/lib/ronin/support/version.rb +1 -1
  47. data/lib/ronin/templates/erb.rb +4 -0
  48. data/lib/ronin/templates/template.rb +10 -0
  49. data/spec/extensions/string_spec.rb +4 -4
  50. data/spec/formatting/html/integer_spec.rb +66 -0
  51. data/spec/formatting/html/string_spec.rb +103 -0
  52. data/spec/formatting/http/string_spec.rb +1 -1
  53. data/spec/formatting/text/string_spec.rb +18 -66
  54. data/spec/mixin_spec.rb +53 -0
  55. data/spec/network/http/http_spec.rb +0 -7
  56. data/spec/network/http/proxy_spec.rb +2 -2
  57. data/spec/network/smtp/email_spec.rb +100 -0
  58. data/spec/path_spec.rb +13 -13
  59. data/spec/templates/helpers/data.rb +1 -1
  60. metadata +52 -33
@@ -37,6 +37,8 @@ module Ronin
37
37
  # @return [Array]
38
38
  # The stack of directory paths.
39
39
  #
40
+ # @api semipublic
41
+ #
40
42
  def template_dirs
41
43
  @template_dirs ||= []
42
44
  end
@@ -49,6 +51,8 @@ module Ronin
49
51
  # Returns the first path in {#template_dirs}, or `nil` if
50
52
  # {#template_dirs} is empty.
51
53
  #
54
+ # @api semipublic
55
+ #
52
56
  def template_dir
53
57
  template_dirs.first
54
58
  end
@@ -68,6 +72,8 @@ module Ronin
68
72
  # @example
69
73
  # find_template 'sub/path/template.erb'
70
74
  #
75
+ # @api semipublic
76
+ #
71
77
  def find_template(sub_path)
72
78
  sub_path = sub_path.to_s
73
79
 
@@ -107,6 +113,8 @@ module Ronin
107
113
  # # do stuff with the full path
108
114
  # end
109
115
  #
116
+ # @api semipublic
117
+ #
110
118
  def enter_template(sub_path)
111
119
  sub_path = sub_path.to_s
112
120
 
@@ -143,6 +151,8 @@ module Ronin
143
151
  # # ...
144
152
  # end
145
153
  #
154
+ # @api semipublic
155
+ #
146
156
  def read_template(template_path)
147
157
  enter_template(template_path) do |path|
148
158
  contents = File.read(path)
@@ -107,27 +107,27 @@ describe String do
107
107
  end
108
108
  end
109
109
 
110
- describe "#common_postfix" do
110
+ describe "#common_suffix" do
111
111
  it "should find the common postfix between two Strings" do
112
112
  one = 'Tell me baby whats my name'
113
113
  two = "Can't you guess my name"
114
114
  common = 's my name'
115
115
 
116
- one.common_postfix(two).should == common
116
+ one.common_suffix(two).should == common
117
117
  end
118
118
 
119
119
  it "should return an empty String if there is no common postfix" do
120
120
  one = 'You got to right up, stand up'
121
121
  two = 'stand up for your rights'
122
122
 
123
- one.common_postfix(two).should == ''
123
+ one.common_suffix(two).should == ''
124
124
  end
125
125
 
126
126
  it "should return an empty String if one of the strings is also empty" do
127
127
  one = 'You and I must fight for our rights'
128
128
  two = ''
129
129
 
130
- one.common_postfix(two).should == ''
130
+ one.common_suffix(two).should == ''
131
131
  end
132
132
  end
133
133
 
@@ -0,0 +1,66 @@
1
+ require 'spec_helper'
2
+ require 'ronin/formatting/extensions/html/integer'
3
+
4
+ describe Integer do
5
+ subject { 0x26 }
6
+
7
+ it "should provide String#html_escape" do
8
+ should respond_to(:html_escape)
9
+ end
10
+
11
+ it "should provide String#format_html" do
12
+ should respond_to(:format_html)
13
+ end
14
+
15
+ it "should provide String#js_escape" do
16
+ should respond_to(:js_escape)
17
+ end
18
+
19
+ it "should provide String#format_js" do
20
+ should respond_to(:format_js)
21
+ end
22
+
23
+ describe "#html_escape" do
24
+ let(:html_escaped) { "&" }
25
+
26
+ it "should HTML escape itself" do
27
+ subject.html_escape.should == html_escaped
28
+ end
29
+ end
30
+
31
+ describe "#format_html" do
32
+ let(:formatted_html) { "&" }
33
+
34
+ it "should HTML format all chars" do
35
+ subject.format_html.should == formatted_html
36
+ end
37
+ end
38
+
39
+ describe "#js_escape" do
40
+ let(:special_byte) { 0x0a }
41
+ let(:escaped_special_byte) { '\n' }
42
+
43
+ let(:normal_byte) { 0x41 }
44
+ let(:normal_char) { 'A' }
45
+
46
+ it "should escape special JavaScript characters" do
47
+ special_byte.js_escape.should == escaped_special_byte
48
+ end
49
+
50
+ it "should ignore normal characters" do
51
+ normal_byte.js_escape.should == normal_char
52
+ end
53
+ end
54
+
55
+ describe "#format_js" do
56
+ let(:js_escaped) { "%26" }
57
+
58
+ it "should JavaScript format ascii bytes" do
59
+ subject.format_js.should == js_escaped
60
+ end
61
+
62
+ it "should JavaScript format unicode bytes" do
63
+ 0xd556.format_js.should == "%uD556"
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,103 @@
1
+ require 'spec_helper'
2
+ require 'ronin/formatting/extensions/html/string'
3
+
4
+ describe String do
5
+ subject { "one & two" }
6
+
7
+ it "should provide String#html_escape" do
8
+ should respond_to(:html_escape)
9
+ end
10
+
11
+ it "should provide String#html_unescape" do
12
+ should respond_to(:html_unescape)
13
+ end
14
+
15
+ it "should provide String#format_html" do
16
+ should respond_to(:format_html)
17
+ end
18
+
19
+ it "should provide String#js_escape" do
20
+ should respond_to(:js_escape)
21
+ end
22
+
23
+ it "should provide String#js_unescape" do
24
+ should respond_to(:js_unescape)
25
+ end
26
+
27
+ it "should provide String#format_js" do
28
+ should respond_to(:format_js)
29
+ end
30
+
31
+ describe "#html_escape" do
32
+ let(:html_escaped) { "one & two" }
33
+
34
+ it "should HTML escape itself" do
35
+ subject.html_escape.should == html_escaped
36
+ end
37
+ end
38
+
39
+ describe "#html_unescape" do
40
+ let(:html_escaped) { "one & two" }
41
+
42
+ it "should HTML unescape itself" do
43
+ html_escaped.html_unescape.should == subject
44
+ end
45
+ end
46
+
47
+ describe "#format_html" do
48
+ let(:formatted_html) do
49
+ "one & two"
50
+ end
51
+
52
+ it "should HTML format all chars" do
53
+ subject.format_html.should == formatted_html
54
+ end
55
+ end
56
+
57
+ describe "#js_escape" do
58
+ let(:special_chars) { "\t\n\r" }
59
+ let(:escaped_special_chars) { '\t\n\r' }
60
+
61
+ let(:normal_chars) { "abc" }
62
+
63
+ it "should escape special JavaScript characters" do
64
+ special_chars.js_escape.should == escaped_special_chars
65
+ end
66
+
67
+ it "should ignore normal characters" do
68
+ normal_chars.js_escape.should == normal_chars
69
+ end
70
+ end
71
+
72
+ describe "#js_unescape" do
73
+ let(:js_unicode) do
74
+ "%u006F%u006E%u0065%u0020%u0026%u0020%u0074%u0077%u006F"
75
+ end
76
+ let(:js_hex) { "%6F%6E%65%20%26%20%74%77%6F" }
77
+ let(:js_mixed) { "one %26 two" }
78
+
79
+ it "should unescape JavaScript unicode characters" do
80
+ js_unicode.js_unescape.should == subject
81
+ end
82
+
83
+ it "should unescape JavaScript hex characters" do
84
+ js_hex.js_unescape.should == subject
85
+ end
86
+
87
+ it "should unescape backslash-escaped characters" do
88
+ "\\b\\t\\n\\f\\r\\\"\\\\".js_unescape.should == "\b\t\n\f\r\"\\"
89
+ end
90
+
91
+ it "should ignore non-escaped characters" do
92
+ js_mixed.js_unescape.should == subject
93
+ end
94
+ end
95
+
96
+ describe "#format_js" do
97
+ let(:js_formatted) { "%6F%6E%65%20%26%20%74%77%6F" }
98
+
99
+ it "should JavaScript escape all characters" do
100
+ subject.format_js.should == js_formatted
101
+ end
102
+ end
103
+ end
@@ -67,7 +67,7 @@ describe String do
67
67
  describe "#format_http" do
68
68
  subject { "mod % 3" }
69
69
 
70
- let(:http_formatted) { "%6d%6f%64%20%25%20%33" }
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
73
  subject.format_http.should == http_formatted
@@ -24,62 +24,6 @@ describe String do
24
24
  should respond_to(:insert_after)
25
25
  end
26
26
 
27
- describe "#format_chars" do
28
- it "should format each character in the String" do
29
- subject.format_chars { |c|
30
- "_#{c}"
31
- }.should == "_h_e_l_l_o"
32
- end
33
-
34
- it "should format specific bytes in a String" do
35
- subject.format_chars(:include => [104, 108]) { |c|
36
- c.upcase
37
- }.should == 'HeLLo'
38
- end
39
-
40
- it "should not format specific bytes in a String" do
41
- subject.format_chars(:exclude => [101, 111]) { |c|
42
- c.upcase
43
- }.should == 'HeLLo'
44
- end
45
-
46
- it "should format ranges of bytes in a String" do
47
- subject.format_chars(:include => (104..108)) { |c|
48
- c.upcase
49
- }.should == 'HeLLo'
50
- end
51
-
52
- it "should not format ranges of bytes in a String" do
53
- subject.format_chars(:exclude => (104..108)) { |c|
54
- c.upcase
55
- }.should == 'hEllO'
56
- end
57
-
58
- it "should format specific chars in a String" do
59
- subject.format_chars(:include => ['h', 'l']) { |c|
60
- c.upcase
61
- }.should == 'HeLLo'
62
- end
63
-
64
- it "should not format specific bytes in a String" do
65
- subject.format_chars(:exclude => ['e', 'o']) { |c|
66
- c.upcase
67
- }.should == 'HeLLo'
68
- end
69
-
70
- it "should format ranges of chars in a String" do
71
- subject.format_chars(:include => ('h'..'l')) { |c|
72
- c.upcase
73
- }.should == 'HeLLo'
74
- end
75
-
76
- it "should not format ranges of chars in a String" do
77
- subject.format_chars(:exclude => ('h'..'l')) { |c|
78
- c.upcase
79
- }.should == 'hEllO'
80
- end
81
- end
82
-
83
27
  describe "#format_bytes" do
84
28
  it "should format each byte in the String" do
85
29
  subject.format_bytes { |b|
@@ -110,28 +54,36 @@ describe String do
110
54
  b - 32
111
55
  }.should == 'hEllO'
112
56
  end
57
+ end
58
+
59
+ describe "#format_chars" do
60
+ it "should format each character in the String" do
61
+ subject.format_chars { |c|
62
+ "#{c}."
63
+ }.should == "h.e.l.l.o."
64
+ end
113
65
 
114
66
  it "should format specific chars in a String" do
115
- subject.format_bytes(:include => ['h', 'l']) { |b|
116
- b - 32
67
+ subject.format_chars(:include => ['h', 'l']) { |c|
68
+ c.upcase
117
69
  }.should == 'HeLLo'
118
70
  end
119
71
 
120
- it "should not format specific bytes in a String" do
121
- subject.format_bytes(:exclude => ['e', 'o']) { |b|
122
- b - 32
123
- }.should == 'HeLLo'
72
+ it "should not format specific chars in a String" do
73
+ subject.format_chars(:exclude => ['h', 'l']) { |c|
74
+ c.upcase
75
+ }.should == 'hEllO'
124
76
  end
125
77
 
126
78
  it "should format ranges of chars in a String" do
127
- subject.format_bytes(:include => ('h'..'l')) { |b|
128
- b - 32
79
+ subject.format_chars(:include => /[h-l]/) { |c|
80
+ c.upcase
129
81
  }.should == 'HeLLo'
130
82
  end
131
83
 
132
84
  it "should not format ranges of chars in a String" do
133
- subject.format_bytes(:exclude => ('h'..'l')) { |b|
134
- b - 32
85
+ subject.format_chars(:exclude => /[h-l]/) { |c|
86
+ c.upcase
135
87
  }.should == 'hEllO'
136
88
  end
137
89
  end
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+ require 'ronin/mixin'
3
+
4
+ module Mixins
5
+ module Test1
6
+ end
7
+
8
+ module Test2
9
+ end
10
+ end
11
+
12
+ describe Mixin do
13
+ subject do
14
+ Module.new do
15
+ include Mixin
16
+
17
+ mixin Mixins::Test1, Mixins::Test2
18
+ mixin { @var = 1 }
19
+ end
20
+ end
21
+
22
+ context "when included" do
23
+ before(:all) do
24
+ @base = Class.new
25
+ @base.send :include, subject
26
+ end
27
+
28
+ it "should include the mixed in modules" do
29
+ @base.should include(Mixins::Test1)
30
+ @base.should include(Mixins::Test2)
31
+ end
32
+
33
+ it "should evaluate the mixin block" do
34
+ @base.instance_variable_get("@var").should == 1
35
+ end
36
+ end
37
+
38
+ context "when extended" do
39
+ before(:all) do
40
+ @base = Object.new
41
+ @base.send :extend, subject
42
+ end
43
+
44
+ it "should extend the mixed in modules" do
45
+ @base.should be_kind_of(Mixins::Test1)
46
+ @base.should be_kind_of(Mixins::Test2)
47
+ end
48
+
49
+ it "should evaluate the mixin block" do
50
+ @base.instance_variable_get("@var").should == 1
51
+ end
52
+ end
53
+ end
@@ -35,13 +35,6 @@ describe Network::HTTP do
35
35
  options[:port].should == url.port
36
36
  end
37
37
 
38
- it "should accept nil" do
39
- options = subject.expand_url(nil)
40
-
41
- options[:port].should == Net::HTTP.default_port
42
- options[:path].should == '/'
43
- end
44
-
45
38
  it "should default :path to '/'" do
46
39
  options = subject.expand_url(URI('http://example.com'))
47
40
 
@@ -3,7 +3,7 @@ require 'ronin/network/http/proxy'
3
3
 
4
4
  describe Network::HTTP::Proxy do
5
5
  describe "parse" do
6
- subject { Network::HTTP::Proxy }
6
+ subject { described_class }
7
7
 
8
8
  it "should parse host-names" do
9
9
  proxy = subject.parse('127.0.0.1')
@@ -46,7 +46,7 @@ describe Network::HTTP::Proxy do
46
46
  end
47
47
 
48
48
  describe "create" do
49
- subject { Network::HTTP::Proxy }
49
+ subject { described_class }
50
50
 
51
51
  let(:host) { '127.0.0.1' }
52
52
  let(:port) { 8080 }