Skip to content

Commit

Permalink
Set scheme when using ENV to enable SSL (#155)
Browse files Browse the repository at this point in the history
* Set scheme if `nil` when using ENV to enable SSL
* Replace should syntax with expect syntax in Rack::Test::Session spec

Thanks to @neilang and @rafaelgonzalez for doing this. (@perlun was merely the person rebasing their work into master)
  • Loading branch information
neilang authored and perlun committed May 12, 2017
1 parent e04384f commit 2b23d2a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/rack/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ def env_for(path, env)
def process_request(uri, env)
uri = URI.parse(uri)
uri.host ||= @default_host
uri.scheme ||= "https" if env["HTTPS"] == "on"

@rack_mock_session.request(uri, env)

Expand Down
10 changes: 10 additions & 0 deletions spec/rack/test/cookie_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,16 @@
expect(rack_mock_session.cookie_jar['secure-cookie']).to eq('set')
end

it "supports secure cookies when enabling SSL via env" do
get "//example.com/cookies/set-secure", { "value" => "set" }, "HTTPS" => "on"
get "//example.com/cookies/show", nil, "HTTPS" => "off"
check expect(last_request.cookies).to eq({})

get "//example.com/cookies/show", nil, "HTTPS" => "on"
expect(last_request.cookies).to eq({ "secure-cookie" => "set" })
expect(rack_mock_session.cookie_jar['secure-cookie']).to eq('set')
end

it "keeps separate cookie jars for different domains" do
get "http://example.com/cookies/set", "value" => "example"
get "http://example.com/cookies/show"
Expand Down

0 comments on commit 2b23d2a

Please sign in to comment.