Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set scheme when using ENV to enable SSL #155

Merged
merged 5 commits into from
May 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should go with "true" and "false" here instead of on and off? What do you think @neilang? /cc @junaruga

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My memory is a little vague around the details of this change. My guess is that this follows an already defined convention when testing with SSL. Ideally you could support both versions e.g. %w(on true).include?(env["HTTPS"]). However I would delegate that decision to the maintainers, there is probably good reason for using "on" that I'm not aware of.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, if we have used "on" previously I'm fine with that. Thanks for the input @neilang


@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