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

Commit

Permalink
Merge pull request #11405 from brave/issue-11401
Browse files Browse the repository at this point in the history
Bypass cookie mismatch error on google login
  • Loading branch information
bsclifton authored Oct 11, 2017
2 parents 13ab771 + 8583ccb commit 076421c
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
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

0 comments on commit 076421c

Please sign in to comment.