feat(storage): add samples and system tests for bucket encryption enforcement#4272
feat(storage): add samples and system tests for bucket encryption enforcement#4272thiyaguk09 wants to merge 4 commits intoGoogleCloudPlatform:mainfrom
Conversation
…orcement Adds comprehensive code samples and system tests to verify Google-managed, Customer-managed, and Customer-supplied encryption enforcement logic. - Add setBucketEncryptionEnforcementConfig.js sample - Add getBucketEncryptionEnforcementConfig.js sample - Add updateBucketEncryptionEnforcementConfig.js sample - Add system tests to verify CLI output and backend metadata state - Ensure server-side effectiveTime is correctly captured and displayed
|
Here is the summary of changes. You are about to add 3 region tags.
This comment is generated by snippet-bot.
|
There was a problem hiding this comment.
Code Review
This pull request introduces three new code samples and corresponding system tests for managing bucket encryption enforcement configurations in Google Cloud Storage. The new samples demonstrate how to retrieve, set, and update or clear enforcement settings for Google-managed (GMEK), customer-managed (CMEK), and customer-supplied (CSEK) encryption. I have no feedback to provide as there are no review comments to evaluate.
| @@ -0,0 +1,112 @@ | |||
| // Copyright 2019 Google LLC | |||
|
|
||
| assert.include(output, 'Google Managed (GMEK) Enforcement:'); | ||
| assert.include(output, 'Mode: FullyRestricted'); | ||
| assert.match(output, /Effective:/); |
There was a problem hiding this comment.
These tests are not robust, it's just checking a substring match.
as in this case you're trying to assert FullyRestricted Mode on GMEK, however the following code would still match the substring and
Google Managed (GMEK) Enforcement:
Mode: NotRestricted
Customer Managed (CMEK) Enforcement:
Mode: FullyRestricted
There was a problem hiding this comment.
The Better Architecture: Test the State, not the String (Testing the API)
// 1. Assert the script ran without throwing errors
const output = execSync(node setBucketEncryptionEnforcementConfig.js ${bucketName} ${defaultKmsKeyName});
// 2. Fetch the actual truth from the GCP API
const [metadata] = await bucket.getMetadata();
const encryptionConfig = metadata.encryption || {};
// 3. Assert against the actual state object
assert.strictEqual(
encryptionConfig.googleManagedEncryptionEnforcementConfig?.restrictionMode,
'FullyRestricted',
'GMEK should be FullyRestricted'
);
// Add equivalent assertions for CMEK and CSEK based on the actual
// structure of metadata.encryption in the Google Cloud Storage API
assert.strictEqual(encryptionConfig.defaultKmsKeyName, defaultKmsKeyName);
Description
Adds comprehensive code samples and system tests to verify Google-managed,
Customer-managed, and Customer-supplied encryption enforcement logic.
Checklist
npm test(see Testing)npm run lint(see Style)GoogleCloudPlatform/nodejs-docs-samples. Not a fork.