diff --git a/composer.json b/composer.json index 3972104..e0e5340 100755 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ "google/cloud-storage": "~1.0" }, "require-dev": { - "phpunit/phpunit": "~4.0", + "phpunit/phpunit": "~5.0", "mockery/mockery": "0.9.*" }, "autoload": { diff --git a/src/GoogleStorageAdapter.php b/src/GoogleStorageAdapter.php index d5e6c9d..a3e6b51 100755 --- a/src/GoogleStorageAdapter.php +++ b/src/GoogleStorageAdapter.php @@ -140,12 +140,14 @@ protected function getOptionsFromConfig(Config $config) { $options = []; - if ($visibility = $config->get('visibility')) { - $options['predefinedAcl'] = $this->getPredefinedAclForVisibility($visibility); - } else { - // if a file is created without an acl, it isn't accessible via the console - // we therefore default to private - $options['predefinedAcl'] = $this->getPredefinedAclForVisibility(AdapterInterface::VISIBILITY_PRIVATE); + if (empty($this->bucket->info()['iamConfiguration']['uniformBucketLevelAccess']['enabled'])) { + if ($visibility = $config->get('visibility')) { + $options['predefinedAcl'] = $this->getPredefinedAclForVisibility($visibility); + } else { + // if a file is created without an acl, it isn't accessible via the console + // we therefore default to private + $options['predefinedAcl'] = $this->getPredefinedAclForVisibility(AdapterInterface::VISIBILITY_PRIVATE); + } } if ($metadata = $config->get('metadata')) { diff --git a/tests/GoogleStorageAdapterTests.php b/tests/GoogleStorageAdapterTests.php index 450dc51..1ab6ef1 100755 --- a/tests/GoogleStorageAdapterTests.php +++ b/tests/GoogleStorageAdapterTests.php @@ -43,11 +43,16 @@ public function testWrite() $storageObject->shouldReceive('info') ->once() ->andReturn([ + 'iamConfiguration' => ['uniformBucketLevelAccess' => ['enabled' => false]], 'updated' => '2016-09-26T14:44:42+00:00', 'contentType' => 'text/plain', 'size' => 5, ]); + $bucket->shouldReceive('info') + ->andReturn([ + 'iamConfiguration' => ['uniformBucketLevelAccess' => ['enabled' => false]] + ]); $bucket->shouldReceive('upload') ->withArgs([ 'This is the file contents.', @@ -92,6 +97,11 @@ public function testWriteWithPrivateVisibility() 'size' => 5, ]); + $bucket->shouldReceive('info') + ->andReturn([ + 'iamConfiguration' => ['uniformBucketLevelAccess' => ['enabled' => false]] + ]); + $bucket->shouldReceive('upload') ->withArgs([ 'This is the file contents.', @@ -136,6 +146,10 @@ public function testWriteWithPublicVisibility() 'size' => 5, ]); + $bucket->shouldReceive('info') + ->andReturn([ + 'iamConfiguration' => ['uniformBucketLevelAccess' => ['enabled' => false]] + ]); $bucket->shouldReceive('upload') ->withArgs([ 'This is the file contents.', @@ -182,6 +196,10 @@ public function testWriteStream() 'size' => 5, ]); + $bucket->shouldReceive('info') + ->andReturn([ + 'iamConfiguration' => ['uniformBucketLevelAccess' => ['enabled' => false]] + ]); $bucket->shouldReceive('upload') ->withArgs([ $stream, @@ -365,6 +383,10 @@ public function testDeleteDir() 'size' => 5, ]); + $bucket->shouldReceive('info') + ->andReturn([ + 'iamConfiguration' => ['uniformBucketLevelAccess' => ['enabled' => false]] + ]); $bucket->shouldReceive('object') ->with('prefix/dir_name/directory1/file1.txt') ->once() @@ -411,6 +433,11 @@ public function testDeleteDirWithTrailingSlash() 'size' => 5, ]); + $bucket->shouldReceive('info') + ->andReturn([ + 'iamConfiguration' => ['uniformBucketLevelAccess' => ['enabled' => false]] + ]); + $bucket->shouldReceive('object') ->with('prefix/dir_name/directory1/file1.txt') ->once() @@ -461,6 +488,10 @@ public function testSetVisibilityPrivate() 'size' => 5, ]); + $bucket->shouldReceive('info') + ->andReturn([ + 'iamConfiguration' => ['uniformBucketLevelAccess' => ['enabled' => false]] + ]); $bucket->shouldReceive('object') ->with('prefix/file1.txt') ->once() @@ -502,6 +533,10 @@ public function testSetVisibilityPublic() 'size' => 5, ]); + $bucket->shouldReceive('info') + ->andReturn([ + 'iamConfiguration' => ['uniformBucketLevelAccess' => ['enabled' => false]] + ]); $bucket->shouldReceive('object') ->with('prefix/file1.txt') ->once() @@ -555,6 +590,10 @@ public function testRead() 'size' => 5, ]); + $bucket->shouldReceive('info') + ->andReturn([ + 'iamConfiguration' => ['uniformBucketLevelAccess' => ['enabled' => false]] + ]); $bucket->shouldReceive('object') ->with('prefix/file.txt') ->once() @@ -596,6 +635,10 @@ public function testReadStream() 'size' => 5, ]); + $bucket->shouldReceive('info') + ->andReturn([ + 'iamConfiguration' => ['uniformBucketLevelAccess' => ['enabled' => false]] + ]); $bucket->shouldReceive('object') ->with('prefix/file.txt') ->once() @@ -731,6 +774,10 @@ public function testGetMetadataForFile() 'size' => 5, ]); + $bucket->shouldReceive('info') + ->andReturn([ + 'iamConfiguration' => ['uniformBucketLevelAccess' => ['enabled' => false]] + ]); $bucket->shouldReceive('object') ->with('prefix/file.txt') ->once() @@ -769,6 +816,10 @@ public function testGetMetadataForDir() 'size' => 0, ]); + $bucket->shouldReceive('info') + ->andReturn([ + 'iamConfiguration' => ['uniformBucketLevelAccess' => ['enabled' => false]] + ]); $bucket->shouldReceive('object') ->with('prefix/directory') ->once() @@ -807,6 +858,10 @@ public function testGetSize() 'size' => 5, ]); + $bucket->shouldReceive('info') + ->andReturn([ + 'iamConfiguration' => ['uniformBucketLevelAccess' => ['enabled' => false]] + ]); $bucket->shouldReceive('object') ->with('prefix/file.txt') ->once() @@ -837,6 +892,10 @@ public function testGetMimetype() 'size' => 5, ]); + $bucket->shouldReceive('info') + ->andReturn([ + 'iamConfiguration' => ['uniformBucketLevelAccess' => ['enabled' => false]] + ]); $bucket->shouldReceive('object') ->with('prefix/file.txt') ->once() @@ -867,6 +926,10 @@ public function testGetTimestamp() 'size' => 5, ]); + $bucket->shouldReceive('info') + ->andReturn([ + 'iamConfiguration' => ['uniformBucketLevelAccess' => ['enabled' => false]] + ]); $bucket->shouldReceive('object') ->with('prefix/file.txt') ->once()