|
1 | 1 | const assert = require('assert'); |
2 | 2 | const { BucketInfo, BucketPolicy } = require('arsenal').models; |
| 3 | +const AuthInfo = require('arsenal').auth.AuthInfo; |
3 | 4 | const constants = require('../../../constants'); |
4 | 5 | const { isBucketAuthorized, isObjAuthorized, validatePolicyResource } |
5 | 6 | = require('../../../lib/api/apiUtils/authorization/permissionChecks'); |
@@ -35,6 +36,9 @@ const basePolicyObj = { |
35 | 36 | }; |
36 | 37 | const bucketName = 'matchme'; |
37 | 38 | const log = new DummyRequestLogger(); |
| 39 | +const publicUserAuthInfo = new AuthInfo({ |
| 40 | + canonicalID: constants.publicId, |
| 41 | +}); |
38 | 42 |
|
39 | 43 | const authTests = [ |
40 | 44 | { |
@@ -292,11 +296,21 @@ describe('bucket policy authorization', () => { |
292 | 296 | it('should allow access to public user if principal is set to "*"', |
293 | 297 | done => { |
294 | 298 | const allowed = isBucketAuthorized(bucket, bucAction, |
295 | | - constants.publicId, null, log); |
| 299 | + constants.publicId, publicUserAuthInfo, log); |
296 | 300 | assert.equal(allowed, true); |
297 | 301 | done(); |
298 | 302 | }); |
299 | 303 |
|
| 304 | + it('should deny access to public user if principal is not set to "*"', function itFn(done) { |
| 305 | + const newPolicy = this.test.basePolicy; |
| 306 | + newPolicy.Statement[0].Principal = { AWS: authInfo.getArn() }; |
| 307 | + bucket.setBucketPolicy(newPolicy); |
| 308 | + const allowed = isBucketAuthorized(bucket, bucAction, |
| 309 | + constants.publicId, publicUserAuthInfo, log); |
| 310 | + assert.equal(allowed, false); |
| 311 | + done(); |
| 312 | + }); |
| 313 | + |
300 | 314 | authTests.forEach(t => { |
301 | 315 | it(`${t.name}bucket owner`, function itFn(done) { |
302 | 316 | const newPolicy = this.test.basePolicy; |
@@ -376,7 +390,7 @@ describe('bucket policy authorization', () => { |
376 | 390 | it('should allow access to public user if principal is set to "*"', |
377 | 391 | done => { |
378 | 392 | const allowed = isObjAuthorized(bucket, object, objAction, |
379 | | - constants.publicId, null, log); |
| 393 | + constants.publicId, publicUserAuthInfo, log); |
380 | 394 | assert.equal(allowed, true); |
381 | 395 | done(); |
382 | 396 | }); |
|
0 commit comments