[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DBW: Audit for notification permissions on start #1064

Merged

Conversation

patrickhulce
Copy link
Collaborator

Addresses #1060

@patrickhulce
Copy link
Collaborator Author

Note: this doesn't seem to work when the permissions request comes from a different domain from within an iframe (test url: https://developer.mozilla.org/en-US/docs/Web/API/Notification)

Copy link
Contributor
@ebidel ebidel left a comment

Choose a reason for hiding this comment

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

Nice. Looks ripe for an "audit helper" now that we have duplication between gatherers. I'd imagine we'll eventually have a few more of these permission gatherers (media apis, etc.)

}).catch(err => {
this.artifact = {
value: -1,
debugString: err && err.toString()
Copy link
Contributor

Choose a reason for hiding this comment

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

geolocation uses e.message. Can we make them consistent?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

sure, do we want to standardize on message and not include the error name then? would have benefit of accepting non-Error objects I suppose too

Copy link
Contributor

Choose a reason for hiding this comment

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

err.toString() might be more noise in the html report. Not sure how that will look.

afterPass(options) {
return options.driver.evaluateAsync(`(${queryNotificationPermission.toString()}())`)
.then(state => {
if (state === 'granted' || state === 'denied') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add || state === 'denied' to the geolocation audit too? It only checks state === 'granted' atm.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

@ebidel
Copy link
Contributor
ebidel commented Nov 28, 2016

Note: this doesn't seem to work when the permissions request comes from a different domain from within an iframe (test url: https://developer.mozilla.org/en-US/docs/Web/API/Notification)

Can you file a bug for that? I suspect that also applies to the geolocation audit and we'll need to think of a solution.

@patrickhulce patrickhulce changed the title DBW: Audit for Notification Permissions on Start DBW: Audit for notification permissions on start Nov 28, 2016
/* global navigator */

/* istanbul ignore next */
function queryNotificationPermission() {
Copy link
Member

Choose a reason for hiding this comment

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

yeah, it would be great to pull this out into driver.queryPermissionStatus or whatever

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

will do

*/
queryPermissionState(name) {
const expressionToEval = `
(function () {
Copy link
Member

Choose a reason for hiding this comment

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

any reason to wrap? navigator.permissions.query({name: ${name}}).then(result => result.state) is also an expression

Copy link
Member

Choose a reason for hiding this comment

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

also, any specific reason for the JSON.stringify?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Eh I guess no wrap necessary, and just in case name contained a ' or " didn't want an inscrutable error message

@@ -433,12 +433,14 @@ class Driver {
* See https://developer.mozilla.org/en-US/docs/Web/API/Permissions/query.
*/
queryPermissionState(name) {
if (['geolocation', 'notifications', 'midi', 'push'].indexOf(name) === -1) {
Copy link
Contributor
@ebidel ebidel Nov 29, 2016

Choose a reason for hiding this comment

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

The API already rejects for cases it doesn't understand:

screen shot 2016-11-28 at 5 13 45 pm

Can we use that instead of enumerating all the types ourselves?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah @ebidel this was to remove the JSON.stringify in response to @brendankenny's feedback since a malformed name wouldn't ever reach the friendly message. i'd lean toward my original stringify and let Chrome handle the enum check but I don't feel terribly strongly

Copy link
Member

Choose a reason for hiding this comment

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

I'm not too concerned about protecting against all errors like this. Shouldn't exceptionDetails/when we land #1037 catch syntax errors like that?

Copy link
Contributor

Choose a reason for hiding this comment

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

Gotcha. I think leaving off JSON.stringify is ok since we'll be the ones writing the majority of audits.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, shuttle wifi catch up! @brendankenny said the same thing :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

alright fair enough

@patrickhulce
Copy link
Collaborator Author

PTAL :)

Copy link
Member
@brendankenny brendankenny left a comment

Choose a reason for hiding this comment

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

LGTM ⏱🍿👮:no_good_man:

@brendankenny brendankenny merged commit 93cbff3 into GoogleChrome:master Dec 1, 2016
@brendankenny
Copy link
Member

@patrickhulce whoops, totally missed that the notification-on-start audit doesn't have any tests. Should be fairly fast, can basically just copy the geolocation one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants