Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uniform access rules on upload #120

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"google/cloud-storage": "~1.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0",
"phpunit/phpunit": "~5.0",
"mockery/mockery": "0.9.*"
},
"autoload": {
Expand Down
14 changes: 8 additions & 6 deletions src/GoogleStorageAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand Down
63 changes: 63 additions & 0 deletions tests/GoogleStorageAdapterTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand Down Expand Up @@ -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.',
Expand Down Expand Up @@ -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.',
Expand Down Expand Up @@ -182,6 +196,10 @@ public function testWriteStream()
'size' => 5,
]);

$bucket->shouldReceive('info')
->andReturn([
'iamConfiguration' => ['uniformBucketLevelAccess' => ['enabled' => false]]
]);
$bucket->shouldReceive('upload')
->withArgs([
$stream,
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -769,6 +816,10 @@ public function testGetMetadataForDir()
'size' => 0,
]);

$bucket->shouldReceive('info')
->andReturn([
'iamConfiguration' => ['uniformBucketLevelAccess' => ['enabled' => false]]
]);
$bucket->shouldReceive('object')
->with('prefix/directory')
->once()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down