Skip to content
This repository was archived by the owner on Dec 11, 2019. It is now read-only.

Bypass cookie mismatch error on google login #11405

Merged
merged 2 commits into from
Oct 11, 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
15 changes: 15 additions & 0 deletions app/importer.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,17 @@ importer.on('add-keywords', (e, templateUrls, uniqueOnHostAndPath) => {
importer.on('add-autofill-form-data-entries', (e, detail) => {
})

const shouldSkipCookie = (cookie) => {
// Bypassing cookie mismatch error in
// https://github.com/brave/browser-laptop/issues/11401
if (cookie.domain === '.google.com' &&
['https://notifications.google.com', 'https://accounts.google.com'].includes(cookie.url)) {
return true
}
return false
}
module.exports.shouldSkipCookie = shouldSkipCookie

importer.on('add-cookies', (e, cookies) => {
for (let i = 0; i < cookies.length; ++i) {
const cookie = {
Expand All @@ -234,9 +245,13 @@ importer.on('add-cookies', (e, cookies) => {
httpOnly: cookies[i].httponly,
expirationDate: cookies[i].expiry_date
}
if (shouldSkipCookie(cookie)) {
continue
}
session.defaultSession.cookies.set(cookie, (error) => {
if (error) {
console.error(error)
console.error(cookie)
}
})
}
Expand Down
35 changes: 35 additions & 0 deletions test/unit/app/importerTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* global describe, before, after, it */
const mockery = require('mockery')
const assert = require('assert')

require('../braveUnit')

describe('importer unit tests', function () {
let importer
const fakeElectron = require('../lib/fakeElectron')

before(function () {
mockery.enable({
warnOnReplace: false,
warnOnUnregistered: false,
useCleanCache: true
})
mockery.registerMock('electron', fakeElectron)
mockery.registerMock('./adBlock', {adBlockResourceName: 'adblock'})
importer = require('../../../app/importer')
})

after(function () {
mockery.disable()
})

describe('shouldSkipCookie', function () {
it('returns true if domain is google and URL is one which has a mismatch', function () {
assert.equal(importer.shouldSkipCookie({domain: '.google.com', url: 'https://notifications.google.com'}), true)
})

it('returns false for other cases', function () {
assert.equal(importer.shouldSkipCookie({domain: '.brave.com', url: 'https://brave.com'}), false)
})
})
})
5 changes: 4 additions & 1 deletion test/unit/lib/fakeElectron.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ const fakeElectron = {
extensions: {
createTab: function () {}
},
autoUpdater: new EventEmitter()
autoUpdater: new EventEmitter(),
importer: {
on: () => {}
}
}

module.exports = fakeElectron