Skip to content

Commit de78021

Browse files
Add test for OPTIONS * handling.
1 parent c263672 commit de78021

File tree

8 files changed

+83
-29
lines changed

8 files changed

+83
-29
lines changed

gems/passenger-v6-rack-v2.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@
1313

1414
# export RACK_CONFORM_SERVER="passenger start"
1515
# export RACK_CONFORM_ENDPOINT="http://127.0.0.1:3000"
16+
17+
::RACK_CONFORM_BROKEN = [:options_star]

gems/webrick-rack-v2.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@
77

88
gem "rack", "~> 2.0"
99
gem "webrick"
10+
11+
::RACK_CONFORM_BROKEN = [:options_star]

gems/webrick-rack-v3.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
eval_gemfile "../gems.rb"
77

8-
gem "rack", "~> 3.0.1"
8+
gem "rack", "~> 3.2"
99
gem "webrick"
1010
gem "rackup"
11+
12+
# export RACK_CONFORM_SERVER="rackup -s webrick"
13+
# export RACK_CONFORM_ENDPOINT="http://127.0.0.1:9292"

lib/rack/conform.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,15 @@
55

66
require_relative "conform/version"
77
require_relative "conform/application"
8+
9+
module Rack
10+
module Conform
11+
def self.broken?(feature)
12+
if defined?(::RACK_CONFORM_BROKEN)
13+
::RACK_CONFORM_BROKEN.include?(feature)
14+
else
15+
false
16+
end
17+
end
18+
end
19+
end

lib/rack/conform/application.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def test_middleware_body_itself(env)
114114
Middleware::BodyItself.new(self).call(env)
115115
end
116116

117-
def test_options_star(env)
117+
def test_options(env)
118118
request_method = env["REQUEST_METHOD"]
119119
path_info = env["PATH_INFO"]
120120

@@ -129,7 +129,7 @@ def test_method_for(env)
129129

130130
# Special case for OPTIONS * request:
131131
if request_method == "OPTIONS"
132-
return :test_options_star
132+
return :test_options
133133
end
134134

135135
parts = path_info.split("/")

readme.md

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@ Rack has pretty decent support for validating applications do the right thing us
1414

1515
### Servers Tested
1616

17-
- Falcon (Rack 2 & 3)
18-
- Puma (Rack 2)
19-
- Passenger (Rack 2)
20-
- Unicorn (Rack 2)
21-
- Thin (Rack 2)
17+
| Server | Rack 2 | Rack 3 | Broken Features |
18+
|-----------|:------:|:------:|-------------------------|
19+
| Falcon ||| |
20+
| Pitchfork || | |
21+
| Passenger || | `options_star` |
22+
| Puma ||| |
23+
| Thin || | |
24+
| Unicorn || | |
25+
| Webrick ||| `options_star` (Rack 2) |
2226

2327
## Usage
2428

@@ -66,6 +70,17 @@ export RACK_CONFORM_ENDPOINT="http://localhost:9292"
6670
bundle exec sus
6771
```
6872

73+
### Passenger
74+
75+
``` bash
76+
export BUNDLE_GEMFILE="gems/passenger-v6-rack-v2.rb"
77+
bundle install
78+
passenger start # Install passenger and then exit.
79+
export RACK_CONFORM_SERVER="passenger start"
80+
export RACK_CONFORM_ENDPOINT="http://127.0.0.1:3000"
81+
bundle exec sus
82+
```
83+
6984
### Starting A Server
7085

7186
You can also start a server running the conform application for independent testing (e.g. using `curl`).

test/rack/conform/options.rb

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# frozen_string_literal: true
2+
3+
# Released under the MIT License.
4+
# Copyright, 2024, by Samuel Williams.
5+
6+
require "rack/conform"
7+
8+
require "client_context"
9+
include ClientContext
10+
11+
require "protocol/http/request"
12+
13+
it "can handle OPTIONS / request" do
14+
request = Protocol::HTTP::Request.new(
15+
endpoint.scheme, endpoint.authority, "OPTIONS", "/", nil, Protocol::HTTP::Headers.new, nil
16+
)
17+
18+
response = client.call(request)
19+
expect(response.status).to be == 200
20+
expect(response.read).to be == "OPTIONS /"
21+
ensure
22+
response&.finish
23+
end
24+
25+
it "can handle OPTIONS * request" do
26+
skip("Unsuppported by server!") if ::Rack::Conform.broken?(:options_star)
27+
28+
request = Protocol::HTTP::Request.new(
29+
endpoint.scheme, endpoint.authority, "OPTIONS", "*", nil, Protocol::HTTP::Headers.new, nil
30+
)
31+
32+
response = client.call(request)
33+
expect(response.status).to be == 200
34+
if ::Rack::RELEASE > "3.2"
35+
expect(response.read).to be == "OPTIONS *"
36+
else
37+
expect(response.read).to be(:start_with?, "OPTIONS")
38+
end
39+
ensure
40+
response&.finish
41+
end

test/rack/conform/options_star.rb

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)