ronin-support 0.1.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (127) hide show
  1. data/.document +4 -0
  2. data/.rspec +1 -0
  3. data/.yardopts +1 -0
  4. data/COPYING.txt +504 -0
  5. data/ChangeLog.md +4 -0
  6. data/Gemfile +23 -0
  7. data/README.md +98 -0
  8. data/Rakefile +29 -0
  9. data/gemspec.yml +20 -0
  10. data/lib/ronin/extensions.rb +28 -0
  11. data/lib/ronin/extensions/file.rb +63 -0
  12. data/lib/ronin/extensions/ip_addr.rb +220 -0
  13. data/lib/ronin/extensions/kernel.rb +45 -0
  14. data/lib/ronin/extensions/meta.rb +22 -0
  15. data/lib/ronin/extensions/meta/object.rb +24 -0
  16. data/lib/ronin/extensions/string.rb +200 -0
  17. data/lib/ronin/formatting.rb +26 -0
  18. data/lib/ronin/formatting/binary.rb +22 -0
  19. data/lib/ronin/formatting/digest.rb +22 -0
  20. data/lib/ronin/formatting/extensions.rb +25 -0
  21. data/lib/ronin/formatting/extensions/binary.rb +24 -0
  22. data/lib/ronin/formatting/extensions/binary/file.rb +35 -0
  23. data/lib/ronin/formatting/extensions/binary/integer.rb +147 -0
  24. data/lib/ronin/formatting/extensions/binary/string.rb +363 -0
  25. data/lib/ronin/formatting/extensions/digest.rb +23 -0
  26. data/lib/ronin/formatting/extensions/digest/file.rb +117 -0
  27. data/lib/ronin/formatting/extensions/digest/string.rb +80 -0
  28. data/lib/ronin/formatting/extensions/http.rb +23 -0
  29. data/lib/ronin/formatting/extensions/http/integer.rb +57 -0
  30. data/lib/ronin/formatting/extensions/http/string.rb +102 -0
  31. data/lib/ronin/formatting/extensions/text.rb +23 -0
  32. data/lib/ronin/formatting/extensions/text/array.rb +125 -0
  33. data/lib/ronin/formatting/extensions/text/string.rb +206 -0
  34. data/lib/ronin/formatting/http.rb +22 -0
  35. data/lib/ronin/formatting/text.rb +22 -0
  36. data/lib/ronin/network.rb +29 -0
  37. data/lib/ronin/network/esmtp.rb +22 -0
  38. data/lib/ronin/network/extensions.rb +29 -0
  39. data/lib/ronin/network/extensions/esmtp.rb +22 -0
  40. data/lib/ronin/network/extensions/esmtp/net.rb +100 -0
  41. data/lib/ronin/network/extensions/http.rb +22 -0
  42. data/lib/ronin/network/extensions/http/net.rb +661 -0
  43. data/lib/ronin/network/extensions/imap.rb +22 -0
  44. data/lib/ronin/network/extensions/imap/net.rb +124 -0
  45. data/lib/ronin/network/extensions/pop3.rb +22 -0
  46. data/lib/ronin/network/extensions/pop3/net.rb +92 -0
  47. data/lib/ronin/network/extensions/smtp.rb +22 -0
  48. data/lib/ronin/network/extensions/smtp/net.rb +110 -0
  49. data/lib/ronin/network/extensions/ssl.rb +22 -0
  50. data/lib/ronin/network/extensions/ssl/net.rb +147 -0
  51. data/lib/ronin/network/extensions/tcp.rb +22 -0
  52. data/lib/ronin/network/extensions/tcp/net.rb +304 -0
  53. data/lib/ronin/network/extensions/telnet.rb +22 -0
  54. data/lib/ronin/network/extensions/telnet/net.rb +156 -0
  55. data/lib/ronin/network/extensions/udp.rb +22 -0
  56. data/lib/ronin/network/extensions/udp/net.rb +226 -0
  57. data/lib/ronin/network/http.rb +24 -0
  58. data/lib/ronin/network/http/exceptions.rb +22 -0
  59. data/lib/ronin/network/http/exceptions/unknown_request.rb +29 -0
  60. data/lib/ronin/network/http/http.rb +290 -0
  61. data/lib/ronin/network/http/proxy.rb +307 -0
  62. data/lib/ronin/network/imap.rb +49 -0
  63. data/lib/ronin/network/network.rb +41 -0
  64. data/lib/ronin/network/pop3.rb +49 -0
  65. data/lib/ronin/network/smtp.rb +24 -0
  66. data/lib/ronin/network/smtp/email.rb +143 -0
  67. data/lib/ronin/network/smtp/smtp.rb +68 -0
  68. data/lib/ronin/network/ssl.rb +47 -0
  69. data/lib/ronin/network/tcp.rb +22 -0
  70. data/lib/ronin/network/telnet.rb +109 -0
  71. data/lib/ronin/network/udp.rb +22 -0
  72. data/lib/ronin/path.rb +132 -0
  73. data/lib/ronin/support.rb +28 -0
  74. data/lib/ronin/support/inflector.rb +40 -0
  75. data/lib/ronin/support/version.rb +27 -0
  76. data/lib/ronin/templates.rb +23 -0
  77. data/lib/ronin/templates/erb.rb +75 -0
  78. data/lib/ronin/templates/template.rb +161 -0
  79. data/ronin-support.gemspec +10 -0
  80. data/spec/extensions/file_spec.rb +24 -0
  81. data/spec/extensions/ip_addr_spec.rb +171 -0
  82. data/spec/extensions/kernel_spec.rb +30 -0
  83. data/spec/extensions/string_spec.rb +177 -0
  84. data/spec/formatting/binary/helpers/hexdumps.rb +16 -0
  85. data/spec/formatting/binary/helpers/hexdumps/ascii.bin +0 -0
  86. data/spec/formatting/binary/helpers/hexdumps/hexdump_decimal_shorts.txt +17 -0
  87. data/spec/formatting/binary/helpers/hexdumps/hexdump_hex_bytes.txt +17 -0
  88. data/spec/formatting/binary/helpers/hexdumps/hexdump_hex_shorts.txt +17 -0
  89. data/spec/formatting/binary/helpers/hexdumps/hexdump_octal_bytes.txt +17 -0
  90. data/spec/formatting/binary/helpers/hexdumps/hexdump_octal_shorts.txt +17 -0
  91. data/spec/formatting/binary/helpers/hexdumps/hexdump_repeated.txt +6 -0
  92. data/spec/formatting/binary/helpers/hexdumps/od_decimal_bytes.txt +17 -0
  93. data/spec/formatting/binary/helpers/hexdumps/od_decimal_ints.txt +17 -0
  94. data/spec/formatting/binary/helpers/hexdumps/od_decimal_quads.txt +17 -0
  95. data/spec/formatting/binary/helpers/hexdumps/od_decimal_shorts.txt +17 -0
  96. data/spec/formatting/binary/helpers/hexdumps/od_hex_bytes.txt +17 -0
  97. data/spec/formatting/binary/helpers/hexdumps/od_hex_ints.txt +17 -0
  98. data/spec/formatting/binary/helpers/hexdumps/od_hex_quads.txt +17 -0
  99. data/spec/formatting/binary/helpers/hexdumps/od_hex_shorts.txt +17 -0
  100. data/spec/formatting/binary/helpers/hexdumps/od_octal_bytes.txt +17 -0
  101. data/spec/formatting/binary/helpers/hexdumps/od_octal_ints.txt +17 -0
  102. data/spec/formatting/binary/helpers/hexdumps/od_octal_quads.txt +17 -0
  103. data/spec/formatting/binary/helpers/hexdumps/od_octal_shorts.txt +17 -0
  104. data/spec/formatting/binary/helpers/hexdumps/od_repeated.txt +6 -0
  105. data/spec/formatting/binary/helpers/hexdumps/repeated.bin +1 -0
  106. data/spec/formatting/binary/integer_spec.rb +140 -0
  107. data/spec/formatting/binary/string_spec.rb +306 -0
  108. data/spec/formatting/digest/string_spec.rb +82 -0
  109. data/spec/formatting/http/integer_spec.rb +42 -0
  110. data/spec/formatting/http/string_spec.rb +76 -0
  111. data/spec/formatting/text/array_spec.rb +105 -0
  112. data/spec/formatting/text/string_spec.rb +180 -0
  113. data/spec/network/http/http_spec.rb +280 -0
  114. data/spec/network/http/proxy_spec.rb +150 -0
  115. data/spec/network/network_spec.rb +8 -0
  116. data/spec/network/ssl_spec.rb +14 -0
  117. data/spec/path_spec.rb +84 -0
  118. data/spec/spec_helper.rb +4 -0
  119. data/spec/support_spec.rb +8 -0
  120. data/spec/templates/classes/example_erb.rb +11 -0
  121. data/spec/templates/classes/example_template.rb +35 -0
  122. data/spec/templates/erb_spec.rb +21 -0
  123. data/spec/templates/helpers/data.rb +9 -0
  124. data/spec/templates/helpers/data/includes/_relative.erb +1 -0
  125. data/spec/templates/helpers/data/templates/example.erb +1 -0
  126. data/spec/templates/template_spec.rb +54 -0
  127. metadata +286 -0
