Skip to content

Commit

Permalink
fix(Storage): allowing to set an empty value as prefix for the S3 Key (
Browse files Browse the repository at this point in the history
…#931)

* allowing to set an empty value as prefix for the S3 Key

* removed unwanted spacing created by the IDE

* addest test cases for empty custom s3 key prefix and for non-empty custom s3 prefix
  • Loading branch information
Martin Nowosad authored and Nidhi Sharma committed May 29, 2018
1 parent a69c29e commit 240e50b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
31 changes: 31 additions & 0 deletions packages/aws-amplify/__tests__/Storage/Storage-unit-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,37 @@ describe('Storage', () => {
curCredSpyOn.mockClear();
});

test('sets an empty custom public key', async () => {
const curCredSpyOn = jest.spyOn(Auth.prototype, 'currentCredentials')
.mockImplementationOnce(() => {
return new Promise((res, rej) => {
res({
identityId: 'id'
});
});
});
const storage = new Storage(options);
const spy = jest.spyOn(S3.prototype, 'getSignedUrl');
await storage.get('my_key', {customPrefix: {public: ''}});
expect(spy).toHaveBeenCalledWith('getObject', {"Bucket": "bucket", "Key": "my_key"});
});

test('sets a custom key for public accesses', async () => {
const curCredSpyOn = jest.spyOn(Auth.prototype, 'currentCredentials')
.mockImplementationOnce(() => {
return new Promise((res, rej) => {
res({
identityId: 'id'
});
});
});

const storage = new Storage(options);
const spy = jest.spyOn(S3.prototype, 'getSignedUrl');
await storage.get('my_key', {customPrefix: {public: '123/'}});
expect(spy).toHaveBeenCalledWith('getObject', {"Bucket": "bucket", "Key": "123/my_key"});
});

test('get object with expires option', async () => {
const curCredSpyOn = jest.spyOn(Auth.prototype, 'currentCredentials')
.mockImplementationOnce(() => {
Expand Down
7 changes: 4 additions & 3 deletions packages/aws-amplify/src/Storage/Storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,10 @@ export default class StorageClass {

const customPrefix = options.customPrefix || {};
const identityId = options.identityId || credentials.identityId;
const privatePath = (customPrefix.private || 'private/') + identityId + '/';
const protectedPath = (customPrefix.protected || 'protected/') + identityId + '/';
const publicPath = customPrefix.public || 'public/';
const privatePath = (customPrefix.private !== undefined ? customPrefix.private : 'private/') + identityId + '/';
const protectedPath = (customPrefix.protected !== undefined ?
customPrefix.protected : 'protected/') + identityId + '/';
const publicPath = customPrefix.public !== undefined ? customPrefix.public : 'public/';

switch (level) {
case 'private':
Expand Down

0 comments on commit 240e50b

Please sign in to comment.