Skip to content

Commit b7ac6a3

Browse files
authored
update e2e test for storage access outputs (aws-amplify#2063)
* update backend output test for storage access outputs * move assertion to post deployment
1 parent 970d555 commit b7ac6a3

File tree

5 files changed

+42
-1
lines changed

5 files changed

+42
-1
lines changed

.changeset/healthy-planes-live.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

packages/integration-tests/src/test-e2e/backend_output.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ import { DataStorageAuthWithTriggerTestProjectCreator } from '../test-project-se
2424
import { SQSClient } from '@aws-sdk/client-sqs';
2525
import { setupDeployedBackendClient } from '../test-project-setup/setup_deployed_backend_client.js';
2626

27+
/**
28+
* This E2E test is to check whether current (aka latest) repository content introduces breaking changes
29+
* for our deployed backend client to read outputs.
30+
*/
31+
2732
// Different root test dir to avoid race conditions with e2e deployment tests
2833
const rootTestDir = fileURLToPath(
2934
new URL('../e2e-outputs-tests', import.meta.url)
@@ -83,7 +88,6 @@ void describe(
8388

8489
await testProject.deploy(branchBackendIdentifier, sharedSecretsEnv);
8590
await testProject.assertPostDeployment(branchBackendIdentifier);
86-
8791
await testProject.assertDeployedClientOutputs(branchBackendIdentifier);
8892
});
8993
}

packages/integration-tests/src/test-project-setup/data_storage_auth_with_triggers.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
SQSClient,
2424
} from '@aws-sdk/client-sqs';
2525
import { e2eToolingClientConfig } from '../e2e_tooling_client_config.js';
26+
import isMatch from 'lodash.ismatch';
2627

2728
/**
2829
* Creates test projects with data, storage, and auth categories.
@@ -298,6 +299,31 @@ class DataStorageAuthWithTriggerTestProject extends TestProjectBase {
298299
);
299300
assert.ok(fileContent.includes('newKey: string;')); // Env var added via addEnvironment
300301
assert.ok(fileContent.includes('TEST_SECRET: string;')); // Env var added via defineFunction
302+
303+
// assert storage access paths are correct in stack outputs
304+
const outputsObject = JSON.parse(
305+
await fs.readFile(
306+
path.join(this.projectDirPath, 'amplify_outputs.json'),
307+
'utf-8'
308+
)
309+
);
310+
assert.ok(
311+
isMatch(outputsObject.storage.buckets[0].paths, {
312+
'public/*': {
313+
guest: ['get', 'list'],
314+
authenticated: ['get', 'list', 'write'],
315+
groupsAdmins: ['get', 'list', 'write', 'delete'],
316+
},
317+
'protected/*': {
318+
authenticated: ['get', 'list'],
319+
groupsAdmins: ['get', 'list', 'write', 'delete'],
320+
},
321+
'protected/${cognito-identity.amazonaws.com:sub}/*': {
322+
// eslint-disable-next-line spellcheck/spell-checker
323+
entityidentity: ['get', 'list', 'write', 'delete'],
324+
},
325+
})
326+
);
301327
}
302328

303329
private getUpdateReplacementDefinition = (suffix: string) => ({

packages/integration-tests/src/test-projects/data-storage-auth-with-triggers-ts/amplify/auth/resource.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ export const auth = defineAuth({
2424
triggers: {
2525
postConfirmation: defaultNodeFunc,
2626
},
27+
groups: ['Admins'],
2728
});

packages/integration-tests/src/test-projects/data-storage-auth-with-triggers-ts/amplify/storage/resource.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ export const storage = defineStorage({
1616
'public/*': [
1717
allow.resource(defaultNodeFunc).to(['read', 'write']),
1818
allow.resource(node16Func).to(['read', 'write']),
19+
allow.guest.to(['read']),
20+
allow.authenticated.to(['read', 'write']),
21+
allow.groups(['Admins']).to(['read', 'write', 'delete']),
22+
],
23+
'protected/{entity_id}/*': [
24+
allow.authenticated.to(['read']),
25+
allow.entity('identity').to(['read', 'write', 'delete']),
26+
allow.groups(['Admins']).to(['read', 'write', 'delete']),
1927
],
2028
}),
2129
});

0 commit comments

Comments
 (0)