ronin-web 0.3.0.pre2 → 1.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.editorconfig +11 -0
- data/.github/workflows/ruby.yml +31 -0
- data/.gitignore +13 -0
- data/.mailmap +1 -0
- data/.ruby-version +1 -0
- data/COPYING.txt +3 -3
- data/ChangeLog.md +115 -67
- data/Gemfile +42 -37
- data/README.md +159 -144
- data/Rakefile +16 -7
- data/bin/ronin-web +10 -18
- data/data/new/nokogiri.rb.erb +12 -0
- data/data/new/server.rb.erb +22 -0
- data/data/new/spider.rb.erb +26 -0
- data/data/new/webapp/.gitignore +15 -0
- data/data/new/webapp/.ruby-version.erb +1 -0
- data/data/new/webapp/Dockerfile.erb +11 -0
- data/data/new/webapp/Gemfile +6 -0
- data/data/new/webapp/app.rb.erb +15 -0
- data/data/new/webapp/config.ru +4 -0
- data/data/new/webapp/docker-compose.yml.erb +9 -0
- data/gemspec.yml +32 -17
- data/lib/ronin/web/cli/command.rb +36 -0
- data/lib/ronin/web/cli/commands/diff.rb +106 -0
- data/lib/ronin/web/cli/commands/html.rb +174 -0
- data/lib/ronin/web/cli/commands/irb.rb +56 -0
- data/lib/ronin/web/cli/commands/new/nokogiri.rb +85 -0
- data/lib/ronin/web/cli/commands/new/server.rb +96 -0
- data/lib/ronin/web/cli/commands/new/spider.rb +315 -0
- data/lib/ronin/web/cli/commands/new/webapp.rb +123 -0
- data/lib/ronin/web/cli/commands/new.rb +64 -0
- data/lib/ronin/web/cli/commands/reverse_proxy.rb +215 -0
- data/lib/ronin/web/cli/commands/server.rb +155 -0
- data/lib/ronin/web/cli/commands/spider.rb +822 -0
- data/lib/ronin/web/cli/ruby_shell.rb +50 -0
- data/lib/ronin/web/cli.rb +44 -0
- data/lib/ronin/web/html.rb +85 -0
- data/lib/ronin/web/mechanize.rb +79 -0
- data/lib/ronin/web/root.rb +27 -0
- data/lib/ronin/web/version.rb +7 -10
- data/lib/ronin/web/xml.rb +85 -0
- data/lib/ronin/web.rb +372 -13
- data/man/ronin-web-diff.1 +41 -0
- data/man/ronin-web-diff.1.md +30 -0
- data/man/ronin-web-html.1 +89 -0
- data/man/ronin-web-html.1.md +66 -0
- data/man/ronin-web-irb.1 +31 -0
- data/man/ronin-web-irb.1.md +22 -0
- data/man/ronin-web-new-nokogiri.1 +41 -0
- data/man/ronin-web-new-nokogiri.1.md +30 -0
- data/man/ronin-web-new-server.1 +45 -0
- data/man/ronin-web-new-server.1.md +33 -0
- data/man/ronin-web-new-spider.1 +173 -0
- data/man/ronin-web-new-spider.1.md +129 -0
- data/man/ronin-web-new-webapp.1 +53 -0
- data/man/ronin-web-new-webapp.1.md +39 -0
- data/man/ronin-web-new.1 +59 -0
- data/man/ronin-web-new.1.md +44 -0
- data/man/ronin-web-reverse-proxy.1 +63 -0
- data/man/ronin-web-reverse-proxy.1.md +47 -0
- data/man/ronin-web-server.1 +59 -0
- data/man/ronin-web-server.1.md +43 -0
- data/man/ronin-web-spider.1 +225 -0
- data/man/ronin-web-spider.1.md +168 -0
- data/man/ronin-web.1 +41 -0
- data/man/ronin-web.1.md +30 -0
- data/ronin-web.gemspec +57 -11
- data/spec/cli/ruby_shell_spec.rb +14 -0
- data/spec/html_spec.rb +43 -0
- data/spec/mechanize_spec.rb +72 -0
- data/spec/spec_helper.rb +5 -3
- data/spec/web_spec.rb +97 -0
- data/spec/xml_spec.rb +42 -0
- metadata +237 -217
- data/.gemtest +0 -0
- data/lib/ronin/network/mixins/web.rb +0 -256
- data/lib/ronin/web/extensions/nokogiri/xml/attr.rb +0 -47
- data/lib/ronin/web/extensions/nokogiri/xml/document.rb +0 -48
- data/lib/ronin/web/extensions/nokogiri/xml/element.rb +0 -57
- data/lib/ronin/web/extensions/nokogiri/xml/node.rb +0 -86
- data/lib/ronin/web/extensions/nokogiri/xml/text.rb +0 -47
- data/lib/ronin/web/extensions/nokogiri/xml.rb +0 -27
- data/lib/ronin/web/extensions/nokogiri.rb +0 -23
- data/lib/ronin/web/extensions.rb +0 -23
- data/lib/ronin/web/middleware/base.rb +0 -144
- data/lib/ronin/web/middleware/directories.rb +0 -179
- data/lib/ronin/web/middleware/files.rb +0 -144
- data/lib/ronin/web/middleware/filters/campaign_filter.rb +0 -77
- data/lib/ronin/web/middleware/filters/ip_filter.rb +0 -73
- data/lib/ronin/web/middleware/filters/path_filter.rb +0 -73
- data/lib/ronin/web/middleware/filters/referer_filter.rb +0 -71
- data/lib/ronin/web/middleware/filters/user_agent_filter.rb +0 -71
- data/lib/ronin/web/middleware/filters/vhost_filter.rb +0 -71
- data/lib/ronin/web/middleware/filters.rb +0 -28
- data/lib/ronin/web/middleware/helpers.rb +0 -145
- data/lib/ronin/web/middleware/proxy.rb +0 -265
- data/lib/ronin/web/middleware/proxy_request.rb +0 -262
- data/lib/ronin/web/middleware/request.rb +0 -79
- data/lib/ronin/web/middleware/response.rb +0 -33
- data/lib/ronin/web/middleware/router.rb +0 -167
- data/lib/ronin/web/middleware/rule.rb +0 -103
- data/lib/ronin/web/middleware.rb +0 -27
- data/lib/ronin/web/proxy/app.rb +0 -32
- data/lib/ronin/web/proxy/base.rb +0 -46
- data/lib/ronin/web/proxy/web.rb +0 -46
- data/lib/ronin/web/proxy.rb +0 -25
- data/lib/ronin/web/server/app.rb +0 -32
- data/lib/ronin/web/server/base.rb +0 -461
- data/lib/ronin/web/server/web.rb +0 -66
- data/lib/ronin/web/server.rb +0 -25
- data/lib/ronin/web/spider.rb +0 -115
- data/lib/ronin/web/web.rb +0 -573
- data/spec/helpers/output.rb +0 -3
- data/spec/web/extensions/nokogiri_spec.rb +0 -38
- data/spec/web/helpers/rack_app.rb +0 -31
- data/spec/web/helpers/root/test1/index.html +0 -1
- data/spec/web/helpers/root/test1/test1.txt +0 -1
- data/spec/web/helpers/root/test1.txt +0 -1
- data/spec/web/helpers/root/test2/test2.txt +0 -1
- data/spec/web/helpers/root/test2.txt +0 -1
- data/spec/web/helpers/root/test3/test3.txt +0 -1
- data/spec/web/helpers/root/test3.txt +0 -1
- data/spec/web/helpers/root.rb +0 -15
- data/spec/web/middleware/directories_spec.rb +0 -86
- data/spec/web/middleware/files_spec.rb +0 -57
- data/spec/web/middleware/filters/campaign_filter_spec.rb +0 -30
- data/spec/web/middleware/filters/ip_filter_spec.rb +0 -25
- data/spec/web/middleware/filters/path_filter_spec.rb +0 -29
- data/spec/web/middleware/filters/referer_filter_spec.rb +0 -25
- data/spec/web/middleware/filters/user_agent_filter_spec.rb +0 -25
- data/spec/web/middleware/filters/vhost_filter_spec.rb +0 -23
- data/spec/web/middleware/proxy_spec.rb +0 -67
- data/spec/web/middleware/response_spec.rb +0 -20
- data/spec/web/middleware/router_spec.rb +0 -65
- data/spec/web/middleware/rule_spec.rb +0 -37
- data/spec/web/proxy/base_spec.rb +0 -8
- data/spec/web/server/base_spec.rb +0 -77
- data/spec/web/server/classes/public1/static1.txt +0 -1
- data/spec/web/server/classes/public2/static2.txt +0 -1
- data/spec/web/server/classes/sub_app.rb +0 -13
- data/spec/web/server/classes/test_app.rb +0 -20
- data/spec/web/web_spec.rb +0 -157
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'ronin/web/extensions/nokogiri'
|
3
|
-
|
4
|
-
require 'nokogiri'
|
5
|
-
|
6
|
-
describe Nokogiri::HTML do
|
7
|
-
before(:all) do
|
8
|
-
@doc = Nokogiri::HTML(%{<html><head><title>test</title></head><body><p><b>This is a test</b> html <i>page</i>.</p></body></html>})
|
9
|
-
|
10
|
-
@edited_doc = Nokogiri::HTML(%{<html><head><title>test</title></head><body><p><b>This is a test</b> html page.</p></body></html>})
|
11
|
-
end
|
12
|
-
|
13
|
-
it "should be able to test if two elements are equal" do
|
14
|
-
elem1 = @doc.at('b')
|
15
|
-
elem2 = @edited_doc.at('b')
|
16
|
-
|
17
|
-
elem1.should == elem2
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should be able to test if two elements are not equal" do
|
21
|
-
elem1 = @doc.at('p').children.last
|
22
|
-
elem2 = @edited_doc.at('b')
|
23
|
-
|
24
|
-
elem1.should_not == elem2
|
25
|
-
end
|
26
|
-
|
27
|
-
it "should be able to traverse over every text node" do
|
28
|
-
text = []
|
29
|
-
|
30
|
-
@doc.traverse_text { |node| text << node.content }
|
31
|
-
|
32
|
-
text.should == ['test', 'This is a test', ' html ', 'page', '.']
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should provide a count of all sub-children" do
|
36
|
-
@doc.total_children.should == 12
|
37
|
-
end
|
38
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
begin
|
2
|
-
require 'rack/test'
|
3
|
-
rescue Gem::LoadError => e
|
4
|
-
raise(e)
|
5
|
-
rescue ::LoadError
|
6
|
-
STDERR.puts "Error: please install the rack-test gem in order to run the spec tests"
|
7
|
-
exit -1
|
8
|
-
end
|
9
|
-
|
10
|
-
module Helpers
|
11
|
-
module Web
|
12
|
-
module RackApp
|
13
|
-
include Rack::Test::Methods
|
14
|
-
|
15
|
-
attr_reader :app
|
16
|
-
|
17
|
-
def app=(server)
|
18
|
-
@app = server
|
19
|
-
@app.set :environment, :test
|
20
|
-
end
|
21
|
-
|
22
|
-
def get_host(path,host,params={},headers={})
|
23
|
-
get(path,params,headers.merge('HTTP_HOST' => host))
|
24
|
-
end
|
25
|
-
|
26
|
-
def post_host(path,host,params={},headers={})
|
27
|
-
post(path,params,headers.merge('HTTP_HOST' => host))
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
index1
|
@@ -1 +0,0 @@
|
|
1
|
-
test1
|
@@ -1 +0,0 @@
|
|
1
|
-
test1
|
@@ -1 +0,0 @@
|
|
1
|
-
test2
|
@@ -1 +0,0 @@
|
|
1
|
-
test2
|
@@ -1 +0,0 @@
|
|
1
|
-
test3
|
@@ -1 +0,0 @@
|
|
1
|
-
test3
|
data/spec/web/helpers/root.rb
DELETED
@@ -1,86 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'ronin/web/middleware/directories'
|
3
|
-
|
4
|
-
require 'web/helpers/rack_app'
|
5
|
-
require 'web/helpers/root'
|
6
|
-
|
7
|
-
describe Web::Middleware::Directories do
|
8
|
-
include Helpers::Web::RackApp
|
9
|
-
|
10
|
-
before(:all) do
|
11
|
-
self.app = Class.new(Sinatra::Base) do
|
12
|
-
extend Helpers::Web::Root
|
13
|
-
|
14
|
-
use Ronin::Web::Middleware::Directories do |dirs|
|
15
|
-
dirs.map '/test', root_path('test1')
|
16
|
-
dirs.map '/test/sub', root_path('test2')
|
17
|
-
dirs.map '/test/overriden', root_path('test3')
|
18
|
-
dirs.map '/', root_path
|
19
|
-
end
|
20
|
-
|
21
|
-
get '/test/overriden/*' do
|
22
|
-
'should not receive this'
|
23
|
-
end
|
24
|
-
|
25
|
-
get '/test/other' do
|
26
|
-
'other'
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe "index_names" do
|
32
|
-
subject { Web::Middleware::Directories.index_names }
|
33
|
-
|
34
|
-
it { should include('index.html') }
|
35
|
-
it { should include('index.xhtml') }
|
36
|
-
it { should include('index.htm') }
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should map remote directories to local directories" do
|
40
|
-
get '/test/test1.txt'
|
41
|
-
|
42
|
-
last_response.should be_ok
|
43
|
-
last_response.body.should == "test1\n"
|
44
|
-
end
|
45
|
-
|
46
|
-
it "should map remote directories to index files in local directories" do
|
47
|
-
get '/test/'
|
48
|
-
|
49
|
-
last_response.should be_ok
|
50
|
-
last_response.body.should == "index1\n"
|
51
|
-
end
|
52
|
-
|
53
|
-
it "should pass the request to the app if no index file exists" do
|
54
|
-
get '/test/sub/'
|
55
|
-
|
56
|
-
last_response.should_not be_ok
|
57
|
-
end
|
58
|
-
|
59
|
-
it "should match the whole remote path" do
|
60
|
-
get '/test/sub/test2.txt'
|
61
|
-
|
62
|
-
last_response.should be_ok
|
63
|
-
last_response.body.should == "test2\n"
|
64
|
-
end
|
65
|
-
|
66
|
-
it "should map local directories to the root directory" do
|
67
|
-
get '/test1/test1.txt'
|
68
|
-
|
69
|
-
last_response.should be_ok
|
70
|
-
last_response.body.should == "test1\n"
|
71
|
-
end
|
72
|
-
|
73
|
-
it "should match requests before the app" do
|
74
|
-
get '/test/overriden/test3.txt'
|
75
|
-
|
76
|
-
last_response.should be_ok
|
77
|
-
last_response.body.should == "test3\n"
|
78
|
-
end
|
79
|
-
|
80
|
-
it "should still route un-matched requests to the app" do
|
81
|
-
get '/test/other'
|
82
|
-
|
83
|
-
last_response.should be_ok
|
84
|
-
last_response.body.should == 'other'
|
85
|
-
end
|
86
|
-
end
|
@@ -1,57 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'ronin/web/middleware/files'
|
3
|
-
|
4
|
-
require 'web/helpers/rack_app'
|
5
|
-
require 'web/helpers/root'
|
6
|
-
|
7
|
-
describe Web::Middleware::Files do
|
8
|
-
include Helpers::Web::RackApp
|
9
|
-
|
10
|
-
before(:all) do
|
11
|
-
self.app = Class.new(Sinatra::Base) do
|
12
|
-
extend Helpers::Web::Root
|
13
|
-
|
14
|
-
use Ronin::Web::Middleware::Files do |files|
|
15
|
-
files.map '/test', root_path('test1.txt')
|
16
|
-
files.map '/test/sub', root_path('test2.txt')
|
17
|
-
files.map '/test/overriden', root_path('test3.txt')
|
18
|
-
end
|
19
|
-
|
20
|
-
get '/test/overriden' do
|
21
|
-
'should not receive this'
|
22
|
-
end
|
23
|
-
|
24
|
-
get '/test/other' do
|
25
|
-
'other'
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
it "should map remote files to local files" do
|
31
|
-
get '/test'
|
32
|
-
|
33
|
-
last_response.should be_ok
|
34
|
-
last_response.body.should == "test1\n"
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should match the whole remote path" do
|
38
|
-
get '/test/sub'
|
39
|
-
|
40
|
-
last_response.should be_ok
|
41
|
-
last_response.body.should == "test2\n"
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should match requests before the app" do
|
45
|
-
get '/test/overriden'
|
46
|
-
|
47
|
-
last_response.should be_ok
|
48
|
-
last_response.body.should == "test3\n"
|
49
|
-
end
|
50
|
-
|
51
|
-
it "should still route un-matched requests to the app" do
|
52
|
-
get '/test/other'
|
53
|
-
|
54
|
-
last_response.should be_ok
|
55
|
-
last_response.body.should == 'other'
|
56
|
-
end
|
57
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'ronin/web/middleware/filters/campaign_filter'
|
3
|
-
|
4
|
-
describe Web::Middleware::Filters::CampaignFilter do
|
5
|
-
subject { Web::Middleware::Filters::CampaignFilter }
|
6
|
-
|
7
|
-
let(:name) { 'Ronin::Web::Middleware' }
|
8
|
-
let(:ip) { '192.168.1.42' }
|
9
|
-
|
10
|
-
before(:all) do
|
11
|
-
campaign = Campaign.new(
|
12
|
-
:name => name,
|
13
|
-
:description => 'Campaign for Ronin::Web::Middleware::Rules::CampaignRule'
|
14
|
-
)
|
15
|
-
campaign.addresses << IPAddress.new(:address => ip)
|
16
|
-
|
17
|
-
campaign.save
|
18
|
-
end
|
19
|
-
|
20
|
-
before(:each) do
|
21
|
-
@request = mock('request')
|
22
|
-
@request.should_receive(:ip).and_return(ip)
|
23
|
-
end
|
24
|
-
|
25
|
-
it "should match requests by IP Address and targeting Campaign" do
|
26
|
-
filter = subject.new(name)
|
27
|
-
|
28
|
-
filter.match?(@request).should == true
|
29
|
-
end
|
30
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'ronin/web/middleware/filters/ip_filter'
|
3
|
-
|
4
|
-
describe Web::Middleware::Filters::IPFilter do
|
5
|
-
subject { Web::Middleware::Filters::IPFilter }
|
6
|
-
|
7
|
-
let(:ip) { '192.168.1.42' }
|
8
|
-
|
9
|
-
before(:each) do
|
10
|
-
@request = mock('request')
|
11
|
-
@request.should_receive(:ip).and_return(ip)
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should match requests using an IPAddr" do
|
15
|
-
filter = subject.new(ip)
|
16
|
-
|
17
|
-
filter.match?(@request).should == true
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should match requests using an IPAddr range" do
|
21
|
-
filter = subject.new('192.168.1.1/24')
|
22
|
-
|
23
|
-
filter.match?(@request).should == true
|
24
|
-
end
|
25
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'ronin/web/middleware/filters/path_filter'
|
3
|
-
|
4
|
-
describe Web::Middleware::Filters::PathFilter do
|
5
|
-
subject { Web::Middleware::Filters::PathFilter }
|
6
|
-
|
7
|
-
before(:each) do
|
8
|
-
@request = mock('request')
|
9
|
-
@request.should_receive(:path).and_return('/path/sub/dir')
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should match requests using an absolute path" do
|
13
|
-
filter = subject.new('/path/sub')
|
14
|
-
|
15
|
-
filter.match?(@request).should == true
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should match requests using an path fragment" do
|
19
|
-
filter = subject.new('sub/dir')
|
20
|
-
|
21
|
-
filter.match?(@request).should == true
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should match requests using a Regexp" do
|
25
|
-
filter = subject.new(/\/sub\//)
|
26
|
-
|
27
|
-
filter.match?(@request).should == true
|
28
|
-
end
|
29
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'ronin/web/middleware/filters/referer_filter'
|
3
|
-
|
4
|
-
describe Web::Middleware::Filters::RefererFilter do
|
5
|
-
subject { Web::Middleware::Filters::RefererFilter }
|
6
|
-
|
7
|
-
let(:referer) { 'http://www.example.com/page.html' }
|
8
|
-
|
9
|
-
before(:each) do
|
10
|
-
@request = mock('request')
|
11
|
-
@request.should_receive(:referer).and_return(referer)
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should match requests using a String" do
|
15
|
-
filter = subject.new(referer)
|
16
|
-
|
17
|
-
filter.match?(@request).should == true
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should match requests using a Regexp" do
|
21
|
-
filter = subject.new(/example\.com/)
|
22
|
-
|
23
|
-
filter.match?(@request).should == true
|
24
|
-
end
|
25
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'ronin/web/middleware/filters/user_agent_filter'
|
3
|
-
|
4
|
-
describe Web::Middleware::Filters::UserAgentFilter do
|
5
|
-
subject { Web::Middleware::Filters::UserAgentFilter }
|
6
|
-
|
7
|
-
let(:user_agent) { 'Windows-RSS-Platform/1.0 (MSIE 7.0; Windows NT 5.1)' }
|
8
|
-
|
9
|
-
before(:each) do
|
10
|
-
@request = mock('request')
|
11
|
-
@request.should_receive(:user_agent).and_return(user_agent)
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should match requests using a String" do
|
15
|
-
filter = subject.new(user_agent)
|
16
|
-
|
17
|
-
filter.match?(@request).should == true
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should match requests using a Regexp" do
|
21
|
-
filter = subject.new(/(MSIE|Windows)/)
|
22
|
-
|
23
|
-
filter.match?(@request).should == true
|
24
|
-
end
|
25
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'ronin/web/middleware/filters/vhost_filter'
|
3
|
-
|
4
|
-
describe Web::Middleware::Filters::VHostFilter do
|
5
|
-
subject { Web::Middleware::Filters::VHostFilter }
|
6
|
-
|
7
|
-
before(:each) do
|
8
|
-
@request = mock('request')
|
9
|
-
@request.should_receive(:host).and_return('domain.example.com')
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should match requests using a String" do
|
13
|
-
filter = subject.new('domain.example.com')
|
14
|
-
|
15
|
-
filter.match?(@request).should == true
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should match requests using a Regexp" do
|
19
|
-
filter = subject.new(/example\.com/)
|
20
|
-
|
21
|
-
filter.match?(@request).should == true
|
22
|
-
end
|
23
|
-
end
|
@@ -1,67 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'ronin/web/middleware/proxy'
|
3
|
-
|
4
|
-
require 'web/helpers/rack_app'
|
5
|
-
|
6
|
-
describe Web::Middleware::Proxy do
|
7
|
-
include Helpers::Web::RackApp
|
8
|
-
|
9
|
-
before(:all) do
|
10
|
-
self.app = Class.new(Sinatra::Base) do
|
11
|
-
use Ronin::Web::Middleware::Proxy, :path => '/login' do |proxy|
|
12
|
-
proxy.every_request do |request|
|
13
|
-
request.scheme = 'https'
|
14
|
-
request.host = 'github.com'
|
15
|
-
request.port = 443
|
16
|
-
request.referer = 'http://github.com/login'
|
17
|
-
end
|
18
|
-
|
19
|
-
proxy.every_response do |response|
|
20
|
-
response.body.each { |chunk| chunk.gsub!('https:','http:') }
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
get '/' do
|
25
|
-
'unproxied'
|
26
|
-
end
|
27
|
-
|
28
|
-
get '/login' do
|
29
|
-
'unproxied login'
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
it "should proxy requests that match the proxies filters" do
|
35
|
-
pending "http://github.com/brynary/rack-test/issues#issue/16" do
|
36
|
-
get '/login'
|
37
|
-
|
38
|
-
last_response.should be_ok
|
39
|
-
last_response.body.should_not == 'unproxied login'
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should allow rewriting proxied requests" do
|
44
|
-
pending "http://github.com/brynary/rack-test/issues#issue/16" do
|
45
|
-
get '/login'
|
46
|
-
|
47
|
-
last_response.should be_ok
|
48
|
-
last_response.body.should include('Log in')
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
it "should allow rewriting proxied responses" do
|
53
|
-
pending "http://github.com/brynary/rack-test/issues#issue/16" do
|
54
|
-
get '/login'
|
55
|
-
|
56
|
-
last_response.should be_ok
|
57
|
-
last_response.body.should_not include('https:')
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
it "should still route un-matched requests to the app" do
|
62
|
-
get '/'
|
63
|
-
|
64
|
-
last_response.should be_ok
|
65
|
-
last_response.body.should == 'unproxied'
|
66
|
-
end
|
67
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'ronin/web/middleware/response'
|
3
|
-
|
4
|
-
describe Web::Middleware::Response do
|
5
|
-
subject do
|
6
|
-
Web::Middleware::Response.new(
|
7
|
-
['Hello'],
|
8
|
-
200,
|
9
|
-
{'Content-Type' => 'text/html'}
|
10
|
-
)
|
11
|
-
end
|
12
|
-
|
13
|
-
it "should allow implicit splatting" do
|
14
|
-
status, headers, body = subject
|
15
|
-
|
16
|
-
status.should == 200
|
17
|
-
headers['Content-Type'].should == 'text/html'
|
18
|
-
body.should == subject
|
19
|
-
end
|
20
|
-
end
|
@@ -1,65 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'ronin/web/middleware/router'
|
3
|
-
|
4
|
-
require 'web/helpers/rack_app'
|
5
|
-
|
6
|
-
describe Web::Middleware::Router do
|
7
|
-
include Helpers::Web::RackApp
|
8
|
-
|
9
|
-
before(:all) do
|
10
|
-
self.app = Class.new(Sinatra::Base) do
|
11
|
-
FakeApp = Class.new(Sinatra::Base) do
|
12
|
-
|
13
|
-
get '/test/1' do
|
14
|
-
'fake'
|
15
|
-
end
|
16
|
-
|
17
|
-
get '/test/2' do
|
18
|
-
'fake'
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
use Ronin::Web::Middleware::Router do |router|
|
24
|
-
router.draw :referer => /google\.com/, :to => FakeApp
|
25
|
-
|
26
|
-
router.draw :user_agent => /MSIE/,
|
27
|
-
:referer => /myspace\.com/,
|
28
|
-
:to => FakeApp
|
29
|
-
end
|
30
|
-
|
31
|
-
get '/test/1' do
|
32
|
-
'real'
|
33
|
-
end
|
34
|
-
|
35
|
-
get '/test/2' do
|
36
|
-
'real'
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should route matched requests to other apps" do
|
43
|
-
get '/test/1', {}, {'HTTP_REFERER' => 'http://www.google.com/'}
|
44
|
-
|
45
|
-
last_response.should be_ok
|
46
|
-
last_response.body.should == 'fake'
|
47
|
-
end
|
48
|
-
|
49
|
-
it "should not route requests that do not match all rules" do
|
50
|
-
get '/test/2', {}, {
|
51
|
-
'HTTP_REFERER' => 'http://www.myspace.com/',
|
52
|
-
'HTTP_USER_AGENT' => 'Curl'
|
53
|
-
}
|
54
|
-
|
55
|
-
last_response.should be_ok
|
56
|
-
last_response.body.should_not == 'fake'
|
57
|
-
end
|
58
|
-
|
59
|
-
it "should still route un-matched requests to the app" do
|
60
|
-
get '/test/1'
|
61
|
-
|
62
|
-
last_response.should be_ok
|
63
|
-
last_response.body.should == 'real'
|
64
|
-
end
|
65
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'ronin/web/middleware/rule'
|
3
|
-
|
4
|
-
describe Web::Middleware::Rule do
|
5
|
-
subject { Web::Middleware::Rule }
|
6
|
-
|
7
|
-
before(:each) do
|
8
|
-
@request = mock('request')
|
9
|
-
|
10
|
-
@request.stub!(:host).and_return('www.example.com')
|
11
|
-
@request.stub!(:path).and_return('/path/sub/dir')
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should match requests by default" do
|
15
|
-
rule = subject.new()
|
16
|
-
|
17
|
-
rule.match?(@request).should == true
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should match requests against all filters" do
|
21
|
-
rule = subject.new(
|
22
|
-
:vhost => 'www.example.com',
|
23
|
-
:path => '/path/sub/dir'
|
24
|
-
)
|
25
|
-
|
26
|
-
rule.match?(@request).should == true
|
27
|
-
end
|
28
|
-
|
29
|
-
it "should match requests against against custom logic" do
|
30
|
-
rule = subject.new(
|
31
|
-
:path => '/path/sub/dir',
|
32
|
-
:when => lambda { |request| request.host =~ /example/ }
|
33
|
-
)
|
34
|
-
|
35
|
-
rule.match?(@request).should == true
|
36
|
-
end
|
37
|
-
end
|