From 1e6067f54cc710ef0b630cc27b16a61c7be08ae1 Mon Sep 17 00:00:00 2001 From: Sven Fuchs Date: Wed, 27 Feb 2013 01:35:53 +0100 Subject: [PATCH] cookies are split by ; --- lib/travis/web/app/alt_versions.rb | 16 +++++----------- spec/app_spec.rb | 4 ++-- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/lib/travis/web/app/alt_versions.rb b/lib/travis/web/app/alt_versions.rb index f59e3c53..8d17fdc2 100644 --- a/lib/travis/web/app/alt_versions.rb +++ b/lib/travis/web/app/alt_versions.rb @@ -9,27 +9,21 @@ class Travis::Web::App::AltVersions alt = alt_from_params(env) || alt_from_cookie(env) env['travis.alt'] = alt if alt status, headers, body = app.call(env) - set_cookie(headers, alt) if alt + headers['Set-Cookie'] = cookie(alt) if alt [status, headers, body] end private - def set_cookie(headers, alt) - cookie = "alt=#{alt}; path=/; max-age=#{alt == 'default' ? 0 : 86400}" - puts "setting cookie #{cookie}" - headers['Set-Cookie'] = cookie + def cookie(alt) + "alt=#{alt}; path=/; max-age=#{alt == 'default' ? 0 : 86400}" end def alt_from_params(env) - alt_from_string env['QUERY_STRING'] + $1 if env['QUERY_STRING'] =~ /alt=([^&]*)/ end def alt_from_cookie(env) - alt_from_string env['HTTP_COOKIE'] - end - - def alt_from_string(string) - $1 if string =~ /alt=([^&]*)/ + $1 if env['HTTP_COOKIE'] =~ /alt=([^;]*)/ end end diff --git a/spec/app_spec.rb b/spec/app_spec.rb index acef4049..919578da 100644 --- a/spec/app_spec.rb +++ b/spec/app_spec.rb @@ -42,12 +42,12 @@ describe Travis::Web::App do example { last_response.should be_ok } example { last_response.body.should include('/assets/foo/styles/app.css') } example { last_response.body.should include('/assets/foo/scripts/app.js') } - example { headers['Set-Cookie'].should == 'alt=foo; Domain=travis-ci.org; Secure; Max-Age=86400' } + example { headers['Set-Cookie'].should == 'alt=foo; path=/; max-age=86400' } end context 'passing default as an alt param' do before { get('/?alt=default') } - example { headers['Set-Cookie'].should == 'alt=default; Domain=travis-ci.org; Secure; Max-Age=0' } + example { headers['Set-Cookie'].should == 'alt=default; path=/; max-age=0' } end end end