-
Notifications
You must be signed in to change notification settings - Fork 82
Fix anonymous user access with public_access defined and fix public_access tests #9007
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,7 +46,7 @@ async function run_on_random_bucket(s3, bucket_prefix, cb) { | |
try { | ||
await cb(bucket); | ||
} finally { | ||
await s3.deleteBucket({ Bucket: bucket }); | ||
await s3.deleteBucket({ Bucket: bucket }).catch(() => { /* nothing */ }); | ||
} | ||
} | ||
|
||
|
@@ -110,29 +110,33 @@ mocha.describe('noobaa public access block test', function() { | |
|
||
mocha.it('put_public_access_block must throw when acls are used', async function() { | ||
await run_on_random_bucket(s3_owner, bucket_prefix, async bucket => { | ||
try { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is the difference between the old tests and the new? can you add a short explanation in the PR of why did the test not work, and what you changed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, actually |
||
await s3_owner.putPublicAccessBlock({ | ||
await assert.rejects( | ||
s3_owner.putPublicAccessBlock({ | ||
Bucket: bucket, | ||
PublicAccessBlockConfiguration: { | ||
BlockPublicAcls: true, | ||
} | ||
}); | ||
assert.fail("expected to fail"); | ||
} catch (error) { | ||
assert(error.Code === S3Error.AccessControlListNotSupported.code); | ||
} | ||
}), | ||
error => { | ||
// @ts-ignore | ||
assert(error.Code === S3Error.AccessControlListNotSupported.code); | ||
return true; | ||
} | ||
); | ||
|
||
try { | ||
await s3_owner.putPublicAccessBlock({ | ||
await assert.rejects( | ||
s3_owner.putPublicAccessBlock({ | ||
Bucket: bucket, | ||
PublicAccessBlockConfiguration: { | ||
IgnorePublicAcls: true, | ||
} | ||
}); | ||
assert.fail("expected to fail"); | ||
} catch (error) { | ||
assert(error.Code === S3Error.AccessControlListNotSupported.code); | ||
} | ||
}), | ||
error => { | ||
// @ts-ignore | ||
assert(error.Code === S3Error.AccessControlListNotSupported.code); | ||
return true; | ||
} | ||
); | ||
}); | ||
}); | ||
|
||
|
@@ -146,15 +150,12 @@ mocha.describe('noobaa public access block test', function() { | |
}); | ||
|
||
// Ensure we cannot put a public policy on this bucket | ||
try { | ||
await s3_owner.putBucketPolicy({ | ||
await assert.rejects( | ||
s3_owner.putBucketPolicy({ | ||
Bucket: bucket, | ||
Policy: generate_public_policy(bucket), | ||
}); | ||
assert.fail("expected to fail"); | ||
} catch { | ||
assert.ok(true); | ||
} | ||
}) | ||
); | ||
|
||
await s3_owner.deletePublicAccessBlock({ | ||
Bucket: bucket, | ||
|
@@ -163,7 +164,7 @@ mocha.describe('noobaa public access block test', function() { | |
}); | ||
|
||
mocha.it('public_access_block should work when restrict public buckets is used', async function() { | ||
await run_on_random_bucket(s3_owner, bucket_prefix, async bucket => { | ||
await run_on_random_bucket(s3_owner, bucket_prefix, async function(bucket) { | ||
const KEY = "key"; | ||
|
||
await s3_owner.putObject({ | ||
|
@@ -191,16 +192,13 @@ mocha.describe('noobaa public access block test', function() { | |
} | ||
}); | ||
|
||
try { | ||
// Ensure anon can no longer access | ||
await s3_anon.getObject({ | ||
// Ensure anon can no longer access | ||
await assert.rejects( | ||
s3_anon.getObject({ | ||
Bucket: bucket, | ||
Key: KEY, | ||
}); | ||
assert.fail("expected to fail after PublicAccessBlock"); | ||
} catch { | ||
assert.ok(true); | ||
} | ||
}), | ||
); | ||
|
||
await s3_owner.deletePublicAccessBlock({ | ||
Bucket: bucket, | ||
|
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.
why would delete bucket fail? shouldn't we handle such failure?
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.
Because sometimes the cb code might forget to delete all the objects (and their versions) from the bucket but that doesn't effect the correctness.
Failing to delete should be OK if the
cb
deems so. We can obviously write code to handle those cases but I think that would be more fragile without adding anything to the correctness of the respective tests. WDYT?