Skip to content

Conversation

@dmitrizagidulin
Copy link
Contributor

No description provided.

package.json Outdated
"rimraf": "^2.5.0",
"run-waterfall": "^1.1.3",
"solid-namespace": "^0.1.0",
"solid-permissions": "git://github.com/solid/solid-permissions.git#dz_allows_helpers",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Temporary (for this pr review only), until PR solid-contrib/solid-permissions#3 gets merged.

@dmitrizagidulin
Copy link
Contributor Author

@dan-f @nicola - ready for review.

var possibleACLs = ACLChecker.possibleACLs(resource, this.suffix)
// If this is an ACL, Control mode must be present for any operations
if (this.isAcl(resource)) {
if (this.isAcl(resource, this.suffix)) {
Copy link
Contributor

@nicola nicola Sep 18, 2016

Choose a reason for hiding this comment

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

Can this.suffix not be used directly in this.isAcl?
In the rest of the code this.isAcl doesn't take any second parameter

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, missed this bit when I was refactoring. Thanks!

rdf: rdf,
strictOrigin: this.strictOrigin,
isAcl: (uri) => { return this.isAcl(uri) },
aclUrlFor: (uri) => { return this.aclUrlFor(uri) }
Copy link
Contributor

Choose a reason for hiding this comment

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

at this point, can we not pass the entire ACL instance?
(maybe not)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could? I'd rather be explicit, though..

let aclOptions = {
aclSuffix: this.suffix,
graph: graph,
host: options.host,
Copy link
Contributor

Choose a reason for hiding this comment

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

how is this used?
where is host set and what is this set to?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

host gets set in the allow handler, here.
It's used by the 'enforce strict origin' code in the permissions lib.

Copy link
Contributor

Choose a reason for hiding this comment

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

perfect! works with me!

Copy link
Contributor

@dan-f dan-f left a comment

Choose a reason for hiding this comment

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

A couple requests

  1. Could you help me with my API questions?
  2. It looks like you introduced some error handling in findRule. Could you add tests to cover that error handling?

Looks good other than that!

}
return callback(null)
})
.catch(err => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you clarify the distinction between a rejected promise and a resolved promise with a falsy value in checkAccess?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure thing. checkAccess() resolves with either a truthy value (which means the user has access), or a falsy value (which means the user does not have access). A rejected promise means an error (parsing error, argument error, network errors, etc).

}

/**
* @method findRule
Copy link
Contributor

Choose a reason for hiding this comment

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

Awesome JSDoc, but what does this method do?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Heh, yeah, I s'pose it wouldn't hurt to add an actual description.

.then(hasAccess => {
if (hasAccess) {
debug(`${mode} access permitted to ${user}`)
return callback()
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this method is called findRule, I think I assumed that the callback function would get passed the access rule/policy for the given user.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, now that it's refactored the findRule name doesn't make as much sense. I'll rename it to something like checkAccess.

@dmitrizagidulin
Copy link
Contributor Author

It looks like you introduced some error handling in findRule. Could you add tests to cover that error handling?

I don't think there's any additional error handling introduced. The existing test suite should cover the various cases.

@dan-f
Copy link
Contributor

dan-f commented Sep 19, 2016

I don't think there's any additional error handling introduced. The existing test suite should cover the various cases.

I don't see tests for the "parsing error, argument error, network errors" cases.

@dmitrizagidulin
Copy link
Contributor Author

I don't see tests for the "parsing error, argument error, network errors" cases.

Those belong in the permissions library, though, not here.

@dan-f
Copy link
Contributor

dan-f commented Sep 19, 2016

Those belong in the permissions library, though, not here.

... which I just checked and does not have tests for such cases.

@dmitrizagidulin
Copy link
Contributor Author

I'm not sure I understand your point. This PR is a net increase in test coverage, in this acl checking code.

@dan-f
Copy link
Contributor

dan-f commented Sep 19, 2016

I'm not sure I understand your point. This PR is a net increase in test coverage, in this acl checking code.

My point is that checkAccess is supposed to catch network (and other?) errors, and return false, that the user does not have access in such cases. But those cases are not covered either in node-solid-server nor in the permissions library. We should have a test case that demonstrates that the error handling actually works as expected, since we don't want to accidentally give permissions when the network fails, for example.

@dmitrizagidulin
Copy link
Contributor Author

@dan-f so I've been looking at this issue (testing the .catch() clause of checkAccess) for a bit.
I'm still not really seeing what I can do here.
Am I testing the Promise error behavior? (That if there's an error inside a promise, it'll go into the .catch(err) clause?) That doesn't seem right - that's up to the Node foundation etc.
Am I testing that if checkAccess() calls the callback() with an error, the user is denied access? The rest of the existing suite checks that.
I don't really see what else I can do here.

@dan-f
Copy link
Contributor

dan-f commented Sep 26, 2016

@dmitrizagidulin the code path I'm thinking of is where the call to acls.checkAccess(resource, user, mode) returns a Promise which rejects. You told me above that your library rejects a promise in the case of "parsing error, argument error, network errors, etc," so shouldn't we verify that this consumer code handles permissions correctly when one of those errors arise?

@dmitrizagidulin
Copy link
Contributor Author

@dan-f Added proxyquire-based unit tests for acl-checker.checkAccess().

@dan-f
Copy link
Contributor

dan-f commented Sep 29, 2016

Looks awesome, @dmitrizagidulin. Thanks! 👍

@dmitrizagidulin dmitrizagidulin merged commit 99c2cb1 into master Sep 29, 2016
@dmitrizagidulin dmitrizagidulin deleted the external_permissions_lib branch September 29, 2016 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants