Compare commits
4 Commits
master
...
developmen
Author | SHA1 | Date |
---|---|---|
![]() |
e9441c6cbe | |
![]() |
c144a8cbe5 | |
![]() |
965a80fe0d | |
![]() |
d57e3a94b7 |
lib/api/apiUtils/authorization
tests/unit/api
|
@ -293,6 +293,10 @@ function _checkPrincipal(requester, principal) {
|
||||||
if (principal === '*') {
|
if (principal === '*') {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
// User in unauthenticated (anonymous request)
|
||||||
|
if (requester === undefined) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (principal === requester) {
|
if (principal === requester) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const { BucketInfo, BucketPolicy } = require('arsenal').models;
|
const { BucketInfo, BucketPolicy } = require('arsenal').models;
|
||||||
|
const AuthInfo = require('arsenal').auth.AuthInfo;
|
||||||
const constants = require('../../../constants');
|
const constants = require('../../../constants');
|
||||||
const { isBucketAuthorized, isObjAuthorized, validatePolicyResource }
|
const { isBucketAuthorized, isObjAuthorized, validatePolicyResource }
|
||||||
= require('../../../lib/api/apiUtils/authorization/permissionChecks');
|
= require('../../../lib/api/apiUtils/authorization/permissionChecks');
|
||||||
|
@ -35,6 +36,9 @@ const basePolicyObj = {
|
||||||
};
|
};
|
||||||
const bucketName = 'matchme';
|
const bucketName = 'matchme';
|
||||||
const log = new DummyRequestLogger();
|
const log = new DummyRequestLogger();
|
||||||
|
const publicUserAuthInfo = new AuthInfo({
|
||||||
|
canonicalID: constants.publicId,
|
||||||
|
});
|
||||||
|
|
||||||
const authTests = [
|
const authTests = [
|
||||||
{
|
{
|
||||||
|
@ -292,11 +296,21 @@ describe('bucket policy authorization', () => {
|
||||||
it('should allow access to public user if principal is set to "*"',
|
it('should allow access to public user if principal is set to "*"',
|
||||||
done => {
|
done => {
|
||||||
const allowed = isBucketAuthorized(bucket, bucAction,
|
const allowed = isBucketAuthorized(bucket, bucAction,
|
||||||
constants.publicId, null, log);
|
constants.publicId, publicUserAuthInfo, log);
|
||||||
assert.equal(allowed, true);
|
assert.equal(allowed, true);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should deny access to public user if principal is not set to "*"', function itFn(done) {
|
||||||
|
const newPolicy = this.test.basePolicy;
|
||||||
|
newPolicy.Statement[0].Principal = { AWS: authInfo.getArn() };
|
||||||
|
bucket.setBucketPolicy(newPolicy);
|
||||||
|
const allowed = isBucketAuthorized(bucket, bucAction,
|
||||||
|
constants.publicId, publicUserAuthInfo, log);
|
||||||
|
assert.equal(allowed, false);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
authTests.forEach(t => {
|
authTests.forEach(t => {
|
||||||
it(`${t.name}bucket owner`, function itFn(done) {
|
it(`${t.name}bucket owner`, function itFn(done) {
|
||||||
const newPolicy = this.test.basePolicy;
|
const newPolicy = this.test.basePolicy;
|
||||||
|
@ -376,7 +390,7 @@ describe('bucket policy authorization', () => {
|
||||||
it('should allow access to public user if principal is set to "*"',
|
it('should allow access to public user if principal is set to "*"',
|
||||||
done => {
|
done => {
|
||||||
const allowed = isObjAuthorized(bucket, object, objAction,
|
const allowed = isObjAuthorized(bucket, object, objAction,
|
||||||
constants.publicId, null, log);
|
constants.publicId, publicUserAuthInfo, log);
|
||||||
assert.equal(allowed, true);
|
assert.equal(allowed, true);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue