ronin-web-server 0.1.0.beta1 → 0.1.0.beta2
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.
- checksums.yaml +4 -4
- data/.yardopts +1 -1
- data/ChangeLog.md +3 -0
- data/README.md +1 -1
- data/gemspec.yml +2 -2
- data/lib/ronin/web/server/app.rb +1 -1
- data/lib/ronin/web/server/base.rb +7 -42
- data/lib/ronin/web/server/conditions.rb +1 -1
- data/lib/ronin/web/server/helpers.rb +1 -1
- data/lib/ronin/web/server/request.rb +1 -1
- data/lib/ronin/web/server/response.rb +1 -1
- data/lib/ronin/web/server/reverse_proxy/request.rb +1 -1
- data/lib/ronin/web/server/reverse_proxy/response.rb +1 -1
- data/lib/ronin/web/server/reverse_proxy.rb +1 -1
- data/lib/ronin/web/server/routing.rb +1 -1
- data/lib/ronin/web/server/version.rb +2 -2
- data/lib/ronin/web/server.rb +1 -1
- data/ronin-web-server.gemspec +2 -1
- metadata +5 -23
- data/spec/base_spec.rb +0 -73
- data/spec/classes/public1/static1.txt +0 -1
- data/spec/classes/public2/static2.txt +0 -1
- data/spec/classes/sub_app.rb +0 -13
- data/spec/classes/test_app.rb +0 -20
- data/spec/helpers/rack_app.rb +0 -24
- data/spec/request_spec.rb +0 -58
- data/spec/response_spec.rb +0 -8
- data/spec/reverse_proxy/request_spec.rb +0 -200
- data/spec/reverse_proxy/response_spec.rb +0 -8
- data/spec/reverse_proxy_spec.rb +0 -223
- data/spec/spec_helper.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12765156008589491d49fc0daacb1a10ee5cd772e245052c0d7f335fe905c3b3
|
4
|
+
data.tar.gz: fe1ca6647e5527d39f473356246f19db946cd0cf5fae1b4122038e7ad63e0816
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c27e82e2e45ae189645917324e5a46e6098819a4567b6562c63eee91fd2afdcdf69fba087435af6b3a13f3d87e2872534d29ba5a4f92ae492d1cc306e9ca99d
|
7
|
+
data.tar.gz: df896a19879909dfe1cd5e7156712069736bb1dbc23e4b64a4c7f2ddfa69637d0079702cf203ecaf27007e03b1fe3ac946a728553c1f1f501dcc746b69a12122
|
data/.yardopts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
--markup markdown --title '
|
1
|
+
--markup markdown --title 'Ronin::Web::Server Documentation' --protected
|
data/ChangeLog.md
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
### 0.1.0 / 2023-XX-XX
|
2
2
|
|
3
|
+
* Extracted and refactored from [ronin-web](https://github.com/ronin-rb/ronin-web/tree/v0.3.0.rc1).
|
4
|
+
* Relicensed as LGPL-3.0.
|
3
5
|
* Initial release:
|
6
|
+
* Requires `ruby` >= 3.0.0.
|
4
7
|
* Provides a [Sinatra][sinatra] based
|
5
8
|
{Ronin::Web::Server::Base web server base class}.
|
6
9
|
* Supports additional routing helper methods:
|
data/README.md
CHANGED
@@ -154,7 +154,7 @@ gem 'ronin-web-server', '~> 0.1'
|
|
154
154
|
|
155
155
|
ronin-web-server - A custom Ruby web server based on Sinatra.
|
156
156
|
|
157
|
-
Copyright (c) 2006-
|
157
|
+
Copyright (c) 2006-2023 Hal Brodigan (postmodern.mod3 at gmail.com)
|
158
158
|
|
159
159
|
ronin-web-server is free software: you can redistribute it and/or modify
|
160
160
|
it under the terms of the GNU Lesser General Public License as published
|
data/gemspec.yml
CHANGED
@@ -11,10 +11,10 @@ homepage: https://ronin-rb.dev/
|
|
11
11
|
has_yard: true
|
12
12
|
|
13
13
|
metadata:
|
14
|
-
documentation_uri: https://
|
14
|
+
documentation_uri: https://ronin-rb.dev/docs/ronin-web-server
|
15
15
|
source_code_uri: https://github.com/postmodern/ronin-web-server
|
16
16
|
bug_tracker_uri: https://github.com/postmodern/ronin-web-server/issues
|
17
|
-
changelog_uri: https://github.com/postmodern/ronin-web-server/blob/
|
17
|
+
changelog_uri: https://github.com/postmodern/ronin-web-server/blob/main/ChangeLog.md
|
18
18
|
rubygems_mfa_required: 'true'
|
19
19
|
|
20
20
|
required_ruby_version: ">= 3.0.0"
|
data/lib/ronin/web/server/app.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
#
|
3
3
|
# ronin-web-server - A custom Ruby web server based on Sinatra.
|
4
4
|
#
|
5
|
-
# Copyright (c) 2006-
|
5
|
+
# Copyright (c) 2006-2023 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
6
|
#
|
7
7
|
# ronin-web-server is free software: you can redistribute it and/or modify
|
8
8
|
# it under the terms of the GNU Lesser General Public License as published
|
@@ -2,7 +2,7 @@
|
|
2
2
|
#
|
3
3
|
# ronin-web-server - A custom Ruby web server based on Sinatra.
|
4
4
|
#
|
5
|
-
# Copyright (c) 2006-
|
5
|
+
# Copyright (c) 2006-2023 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
6
|
#
|
7
7
|
# ronin-web-server is free software: you can redistribute it and/or modify
|
8
8
|
# it under the terms of the GNU Lesser General Public License as published
|
@@ -160,52 +160,17 @@ module Ronin
|
|
160
160
|
# Specifies wether the server will run in the background or run
|
161
161
|
# in the foreground.
|
162
162
|
#
|
163
|
+
# @raise [Errno::EADDRINUSE]
|
164
|
+
# The port is already in use.
|
165
|
+
#
|
163
166
|
# @api public
|
164
167
|
#
|
165
|
-
def self.run!(options={})
|
166
|
-
set(options)
|
167
|
-
|
168
|
-
handler = detect_rack_handler
|
169
|
-
handler_name = handler.name.gsub(/.*::/, '')
|
170
|
-
|
171
|
-
# rubocop:disable Lint/ShadowingOuterLocalVariable
|
172
|
-
runner = lambda { |handler,server|
|
173
|
-
begin
|
174
|
-
handler.run(server,Host: bind, Port: port) do |server|
|
175
|
-
trap(:INT) { quit!(server,handler_name) }
|
176
|
-
trap(:TERM) { quit!(server,handler_name) }
|
177
|
-
|
178
|
-
set :running, true
|
179
|
-
end
|
180
|
-
rescue Errno::EADDRINUSE
|
181
|
-
warn "ronin-web-server: address is already in use: #{bind}:#{port}"
|
182
|
-
end
|
183
|
-
}
|
184
|
-
# rubocop:enable Lint/ShadowingOuterLocalVariable
|
185
|
-
|
168
|
+
def self.run!(options={},&block)
|
186
169
|
if options[:background]
|
187
|
-
Thread.new(
|
170
|
+
Thread.new(options) { |options| super(options) }
|
188
171
|
else
|
189
|
-
|
172
|
+
super(options,&block)
|
190
173
|
end
|
191
|
-
|
192
|
-
return self
|
193
|
-
end
|
194
|
-
|
195
|
-
#
|
196
|
-
# Stops the web server.
|
197
|
-
#
|
198
|
-
# @param [#call] server
|
199
|
-
# The Rack Handler server.
|
200
|
-
#
|
201
|
-
# @param [String] handler_name
|
202
|
-
# The name of the handler.
|
203
|
-
#
|
204
|
-
# @api semipublic
|
205
|
-
#
|
206
|
-
def self.quit!(server,handler_name)
|
207
|
-
# Use thins' hard #stop! if available, otherwise just #stop
|
208
|
-
server.respond_to?(:stop!) ? server.stop! : server.stop
|
209
174
|
end
|
210
175
|
|
211
176
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
#
|
3
3
|
# ronin-web-server - A custom Ruby web server based on Sinatra.
|
4
4
|
#
|
5
|
-
# Copyright (c) 2006-
|
5
|
+
# Copyright (c) 2006-2023 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
6
|
#
|
7
7
|
# ronin-web-server is free software: you can redistribute it and/or modify
|
8
8
|
# it under the terms of the GNU Lesser General Public License as published
|
@@ -2,7 +2,7 @@
|
|
2
2
|
#
|
3
3
|
# ronin-web-server - A custom Ruby web server based on Sinatra.
|
4
4
|
#
|
5
|
-
# Copyright (c) 2006-
|
5
|
+
# Copyright (c) 2006-2023 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
6
|
#
|
7
7
|
# ronin-web-server is free software: you can redistribute it and/or modify
|
8
8
|
# it under the terms of the GNU Lesser General Public License as published
|
@@ -2,7 +2,7 @@
|
|
2
2
|
#
|
3
3
|
# ronin-web-server - A custom Ruby web server based on Sinatra.
|
4
4
|
#
|
5
|
-
# Copyright (c) 2006-
|
5
|
+
# Copyright (c) 2006-2023 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
6
|
#
|
7
7
|
# ronin-web-server is free software: you can redistribute it and/or modify
|
8
8
|
# it under the terms of the GNU Lesser General Public License as published
|
@@ -2,7 +2,7 @@
|
|
2
2
|
#
|
3
3
|
# ronin-web-server - A custom Ruby web server based on Sinatra.
|
4
4
|
#
|
5
|
-
# Copyright (c) 2006-
|
5
|
+
# Copyright (c) 2006-2023 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
6
|
#
|
7
7
|
# ronin-web-server is free software: you can redistribute it and/or modify
|
8
8
|
# it under the terms of the GNU Lesser General Public License as published
|
@@ -2,7 +2,7 @@
|
|
2
2
|
#
|
3
3
|
# ronin-web-server - A custom Ruby web server based on Sinatra.
|
4
4
|
#
|
5
|
-
# Copyright (c) 2006-
|
5
|
+
# Copyright (c) 2006-2023 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
6
|
#
|
7
7
|
# ronin-web-server is free software: you can redistribute it and/or modify
|
8
8
|
# it under the terms of the GNU Lesser General Public License as published
|
@@ -2,7 +2,7 @@
|
|
2
2
|
#
|
3
3
|
# ronin-web-server - A custom Ruby web server based on Sinatra.
|
4
4
|
#
|
5
|
-
# Copyright (c) 2006-
|
5
|
+
# Copyright (c) 2006-2023 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
6
|
#
|
7
7
|
# ronin-web-server is free software: you can redistribute it and/or modify
|
8
8
|
# it under the terms of the GNU Lesser General Public License as published
|
@@ -2,7 +2,7 @@
|
|
2
2
|
#
|
3
3
|
# ronin-web-server - A custom Ruby web server based on Sinatra.
|
4
4
|
#
|
5
|
-
# Copyright (c) 2006-
|
5
|
+
# Copyright (c) 2006-2023 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
6
|
#
|
7
7
|
# ronin-web-server is free software: you can redistribute it and/or modify
|
8
8
|
# it under the terms of the GNU Lesser General Public License as published
|
@@ -2,7 +2,7 @@
|
|
2
2
|
#
|
3
3
|
# ronin-web-server - A custom Ruby web server based on Sinatra.
|
4
4
|
#
|
5
|
-
# Copyright (c) 2006-
|
5
|
+
# Copyright (c) 2006-2023 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
6
|
#
|
7
7
|
# ronin-web-server is free software: you can redistribute it and/or modify
|
8
8
|
# it under the terms of the GNU Lesser General Public License as published
|
@@ -2,7 +2,7 @@
|
|
2
2
|
#
|
3
3
|
# ronin-web-server - A custom Ruby web server based on Sinatra.
|
4
4
|
#
|
5
|
-
# Copyright (c) 2006-
|
5
|
+
# Copyright (c) 2006-2023 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
6
|
#
|
7
7
|
# ronin-web-server is free software: you can redistribute it and/or modify
|
8
8
|
# it under the terms of the GNU Lesser General Public License as published
|
@@ -22,7 +22,7 @@ module Ronin
|
|
22
22
|
module Web
|
23
23
|
module Server
|
24
24
|
# ronin-web-server version
|
25
|
-
VERSION = '0.1.0.
|
25
|
+
VERSION = '0.1.0.beta2'
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
data/lib/ronin/web/server.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
#
|
3
3
|
# ronin-web-server - A custom Ruby web server based on Sinatra.
|
4
4
|
#
|
5
|
-
# Copyright (c) 2006-
|
5
|
+
# Copyright (c) 2006-2023 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
6
|
#
|
7
7
|
# ronin-web-server is free software: you can redistribute it and/or modify
|
8
8
|
# it under the terms of the GNU Lesser General Public License as published
|
data/ronin-web-server.gemspec
CHANGED
@@ -25,13 +25,14 @@ Gem::Specification.new do |gem|
|
|
25
25
|
gem.files = `git ls-files`.split($/)
|
26
26
|
gem.files = glob[gemspec['files']] if gemspec['files']
|
27
27
|
gem.files += Array(gemspec['generated_files'])
|
28
|
+
# exclude test files from the packages gem
|
29
|
+
gem.files -= glob[gemspec['test_files'] || 'spec/{**/}*']
|
28
30
|
|
29
31
|
gem.executables = gemspec.fetch('executables') do
|
30
32
|
glob['bin/*'].map { |path| File.basename(path) }
|
31
33
|
end
|
32
34
|
|
33
35
|
gem.extensions = glob[gemspec['extensions'] || 'ext/**/extconf.rb']
|
34
|
-
gem.test_files = glob[gemspec['test_files'] || 'spec/{**/}*_spec.rb']
|
35
36
|
gem.extra_rdoc_files = glob[gemspec['extra_doc_files'] || '*.{txt,md}']
|
36
37
|
|
37
38
|
gem.require_paths = Array(gemspec.fetch('require_paths') {
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ronin-web-server
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0.
|
4
|
+
version: 0.1.0.beta2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Postmodern
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-01-
|
11
|
+
date: 2023-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: webrick
|
@@ -131,26 +131,14 @@ files:
|
|
131
131
|
- lib/ronin/web/server/routing.rb
|
132
132
|
- lib/ronin/web/server/version.rb
|
133
133
|
- ronin-web-server.gemspec
|
134
|
-
- spec/base_spec.rb
|
135
|
-
- spec/classes/public1/static1.txt
|
136
|
-
- spec/classes/public2/static2.txt
|
137
|
-
- spec/classes/sub_app.rb
|
138
|
-
- spec/classes/test_app.rb
|
139
|
-
- spec/helpers/rack_app.rb
|
140
|
-
- spec/request_spec.rb
|
141
|
-
- spec/response_spec.rb
|
142
|
-
- spec/reverse_proxy/request_spec.rb
|
143
|
-
- spec/reverse_proxy/response_spec.rb
|
144
|
-
- spec/reverse_proxy_spec.rb
|
145
|
-
- spec/spec_helper.rb
|
146
134
|
homepage: https://ronin-rb.dev/
|
147
135
|
licenses:
|
148
136
|
- LGPL-3.0
|
149
137
|
metadata:
|
150
|
-
documentation_uri: https://
|
138
|
+
documentation_uri: https://ronin-rb.dev/docs/ronin-web-server
|
151
139
|
source_code_uri: https://github.com/postmodern/ronin-web-server
|
152
140
|
bug_tracker_uri: https://github.com/postmodern/ronin-web-server/issues
|
153
|
-
changelog_uri: https://github.com/postmodern/ronin-web-server/blob/
|
141
|
+
changelog_uri: https://github.com/postmodern/ronin-web-server/blob/main/ChangeLog.md
|
154
142
|
rubygems_mfa_required: 'true'
|
155
143
|
post_install_message:
|
156
144
|
rdoc_options: []
|
@@ -171,10 +159,4 @@ rubygems_version: 3.3.26
|
|
171
159
|
signing_key:
|
172
160
|
specification_version: 4
|
173
161
|
summary: A custom Ruby web server based on Sinatra.
|
174
|
-
test_files:
|
175
|
-
- spec/base_spec.rb
|
176
|
-
- spec/request_spec.rb
|
177
|
-
- spec/response_spec.rb
|
178
|
-
- spec/reverse_proxy/request_spec.rb
|
179
|
-
- spec/reverse_proxy/response_spec.rb
|
180
|
-
- spec/reverse_proxy_spec.rb
|
162
|
+
test_files: []
|
data/spec/base_spec.rb
DELETED
@@ -1,73 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'ronin/web/server/base'
|
3
|
-
|
4
|
-
require 'classes/test_app'
|
5
|
-
require 'helpers/rack_app'
|
6
|
-
|
7
|
-
describe Ronin::Web::Server::Base do
|
8
|
-
include Helpers::Web::RackApp
|
9
|
-
|
10
|
-
before(:all) do
|
11
|
-
self.app = TestApp
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should still bind blocks to paths" do
|
15
|
-
get '/tests/get'
|
16
|
-
|
17
|
-
expect(last_response).to be_ok
|
18
|
-
expect(last_response.body).to eq('block tested')
|
19
|
-
end
|
20
|
-
|
21
|
-
it "should bind a block to a path for all request types" do
|
22
|
-
post '/tests/any'
|
23
|
-
|
24
|
-
expect(last_response).to be_ok
|
25
|
-
expect(last_response.body).to eq('any tested')
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should have a default response" do
|
29
|
-
get '/totally/non/existant/path'
|
30
|
-
|
31
|
-
expect(last_response).not_to be_ok
|
32
|
-
expect(last_response.body).to be_empty
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should allow for defining custom responses" do
|
36
|
-
TestApp.default do
|
37
|
-
halt 404, 'nothing to see here'
|
38
|
-
end
|
39
|
-
|
40
|
-
get '/whats/here'
|
41
|
-
|
42
|
-
expect(last_response).not_to be_ok
|
43
|
-
expect(last_response.body).to eq('nothing to see here')
|
44
|
-
end
|
45
|
-
|
46
|
-
it "should map paths to sub-apps" do
|
47
|
-
get '/tests/subapp/'
|
48
|
-
|
49
|
-
expect(last_response).to be_ok
|
50
|
-
expect(last_response.body).to eq('SubApp')
|
51
|
-
end
|
52
|
-
|
53
|
-
it "should not modify the path_info as it maps paths to sub-apps" do
|
54
|
-
get '/tests/subapp/hello'
|
55
|
-
|
56
|
-
expect(last_response).to be_ok
|
57
|
-
expect(last_response.body).to eq('SubApp greets you')
|
58
|
-
end
|
59
|
-
|
60
|
-
it "should host static content from public directories" do
|
61
|
-
get '/static1.txt'
|
62
|
-
|
63
|
-
expect(last_response).to be_ok
|
64
|
-
expect(last_response.body).to eq("Static file1.\n")
|
65
|
-
end
|
66
|
-
|
67
|
-
it "should host static content from multiple public directories" do
|
68
|
-
get '/static2.txt'
|
69
|
-
|
70
|
-
expect(last_response).to be_ok
|
71
|
-
expect(last_response.body).to eq("Static file2.\n")
|
72
|
-
end
|
73
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
Static file1.
|
@@ -1 +0,0 @@
|
|
1
|
-
Static file2.
|
data/spec/classes/sub_app.rb
DELETED
data/spec/classes/test_app.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'ronin/web/server/base'
|
2
|
-
|
3
|
-
require '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
|
-
mount '/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
|
data/spec/helpers/rack_app.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'rack/test'
|
2
|
-
|
3
|
-
module Helpers
|
4
|
-
module Web
|
5
|
-
module RackApp
|
6
|
-
include Rack::Test::Methods
|
7
|
-
|
8
|
-
attr_reader :app
|
9
|
-
|
10
|
-
def app=(server)
|
11
|
-
@app = server
|
12
|
-
@app.set :environment, :test
|
13
|
-
end
|
14
|
-
|
15
|
-
def get_host(path,host,params={},headers={})
|
16
|
-
get(path,params,headers.merge('HTTP_HOST' => host))
|
17
|
-
end
|
18
|
-
|
19
|
-
def post_host(path,host,params={},headers={})
|
20
|
-
post(path,params,headers.merge('HTTP_HOST' => host))
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
data/spec/request_spec.rb
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'ronin/web/server/request'
|
3
|
-
|
4
|
-
describe Ronin::Web::Server::Request do
|
5
|
-
it "must provide the same methods as Sinatra::Request" do
|
6
|
-
expect(described_class).to be < Sinatra::Request
|
7
|
-
end
|
8
|
-
|
9
|
-
let(:env) { {} }
|
10
|
-
|
11
|
-
subject { described_class.new(env) }
|
12
|
-
|
13
|
-
describe "#ip_with_port" do
|
14
|
-
let(:ip) { '127.0.0.1' }
|
15
|
-
|
16
|
-
context "when REMOTE_PORT is set" do
|
17
|
-
let(:port) { 8000 }
|
18
|
-
let(:env) do
|
19
|
-
{'REMOTE_ADDR' => ip, 'REMOTE_PORT' => port}
|
20
|
-
end
|
21
|
-
|
22
|
-
it "must return REMOTE_ADDR:REMOTE_PORT" do
|
23
|
-
expect(subject.ip_with_port).to eq("#{ip}:#{port}")
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
context "when REMOTE_PORT is not set" do
|
28
|
-
let(:env) do
|
29
|
-
{'REMOTE_ADDR' => ip}
|
30
|
-
end
|
31
|
-
|
32
|
-
it "must return the REMOTE_ADDR" do
|
33
|
-
expect(subject.ip_with_port).to eq(ip)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
describe "#headers" do
|
39
|
-
let(:header1) { 'header1 value' }
|
40
|
-
let(:header2) { 'header2 value' }
|
41
|
-
let(:env) do
|
42
|
-
{
|
43
|
-
'HTTP_HEADER1' => header1,
|
44
|
-
'FOO_BAR' => 'foo',
|
45
|
-
'HTTP_HEADER2' => header2
|
46
|
-
}
|
47
|
-
end
|
48
|
-
|
49
|
-
it "must return a Hash of all HTTP_* headers" do
|
50
|
-
expect(subject.headers).to eq(
|
51
|
-
{
|
52
|
-
'Header1' => header1,
|
53
|
-
'Header2' => header2
|
54
|
-
}
|
55
|
-
)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
data/spec/response_spec.rb
DELETED
@@ -1,200 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'ronin/web/server/reverse_proxy/request'
|
3
|
-
|
4
|
-
describe Ronin::Web::Server::ReverseProxy::Request do
|
5
|
-
it "must provide the same methods as Ronin::Web::Server::Request" do
|
6
|
-
expect(described_class).to be < Ronin::Web::Server::Request
|
7
|
-
end
|
8
|
-
|
9
|
-
let(:env) { {} }
|
10
|
-
|
11
|
-
subject { described_class.new(env) }
|
12
|
-
|
13
|
-
describe "#host=" do
|
14
|
-
let(:host) { 'example.com' }
|
15
|
-
let(:new_host) { 'evil.com' }
|
16
|
-
let(:env) do
|
17
|
-
{'HTTP_HOST' => host}
|
18
|
-
end
|
19
|
-
|
20
|
-
before { subject.host = new_host }
|
21
|
-
|
22
|
-
it "must set HTTP_HOST" do
|
23
|
-
expect(env['HTTP_HOST']).to eq(new_host)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
describe "#port=" do
|
28
|
-
let(:port) { 80 }
|
29
|
-
let(:new_port) { 8080 }
|
30
|
-
let(:env) do
|
31
|
-
{'SERVER_PORT' => port}
|
32
|
-
end
|
33
|
-
|
34
|
-
before { subject.port = new_port }
|
35
|
-
|
36
|
-
it "must set SERVER_PORT" do
|
37
|
-
expect(env['SERVER_PORT']).to eq(new_port)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
describe "#scheme=" do
|
42
|
-
let(:scheme) { 'https' }
|
43
|
-
let(:new_scheme) { 'http' }
|
44
|
-
let(:env) do
|
45
|
-
{'rack.url_scheme' => scheme}
|
46
|
-
end
|
47
|
-
|
48
|
-
before { subject.scheme = new_scheme }
|
49
|
-
|
50
|
-
it "must set rack.url_scheme" do
|
51
|
-
expect(env['rack.url_scheme']).to eq(new_scheme)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
describe "#ssl=" do
|
56
|
-
context "when given true" do
|
57
|
-
before { subject.ssl = true }
|
58
|
-
|
59
|
-
it "must set #port to 443" do
|
60
|
-
expect(subject.port).to eq(443)
|
61
|
-
end
|
62
|
-
|
63
|
-
it "must set #scheme to 'https'" do
|
64
|
-
expect(subject.scheme).to eq('https')
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
context "when given false" do
|
69
|
-
before { subject.ssl = false }
|
70
|
-
|
71
|
-
it "must set #port to 80" do
|
72
|
-
expect(subject.port).to eq(80)
|
73
|
-
end
|
74
|
-
|
75
|
-
it "must set #scheme to 'http'" do
|
76
|
-
expect(subject.scheme).to eq('http')
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
describe "#request_method=" do
|
82
|
-
let(:request_method) { 'GET' }
|
83
|
-
let(:new_request_method) { 'POST' }
|
84
|
-
let(:env) do
|
85
|
-
{'REQUEST_METHOD' => request_method}
|
86
|
-
end
|
87
|
-
|
88
|
-
before { subject.request_method = new_request_method }
|
89
|
-
|
90
|
-
it "must set REQUEST_METHOD" do
|
91
|
-
expect(env['REQUEST_METHOD']).to eq(new_request_method)
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
describe "#query_string=" do
|
96
|
-
let(:query_string) { 'GET' }
|
97
|
-
let(:new_query_string) { 'POST' }
|
98
|
-
let(:env) do
|
99
|
-
{'QUERY_STRING' => query_string}
|
100
|
-
end
|
101
|
-
|
102
|
-
before { subject.query_string = new_query_string }
|
103
|
-
|
104
|
-
it "must set QUERY_STRING" do
|
105
|
-
expect(env['QUERY_STRING']).to eq(new_query_string)
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
describe "#xhr=" do
|
110
|
-
context "when given true" do
|
111
|
-
before { subject.xhr = true }
|
112
|
-
|
113
|
-
it "must set HTTP_X_REQUESTED_WITH to 'XMLHttpRequest'" do
|
114
|
-
expect(env['HTTP_X_REQUESTED_WITH']).to eq('XMLHttpRequest')
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
context "when given false" do
|
119
|
-
let(:env) do
|
120
|
-
{'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest'}
|
121
|
-
end
|
122
|
-
|
123
|
-
before { subject.xhr = false }
|
124
|
-
|
125
|
-
it "must delete the HTTP_X_REQUESTED_WITH header" do
|
126
|
-
expect(env['HTTP_X_REQUESTED_WITH']).to be(nil)
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
describe "#content_type=" do
|
132
|
-
let(:content_type) { 'text/html' }
|
133
|
-
let(:new_content_type) { 'text/xml' }
|
134
|
-
let(:env) do
|
135
|
-
{'CONTENT_TYPE' => content_type}
|
136
|
-
end
|
137
|
-
|
138
|
-
before { subject.content_type = new_content_type }
|
139
|
-
|
140
|
-
it "must set CONTENT_TYPE" do
|
141
|
-
expect(env['CONTENT_TYPE']).to eq(new_content_type)
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
describe "#accept_encoding=" do
|
146
|
-
let(:accept_encoding) { 'gzip' }
|
147
|
-
let(:new_accept_encoding) { '*' }
|
148
|
-
let(:env) do
|
149
|
-
{'HTTP_ACCEPT_ENCODING' => accept_encoding}
|
150
|
-
end
|
151
|
-
|
152
|
-
before { subject.accept_encoding = new_accept_encoding }
|
153
|
-
|
154
|
-
it "must set HTTP_ACCEPT_ENCODING" do
|
155
|
-
expect(env['HTTP_ACCEPT_ENCODING']).to eq(new_accept_encoding)
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
describe "#user_agent=" do
|
160
|
-
let(:user_agent) { 'FireFox' }
|
161
|
-
let(:new_user_agent) { 'Chrome' }
|
162
|
-
let(:env) do
|
163
|
-
{'HTTP_USER_AGENT' => user_agent}
|
164
|
-
end
|
165
|
-
|
166
|
-
before { subject.user_agent = new_user_agent }
|
167
|
-
|
168
|
-
it "must set HTTP_USER_AGENT" do
|
169
|
-
expect(env['HTTP_USER_AGENT']).to eq(new_user_agent)
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
describe "#referer=" do
|
174
|
-
let(:referer) { 'http://example.com/' }
|
175
|
-
let(:new_referer) { 'http://evil.com/' }
|
176
|
-
let(:env) do
|
177
|
-
{'HTTP_REFERER' => referer}
|
178
|
-
end
|
179
|
-
|
180
|
-
before { subject.referer = new_referer }
|
181
|
-
|
182
|
-
it "must set HTTP_REFERER" do
|
183
|
-
expect(env['HTTP_REFERER']).to eq(new_referer)
|
184
|
-
end
|
185
|
-
end
|
186
|
-
|
187
|
-
describe "#body=" do
|
188
|
-
let(:body) { '<html><body>test</body></html>' }
|
189
|
-
let(:new_body) { '<html><body>rewritten!</body></html>' }
|
190
|
-
let(:env) do
|
191
|
-
{'rack.input' => body}
|
192
|
-
end
|
193
|
-
|
194
|
-
before { subject.body = new_body }
|
195
|
-
|
196
|
-
it "must set rack.input" do
|
197
|
-
expect(env['rack.input']).to eq(new_body)
|
198
|
-
end
|
199
|
-
end
|
200
|
-
end
|
@@ -1,8 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'ronin/web/server/reverse_proxy/response'
|
3
|
-
|
4
|
-
describe Ronin::Web::Server::ReverseProxy::Response do
|
5
|
-
it "must provide the same methods as Ronin::Web::Server::Response" do
|
6
|
-
expect(described_class).to be < Ronin::Web::Server::Response
|
7
|
-
end
|
8
|
-
end
|
data/spec/reverse_proxy_spec.rb
DELETED
@@ -1,223 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'ronin/web/server/reverse_proxy'
|
3
|
-
|
4
|
-
require 'webmock/rspec'
|
5
|
-
|
6
|
-
describe Ronin::Web::Server::ReverseProxy do
|
7
|
-
describe "#initialize" do
|
8
|
-
context "when given a block" do
|
9
|
-
it "must pass the newly created reverse proxy object" do
|
10
|
-
expect { |b|
|
11
|
-
described_class.new(&b)
|
12
|
-
}.to yield_with_args(described_class)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
describe "#call" do
|
18
|
-
let(:request_method) { 'GET' }
|
19
|
-
let(:path) { '/' }
|
20
|
-
let(:port) { 80 }
|
21
|
-
let(:host) { 'example.com' }
|
22
|
-
let(:body) { '' }
|
23
|
-
let(:env) do
|
24
|
-
{
|
25
|
-
'REQUEST_METHOD' => request_method,
|
26
|
-
'REQUEST_PATH' => path,
|
27
|
-
'PATH_INFO' => path,
|
28
|
-
'HTTP_HOST' => host,
|
29
|
-
'SERVER_PORT' => port,
|
30
|
-
'rack.input' => StringIO.new(body)
|
31
|
-
}
|
32
|
-
end
|
33
|
-
|
34
|
-
let(:http_request_method) { request_method.downcase.to_sym }
|
35
|
-
let(:http_request_uri) do
|
36
|
-
URI::HTTP.build(host: host, port: port, path: path)
|
37
|
-
end
|
38
|
-
|
39
|
-
let(:http_response_status) { 200 }
|
40
|
-
let(:http_response_headers) do
|
41
|
-
{'X-Foo' => 'bar'}
|
42
|
-
end
|
43
|
-
let(:http_response_body) { nil }
|
44
|
-
|
45
|
-
before do
|
46
|
-
stub_request(:get,http_request_uri).to_return(
|
47
|
-
status: http_response_status,
|
48
|
-
headers: http_response_headers,
|
49
|
-
body: http_response_body
|
50
|
-
)
|
51
|
-
end
|
52
|
-
|
53
|
-
it "must return a #{described_class::Response} object" do
|
54
|
-
expect(subject.call(env)).to be_kind_of(described_class::Response)
|
55
|
-
end
|
56
|
-
|
57
|
-
it "must make an HTTP request for the requested Host header and path" do
|
58
|
-
subject.call(env)
|
59
|
-
|
60
|
-
expect(WebMock).to have_requested(http_request_method,http_request_uri)
|
61
|
-
end
|
62
|
-
|
63
|
-
it "must return all HTTP response headers in the respones object" do
|
64
|
-
response = subject.call(env)
|
65
|
-
|
66
|
-
expect(response.headers).to include(http_response_headers)
|
67
|
-
end
|
68
|
-
|
69
|
-
it "must default the response body to an empty String" do
|
70
|
-
response = subject.call(env)
|
71
|
-
|
72
|
-
expect(response.body).to eq([''])
|
73
|
-
end
|
74
|
-
|
75
|
-
context "when the #on_request callback is set" do
|
76
|
-
it "must pass the request object to the #on_request callback" do
|
77
|
-
yielded_request = nil
|
78
|
-
|
79
|
-
reverse_proxy = described_class.new do |proxy|
|
80
|
-
proxy.on_request do |request|
|
81
|
-
yielded_request = request
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
reverse_proxy.call(env)
|
86
|
-
|
87
|
-
expect(yielded_request).to be_kind_of(described_class::Request)
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
context "when the #on_response callback is set" do
|
92
|
-
it "must pass the response object to the #on_response callback" do
|
93
|
-
yielded_response = nil
|
94
|
-
|
95
|
-
reverse_proxy = described_class.new do |proxy|
|
96
|
-
proxy.on_response do |response|
|
97
|
-
yielded_response = response
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
reverse_proxy.call(env)
|
102
|
-
|
103
|
-
expect(yielded_response).to be_kind_of(described_class::Response)
|
104
|
-
end
|
105
|
-
|
106
|
-
context "when the #on_response callback accepts two arguments" do
|
107
|
-
it "must pass both the request and the response objects" do
|
108
|
-
yielded_request = nil
|
109
|
-
yielded_response = nil
|
110
|
-
|
111
|
-
reverse_proxy = described_class.new do |proxy|
|
112
|
-
proxy.on_response do |request,response|
|
113
|
-
yielded_request = request
|
114
|
-
yielded_response = response
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
reverse_proxy.call(env)
|
119
|
-
|
120
|
-
expect(yielded_request).to be_kind_of(described_class::Request)
|
121
|
-
expect(yielded_response).to be_kind_of(described_class::Response)
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
describe "#connection_for" do
|
128
|
-
let(:host) { 'example.com' }
|
129
|
-
let(:port) { 443 }
|
130
|
-
let(:ssl) { true }
|
131
|
-
|
132
|
-
context "when there is no connection for the host/port/ssl combination" do
|
133
|
-
it "must return a new Ronin::Support::Network::HTTP instance for the host/port/ssl combination" do
|
134
|
-
http = subject.connection_for(host,port,ssl: ssl)
|
135
|
-
|
136
|
-
expect(http).to be_kind_of(Ronin::Support::Network::HTTP)
|
137
|
-
expect(http.host).to eq(host)
|
138
|
-
expect(http.port).to eq(port)
|
139
|
-
expect(http.ssl?).to eq(ssl)
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
context "when there is an existing connection for the host/port/ssl combination" do
|
144
|
-
it "must return the existing Ronin::Support::Network::HTTP instance for the host/port/ssl combination" do
|
145
|
-
expect(subject.connection_for(host,port,ssl: ssl)).to be(
|
146
|
-
subject.connection_for(host,port,ssl: ssl)
|
147
|
-
)
|
148
|
-
end
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
describe "#reverse_proxy" do
|
153
|
-
let(:request_method) { 'GET' }
|
154
|
-
let(:path) { '/' }
|
155
|
-
let(:port) { 80 }
|
156
|
-
let(:host) { 'example.com' }
|
157
|
-
let(:body) { '' }
|
158
|
-
let(:env) do
|
159
|
-
{
|
160
|
-
'REQUEST_METHOD' => request_method,
|
161
|
-
'REQUEST_PATH' => path,
|
162
|
-
'PATH_INFO' => path,
|
163
|
-
'HTTP_HOST' => host,
|
164
|
-
'SERVER_PORT' => port,
|
165
|
-
'rack.input' => StringIO.new(body)
|
166
|
-
}
|
167
|
-
end
|
168
|
-
let(:request) { described_class::Request.new(env) }
|
169
|
-
|
170
|
-
let(:http_request_method) { request_method.downcase.to_sym }
|
171
|
-
let(:http_request_uri) do
|
172
|
-
URI::HTTP.build(host: host, port: port, path: path)
|
173
|
-
end
|
174
|
-
|
175
|
-
let(:http_response_status) { 200 }
|
176
|
-
let(:http_response_headers) do
|
177
|
-
{'X-Foo' => 'bar'}
|
178
|
-
end
|
179
|
-
let(:http_response_body) { nil }
|
180
|
-
|
181
|
-
before do
|
182
|
-
stub_request(:get,http_request_uri).to_return(
|
183
|
-
status: http_response_status,
|
184
|
-
headers: http_response_headers,
|
185
|
-
body: http_response_body
|
186
|
-
)
|
187
|
-
end
|
188
|
-
|
189
|
-
it "must return a #{described_class::Response} object" do
|
190
|
-
expect(subject.reverse_proxy(request)).to be_kind_of(described_class::Response)
|
191
|
-
end
|
192
|
-
|
193
|
-
it "must make an HTTP request for the requested Host header and path" do
|
194
|
-
subject.reverse_proxy(request)
|
195
|
-
|
196
|
-
expect(WebMock).to have_requested(http_request_method,http_request_uri)
|
197
|
-
end
|
198
|
-
|
199
|
-
it "must return all HTTP response headers in the respones object" do
|
200
|
-
response = subject.reverse_proxy(request)
|
201
|
-
|
202
|
-
expect(response.headers).to include(http_response_headers)
|
203
|
-
end
|
204
|
-
|
205
|
-
it "must default the response body to an empty String" do
|
206
|
-
response = subject.reverse_proxy(request)
|
207
|
-
|
208
|
-
expect(response.body).to eq([''])
|
209
|
-
end
|
210
|
-
|
211
|
-
context "when the response contains the 'Transfer-Encoding' header" do
|
212
|
-
let(:http_response_headers) do
|
213
|
-
{'Transfer-Encoding' => 'chunked'}
|
214
|
-
end
|
215
|
-
|
216
|
-
it "must omit the 'Transfer-Encoding' header from the response" do
|
217
|
-
response = subject.reverse_proxy(request)
|
218
|
-
|
219
|
-
expect(response.headers).to_not have_key('Transfer-Encoding')
|
220
|
-
end
|
221
|
-
end
|
222
|
-
end
|
223
|
-
end
|