ronin-web 0.3.0.rc1 → 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 -70
- data/Gemfile +42 -37
- data/README.md +159 -145
- data/Rakefile +12 -3
- data/bin/ronin-web +9 -17
- 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 -14
- 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 +34 -36
- 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 +39 -109
- 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 +236 -224
- data/.gemtest +0 -0
- data/data/ronin/web/user_agents.yml +0 -247
- data/lib/ronin/network/mixins/web.rb +0 -258
- data/lib/ronin/web/config.rb +0 -34
- 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 -120
- data/lib/ronin/web/user_agents.rb +0 -196
- data/lib/ronin/web/web.rb +0 -560
- data/spec/helpers/output.rb +0 -3
- data/spec/web/extensions/nokogiri_spec.rb +0 -38
- data/spec/web/helpers/rack_app.rb +0 -24
- 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/mechanize_spec.rb +0 -62
- 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/user_agents_spec.rb +0 -56
- data/spec/web/web_spec.rb +0 -101
data/spec/web/mechanize_spec.rb
DELETED
@@ -1,62 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'ronin/web/mechanize'
|
3
|
-
|
4
|
-
describe Web::Mechanize do
|
5
|
-
describe "#initialize" do
|
6
|
-
describe ":user_agent" do
|
7
|
-
before(:all) do
|
8
|
-
Web.user_agent = 'test'
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should default to Web.user_agent" do
|
12
|
-
described_class.new.user_agent.should == 'test'
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should support using a custom User-Agent string" do
|
16
|
-
agent = described_class.new(:user_agent => 'test2')
|
17
|
-
|
18
|
-
agent.user_agent.should == 'test2'
|
19
|
-
end
|
20
|
-
|
21
|
-
it "should support using a custom User-Agent alias" do
|
22
|
-
agent = described_class.new(:user_agent_alias => 'iPhone')
|
23
|
-
|
24
|
-
agent.user_agent.should == "Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1C28 Safari/419.3"
|
25
|
-
end
|
26
|
-
|
27
|
-
after(:all) do
|
28
|
-
Web.user_agent = nil
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
describe ":proxy" do
|
33
|
-
let(:host) { '127.0.0.1' }
|
34
|
-
let(:port) { 8080 }
|
35
|
-
let(:proxy) {
|
36
|
-
Network::HTTP::Proxy.new(:host => host, :port => port)
|
37
|
-
}
|
38
|
-
|
39
|
-
before(:all) do
|
40
|
-
Web.proxy = {:host => 'www.example.com', :port => port}
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should default to Web.proxy" do
|
44
|
-
agent = described_class.new
|
45
|
-
|
46
|
-
agent.proxy_addr.should == Web.proxy.host
|
47
|
-
agent.proxy_port.should == Web.proxy.port
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should support using custom proxies" do
|
51
|
-
agent = described_class.new(:proxy => proxy)
|
52
|
-
|
53
|
-
agent.proxy_addr.should == host
|
54
|
-
agent.proxy_port.should == port
|
55
|
-
end
|
56
|
-
|
57
|
-
after(:all) do
|
58
|
-
Web.proxy = nil
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
@@ -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
|
data/spec/web/proxy/base_spec.rb
DELETED
@@ -1,77 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'ronin/web/server/base'
|
3
|
-
|
4
|
-
require 'web/server/classes/test_app'
|
5
|
-
require 'web/helpers/rack_app'
|
6
|
-
|
7
|
-
describe Web::Server::Base do
|
8
|
-
include Helpers::Web::RackApp
|
9
|
-
|
10
|
-
before(:all) do
|
11
|
-
self.app = TestApp
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should find a suitable Rack::Handler for the web server" do
|
15
|
-
TestApp.handler_class.should_not be_nil
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should still bind blocks to paths" do
|
19
|
-
get '/tests/get'
|
20
|
-
|
21
|
-
last_response.should be_ok
|
22
|
-
last_response.body.should == 'block tested'
|
23
|
-
end
|
24
|
-
|
25
|
-
it "should bind a block to a path for all request types" do
|
26
|
-
post '/tests/any'
|
27
|
-
|
28
|
-
last_response.should be_ok
|
29
|
-
last_response.body.should == 'any tested'
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should have a default response" do
|
33
|
-
get '/totally/non/existant/path'
|
34
|
-
|
35
|
-
last_response.should_not be_ok
|
36
|
-
last_response.body.should be_empty
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should allow for defining custom responses" do
|
40
|
-
TestApp.default do
|
41
|
-
halt 404, 'nothing to see here'
|
42
|
-
end
|
43
|
-
|
44
|
-
get '/whats/here'
|
45
|
-
|
46
|
-
last_response.should_not be_ok
|
47
|
-
last_response.body.should == 'nothing to see here'
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should map paths to sub-apps" do
|
51
|
-
get '/tests/subapp/'
|
52
|
-
|
53
|
-
last_response.should be_ok
|
54
|
-
last_response.body.should == 'SubApp'
|
55
|
-
end
|
56
|
-
|
57
|
-
it "should not modify the path_info as it maps paths to sub-apps" do
|
58
|
-
get '/tests/subapp/hello'
|
59
|
-
|
60
|
-
last_response.should be_ok
|
61
|
-
last_response.body.should == 'SubApp greets you'
|
62
|
-
end
|
63
|
-
|
64
|
-
it "should host static content from public directories" do
|
65
|
-
get '/static1.txt'
|
66
|
-
|
67
|
-
last_response.should be_ok
|
68
|
-
last_response.body.should == "Static file1.\n"
|
69
|
-
end
|
70
|
-
|
71
|
-
it "should host static content from multiple public directories" do
|
72
|
-
get '/static2.txt'
|
73
|
-
|
74
|
-
last_response.should be_ok
|
75
|
-
last_response.body.should == "Static file2.\n"
|
76
|
-
end
|
77
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
Static file1.
|
@@ -1 +0,0 @@
|
|
1
|
-
Static file2.
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'ronin/web/server/base'
|
2
|
-
|
3
|
-
require 'web/server/classes/sub_app'
|
4
|
-
|
5
|
-
class TestApp < Ronin::Web::Server::Base
|
6
|
-
|
7
|
-
get '/tests/get' do
|
8
|
-
'block tested'
|
9
|
-
end
|
10
|
-
|
11
|
-
any '/tests/any' do
|
12
|
-
'any tested'
|
13
|
-
end
|
14
|
-
|
15
|
-
map '/tests/subapp/', SubApp
|
16
|
-
|
17
|
-
public_dir File.join(File.dirname(__FILE__),'public1')
|
18
|
-
public_dir File.join(File.dirname(__FILE__),'public2')
|
19
|
-
|
20
|
-
end
|