From caea1d6b5846eff305105d168d97ca2b02990883 Mon Sep 17 00:00:00 2001 From: Stephen Sawchuk Date: Mon, 23 Mar 2015 15:02:29 -0400 Subject: [PATCH] add regression tests --- lib/storage/bucket.js | 10 +---- regression/storage.js | 91 ++++++++++++++++++++++++++++++++++++++++++ test/storage/bucket.js | 12 +----- 3 files changed, 93 insertions(+), 20 deletions(-) diff --git a/lib/storage/bucket.js b/lib/storage/bucket.js index 8531d32bb73d..af7f5631e587 100644 --- a/lib/storage/bucket.js +++ b/lib/storage/bucket.js @@ -570,15 +570,7 @@ Bucket.prototype.makePublic = function(options, callback) { options = options || {}; options.public = true; - async.parallel([ - setPredefinedAcl, - addAclPermissions, - makeFilesPublic - ], callback); - - function setPredefinedAcl(done) { - self.setPredefinedAcl_(options, done); - } + async.parallel([addAclPermissions, makeFilesPublic], callback); function addAclPermissions(done) { // Allow reading bucket contents while preserving original permissions. diff --git a/regression/storage.js b/regression/storage.js index 885cd2d1517b..55bc179fb5d7 100644 --- a/regression/storage.js +++ b/regression/storage.js @@ -187,6 +187,58 @@ describe('storage', function() { }); }); + it('should make files public', function(done) { + async.each(['a', 'b', 'c'], createFileWithContent, function(err) { + assert.ifError(err); + + bucket.makePublic({ includeFiles: true }, function(err) { + assert.ifError(err); + + bucket.getFiles(function(err, files) { + assert.ifError(err); + + async.each(files, isFilePublic, function(err) { + assert.ifError(err); + + async.parallel([ + function(next) { + bucket.acl.default.delete({ entity: 'allUsers' }, next); + }, + function(next) { + deleteFiles(bucket, next); + } + ], done); + }); + }); + }); + }); + + function createFileWithContent(content, callback) { + bucket.file(uuid() + '.txt').createWriteStream() + .on('error', callback) + .on('complete', function() { + callback(); + }) + .end(content); + } + + function isFilePublic(file, callback) { + file.acl.get({ entity: 'allUsers' }, function(err, aclObject) { + if (err) { + callback(err); + return; + } + + if (aclObject.entity === 'allUsers' && + aclObject.role === 'READER') { + callback(); + } else { + callback(new Error('File is not public.')); + } + }); + } + }); + it('should be made private', function(done) { bucket.makePublic(function(err) { assert.ifError(err); @@ -201,6 +253,45 @@ describe('storage', function() { }); }); }); + + it('should make files private', function(done) { + async.each(['a', 'b', 'c'], createFileWithContent, function(err) { + assert.ifError(err); + + bucket.makePrivate({ includeFiles: true }, function(err) { + assert.ifError(err); + + bucket.getFiles(function(err, files) { + assert.ifError(err); + + async.each(files, isFilePrivate, function(err) { + assert.ifError(err); + + deleteFiles(bucket, done); + }); + }); + }); + }); + + function createFileWithContent(content, callback) { + bucket.file(uuid() + '.txt').createWriteStream() + .on('error', callback) + .on('complete', function() { + callback(); + }) + .end(content); + } + + function isFilePrivate(file, callback) { + file.acl.get({ entity: 'allUsers' }, function(err) { + if (err && err.code === 404) { + callback(); + } else { + callback(new Error('File is not private.')); + } + }); + } + }); }); describe('files', function() { diff --git a/test/storage/bucket.js b/test/storage/bucket.js index a37145c67bc8..cc90dbcdf78f 100644 --- a/test/storage/bucket.js +++ b/test/storage/bucket.js @@ -447,12 +447,6 @@ describe('Bucket', function() { }); it('should set predefined & default ACL, publicize files', function(done) { - bucket.setPredefinedAcl = function(opts, callback) { - assert.strictEqual(options.public, true); - assert.strictEqual(options.force, true); - callback(); - }; - bucket.acl.default.add = function(opts, callback) { assert.equal(opts.entity, 'allUsers'); assert.equal(opts.role, 'READER'); @@ -472,10 +466,6 @@ describe('Bucket', function() { }); it('should not make files public by default', function(done) { - bucket.setPredefinedAcl = function(opts, callback) { - callback(); - }; - bucket.acl.default.add = function(opts, callback) { callback(); }; @@ -490,7 +480,7 @@ describe('Bucket', function() { it('should execute callback with error', function(done) { var error = new Error('Error.'); - bucket.setPredefinedAcl_ = function(opts, callback) { + bucket.acl.default.add = function(opts, callback) { callback(error); };