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

Allow session cookie handling to work with localhost #67

Merged
merged 2 commits into from
Nov 9, 2018
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
14 changes: 4 additions & 10 deletions app/models/test_track/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,8 @@ def cookie_domain
end

def _cookie_domain
if bare_ip_address?
if bare_ip_address? || fully_qualified_cookie_domain_enabled?
request.host
elsif fully_qualified_cookie_domain_enabled?
fully_qualified_domain
else
wildcard_domain
end
Expand All @@ -108,16 +106,12 @@ def bare_ip_address?
request.host.match(Resolv::AddressRegex)
end

def fully_qualified_domain
public_suffix_host.name
end

def wildcard_domain
"." + public_suffix_host.domain
"." + (public_suffix_domain || request.host)
end

def public_suffix_host
@public_suffix_host ||= PublicSuffix.parse(request.host, default_rule: nil)
def public_suffix_domain
@public_suffix_domain ||= PublicSuffix.domain(request.host, default_rule: nil)
end

def manage_cookies!
Expand Down
2 changes: 1 addition & 1 deletion lib/test_track_rails_client/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module TestTrackRailsClient
VERSION = "4.0.0.alpha13" # rubocop:disable Style/MutableConstant
VERSION = "4.0.0.alpha14" # rubocop:disable Style/MutableConstant
end
14 changes: 4 additions & 10 deletions spec/models/test_track/session_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -235,16 +235,10 @@ def current_clown; end
end
end

it "checks for a valid domain" do
allow(request).to receive(:host).and_return("a.bad.actor;did-this<luzer>")
expect { subject.manage {} }.to raise_error PublicSuffix::DomainInvalid
end

it "checks for a valid domain when fully qualified cookie domains are enabled" do
with_env TEST_TRACK_FULLY_QUALIFIED_COOKIE_DOMAIN_ENABLED: 1 do
allow(request).to receive(:host).and_return("a.bad.actor;did-this<luzer>")
expect { subject.manage {} }.to raise_error PublicSuffix::DomainInvalid
end
it "works with localhost" do
allow(request).to receive(:host).and_return("localhost")
subject.manage {}
expect(cookies['tt_visitor_id'][:domain]).to eq ".localhost"
end

it "doesn't munge an IPv4 hostname" do
Expand Down