ronin-web-server 0.1.0.beta1 → 0.1.0.beta3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b03a351e55978cace7f0c7685913b2eb69f76043d959f25fa221ac5e30fc7737
4
- data.tar.gz: f1de79f2bb53bd318ad517fc44eb36352b73532de58c32653d4da70c01832d4a
3
+ metadata.gz: 3c32a0fe8db0a81c16ca23b030e40e9b7037be55aa9ecbcaccf7d3f89f2cfae6
4
+ data.tar.gz: 6c1fe701cada3c42cf79fad64c89bec28d976895e2cfdc38cc354aea430aabbd
5
5
  SHA512:
6
- metadata.gz: 310070fa76735edb7f01daf99185a8a384aff900e05bd92d9290a35285e7379e18e70ad86130090e383bae21d18888b47ecdd4a6296b976f62c59288dffb8fd1
7
- data.tar.gz: 07dd136fa10a1fa6971b4fae96c3cf56f19e0a65a8cbc13f2a246d358e7f3642f0cdf0271251b0252e4e28147c3ac4e6c982c1c3d9a46be57778fbee291241c2
6
+ metadata.gz: 7828f35bb04b7929d2d27af05149146d7812767724793850371115e163383b561a153b9ff9818954e998e44049d96f9e1bf6ba250351aa3b94e65ff75a4e226b
7
+ data.tar.gz: 3265c6b0f4f5c9d0f8c72ac55013a7bedca3e4559822af63390642b90b8964d9e5fa334863fee7efa321b022602ae4d2c6e49d1bf2cdda98a330115f001984d4
data/.yardopts CHANGED
@@ -1 +1 @@
1
- --markup markdown --title 'ronin-web-server Documentation' --protected
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-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
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://rubydoc.info/gems/ronin-web-server
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/master/ChangeLog.md
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"
@@ -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-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
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-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
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(handler,self,&runner)
170
+ Thread.new(options) { |options| super(options) }
188
171
  else
189
- runner.call(handler,self)
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-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
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-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
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-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
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-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
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-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
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-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
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-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
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
@@ -110,8 +110,8 @@ module Ronin
110
110
  # @param [Hash{String => Object}] env
111
111
  # The rack request env Hash.
112
112
  #
113
- # @return [ReverseProxy::Response]
114
- # The rack response.
113
+ # @return [(Integer, Hash{String => String}, Array<String>)]
114
+ # The rack response tuple (status, headers, body).
115
115
  #
116
116
  def call(env)
117
117
  request = Request.new(env)
@@ -127,7 +127,7 @@ module Ronin
127
127
  end
128
128
  end
129
129
 
130
- return response
130
+ return [response.status, response.headers, response.body]
131
131
  end
132
132
 
133
133
  #
@@ -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-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
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-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
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.beta1'
25
+ VERSION = '0.1.0.beta3'
26
26
  end
27
27
  end
28
28
  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-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
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
@@ -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.beta1
4
+ version: 0.1.0.beta3
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-01 00:00:00.000000000 Z
11
+ date: 2023-01-14 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://rubydoc.info/gems/ronin-web-server
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/master/ChangeLog.md
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.
@@ -1,13 +0,0 @@
1
- require 'ronin/web/server/base'
2
-
3
- class SubApp < Ronin::Web::Server::Base
4
-
5
- get '/hello' do
6
- 'SubApp greets you'
7
- end
8
-
9
- get '/' do
10
- 'SubApp'
11
- end
12
-
13
- end
@@ -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
@@ -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
@@ -1,8 +0,0 @@
1
- require 'spec_helper'
2
- require 'ronin/web/server/response'
3
-
4
- describe Ronin::Web::Server::Response do
5
- it "must provide the same methods as Sinatra::Response" do
6
- expect(described_class).to be < Sinatra::Response
7
- end
8
- end
@@ -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
@@ -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
data/spec/spec_helper.rb DELETED
@@ -1,9 +0,0 @@
1
- require 'rspec'
2
- require 'simplecov'
3
- require 'ronin/web/server/version'
4
-
5
- SimpleCov.start
6
-
7
- RSpec.configure do |c|
8
- c.include Ronin::Web::Server
9
- end