Skip to content

Commit

Permalink
chore: added test for listObjectsPolicy
Browse files Browse the repository at this point in the history
  • Loading branch information
akshbhu committed Jan 29, 2021
1 parent 24be602 commit c55b1a1
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions packages/amplify-e2e-tests/src/__tests__/function_2.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import {
addApiWithSchema,
addAuthWithDefault,
addDDBWithTrigger,
addFunction,
addS3StorageWithSettings,
addSimpleDDB,
AddStorageSettings,
amplifyPush,
amplifyPushAuth,
amplifyPushForce,
createNewProjectDir,
deleteProject,
deleteProjectDir,
Expand Down Expand Up @@ -33,6 +37,61 @@ describe('nodejs', () => {
deleteProjectDir(projRoot);
});

it('lambda with s3 permissions should be able to call listObjects', async () => {
await initJSProjectWithProfile(projRoot, {});
const random = Math.floor(Math.random() * 10000);
const fnName = `integtestfn${random}`;
const s3Name = `integtestfn${random}`;
const options: AddStorageSettings = {
resourceName: s3Name,
bucketName: s3Name,
};
await addAuthWithDefault(projRoot);
await addS3StorageWithSettings(projRoot, options);
await addFunction(
projRoot,
{
name: fnName,
functionTemplate: 'Hello World',
additionalPermissions: {
permissions: ['storage'],
resources: [s3Name],
choices: ['auth', 'storage', 'function', 'api'],
operations: ['create', 'update', 'read', 'delete'],
},
},
'nodejs',
);

overrideFunctionSrc(
projRoot,
fnName,
`
const AWS = require('aws-sdk');
const awsS3Client = new AWS.S3();
exports.handler = function(event, context) {
let listObjects = await awsS3Client
.listObjectsV2({
Bucket: process.env.STORAGE_INTEGTESTFN${random}_BUCKETNAME,
})
.promise();
return listObjects
}
`,
);
await amplifyPushForce(projRoot);
const meta = getProjectMeta(projRoot);
const { BucketName: bucketName, Region: region } = Object.keys(meta.storage).map(key => meta.storage[key])[0].output;
expect(bucketName).toBeDefined();
expect(region).toBeDefined();
const { Name: functionName } = Object.keys(meta.function).map(key => meta.function[key])[0].output;
expect(functionName).toBeDefined();
const result1 = await invokeFunction(functionName, null, region);
expect(result1.StatusCode).toBe(200);
expect(result1.Payload).toBeDefined();
});

it('lambda with dynamoDB permissions should be able to scan ddb', async () => {
await initJSProjectWithProfile(projRoot, {});

Expand Down

0 comments on commit c55b1a1

Please sign in to comment.