Skip to content

Commit

Permalink
fix: pass predefined acl as destinationPredefinedAcl to qs (#872)
Browse files Browse the repository at this point in the history
  • Loading branch information
AVaksman authored and bcoe committed Oct 7, 2019
1 parent 12a99e9 commit 09b8fa4
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/file.ts
Expand Up @@ -323,6 +323,7 @@ interface CopyQuery {
rewriteToken?: string;
userProject?: string;
destinationKmsKeyName?: string;
destinationPredefinedAcl?: string;
}

interface FileQuery {
Expand Down Expand Up @@ -833,7 +834,10 @@ class File extends ServiceObject<File> {
});
}

copy(destination: string | Bucket | File): Promise<CopyResponse>;
copy(
destination: string | Bucket | File,
options?: CopyOptions
): Promise<CopyResponse>;
copy(destination: string | Bucket | File, callback: CopyCallback): void;
copy(
destination: string | Bucket | File,
Expand Down Expand Up @@ -1031,6 +1035,10 @@ class File extends ServiceObject<File> {
query.userProject = options.userProject;
delete options.userProject;
}
if (options.predefinedAcl !== undefined) {
query.destinationPredefinedAcl = options.predefinedAcl;
delete options.predefinedAcl;
}

newFile = newFile! || destBucket.file(destName);

Expand Down
10 changes: 10 additions & 0 deletions system-test/storage.ts
Expand Up @@ -2597,6 +2597,16 @@ describe('storage', () => {
await Promise.all([file.delete, copiedFile.delete()]);
});

it('should respect predefined Acl at file#copy', async () => {
const opts = {destination: 'CloudLogo'};
const [file] = await bucket.upload(FILES.logo.path, opts);
const copyOpts = {predefinedAcl: 'publicRead'};
const [copiedFile] = await file.copy('CloudLogoCopy', copyOpts);
const publicAcl = await isFilePublicAsync(copiedFile);
assert.strictEqual(publicAcl, true);
await Promise.all([file.delete, copiedFile.delete()]);
});

it('should copy a large file', async () => {
const otherBucket = storage.bucket(generateName());
const file = bucket.file('Big');
Expand Down
17 changes: 17 additions & 0 deletions test/file.ts
Expand Up @@ -550,6 +550,23 @@ describe('File', () => {
file.copy(newFile, {destinationKmsKeyName}, assert.ifError);
});

it('should accept predefined Acl', done => {
const options = {
predefinedAcl: 'authenticatedRead',
};
const newFile = new File(BUCKET, 'new-file');
file.request = (reqOpts: DecorateRequestOptions) => {
assert.strictEqual(
reqOpts.qs.destinationPredefinedAcl,
options.predefinedAcl
);
assert.strictEqual(reqOpts.json.destinationPredefinedAcl, undefined);
done();
};

file.copy(newFile, options, assert.ifError);
});

it('should favor the option over the File KMS name', done => {
const newFile = new File(BUCKET, 'new-file');
newFile.kmsKeyName = 'incorrect-kms-key-name';
Expand Down

0 comments on commit 09b8fa4

Please sign in to comment.