From bc4092ad4dc1b94b6de1bf7c386cd170355a1e6a Mon Sep 17 00:00:00 2001 From: Sven Fuchs Date: Mon, 25 Feb 2013 17:42:03 +0100 Subject: [PATCH 01/17] simplify app creation and rename "custom_branch" to "alt" --- config.ru | 2 +- lib/travis/web/app.rb | 173 +++++++++++++++++++++--------------------- spec/app_spec.rb | 30 ++++---- 3 files changed, 103 insertions(+), 102 deletions(-) diff --git a/config.ru b/config.ru index 4e95b1d7..f3272ca3 100644 --- a/config.ru +++ b/config.ru @@ -25,7 +25,7 @@ use Travis::Web::ApiRedirect do |app| app.settings.api_endpoint = ENV['API_ENDPOINT'] if ENV['API_ENDPOINT'] end -run Travis::Web::App.new( +run Travis::Web::App.build( environment: ENV['RACK_ENV'] || 'development', api_endpoint: ENV['API_ENDPOINT'], pusher_key: ENV['PUSHER_KEY'], diff --git a/lib/travis/web/app.rb b/lib/travis/web/app.rb index da5f475b..6ec4f3df 100644 --- a/lib/travis/web/app.rb +++ b/lib/travis/web/app.rb @@ -8,6 +8,8 @@ require 'time' class Travis::Web::App autoload :MobileRedirect, 'travis/web/app/mobile_redirect' + S3_URL = 'https://s3.amazonaws.com/travis-web-production/assets' + # Simple Rack router that behaves like a hash. # Key is the path, value the response. class Router < DelegateClass(Hash) @@ -18,90 +20,110 @@ class Travis::Web::App end def call(env) - if main_app.custom_branch?(env) - main_app.response_for_custom_branch(env) - else - self[env['PATH_INFO']] - end + self[env['PATH_INFO']] end end - def self.new(options = {}) - return super unless options[:environment] == 'development' - proc { |e| super.call(e) } # poor man's reloader + class AltVersions + attr_reader :app + + def initialize(app) + @app = app + end + + def call(env) + alt = alt_from(env) + env['travis.alt'] = alt if alt + status, headers, body = app.call(env) + set_cookies(headers, env['travis.alt']) if env.key?('travis.alt') + [status, headers, body] + end + + def set_cookies(headers, alt) + headers['Set-Cookie'] = "alt=#{alt}; Max-Age=#{alt == 'default' ? 0 : 86400}" + end + + def alt_from(env) + alt_from_params(env) || alt_from_cookie(env) + end + + def alt_from_params(env) + alt_from_string env['QUERY_STRING'] + end + + def alt_from_cookie(env) + alt_from_string env['HTTP_COOKIE'] + end + + def alt_from_string(string) + $1 if string =~ /alt=([^&]*)/ + end end - attr_reader :app, :router, :environment, :version, :last_modified, :age, :options, :root + class << self + def new(options = {}) + return super unless options[:environment] == 'development' + proc { |e| super.call(e) } # poor man's reloader + end + + def build(options = {}) + builder = Rack::Builder.new + if options.fetch(:environment) == 'production' + builder.use Rack::SSL + builder.use Rack::Cache + end + builder.use Rack::Deflater + builder.use Rack::Head + builder.use Rack::Protection::XSSHeader + builder.use Rack::Protection::FrameOptions + builder.use Rack::Protection::PathTraversal + builder.use Rack::ConditionalGet + builder.use Travis::Web::App::AltVersions + builder.run new(options) + builder.to_app + end + end + + attr_reader :routers, :environment, :version, :last_modified, :age, :options, :root def initialize(options = {}) @options = options @environment = options.fetch(:environment) @root = options.fetch(:root) - @router = Router.new(self) - @app = builder.to_app @version = File.read File.expand_path('version', root) @last_modified = Time.now @age = 60 * 60 * 24 * 365 - load_routes + @routers = { default: create_router } end def call(env) - app.call(env) - end - - def response_for_custom_branch(env) - status, headers, body = response_for File.join(root, 'index.html'), custom_branch: custom_branch(env) - response = Rack::Response.new body, status, headers - - if disable_custom_branch?(env) - response.delete_cookie 'custom_branch' - elsif custom_branch_from_params(env) - response.set_cookie 'custom_branch', value: custom_branch_from_params(env), expires: Time.now + 31536000 - end - - response.finish - end - - def custom_branch?(env) - custom_branch(env) || disable_custom_branch?(env) + name = env['travis.alt'] || :default + routers[name] ||= create_router(alt: name) + routers[name].call(env) end private - def disable_custom_branch?(env) - env['QUERY_STRING'] =~ /disable[_-]custom[_-]branch/ + def create_router(options = {}) + router = Router.new(self) + load_routes(router, options) + router end - def custom_branch_from_params(env) - branch = custom_branch_from_string env['QUERY_STRING'] - end - - def custom_branch_from_cookie(env) - custom_branch_from_string env['HTTP_COOKIE'] - end - - def custom_branch_from_string(string) - $1 if string =~ /(? content.bytesize.to_s, - 'Content-Location' => route_for(file), + 'Content-Location' => path_for(file), 'Cache-Control' => cache_control(file), - 'Content-Location' => route_for(file), + 'Content-Location' => path_for(file), 'Content-Type' => mime_type(file), 'ETag' => version, 'Last-Modified' => last_modified.httpdate, @@ -109,7 +131,7 @@ class Travis::Web::App 'Vary' => vary_for(file) } - [ 200, headers, [ content ] ] + [ 200, headers, [content] ] end def each_file @@ -126,18 +148,11 @@ class Travis::Web::App end def index?(file) - file.end_with? 'index.html' - end - - def route_for(file) - file = file.sub("#{root}/", '') - file = File.join(version, file) if prefix? file - file = "" if index? file - "/#{file}" + file.end_with?('index.html') end def cache_control(file) - case route_for(file) + case path_for(file) when '/' then "public, must-revalidate" when '/version' then "no-cache" else "public, max-age=#{age}" @@ -145,13 +160,20 @@ class Travis::Web::App end def vary_for(file) - case route_for(file) + case path_for(file) when '/' then 'Accept' when '/version' then '*' else '' end end + def path_for(file) + file = file.sub("#{root}/", '') + file = File.join(version, file) if prefix?(file) + file = "" if index?(file) + "/#{file}" + end + def mime_type(file) Rack::Mime.mime_type File.extname(file) end @@ -162,28 +184,7 @@ class Travis::Web::App end string.gsub! %r{(src|href)="(?:\/?)((styles|scripts)\/[^"]*)"} do - if opts[:custom_branch] - url = "https://s3.amazonaws.com/travis-web-production/assets/#{opts[:custom_branch]}/#{$2}" - %(#$1="#{url}") - else - %(#$1="/#{version}/#$2") - end + %(#{$1}=#{opts[:alt] ? "#{S3_URL}/#{opts[:alt]}/#{$2}" : "/#{version}/#{$2}"}) end end - - def builder - builder = Rack::Builder.new - if environment == 'production' - builder.use Rack::SSL - builder.use Rack::Cache - end - builder.use Rack::Deflater - builder.use Rack::Head - builder.use Rack::Protection::XSSHeader - builder.use Rack::Protection::FrameOptions - builder.use Rack::Protection::PathTraversal - builder.use Rack::ConditionalGet - builder.run router - builder - end end diff --git a/spec/app_spec.rb b/spec/app_spec.rb index 584616ba..b50f687a 100644 --- a/spec/app_spec.rb +++ b/spec/app_spec.rb @@ -6,7 +6,7 @@ describe Travis::Web::App do end describe 'catch all' do - before { get('/foo/bar') } + before { get('/foo/bar') } example { last_response.should be_ok } example { headers['Content-Location'].should be == '/' } example { headers['Cache-Control'].should include('must-revalidate') } @@ -15,7 +15,7 @@ describe Travis::Web::App do end describe 'assets' do - before { get('/favicon.ico') } + before { get('/favicon.ico') } example { last_response.should be_ok } example { headers['Content-Location'].should be == '/favicon.ico' } example { headers['Cache-Control'].should_not include('must-revalidate') } @@ -24,30 +24,30 @@ describe Travis::Web::App do end describe 'version' do - before { get('/version') } + before { get('/version') } example { last_response.should be_ok } example { headers['Content-Location'].should be == '/version' } example { headers['Cache-Control'].should be == 'no-cache' } example { headers['Vary'].split(',').should_not include('Accept') } end - describe 'custom branch' do - context 'when passing custom branch as a param' do - before { get('/?custom-branch=foo') } + describe 'alternate asset versions' do + context 'not passing an alt param' do + before { get('/') } + example { headers['Set-Cookie'].should be_nil } + end + + context 'passing an alt param' do + before { get('/?alt=foo') } 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 include('custom_branch=foo') } + example { headers['Set-Cookie'].should == 'alt=foo; Max-Age=86400' } end - context 'disabling custom branch' do - before { get('/?disable-custom-branch=true') } - example { last_response.should be_ok } - example { last_response.body.should =~ %r{src="/[^\/]+/scripts/app.js} } - example { last_response.body.should_not include('/assets/true/styles/app.css') } - example { last_response.body.should_not include('/assets/foo/styles/app.css') } - example { last_response.body.should_not include('/assets/foo/scripts/app.js') } - example { headers['Set-Cookie'].should include('custom_branch=;') } + context 'passing default as an alt param' do + before { get('/?alt=default') } + example { headers['Set-Cookie'].should == 'alt=default; Max-Age=0' } end end end From 941d1391bbb18ee31409fdcfa50d4fee1a31f93e Mon Sep 17 00:00:00 2001 From: Sven Fuchs Date: Tue, 26 Feb 2013 19:05:49 +0100 Subject: [PATCH 02/17] move AltVersions to its own file, try setting domain and secure on the cookie --- lib/travis/web/app.rb | 47 +++--------------------------- lib/travis/web/app/alt_versions.rb | 33 +++++++++++++++++++++ spec/app_spec.rb | 4 +-- 3 files changed, 39 insertions(+), 45 deletions(-) create mode 100644 lib/travis/web/app/alt_versions.rb diff --git a/lib/travis/web/app.rb b/lib/travis/web/app.rb index 6ec4f3df..6812a731 100644 --- a/lib/travis/web/app.rb +++ b/lib/travis/web/app.rb @@ -6,6 +6,7 @@ require 'delegate' require 'time' class Travis::Web::App + autoload :AltVersions, 'travis/web/app/alt_versions' autoload :MobileRedirect, 'travis/web/app/mobile_redirect' S3_URL = 'https://s3.amazonaws.com/travis-web-production/assets' @@ -24,42 +25,6 @@ class Travis::Web::App end end - class AltVersions - attr_reader :app - - def initialize(app) - @app = app - end - - def call(env) - alt = alt_from(env) - env['travis.alt'] = alt if alt - status, headers, body = app.call(env) - set_cookies(headers, env['travis.alt']) if env.key?('travis.alt') - [status, headers, body] - end - - def set_cookies(headers, alt) - headers['Set-Cookie'] = "alt=#{alt}; Max-Age=#{alt == 'default' ? 0 : 86400}" - end - - def alt_from(env) - alt_from_params(env) || alt_from_cookie(env) - end - - def alt_from_params(env) - alt_from_string env['QUERY_STRING'] - end - - def alt_from_cookie(env) - alt_from_string env['HTTP_COOKIE'] - end - - def alt_from_string(string) - $1 if string =~ /alt=([^&]*)/ - end - end - class << self def new(options = {}) return super unless options[:environment] == 'development' @@ -68,7 +33,7 @@ class Travis::Web::App def build(options = {}) builder = Rack::Builder.new - if options.fetch(:environment) == 'production' + if options[:environment] == 'production' builder.use Rack::SSL builder.use Rack::Cache end @@ -84,11 +49,10 @@ class Travis::Web::App end end - attr_reader :routers, :environment, :version, :last_modified, :age, :options, :root + attr_reader :routers, :version, :last_modified, :age, :options, :root def initialize(options = {}) @options = options - @environment = options.fetch(:environment) @root = options.fetch(:root) @version = File.read File.expand_path('version', root) @last_modified = Time.now @@ -118,7 +82,6 @@ class Travis::Web::App def response_for(file, options = {}) content = File.read(file) set_config(content, options) if config_needed?(file) - headers = { 'Content-Length' => content.bytesize.to_s, 'Content-Location' => path_for(file), @@ -130,13 +93,11 @@ class Travis::Web::App 'Expires' => (last_modified + age).httpdate, 'Vary' => vary_for(file) } - [ 200, headers, [content] ] end def each_file - pattern = File.join(root, '**/*') - Dir.glob(pattern) { |f| yield f if File.file? f } + Dir.glob(File.join(root, '**/*')) { |file| yield file if File.file?(file) } end def prefix?(file) diff --git a/lib/travis/web/app/alt_versions.rb b/lib/travis/web/app/alt_versions.rb new file mode 100644 index 00000000..61619f41 --- /dev/null +++ b/lib/travis/web/app/alt_versions.rb @@ -0,0 +1,33 @@ +class Travis::Web::App::AltVersions + attr_reader :app + + def initialize(app) + @app = app + end + + def call(env) + alt = alt_from_params(env) || alt_from_cookie(env) + env['travis.alt'] = alt if alt + status, headers, body = app.call(env) + headers['Set-Cookie'] = cookie(alt) if env.key?('travis.alt') + [status, headers, body] + end + + private + + def cookie(alt) + "alt=#{alt}; Domain=travis-ci.org; Secure; Max-Age=#{alt == 'default' ? 0 : 86400}" + end + + def alt_from_params(env) + alt_from_string env['QUERY_STRING'] + end + + def alt_from_cookie(env) + alt_from_string env['HTTP_COOKIE'] + end + + def alt_from_string(string) + $1 if string =~ /alt=([^&]*)/ + end +end diff --git a/spec/app_spec.rb b/spec/app_spec.rb index b50f687a..acef4049 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; Max-Age=86400' } + example { headers['Set-Cookie'].should == 'alt=foo; Domain=travis-ci.org; Secure; Max-Age=86400' } end context 'passing default as an alt param' do before { get('/?alt=default') } - example { headers['Set-Cookie'].should == 'alt=default; Max-Age=0' } + example { headers['Set-Cookie'].should == 'alt=default; Domain=travis-ci.org; Secure; Max-Age=0' } end end end From d686b741bf8a5ce0cc926b3f360b77fd5abc8867 Mon Sep 17 00:00:00 2001 From: Sven Fuchs Date: Tue, 26 Feb 2013 19:12:37 +0100 Subject: [PATCH 03/17] try using the staging domain --- lib/travis/web/app/alt_versions.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/travis/web/app/alt_versions.rb b/lib/travis/web/app/alt_versions.rb index 61619f41..a3ad2b87 100644 --- a/lib/travis/web/app/alt_versions.rb +++ b/lib/travis/web/app/alt_versions.rb @@ -16,7 +16,7 @@ class Travis::Web::App::AltVersions private def cookie(alt) - "alt=#{alt}; Domain=travis-ci.org; Secure; Max-Age=#{alt == 'default' ? 0 : 86400}" + "alt=#{alt}; Domain=staging.travis-ci.org; Secure; Max-Age=#{alt == 'default' ? 0 : 86400}" end def alt_from_params(env) From 5c18bd3406084c43aa6fa36ad82803093394a8bf Mon Sep 17 00:00:00 2001 From: Sven Fuchs Date: Tue, 26 Feb 2013 20:09:47 +0100 Subject: [PATCH 04/17] try using path for the cookie --- lib/travis/web/app/alt_versions.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/travis/web/app/alt_versions.rb b/lib/travis/web/app/alt_versions.rb index a3ad2b87..14cdcd9b 100644 --- a/lib/travis/web/app/alt_versions.rb +++ b/lib/travis/web/app/alt_versions.rb @@ -9,16 +9,12 @@ 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) - headers['Set-Cookie'] = cookie(alt) if env.key?('travis.alt') + headers['Set-Cookie'] = "alt=#{alt}; path=/; Secure" if alt [status, headers, body] end private - def cookie(alt) - "alt=#{alt}; Domain=staging.travis-ci.org; Secure; Max-Age=#{alt == 'default' ? 0 : 86400}" - end - def alt_from_params(env) alt_from_string env['QUERY_STRING'] end From c5aaa8806a16314eaac9970a6d58d562b2c27cee Mon Sep 17 00:00:00 2001 From: Sven Fuchs Date: Tue, 26 Feb 2013 22:55:00 +0100 Subject: [PATCH 05/17] uppercase Path --- lib/travis/web/app/alt_versions.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/travis/web/app/alt_versions.rb b/lib/travis/web/app/alt_versions.rb index 14cdcd9b..119d14fb 100644 --- a/lib/travis/web/app/alt_versions.rb +++ b/lib/travis/web/app/alt_versions.rb @@ -9,7 +9,7 @@ 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) - headers['Set-Cookie'] = "alt=#{alt}; path=/; Secure" if alt + headers['Set-Cookie'] = "alt=#{alt}; Path=/; Secure" if alt [status, headers, body] end From b314670530ee040d02c706824faf8b3a1925a2ef Mon Sep 17 00:00:00 2001 From: Sven Fuchs Date: Tue, 26 Feb 2013 23:00:17 +0100 Subject: [PATCH 06/17] debug output --- lib/travis/web/app/alt_versions.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/travis/web/app/alt_versions.rb b/lib/travis/web/app/alt_versions.rb index 119d14fb..5cb934b8 100644 --- a/lib/travis/web/app/alt_versions.rb +++ b/lib/travis/web/app/alt_versions.rb @@ -9,12 +9,18 @@ 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) - headers['Set-Cookie'] = "alt=#{alt}; Path=/; Secure" if alt + set_cookie(headers, alt) if alt [status, headers, body] end private + def set_cookie(headers, alt) + cookie = "alt=#{alt}; Path=/; Secure" + puts "setting cookie #{cookie}" + headers['Set-Cookie'] = cookie + end + def alt_from_params(env) alt_from_string env['QUERY_STRING'] end From 9bda77e757d6688c4977e310eb0171c5a2e64a0c Mon Sep 17 00:00:00 2001 From: Sven Fuchs Date: Tue, 26 Feb 2013 23:07:09 +0100 Subject: [PATCH 07/17] try removing Secure from the cookie --- lib/travis/web/app/alt_versions.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/travis/web/app/alt_versions.rb b/lib/travis/web/app/alt_versions.rb index 5cb934b8..6d16a23c 100644 --- a/lib/travis/web/app/alt_versions.rb +++ b/lib/travis/web/app/alt_versions.rb @@ -16,7 +16,7 @@ class Travis::Web::App::AltVersions private def set_cookie(headers, alt) - cookie = "alt=#{alt}; Path=/; Secure" + cookie = "alt=#{alt}; path=/" puts "setting cookie #{cookie}" headers['Set-Cookie'] = cookie end From 47765ba8c03c827685137e77ff72857cdcbfc335 Mon Sep 17 00:00:00 2001 From: Sven Fuchs Date: Tue, 26 Feb 2013 23:11:40 +0100 Subject: [PATCH 08/17] try disabling rack/cache --- lib/travis/web/app.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/travis/web/app.rb b/lib/travis/web/app.rb index 6812a731..d459eee3 100644 --- a/lib/travis/web/app.rb +++ b/lib/travis/web/app.rb @@ -35,7 +35,7 @@ class Travis::Web::App builder = Rack::Builder.new if options[:environment] == 'production' builder.use Rack::SSL - builder.use Rack::Cache + # builder.use Rack::Cache end builder.use Rack::Deflater builder.use Rack::Head From 5ae74ddcdc5cac09ea55a1eb8d8a7070dc5fdb70 Mon Sep 17 00:00:00 2001 From: Sven Fuchs Date: Tue, 26 Feb 2013 23:39:03 +0100 Subject: [PATCH 09/17] defer calling things until the document is ready --- public/index.html | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/public/index.html b/public/index.html index fb4970ef..afa54710 100644 --- a/public/index.html +++ b/public/index.html @@ -15,8 +15,10 @@ From b93ce53a7ff701389471ad8f75129cf578863439 Mon Sep 17 00:00:00 2001 From: Sven Fuchs Date: Tue, 26 Feb 2013 23:55:49 +0100 Subject: [PATCH 10/17] restore cookie max_age --- lib/travis/web/app/alt_versions.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/travis/web/app/alt_versions.rb b/lib/travis/web/app/alt_versions.rb index 6d16a23c..f59e3c53 100644 --- a/lib/travis/web/app/alt_versions.rb +++ b/lib/travis/web/app/alt_versions.rb @@ -16,7 +16,7 @@ class Travis::Web::App::AltVersions private def set_cookie(headers, alt) - cookie = "alt=#{alt}; path=/" + cookie = "alt=#{alt}; path=/; max-age=#{alt == 'default' ? 0 : 86400}" puts "setting cookie #{cookie}" headers['Set-Cookie'] = cookie end From 24a38d03e0eb345b27632e9c4fee675478fabbbd Mon Sep 17 00:00:00 2001 From: Sven Fuchs Date: Wed, 27 Feb 2013 00:04:09 +0100 Subject: [PATCH 11/17] Revert "defer calling things until the document is ready" This reverts commit 5ae74ddcdc5cac09ea55a1eb8d8a7070dc5fdb70. --- public/index.html | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/public/index.html b/public/index.html index afa54710..fb4970ef 100644 --- a/public/index.html +++ b/public/index.html @@ -15,10 +15,8 @@ From 1fd16ef55544934b2f379a0273274b5b1a5e0092 Mon Sep 17 00:00:00 2001 From: Sven Fuchs Date: Wed, 27 Feb 2013 00:29:42 +0100 Subject: [PATCH 12/17] rename bootstrapTravis to Travis.run --- assets/scripts/travis.coffee | 6 +++--- public/index.html | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/assets/scripts/travis.coffee b/assets/scripts/travis.coffee index 4b50002e..912b79a8 100644 --- a/assets/scripts/travis.coffee +++ b/assets/scripts/travis.coffee @@ -1,9 +1,6 @@ require 'ext/jquery' require 'ext/ember/namespace' -window.bootstrapTravis = -> - Travis.run() - if window.history.state == undefined window.history.state = {} oldPushState = window.history.pushState @@ -33,6 +30,9 @@ Storage = Em.Object.extend @Travis = Em.Namespace.create Ember.Evented, + run: -> + Travis.run() + config: api_endpoint: $('meta[rel="travis.api_endpoint"]').attr('href') pusher_key: $('meta[name="travis.pusher_key"]').attr('value') diff --git a/public/index.html b/public/index.html index 614e591f..fb4970ef 100644 --- a/public/index.html +++ b/public/index.html @@ -16,7 +16,7 @@ From 1e6067f54cc710ef0b630cc27b16a61c7be08ae1 Mon Sep 17 00:00:00 2001 From: Sven Fuchs Date: Wed, 27 Feb 2013 01:35:53 +0100 Subject: [PATCH 13/17] 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 From 4bdd1834c425004026d80810f2d66dea71332238 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Tue, 5 Mar 2013 21:08:14 +0100 Subject: [PATCH 14/17] Fix passing alt=default param --- lib/travis/web/app/alt_versions.rb | 8 ++++---- spec/app_spec.rb | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/travis/web/app/alt_versions.rb b/lib/travis/web/app/alt_versions.rb index 8d17fdc2..7a3671c7 100644 --- a/lib/travis/web/app/alt_versions.rb +++ b/lib/travis/web/app/alt_versions.rb @@ -7,7 +7,7 @@ class Travis::Web::App::AltVersions def call(env) alt = alt_from_params(env) || alt_from_cookie(env) - env['travis.alt'] = alt if alt + env['travis.alt'] = alt if alt && alt != 'default' status, headers, body = app.call(env) headers['Set-Cookie'] = cookie(alt) if alt [status, headers, body] @@ -16,14 +16,14 @@ class Travis::Web::App::AltVersions private def cookie(alt) - "alt=#{alt}; path=/; max-age=#{alt == 'default' ? 0 : 86400}" + "alt=#{alt == 'default' ? '' : alt}; path=/; max-age=#{alt == 'default' ? 0 : 86400}" end def alt_from_params(env) - $1 if env['QUERY_STRING'] =~ /alt=([^&]*)/ + $1 if env['QUERY_STRING'] =~ /alt=([^&]+)/ end def alt_from_cookie(env) - $1 if env['HTTP_COOKIE'] =~ /alt=([^;]*)/ + $1 if env['HTTP_COOKIE'] =~ /alt=([^;]+)/ end end diff --git a/spec/app_spec.rb b/spec/app_spec.rb index 919578da..535367fb 100644 --- a/spec/app_spec.rb +++ b/spec/app_spec.rb @@ -47,7 +47,8 @@ describe Travis::Web::App do context 'passing default as an alt param' do before { get('/?alt=default') } - example { headers['Set-Cookie'].should == 'alt=default; path=/; max-age=0' } + example { last_response.body.should_not =~ /\/assets\/[^\/]+\/scripts\/app.js/ } + example { headers['Set-Cookie'].should == 'alt=; path=/; max-age=0' } end end end From 74b31362146eda42d0b5387e1945f299d848a7ae Mon Sep 17 00:00:00 2001 From: Mathias Meyer Date: Fri, 8 Mar 2013 10:00:01 +0100 Subject: [PATCH 15/17] Add link to status page. --- assets/scripts/app/templates/layouts/top.hbs | 3 +++ locales/en.yml | 1 + 2 files changed, 4 insertions(+) diff --git a/assets/scripts/app/templates/layouts/top.hbs b/assets/scripts/app/templates/layouts/top.hbs index 0c1ec213..755ff988 100644 --- a/assets/scripts/app/templates/layouts/top.hbs +++ b/assets/scripts/app/templates/layouts/top.hbs @@ -15,6 +15,9 @@
  • {{t layouts.top.docs}}
  • +
  • + Status +
  • {{t layouts.top.github_login}} diff --git a/locales/en.yml b/locales/en.yml index d5ef97fd..19b3e348 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -96,6 +96,7 @@ en: sign_out: Sign Out signing_in: Signing In stats: Stats + status: Status locales: ca: de: Deutsch From 46a107e9ffa7115fe15c6eab7f525f03ff207bc7 Mon Sep 17 00:00:00 2001 From: Mathias Meyer Date: Fri, 8 Mar 2013 13:06:20 +0100 Subject: [PATCH 16/17] Use locale. --- assets/scripts/app/templates/layouts/top.hbs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/scripts/app/templates/layouts/top.hbs b/assets/scripts/app/templates/layouts/top.hbs index 755ff988..acb60c26 100644 --- a/assets/scripts/app/templates/layouts/top.hbs +++ b/assets/scripts/app/templates/layouts/top.hbs @@ -16,7 +16,7 @@ {{t layouts.top.docs}}

  • - Status + {{t layouts.top.status}}
  • From df02b714ecc0ebff9057b83cc076551c98f6ba86 Mon Sep 17 00:00:00 2001 From: Josh Kalderimis Date: Sun, 10 Mar 2013 00:07:20 +1300 Subject: [PATCH 17/17] update the Gemfile to use the secure rubygems, and remove the common queue from the sidebar --- Gemfile | 4 ++-- Gemfile.lock | 2 +- assets/scripts/travis.coffee | 1 - 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index 0ecca317..3f09f9f8 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ -ruby '1.9.3' rescue nil +source 'https://rubygems.org' -source :rubygems +ruby '1.9.3' gem 'puma' gem 'rack-ssl', '~> 1.3' diff --git a/Gemfile.lock b/Gemfile.lock index c5de1e09..4209ca80 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -16,7 +16,7 @@ GIT rake-pipeline (~> 0.6) GEM - remote: http://rubygems.org/ + remote: https://rubygems.org/ specs: POpen4 (0.1.4) Platform (>= 0.4.0) diff --git a/assets/scripts/travis.coffee b/assets/scripts/travis.coffee index 912b79a8..21f4d4f0 100644 --- a/assets/scripts/travis.coffee +++ b/assets/scripts/travis.coffee @@ -56,7 +56,6 @@ Storage = Em.Object.extend '#': ['home', 'index'] QUEUES: [ - { name: 'common', display: 'Common' } { name: 'linux', display: 'Linux' } { name: 'mac_osx', display: 'Mac and OSX' } ]