From d5d57127d93d1c12a2605256aac7c5af30934e79 Mon Sep 17 00:00:00 2001 From: GbArc Date: Mon, 8 Jul 2024 11:46:16 +0200 Subject: [PATCH 1/3] setting tci domain cookie --- app/routes/index.js | 4 ++++ app/services/auth.js | 2 ++ waiter/lib/travis/web/app.rb | 11 +++++++++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/app/routes/index.js b/app/routes/index.js index b7e3691c29..2960a079bb 100644 --- a/app/routes/index.js +++ b/app/routes/index.js @@ -17,6 +17,10 @@ export default Route.extend({ if (!this.auth.signedIn && config.environment !== 'test' && pro && redirect) { window.location.replace('https://www.travis-ci.com'); } + + if (this.auth.signedIn) { + document.cookie = 'travis_auth=true'; + } }, redirect() { diff --git a/app/services/auth.js b/app/services/auth.js index 393456f7ec..dbf2be6ebe 100644 --- a/app/services/auth.js +++ b/app/services/auth.js @@ -115,6 +115,8 @@ export default Service.extend({ signOut(runTeardown = true) { if (this.signedIn) this.api.get('/logout'); + document.cookie = 'travis_auth=false'; + [this.localStorage, this.sessionStorage].forEach(storage => { storage.clearPreferencesData(); }); diff --git a/waiter/lib/travis/web/app.rb b/waiter/lib/travis/web/app.rb index 562d5f0bc0..3faf9516c4 100644 --- a/waiter/lib/travis/web/app.rb +++ b/waiter/lib/travis/web/app.rb @@ -5,6 +5,7 @@ require 'rack/protection' require 'delegate' require 'time' +require 'date' require 'json' require 'travis/utils/deep_merge' require 'digest/md5' @@ -63,12 +64,12 @@ def initialize(options = {}) @server_start = options.fetch(:server_start) @root = options.fetch(:root) @age = 60 * 60 * 24 * 365 - @routers = { default: create_router } + @routers = { }#default: create_router } end def call(env) name = env['travis.alt'] || :default - routers[name] ||= create_router(alt: name) + routers[name] ||= create_router(alt: name, env: env) route = routers[name].call(env) route[1]['Date'] = Time.now.httpdate route @@ -114,6 +115,12 @@ def response_for(file, options = {}) } end + env = options[:env] || [] + cookie = env['HTTP_COOKIE'] + if cookie&.include? 'travis_auth=' + headers['Set-Cookie'] = "travis_logged_in=#{cookie.include?('travis_auth=true').to_s};Domain=travis-ci.com;expires=#{(DateTime.parse(Time.now.to_s)+90).to_s};" + end + [200, headers, [content]] end From f422e946745737c818540ddcee2703679edf9f86 Mon Sep 17 00:00:00 2001 From: GbArc Date: Fri, 12 Jul 2024 09:28:10 +0200 Subject: [PATCH 2/3] cleanup --- app/routes/index.js | 3 ++- app/services/auth.js | 6 ++++-- app/services/cookies.js | 11 +++++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 app/services/cookies.js diff --git a/app/routes/index.js b/app/routes/index.js index 2960a079bb..a23920cd32 100644 --- a/app/routes/index.js +++ b/app/routes/index.js @@ -5,6 +5,7 @@ import { alias } from '@ember/object/computed'; export default Route.extend({ auth: service(), + cookies: service(), tabStates: service(), repositories: service(), features: service(), @@ -19,7 +20,7 @@ export default Route.extend({ } if (this.auth.signedIn) { - document.cookie = 'travis_auth=true'; + this.cookies.setSignedInCookie(true); } }, diff --git a/app/services/auth.js b/app/services/auth.js index dbf2be6ebe..499ff23395 100644 --- a/app/services/auth.js +++ b/app/services/auth.js @@ -50,6 +50,7 @@ export default Service.extend({ utm: service(), permissionsService: service('permissions'), wizardStateService: service('wizard-state'), + cookies: service(), state: STATE.SIGNED_OUT, @@ -98,6 +99,7 @@ export default Service.extend({ const stillLoggedIn = accounts.isAny('vcsId', vcsId); if (!stillLoggedIn) { + this.cookies.setSignedInCookie(false); this.router.transitionTo('signin'); } }, @@ -114,8 +116,7 @@ export default Service.extend({ signOut(runTeardown = true) { if (this.signedIn) this.api.get('/logout'); - - document.cookie = 'travis_auth=false'; + this.cookies.setSignedInCookie(false); [this.localStorage, this.sessionStorage].forEach(storage => { storage.clearPreferencesData(); @@ -151,6 +152,7 @@ export default Service.extend({ }, signUp(provider) { + this.cookies.setSignedInCookie(false); this.set('state', STATE.SIGNING_IN); const url = new URL(this.redirectUrl || window.location.href); diff --git a/app/services/cookies.js b/app/services/cookies.js new file mode 100644 index 0000000000..001689777e --- /dev/null +++ b/app/services/cookies.js @@ -0,0 +1,11 @@ +import Service, { inject as service } from '@ember/service'; + +/** + * Service for cookies + */ +export default Service.extend({ + + setSignedInCookie(value) { + document.cookie = `travis_auth=${value? 'true':'false'}`; + } +}); From b7e0d714055fec5e30785026f013c3c307e302a8 Mon Sep 17 00:00:00 2001 From: GbArc Date: Fri, 19 Jul 2024 09:55:30 +0200 Subject: [PATCH 3/3] fix --- waiter/lib/travis/web/app.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/waiter/lib/travis/web/app.rb b/waiter/lib/travis/web/app.rb index 3faf9516c4..ba5ddd12e1 100644 --- a/waiter/lib/travis/web/app.rb +++ b/waiter/lib/travis/web/app.rb @@ -118,7 +118,7 @@ def response_for(file, options = {}) env = options[:env] || [] cookie = env['HTTP_COOKIE'] if cookie&.include? 'travis_auth=' - headers['Set-Cookie'] = "travis_logged_in=#{cookie.include?('travis_auth=true').to_s};Domain=travis-ci.com;expires=#{(DateTime.parse(Time.now.to_s)+90).to_s};" + headers['Set-Cookie'] = "travis_logged_in=#{cookie.include?('travis_auth=true').to_s};Domain=travis-ci.com;Max-Age=#{86400*90};path=/;" end [200, headers, [content]]