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

Some verified publishers no longer remove green tick at sublevels - Fixes issue #10484 #13675

Merged
merged 1 commit into from
Apr 20, 2018
Merged

Some verified publishers no longer remove green tick at sublevels - Fixes issue #10484 #13675

merged 1 commit into from
Apr 20, 2018

Conversation

jasonrsadler
Copy link
Contributor

@jasonrsadler jasonrsadler commented Mar 31, 2018

Fixes #10484

Submitter Checklist:

  • Submitted a ticket for my issue if one did not already exist.
  • Used Github auto-closing keywords in the commit message.
  • Added/updated tests for this change (for new code or code which already has tests).
  • Ran git rebase -i to squash commits (if needed).
  • Tagged reviewers and labelled the pull request as needed.
  • Request a security/privacy review as needed. (Ask a Brave employee to help if you cannot access this document.)

Test Plan:

Reviewer Checklist:

  • Request a security/privacy review as needed if one was not already requested.

Tests

  • Adequate test coverage exists to prevent regressions
  • Tests should be independent and work correctly when run individually or as a suite ref
  • New files have MPL2 license header

I could only get this to repro on the brianbondy site. All other verified pubs didn't have this problem.

Regardless the addition allows the brianbondy sub levels to show green tick

Review Requested @bsclifton
Security Review Requested @diracdeltas

@codecov-io
Copy link

codecov-io commented Mar 31, 2018

Codecov Report

Merging #13675 into master will decrease coverage by <.01%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master   #13675      +/-   ##
==========================================
- Coverage   56.45%   56.44%   -0.01%     
==========================================
  Files         283      283              
  Lines       28967    28982      +15     
  Branches     4803     4807       +4     
==========================================
+ Hits        16353    16360       +7     
- Misses      12614    12622       +8
Flag Coverage Δ
#unittest 56.44% <100%> (-0.01%) ⬇️
Impacted Files Coverage Δ
app/common/state/ledgerState.js 85.53% <100%> (+0.8%) ⬆️
.../renderer/components/navigation/publisherToggle.js 88.4% <100%> (ø) ⬆️
js/stores/appStoreRenderer.js 91.66% <0%> (-8.34%) ⬇️
app/renderer/components/reduxComponent.js 57.75% <0%> (-3.45%) ⬇️
js/stores/windowStore.js 28.46% <0%> (-0.3%) ⬇️

@jasonrsadler
Copy link
Contributor Author

Recommend leaving this until after #12272

@NejcZdovc
Copy link
Contributor

@jasonrsadler can you please add test for this one?

@jasonrsadler
Copy link
Contributor Author

jasonrsadler commented Apr 4, 2018

@NejcZdovc I've never been able to get the tests to run successfully. Can you tell me what I'm doing wrong. This is on a win10 box. I do npm run watch-test and then npm run test -- --grep="verified". Here's the test:

edited for brevity. webdriver tests not required

@NejcZdovc
Copy link
Contributor

@jasonrsadler I was thinking about unit test for function getLocationProp. You can run unit test with npm run unittest. We don't need webdriver test for this one

@jasonrsadler
Copy link
Contributor Author

Thanks for clarifying.

@jasonrsadler
Copy link
Contributor Author

@NejcZdovc, can you tell me what I'm doing wrong?:

it('verified publisher', function () {
      const url = 'https://www.duckduckgo.com'
      const prop = 'publisher'
      const state = defaultState.setIn(['ledger', 'locations', url, prop], 'duckduckgo.com')
      const result = ledgerState.getLocationProp(state, url, prop)
      assert.equal(result, 'duckduckgo.com')
    })

result is always coming back undefined

@NejcZdovc
Copy link
Contributor

NejcZdovc commented Apr 5, 2018

@jasonrsadler you are getting undefined, because url.substring(0, url.indexOf('/', 8) + 1) is returning empty string and because of that getIn is not returning anything. If I understand code correctly what you want to achieve is to change long url to domain only url. Is that correct?

@jasonrsadler
Copy link
Contributor Author

smacks forehead
Thanks

@jasonrsadler
Copy link
Contributor Author

jasonrsadler commented Apr 5, 2018

@NejcZdovc, would you let me know if this provides adequate coverage? Codecov doesn't seem to be running.

Thanks.

@NejcZdovc
Copy link
Contributor

@jasonrsadler can you please add tests for shortenUrlToDomainTLD function as well? Thank you