@@ -0,0 +1,280 @@
1
+ require 'spec_helper'
2
+ require 'ronin/network/http'
3
+
4
+ describe Network::HTTP do
5
+ describe "proxy" do
6
+ it "should be disabled by default" do
7
+ subject.proxy.should_not be_enabled
8
+ end
9
+ end
10
+
11
+ describe "expand_url" do
12
+ let(:url) { URI('http://example.com:443/path?q=1') }
13
+
14
+ it "should accept URI objects" do
15
+ options = subject.expand_url(url)
16
+
17
+ options[:host].should == url.host
18
+ end
19
+
20
+ it "should accept Hashes" do
21
+ hash = {
22
+ :host => url.host,
23
+ :port => url.port,
24
+ }
25
+ options = subject.expand_url(hash)
26
+
27
+ options[:host].should == url.host
28
+ options[:port].should == url.port
29
+ end
30
+
31
+ it "should accept Strings" do
32
+ options = subject.expand_url(url.to_s)
33
+
34
+ options[:host].should == url.host
35
+ options[:port].should == url.port
36
+ end
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
+ it "should default :path to '/'" do
46
+ options = subject.expand_url(URI('http://example.com'))
47
+
48
+ options[:path].should == '/'
49
+ end
50
+
51
+ it "should append the query-string to the :path options" do
52
+ options = subject.expand_url(url)
53
+
54
+ options[:path].should == "#{url.path}?#{url.query}"
55
+ end
56
+
57
+ it "should set :ssl if the URI scheme is 'https'" do
58
+ options = subject.expand_url(URI('https://example.com'))
59
+
60
+ options[:ssl].should == {}
61
+ end
62
+ end
63
+
64
+ describe "expand_options" do
65
+ it "should expand the :ssl option into a Hash" do
66
+ options = {:ssl => true}
67
+ expanded_options = subject.expand_options(options)
68
+
69
+ expanded_options[:ssl].should == {}
70
+ end
71
+
72
+ it "should added a default port and path" do
73
+ options = {:host => 'example.com'}
74
+ expanded_options = subject.expand_options(options)
75
+
76
+ expanded_options[:port].should == 80
77
+ expanded_options[:path].should == '/'
78
+ end
79
+
80
+ it "should add the default proxy settings" do
81
+ options = {:host => 'example.com'}
82
+ expanded_options = subject.expand_options(options)
83
+
84
+ expanded_options[:proxy].should == subject.proxy
85
+ end
86
+
87
+ it "should disable the proxy settings if :proxy is nil" do
88
+ options = {:host => 'example.com', :proxy => nil}
89
+ expanded_options = subject.expand_options(options)
90
+
91
+ expanded_options[:proxy][:host].should be_nil
92
+ expanded_options[:proxy][:port].should be_nil
93
+ end
94
+
95
+ it "should not modify :proxy if it is a HTTP::Proxy object" do
96
+ proxy = Network::HTTP::Proxy.new(:host => 'proxy.com', :port => 8181)
97
+ options = {:host => 'example.com', :proxy => proxy}
98
+ expanded_options = subject.expand_options(options)
99
+
100
+ expanded_options[:proxy].should == proxy
101
+ end
102
+
103
+ it "should parse the :proxy option" do
104
+ options = {:host => 'example.com', :proxy => 'http://proxy.com:8181'}
105
+ expanded_options = subject.expand_options(options)
106
+
107
+ expanded_options[:proxy][:host].should == 'proxy.com'
108
+ expanded_options[:proxy][:port].should == 8181
109
+ end
110
+
111
+ it "should expand the :url option" do
112
+ options = {:url => 'http://joe:secret@example.com:8080/bla?var'}
113
+ expanded_options = subject.expand_options(options)
114
+
115
+ expanded_options[:url].should be_nil
116
+ expanded_options[:host].should == 'example.com'
117
+ expanded_options[:port].should == 8080
118
+ expanded_options[:user].should == 'joe'
119
+ expanded_options[:password].should == 'secret'
120
+ expanded_options[:path].should == '/bla?var'
121
+ end
122
+
123
+ end
124
+
125
+ describe "headers" do
126
+ it "should convert Symbol options to HTTP Headers" do
127
+ options = {:user_agent => 'bla', :location => 'test'}
128
+
129
+ subject.headers(options).should == {
130
+ 'User-Agent' => 'bla',
131
+ 'Location' => 'test'
132
+ }
133
+ end
134
+
135
+ it "should convert String options to HTTP Headers" do
136
+ options = {'user_agent' => 'bla', 'x-powered-by' => 'PHP'}
137
+
138
+ subject.headers(options).should == {
139
+ 'User-Agent' => 'bla',
140
+ 'X-Powered-By' => 'PHP'
141
+ }
142
+ end
143
+
144
+ it "should convert all values to Strings" do
145
+ mtime = Time.now.to_i
146
+ options = {:modified_by => mtime, :x_accept => :gzip}
147
+
148
+ subject.headers(options).should == {
149
+ 'Modified-By' => mtime.to_s,
150
+ 'X-Accept' => 'gzip'
151
+ }
152
+ end
153
+ end
154
+
155
+ describe "request" do
156
+ it "should handle Symbol names" do
157
+ subject.request(
158
+ :method => :get, :path => '/'
159
+ ).class.should == Net::HTTP::Get
160
+ end
161
+
162
+ it "should handle String names" do
163
+ subject.request(
164
+ :method => 'GET', :path => '/'
165
+ ).class.should == Net::HTTP::Get
166
+ end
167
+
168
+ it "should raise an UnknownRequest exception for invalid names" do
169
+ lambda {
170
+ subject.request(:method => :bla)
171
+ }.should raise_error(subject::UnknownRequest)
172
+ end
173
+
174
+ it "should use a default path" do
175
+ lambda {
176
+ subject.request(:method => :get)
177
+ }.should_not raise_error(ArgumentError)
178
+ end
179
+
180
+ it "should accept the :user option for Basic-Auth" do
181
+ req = subject.request(:method => :get, :user => 'joe')
182
+
183
+ req['authorization'].should == "Basic am9lOg=="
184
+ end
185
+
186
+ it "should accept the :user and :password options for Basic-Auth" do
187
+ req = subject.request(
188
+ :method => :get,
189
+ :user => 'joe',
190
+ :password => 'secret'
191
+ )
192
+
193
+ req['authorization'].should == "Basic am9lOnNlY3JldA=="
194
+ end
195
+
196
+ it "should create HTTP Copy requests" do
197
+ req = subject.request(:method => :copy)
198
+
199
+ req.class.should == Net::HTTP::Copy
200
+ end
201
+
202
+ it "should create HTTP Delete requests" do
203
+ req = subject.request(:method => :delete)
204
+
205
+ req.class.should == Net::HTTP::Delete
206
+ end
207
+
208
+ it "should create HTTP Get requests" do
209
+ req = subject.request(:method => :get)
210
+
211
+ req.class.should == Net::HTTP::Get
212
+ end
213
+
214
+ it "should create HTTP Head requests" do
215
+ req = subject.request(:method => :head)
216
+
217
+ req.class.should == Net::HTTP::Head
218
+ end
219
+
220
+ it "should create HTTP Lock requests" do
221
+ req = subject.request(:method => :lock)
222
+
223
+ req.class.should == Net::HTTP::Lock
224
+ end
225
+
226
+ it "should create HTTP Mkcol requests" do
227
+ req = subject.request(:method => :mkcol)
228
+
229
+ req.class.should == Net::HTTP::Mkcol
230
+ end
231
+
232
+ it "should create HTTP Move requests" do
233
+ req = subject.request(:method => :move)
234
+
235
+ req.class.should == Net::HTTP::Move
236
+ end
237
+
238
+ it "should create HTTP Options requests" do
239
+ req = subject.request(:method => :options)
240
+
241
+ req.class.should == Net::HTTP::Options
242
+ end
243
+
244
+ it "should create HTTP Post requests" do
245
+ req = subject.request(:method => :post)
246
+
247
+ req.class.should == Net::HTTP::Post
248
+ end
249
+
250
+ it "should create HTTP Propfind requests" do
251
+ req = subject.request(:method => :propfind)
252
+
253
+ req.class.should == Net::HTTP::Propfind
254
+ end
255
+
256
+ it "should create HTTP Proppatch requests" do
257
+ req = subject.request(:method => :proppatch)
258
+
259
+ req.class.should == Net::HTTP::Proppatch
260
+ end
261
+
262
+ it "should create HTTP Trace requests" do
263
+ req = subject.request(:method => :trace)
264
+
265
+ req.class.should == Net::HTTP::Trace
266
+ end
267
+
268
+ it "should create HTTP Unlock requests" do
269
+ req = subject.request(:method => :unlock)
270
+
271
+ req.class.should == Net::HTTP::Unlock
272
+ end
273
+
274
+ it "should raise an ArgumentError when :method is not specified" do
275
+ lambda {
276
+ subject.request()
277
+ }.should raise_error(ArgumentError)
278
+ end
279
+ end
280
+ end
@@ -0,0 +1,150 @@
1
+ require 'spec_helper'
2
+ require 'ronin/network/http/proxy'
3
+
4
+ describe Network::HTTP::Proxy do
5
+ describe "parse" do
6
+ subject { Network::HTTP::Proxy }
7
+
8
+ it "should parse host-names" do
9
+ proxy = subject.parse('127.0.0.1')
10
+
11
+ proxy.host.should == '127.0.0.1'
12
+ end
13
+
14
+ it "should parse 'host:port' URLs" do
15
+ proxy = subject.parse('127.0.0.1:80')
16
+
17
+ proxy.host.should == '127.0.0.1'
18
+ proxy.port.should == 80
19
+ end
20
+
21
+ it "should parse 'user@host:port' URLs" do
22
+ proxy = subject.parse('joe@127.0.0.1:80')
23
+
24
+ proxy.user.should == 'joe'
25
+ proxy.host.should == '127.0.0.1'
26
+ proxy.port.should == 80
27
+ end
28
+
29
+ it "should prase 'user:password@host:port' URLs" do
30
+ proxy = subject.parse('joe:lol@127.0.0.1:80')
31
+
32
+ proxy.user.should == 'joe'
33
+ proxy.password.should == 'lol'
34
+ proxy.host.should == '127.0.0.1'
35
+ proxy.port.should == 80
36
+ end
37
+
38
+ it "should ignore http:// prefixes when parsing proxy URLs" do
39
+ proxy = subject.parse('http://joe:lol@127.0.0.1:80')
40
+
41
+ proxy.user.should == 'joe'
42
+ proxy.password.should == 'lol'
43
+ proxy.host.should == '127.0.0.1'
44
+ proxy.port.should == 80
45
+ end
46
+ end
47
+
48
+ describe "create" do
49
+ subject { Network::HTTP::Proxy }
50
+
51
+ let(:host) { '127.0.0.1' }
52
+ let(:port) { 8080 }
53
+
54
+ it "should accept Proxy objects" do
55
+ proxy = subject.new(:host => host, :port => port)
56
+
57
+ subject.create(proxy).should == proxy
58
+ end
59
+
60
+ it "should accept URI::HTTP objects" do
61
+ url = URI::HTTP.build(:host => host, :port => port)
62
+ proxy = subject.create(url)
63
+
64
+ proxy.host.should == host
65
+ proxy.port.should == port
66
+ end
67
+
68
+ it "should accept Hash objects" do
69
+ hash = {:host => host, :port => port}
70
+ proxy = subject.create(hash)
71
+
72
+ proxy.host.should == host
73
+ proxy.port.should == port
74
+ end
75
+
76
+ it "should accept String objects" do
77
+ string = "#{host}:#{port}"
78
+ proxy = subject.create(string)
79
+
80
+ proxy.host.should == host
81
+ proxy.port.should == port
82
+ end
83
+
84
+ it "should accept nil" do
85
+ proxy = subject.create(nil)
86
+
87
+ proxy.should_not be_enabled
88
+ end
89
+ end
90
+
91
+ subject { Network::HTTP::Proxy.new }
92
+
93
+ it "should behave like a Hash" do
94
+ subject[:host] = 'example.com'
95
+ subject[:host].should == 'example.com'
96
+ end
97
+
98
+ it "should not have a host by default" do
99
+ subject.host.should be_nil
100
+ end
101
+
102
+ it "should not have a port by default" do
103
+ subject.port.should be_nil
104
+ end
105
+
106
+ it "should be disabled by default" do
107
+ subject.should_not be_enabled
108
+ end
109
+
110
+ it "should reset the host, port, user and password when disabled" do
111
+ subject[:host] = 'example.com'
112
+ subject[:port] = 9001
113
+ subject[:user] = 'joe'
114
+ subject[:password] = 'lol'
115
+
116
+ subject.disable!
117
+
118
+ subject[:host].should be_nil
119
+ subject[:port].should be_nil
120
+ subject[:user].should be_nil
121
+ subject[:password].should be_nil
122
+ end
123
+
124
+ it "should return a URI::HTTP representing the proxy" do
125
+ subject[:host] = 'example.com'
126
+ subject[:port] = 9001
127
+ subject[:user] = 'joe'
128
+ subject[:password] = 'lol'
129
+
130
+ url = subject.url
131
+
132
+ url.host.should == 'example.com'
133
+ url.port.should == 9001
134
+ url.user.should == 'joe'
135
+ url.password.should == 'lol'
136
+ end
137
+
138
+ it "should return nil when converting a disabled proxy to a URL" do
139
+ subject.url.should be_nil
140
+ end
141
+
142
+ it "should return the host-name when converted to a String" do
143
+ subject[:host] = 'example.com'
144
+ subject.to_s.should == 'example.com'
145
+ end
146
+
147
+ it "should return an empty String when there is no host-name" do
148
+ subject.to_s.should be_empty
149
+ end
150
+ end
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+ require 'ronin/network/network'
3
+
4
+ describe Network do
5
+ it "should determine our public facing IP Address" do
6
+ subject.ip.should_not be_nil
7
+ end
8
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+ require 'ronin/network/ssl'
3
+
4
+ describe Network::SSL do
5
+ describe 'verify' do
6
+ it "should map verify mode names to numeric values" do
7
+ subject.verify(:peer).should == OpenSSL::SSL::VERIFY_PEER
8
+ end
9
+
10
+ it "should default to VERIFY_NONE if no verify mode name is given" do
11
+ subject.verify.should == OpenSSL::SSL::VERIFY_NONE
12
+ end
13
+ end
14
+ end