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 all commits
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 @@
---
---
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ import { DataStorageAuthWithTriggerTestProjectCreator } from '../test-project-se
import { SQSClient } from '@aws-sdk/client-sqs';
import { setupDeployedBackendClient } from '../test-project-setup/setup_deployed_backend_client.js';

/**
* This E2E test is to check whether current (aka latest) repository content introduces breaking changes
* for our deployed backend client to read outputs.
*/

// Different root test dir to avoid race conditions with e2e deployment tests
const rootTestDir = fileURLToPath(
new URL('../e2e-outputs-tests', import.meta.url)
Expand Down Expand Up @@ -83,7 +88,6 @@ void describe(

await testProject.deploy(branchBackendIdentifier, sharedSecretsEnv);
await testProject.assertPostDeployment(branchBackendIdentifier);

await testProject.assertDeployedClientOutputs(branchBackendIdentifier);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
SQSClient,
} from '@aws-sdk/client-sqs';
import { e2eToolingClientConfig } from '../e2e_tooling_client_config.js';
import isMatch from 'lodash.ismatch';

/**
* Creates test projects with data, storage, and auth categories.
Expand Down Expand Up @@ -298,6 +299,31 @@ class DataStorageAuthWithTriggerTestProject extends TestProjectBase {
);
assert.ok(fileContent.includes('newKey: string;')); // Env var added via addEnvironment
assert.ok(fileContent.includes('TEST_SECRET: string;')); // Env var added via defineFunction

// assert storage access paths are correct in stack outputs
const outputsObject = JSON.parse(
await fs.readFile(
path.join(this.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'],
},
})
);
}

private getUpdateReplacementDefinition = (suffix: string) => ({
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']),
],
}),
});
Loading