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

Commit

Permalink
Merge pull request #14289 from ryanml/fix-14283
Browse files Browse the repository at this point in the history
Ensuring http only sites are not added as https in the ledger table
  • Loading branch information
bsclifton authored Jun 4, 2018
2 parents 6c58161 + bce1563 commit 341cb7e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/browser/api/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,7 @@ const addSiteVisit = (state, timestamp, location, tabId, manualAdd = false) => {
return state
}

const protocol = urlParse(location).protocol
location = pageDataUtil.getInfoKey(location)

const minimumVisitTime = getSetting(settings.PAYMENTS_MINIMUM_VISIT_TIME)
Expand Down Expand Up @@ -753,6 +754,7 @@ const addSiteVisit = (state, timestamp, location, tabId, manualAdd = false) => {

return module.exports.saveVisit(state, publisherKey, {
duration,
protocol: protocol,
revisited: revisitP
})
}
Expand All @@ -771,7 +773,11 @@ const saveVisit = (state, publisherKey, options) => {
revisitP: options.revisited,
ignoreMinTime: options.ignoreMinTime || false
})

state = ledgerState.setPublisher(state, publisherKey, synopsis.publishers[publisherKey])
if (options.protocol) {
state = ledgerState.setPublishersProp(state, publisherKey, 'protocol', options.protocol)
}
state = updatePublisherInfo(state)
state = module.exports.checkVerifiedStatus(state, publisherKey)

Expand Down
46 changes: 46 additions & 0 deletions test/unit/app/browser/api/ledgerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -1163,6 +1163,52 @@ describe('ledger api unit tests', function () {
assert(visitsByPublisher['clifton.io'])
})
})
describe('saveVisit', function () {
let setPublishersPropSpy

before(function () {
setPublishersPropSpy = sinon.spy(ledgerState, 'setPublishersProp')
})

beforeEach(function () {
ledgerApi.setSynopsis({
addPublisher: () => {},
options: {},
publishers: {}
})
})

afterEach(function () {
setPublishersPropSpy.reset()
ledgerApi.setSynopsis(undefined)
})

after(function () {
setPublishersPropSpy.restore()
})

it('sets https as protocol for secure site', function () {
const options = {
duration: 5500,
protocol: 'https:',
revisited: false
}
const result = ledgerApi.saveVisit(defaultAppState, 'brave.com', options)
assert.equal('https:', setPublishersPropSpy.getCall(0).args[3])
assert.equal('https:', result.getIn(['ledger', 'synopsis', 'publishers', 'brave.com', 'protocol']))
})

it('sets http as protocol for non-secure site', function () {
const options = {
duration: 5500,
protocol: 'http:',
revisited: false
}
const result = ledgerApi.saveVisit(defaultAppState, 'espn.com', options)
assert.equal('http:', setPublishersPropSpy.getCall(0).args[3])
assert.equal('http:', result.getIn(['ledger', 'synopsis', 'publishers', 'espn.com', 'protocol']))
})
})
describe('addNewLocation', function () {
const tabIdNone = -1
const keepInfo = false
Expand Down

0 comments on commit 341cb7e

Please sign in to comment.