@jasonrsadler
Copy link
Contributor Author

@NejcZdovc, How is this?


shortenUrlToDomainTLD: (url) => {
if (url !== null) {
var hasProtocol = url.includes('://')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please replace this with const

@NejcZdovc
Copy link
Contributor

@jasonrsadler really good tests, great job

},

shortenUrlToDomainTLD: (url) => {
if (url !== null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

url !== null let's change this to url != null. This way we are checking null and undefined

@NejcZdovc NejcZdovc self-requested a review April 6, 2018 14:30
@NejcZdovc
Copy link
Contributor

@jasonrsadler please squash commits and then we are good to go with the code

@jasonrsadler
Copy link
Contributor Author

@NejcZdovc Done. Thanks for the assist and let me know if everything else looks good.

Copy link
Contributor

@NejcZdovc NejcZdovc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++ thank you for good test coverage

@NejcZdovc NejcZdovc modified the milestones: Completed work, 0.22.x Release 2, 0.22.x Release 3 (Beta channel) Apr 6, 2018

it('normal url', function () {
const result = urlUtil.shortenUrlToDomainTLD('https://brave.com')
assert.equal(result, 'https://brave.com/')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jasonrsadler this test should fail. We should not apply / at the end if / was not there from the gecko

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

other unit tests are failing because of that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. But something else is appending the trailing '/' at the end of the url during normal browsing.
Example: using latest release type in brianbondy.com and press enter. The trailing '/' gets appended at the end.

As for the tests, will fix.

Let me know what your opinion is regarding the current navigation behavior.

@@ -508,6 +508,14 @@ const UrlUtil = {
return ip.isPrivate(hostname) || hostname === 'localhost' || whitelistSuffixes.some((suffix) => {
return hostname && hostname.endsWith(`.${suffix}`)
})
},

shortenUrlToDomainTLD: (url) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you just use getBaseDomain from js/lib/baseDomain.js ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nvm, i guess what you want here is the full URL without the path?

this seems like it would fail on URLs that don't include slashes in the protocol, like mailto:

you could do parsed = urlParse(url); return parsed.path ? parsed.split(parsed.path)[0] : url or something like that

Copy link
Member

@diracdeltas diracdeltas Apr 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^ though i guess that doesn't work with URLs that don't have a protocol

since publishers only works on http or https sites, you could fix by

if (!url.startsWith('http://') && !url.startsWith('https://')) { url = `https://${url}` }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@diracdeltas That works well. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@diracdeltas I'm going to go with a combo and also to make sure another protocol isn't passed in.
if (!url.startsWith('http://') && !url.startsWith('https://') && !url.includes('://')) { url = `https://${url}` }

@jasonrsadler
Copy link
Contributor Author

The STR I had I could only reproduce on brianbondy.com. That site seems to be down ATM. Need other sites with this issue to validate.

},

shortenUrlToDomainTLD: (url) => {
if (url != null && (!url.startsWith('http://') && !url.startsWith('https://')) ? `https://${url}` : url) {
Copy link
Member

@diracdeltas diracdeltas Apr 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure I understand this if condition. the part after the first && returns a truthy value, but it doesn't set the URL

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think you mean:

if (url != null) {
  url = (!url.startsWith('http://') && !url.startsWith('https://')) ? `https://${url}` : url
  return url.substring(0, url.indexOf('/', url.indexOf('://') + 3))
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes thank you.

@@ -562,4 +562,51 @@ describe('urlutil', function () {
assert.equal(result, 'http://www.test.com/test.pdf')
})
})

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tests below should be uncommented?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which I guess is why the function passed.

Thanks for catching.

@@ -622,4 +623,32 @@ describe('ledgerState unit test', function () {
assert.equal(result, 'corrupted')
})
})

describe('getVerifiedPublisherLocationProp', function () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: it would be good to have a test case for a URL without a protocol, ex: brianbondy.com

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This got me thinking: From everything I've seen in this so far. URLs already have the protocol resolved before they get to this point. @diracdeltas or @NejcZdovc, do you know of any exceptions where URLs don't have a protocol already before getting to the publisherToggle renderer? If not, then I might have been overthinking shortenUrlToDomainTLD logic

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jasonrsadler I don't know of any examples but I also am not familiar with this code path at all

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not that I am aware

diracdeltas
diracdeltas previously approved these changes Apr 18, 2018
Copy link
Member

@diracdeltas diracdeltas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security review passes. i did not do a functional test because my ledger client seems to be broken locally

@@ -67,12 +67,25 @@ const ledgerState = {
return state.setIn(['ledger', 'locations', url, prop], value)
},

getLocationProp: (state, url, prop) => {
getVerifiedPublisherLocationProp: (state, url, prop) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's remove prop, because we changed this to specific publisher function, so it's not needed anymore

Copy link
Contributor Author

@jasonrsadler jasonrsadler Apr 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

if (prop === 'publisher') {
url = urlUtil.shortenUrlToDomainTLD(url)
}
const urlLocations = state.getIn(['ledger', 'locations']).toJS()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this one can be problematic, perf wise. getVerifiedPublisherLocationProp is called from mergeProps, which is called a lot of times. ['ledger', 'locations'] can be a really big list which we convert from immutable to regular (expensive) and then filter that potential big list.

I didn't run the code yet, but can't we just do state.getIn(['ledger', 'locations', url, prop]) where url is created on line 76?

Copy link
Contributor Author

@jasonrsadler jasonrsadler Apr 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem I was running into is that sometimes the url is formatted inconsistently. Sometimes, there's a '/' at the end, sometimes it's left off which makes it difficult to get an exact match on the key.

I agree ['ledger', 'locations'] will get too big to pass back and forth. I'll need to rethink this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you need someone to brainstorm with just let me know

Copy link
Contributor

@NejcZdovc NejcZdovc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me. The only thing that we need to improve is that filter step


if (!publisherKey) {
const parsedUrl = urlParse(url)
if (parsedUrl) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC this will always be truthy because urlParse returns {} for non-valid URLs

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can do const parsedUrl = urlParse(url) || {} just to be safe and then we can remove that if check

if (!publisherKey) {
const parsedUrl = urlParse(url)
if (parsedUrl) {
publisherKey = parsedUrl.hostname.replace('www', '')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parsedUrl.hostname may be null

also this would turn somesitewww.com into somesite.com. i think you want to either omit the replace or use a regex (/^www\./)

diracdeltas
diracdeltas previously approved these changes Apr 20, 2018
Copy link
Member

@diracdeltas diracdeltas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm security-wise

Copy link
Contributor

@ryanml ryanml left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's related to this PR, but I am no longer seeing a checkmark for verified publishers.

Looks like a publisher verification issue:

Error verifying publisher brianbondy.com: Error: HTTP response 429 for GET /v3/publisher/identity?publisher=brianbondy.com

screen shot 2018-04-19 at 7 21 24 pm

@@ -65,12 +68,28 @@ const ledgerState = {
return state.setIn(['ledger', 'locations', url, prop], value)
},

getVerifiedPublisherLocationProp: (state, url) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getVerifiedPublisherLocationProp -> getVerifiedPublisherLocation

Let's rename it, because we don't have prop anymore

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -18,6 +18,9 @@ const settings = require('../../../js/constants/settings')
const getSetting = require('../../../js/settings').getSetting
const {makeImmutable, isMap} = require('../../common/state/immutableUtil')

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this empty line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@NejcZdovc NejcZdovc self-requested a review April 20, 2018 08:08
WIP -- unit test

Moved url stripping logic to urlutil. Implemented unit tests

Removed logging debug statements

shortenUrlToDomainTLD now more utility than ledger based.

corrected lint

corrected types and checks

merge

lint

wip -- refactor shortenUrlToDomainTLD

wip -- fixup unit tests

wip -- moved logic to own function to get publisher key

Removed file (wrong branch)

Updated url shortener and moved getter to separate getter.

linting

Corrected URL parsing logic and tests

Update verified publisher method and updated tests

corrected parsing for publisher keys

check for null parsedUrl.hostname

Renamed function to reflect params
Copy link
Contributor

@NejcZdovc NejcZdovc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++ code and tests are looking good

@NejcZdovc NejcZdovc merged commit fcf1667 into brave:master Apr 20, 2018
NejcZdovc added a commit that referenced this pull request Apr 20, 2018
Some verified publishers no longer remove green tick at sublevels - Fixes issue #10484
NejcZdovc added a commit that referenced this pull request Apr 20, 2018
Some verified publishers no longer remove green tick at sublevels - Fixes issue #10484
@NejcZdovc
Copy link
Contributor

master fcf1667
0.23 7ca75e8
0.22 e1113e3

@jasonrsadler jasonrsadler deleted the working-dir5 branch April 20, 2018 13:05
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants