-
Notifications
You must be signed in to change notification settings - Fork 975
Some verified publishers no longer remove green tick at sublevels - Fixes issue #10484 #13675
Conversation
Codecov Report
@@ 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
|
Recommend leaving this until after #12272 |
@jasonrsadler can you please add test for this one? |
@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 |
@jasonrsadler I was thinking about unit test for function |
Thanks for clarifying. |
@NejcZdovc, can you tell me what I'm doing wrong?:
result is always coming back undefined |
@jasonrsadler you are getting undefined, because |
smacks forehead |
@NejcZdovc, would you let me know if this provides adequate coverage? Codecov doesn't seem to be running. Thanks. |
@jasonrsadler can you please add tests for |
@NejcZdovc, How is this? |
js/lib/urlutil.js
Outdated
|
||
shortenUrlToDomainTLD: (url) => { | ||
if (url !== null) { | ||
var hasProtocol = url.includes('://') |
There was a problem hiding this comment.
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
@jasonrsadler really good tests, great job |
js/lib/urlutil.js
Outdated
}, | ||
|
||
shortenUrlToDomainTLD: (url) => { | ||
if (url !== null) { |
There was a problem hiding this comment.
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
@jasonrsadler please squash commits and then we are good to go with the code |
@NejcZdovc Done. Thanks for the assist and let me know if everything else looks good. |
There was a problem hiding this 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
test/unit/lib/urlutilTest.js
Outdated
|
||
it('normal url', function () { | ||
const result = urlUtil.shortenUrlToDomainTLD('https://brave.com') | ||
assert.equal(result, 'https://brave.com/') |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
js/lib/urlutil.js
Outdated
@@ -508,6 +508,14 @@ const UrlUtil = { | |||
return ip.isPrivate(hostname) || hostname === 'localhost' || whitelistSuffixes.some((suffix) => { | |||
return hostname && hostname.endsWith(`.${suffix}`) | |||
}) | |||
}, | |||
|
|||
shortenUrlToDomainTLD: (url) => { |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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}` }
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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}` }
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. |
js/lib/urlutil.js
Outdated
}, | ||
|
||
shortenUrlToDomainTLD: (url) => { | ||
if (url != null && (!url.startsWith('http://') && !url.startsWith('https://')) ? `https://${url}` : url) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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))
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes thank you.
test/unit/lib/urlutilTest.js
Outdated
@@ -562,4 +562,51 @@ describe('urlutil', function () { | |||
assert.equal(result, 'http://www.test.com/test.pdf') | |||
}) | |||
}) | |||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 () { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this 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
app/common/state/ledgerState.js
Outdated
@@ -67,12 +67,25 @@ const ledgerState = { | |||
return state.setIn(['ledger', 'locations', url, prop], value) | |||
}, | |||
|
|||
getLocationProp: (state, url, prop) => { | |||
getVerifiedPublisherLocationProp: (state, url, prop) => { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
app/common/state/ledgerState.js
Outdated
if (prop === 'publisher') { | ||
url = urlUtil.shortenUrlToDomainTLD(url) | ||
} | ||
const urlLocations = state.getIn(['ledger', 'locations']).toJS() |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this 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
app/common/state/ledgerState.js
Outdated
|
||
if (!publisherKey) { | ||
const parsedUrl = urlParse(url) | ||
if (parsedUrl) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
app/common/state/ledgerState.js
Outdated
if (!publisherKey) { | ||
const parsedUrl = urlParse(url) | ||
if (parsedUrl) { | ||
publisherKey = parsedUrl.hostname.replace('www', '') |
There was a problem hiding this comment.
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\./
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm security-wise
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
app/common/state/ledgerState.js
Outdated
@@ -65,12 +68,28 @@ const ledgerState = { | |||
return state.setIn(['ledger', 'locations', url, prop], value) | |||
}, | |||
|
|||
getVerifiedPublisherLocationProp: (state, url) => { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
app/common/state/ledgerState.js
Outdated
@@ -18,6 +18,9 @@ const settings = require('../../../js/constants/settings') | |||
const getSetting = require('../../../js/settings').getSetting | |||
const {makeImmutable, isMap} = require('../../common/state/immutableUtil') | |||
|
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
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
There was a problem hiding this 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
Some verified publishers no longer remove green tick at sublevels - Fixes issue #10484
Some verified publishers no longer remove green tick at sublevels - Fixes issue #10484
Fixes #10484
Submitter Checklist:
git rebase -i
to squash commits (if needed).Test Plan:
Reviewer Checklist:
Tests
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