Skip to content
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

update e2e test for storage access outputs #2063

Merged
merged 2 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .changeset/healthy-planes-live.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
29 changes: 29 additions & 0 deletions packages/integration-tests/src/test-e2e/backend_output.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ import { DeployedResourcesFinder } from '../find_deployed_resource.js';
import { DataStorageAuthWithTriggerTestProjectCreator } from '../test-project-setup/data_storage_auth_with_triggers.js';
import { SQSClient } from '@aws-sdk/client-sqs';
import { setupDeployedBackendClient } from '../test-project-setup/setup_deployed_backend_client.js';
import fsp from 'fs/promises';
import path from 'path';
import assert from 'node:assert';
import isMatch from 'lodash.ismatch';

// Different root test dir to avoid race conditions with e2e deployment tests
const rootTestDir = fileURLToPath(
Expand Down Expand Up @@ -84,6 +88,31 @@ void describe(
await testProject.deploy(branchBackendIdentifier, sharedSecretsEnv);
await testProject.assertPostDeployment(branchBackendIdentifier);

// assert storage access paths are correct in stack outputs
const outputsObject = JSON.parse(
await fsp.readFile(
path.join(testProject.projectDirPath, 'amplify_outputs.json'),
'utf-8'
)
);
assert.ok(
isMatch(outputsObject.storage.buckets[0].paths, {
'public/*': {
guest: ['get', 'list'],
authenticated: ['get', 'list', 'write'],
groupsAdmins: ['get', 'list', 'write', 'delete'],
},
'protected/*': {
authenticated: ['get', 'list'],
groupsAdmins: ['get', 'list', 'write', 'delete'],
},
'protected/${cognito-identity.amazonaws.com:sub}/*': {
// eslint-disable-next-line spellcheck/spell-checker
entityidentity: ['get', 'list', 'write', 'delete'],
},
})
);
Copy link
Member

Choose a reason for hiding this comment

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

Is this the right place for this assertion ? I recall we use this test to assure that we can read outputs from project deployed with N-1 version/commit.

I'd rather see it in packages/integration-tests/src/test-project-setup/data_storage_auth_with_triggers.ts post deployment section.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh right, I forgot the intention of this e2e test.

I'll add a comment at the top explaining what this test is for to prevent confusion in the future and move this assertion to post deployment you mentioned.


await testProject.assertDeployedClientOutputs(branchBackendIdentifier);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ export const auth = defineAuth({
triggers: {
postConfirmation: defaultNodeFunc,
},
groups: ['Admins'],
});
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ export const storage = defineStorage({
'public/*': [
allow.resource(defaultNodeFunc).to(['read', 'write']),
allow.resource(node16Func).to(['read', 'write']),
allow.guest.to(['read']),
allow.authenticated.to(['read', 'write']),
allow.groups(['Admins']).to(['read', 'write', 'delete']),
],
'protected/{entity_id}/*': [
allow.authenticated.to(['read']),
allow.entity('identity').to(['read', 'write', 'delete']),
allow.groups(['Admins']).to(['read', 'write', 'delete']),
],
}),
});