-
Notifications
You must be signed in to change notification settings - Fork 536
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #774 from blowmage/storage-acceptance-improvements
- Loading branch information
Showing
27 changed files
with
1,115 additions
and
451 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
# Copyright 2016 Google Inc. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
require "storage_helper" | ||
|
||
describe Gcloud::Storage::Bucket, :acl, :storage do | ||
let(:bucket_name) { $bucket_names.first } | ||
let :bucket do | ||
storage.bucket(bucket_name) || | ||
storage.create_bucket(bucket_name) | ||
end | ||
let(:user_val) { "user-blowmage@gmail.com" } | ||
|
||
before do | ||
# always reset the bucket permissions | ||
bucket.acl.private! | ||
end | ||
|
||
it "adds a reader" do | ||
bucket.acl.readers.wont_include user_val | ||
bucket.acl.add_reader user_val | ||
bucket.acl.readers.must_include user_val | ||
bucket.acl.refresh! | ||
bucket.acl.readers.must_include user_val | ||
bucket.refresh! | ||
bucket.acl.readers.must_include user_val | ||
end | ||
|
||
it "adds a writer" do | ||
bucket.acl.writers.wont_include user_val | ||
bucket.acl.add_writer user_val | ||
bucket.acl.writers.must_include user_val | ||
bucket.acl.refresh! | ||
bucket.acl.writers.must_include user_val | ||
bucket.refresh! | ||
bucket.acl.writers.must_include user_val | ||
end | ||
|
||
it "adds an owner" do | ||
bucket.acl.owners.wont_include user_val | ||
bucket.acl.add_owner user_val | ||
bucket.acl.owners.must_include user_val | ||
bucket.acl.refresh! | ||
bucket.acl.owners.must_include user_val | ||
bucket.refresh! | ||
bucket.acl.owners.must_include user_val | ||
end | ||
|
||
it "updates predefined rules" do | ||
bucket.acl.readers.wont_include "allAuthenticatedUsers" | ||
bucket.acl.auth! | ||
bucket.acl.readers.must_include "allAuthenticatedUsers" | ||
bucket.acl.refresh! | ||
bucket.acl.readers.must_include "allAuthenticatedUsers" | ||
bucket.refresh! | ||
bucket.acl.readers.must_include "allAuthenticatedUsers" | ||
end | ||
|
||
it "deletes rules" do | ||
bucket.acl.auth! | ||
bucket.acl.readers.must_include "allAuthenticatedUsers" | ||
bucket.acl.delete "allAuthenticatedUsers" | ||
bucket.acl.readers.wont_include "allAuthenticatedUsers" | ||
bucket.acl.refresh! | ||
bucket.acl.readers.wont_include "allAuthenticatedUsers" | ||
bucket.refresh! | ||
bucket.acl.readers.wont_include "allAuthenticatedUsers" | ||
end | ||
|
||
it "retrieves and modifies the ACL" do | ||
bucket.acl.owners.wont_be :empty? | ||
bucket.acl.writers.must_be :empty? | ||
bucket.acl.readers.must_be :empty? | ||
|
||
bucket.acl.add_writer user_val | ||
|
||
bucket.acl.owners.wont_be :empty? | ||
bucket.acl.writers.wont_be :empty? | ||
bucket.acl.readers.must_be :empty? | ||
|
||
bucket.acl.writers.must_include user_val | ||
|
||
bucket.acl.reload! | ||
|
||
bucket.acl.writers.must_include user_val | ||
|
||
bucket.reload! | ||
|
||
bucket.acl.writers.must_include user_val | ||
|
||
bucket.acl.delete user_val | ||
|
||
bucket.acl.owners.wont_be :empty? | ||
bucket.acl.writers.must_be :empty? | ||
bucket.acl.readers.must_be :empty? | ||
|
||
bucket.acl.writers.wont_include user_val | ||
|
||
bucket.acl.reload! | ||
|
||
bucket.acl.writers.wont_include user_val | ||
|
||
bucket.reload! | ||
|
||
bucket.acl.writers.wont_include user_val | ||
end | ||
|
||
it "sets predefined ACL rules" do | ||
bucket.acl.authenticatedRead! | ||
bucket.acl.auth! | ||
bucket.acl.auth_read! | ||
bucket.acl.authenticated! | ||
bucket.acl.authenticated_read! | ||
bucket.acl.private! | ||
bucket.acl.projectPrivate! | ||
bucket.acl.project_private! | ||
bucket.acl.publicRead! | ||
bucket.acl.public! | ||
bucket.acl.public_read! | ||
bucket.acl.publicReadWrite! | ||
bucket.acl.public_write! | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
# Copyright 2016 Google Inc. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
require "storage_helper" | ||
|
||
describe Gcloud::Storage::Bucket, :default_acl, :storage do | ||
let(:bucket_name) { $bucket_names.first } | ||
let :bucket do | ||
storage.bucket(bucket_name) || | ||
storage.create_bucket(bucket_name) | ||
end | ||
let(:user_val) { "user-blowmage@gmail.com" } | ||
|
||
before do | ||
# always reset the bucket permissions | ||
bucket.default_acl.private! | ||
end | ||
|
||
it "adds a reader" do | ||
user_val = "user-blowmage@gmail.com" | ||
bucket.default_acl.readers.wont_include user_val | ||
bucket.default_acl.add_reader user_val | ||
bucket.default_acl.readers.must_include user_val | ||
bucket.default_acl.refresh! | ||
bucket.default_acl.readers.must_include user_val | ||
bucket.refresh! | ||
bucket.default_acl.readers.must_include user_val | ||
end | ||
|
||
it "adds an owner" do | ||
user_val = "user-blowmage@gmail.com" | ||
bucket.default_acl.owners.wont_include user_val | ||
bucket.default_acl.add_owner user_val | ||
bucket.default_acl.owners.must_include user_val | ||
bucket.default_acl.refresh! | ||
bucket.default_acl.owners.must_include user_val | ||
bucket.refresh! | ||
bucket.default_acl.owners.must_include user_val | ||
end | ||
|
||
it "updates predefined rules" do | ||
bucket.default_acl.readers.wont_include "allAuthenticatedUsers" | ||
bucket.default_acl.auth! | ||
bucket.default_acl.readers.must_include "allAuthenticatedUsers" | ||
bucket.default_acl.refresh! | ||
bucket.default_acl.readers.must_include "allAuthenticatedUsers" | ||
bucket.refresh! | ||
bucket.default_acl.readers.must_include "allAuthenticatedUsers" | ||
end | ||
|
||
it "deletes rules" do | ||
bucket.default_acl.auth! | ||
bucket.default_acl.readers.must_include "allAuthenticatedUsers" | ||
bucket.default_acl.delete "allAuthenticatedUsers" | ||
bucket.default_acl.readers.wont_include "allAuthenticatedUsers" | ||
bucket.default_acl.refresh! | ||
bucket.default_acl.readers.wont_include "allAuthenticatedUsers" | ||
bucket.refresh! | ||
bucket.default_acl.readers.wont_include "allAuthenticatedUsers" | ||
end | ||
|
||
it "retrieves and modifies the ACL" do | ||
bucket.default_acl.owners.must_be :empty? | ||
bucket.default_acl.readers.must_be :empty? | ||
|
||
bucket.default_acl.add_reader user_val | ||
|
||
bucket.default_acl.owners.must_be :empty? | ||
bucket.default_acl.readers.wont_be :empty? | ||
|
||
bucket.default_acl.readers.must_include user_val | ||
|
||
bucket.default_acl.reload! | ||
|
||
bucket.default_acl.readers.must_include user_val | ||
|
||
bucket.reload! | ||
|
||
bucket.default_acl.readers.must_include user_val | ||
|
||
bucket.default_acl.delete user_val | ||
|
||
bucket.default_acl.owners.must_be :empty? | ||
bucket.default_acl.readers.must_be :empty? | ||
|
||
bucket.default_acl.readers.wont_include user_val | ||
|
||
bucket.default_acl.reload! | ||
|
||
bucket.default_acl.readers.wont_include user_val | ||
|
||
bucket.reload! | ||
|
||
bucket.default_acl.readers.wont_include user_val | ||
end | ||
|
||
it "sets predefined ACL rules" do | ||
bucket.default_acl.authenticatedRead! | ||
bucket.default_acl.auth! | ||
bucket.default_acl.auth_read! | ||
bucket.default_acl.authenticated! | ||
bucket.default_acl.authenticated_read! | ||
bucket.default_acl.bucketOwnerFullControl! | ||
bucket.default_acl.owner_full! | ||
bucket.default_acl.bucketOwnerRead! | ||
bucket.default_acl.owner_read! | ||
bucket.default_acl.private! | ||
bucket.default_acl.projectPrivate! | ||
bucket.default_acl.project_private! | ||
bucket.default_acl.publicRead! | ||
bucket.default_acl.public! | ||
bucket.default_acl.public_read! | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
# Copyright 2016 Google Inc. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
require "storage_helper" | ||
|
||
describe Gcloud::Storage::Bucket, :storage do | ||
let(:bucket_name) { $bucket_names.first } | ||
let :bucket do | ||
storage.bucket(bucket_name) || | ||
storage.create_bucket(bucket_name) | ||
end | ||
|
||
before do | ||
# always reset the bucket permissions | ||
bucket.acl.private! | ||
end | ||
|
||
it "creates and gets and updates and deletes a bucket" do | ||
one_off_bucket_name = "#{bucket_name}_one_off" | ||
|
||
storage.bucket(one_off_bucket_name).must_be :nil? | ||
|
||
one_off_bucket = storage.create_bucket(one_off_bucket_name) | ||
|
||
storage.bucket(one_off_bucket_name).wont_be :nil? | ||
|
||
one_off_bucket.website_main.must_be :nil? | ||
one_off_bucket.website_404.must_be :nil? | ||
one_off_bucket.update do |b| | ||
b.website_main = "index.html" | ||
b.website_404 = "not_found.html" | ||
end | ||
one_off_bucket.website_main.must_equal "index.html" | ||
one_off_bucket.website_404.must_equal "not_found.html" | ||
|
||
one_off_bucket_copy = storage.bucket one_off_bucket_name | ||
one_off_bucket_copy.wont_be :nil? | ||
one_off_bucket_copy.website_main.must_equal "index.html" | ||
one_off_bucket_copy.website_404.must_equal "not_found.html" | ||
|
||
one_off_bucket.files.all &:delete | ||
one_off_bucket.delete | ||
|
||
storage.bucket(one_off_bucket_name).must_be :nil? | ||
end | ||
|
||
it "knows its attributes" do | ||
bucket.id.must_be_kind_of String | ||
bucket.name.must_equal bucket_name | ||
bucket.created_at.must_be_kind_of DateTime | ||
bucket.api_url.must_equal "https://www.googleapis.com/storage/v1/b/#{bucket_name}" | ||
bucket.location.must_be_kind_of String | ||
bucket.logging_bucket.must_be :nil? | ||
bucket.logging_prefix.must_be :nil? | ||
bucket.storage_class.must_equal "STANDARD" | ||
bucket.versioning?.must_be :nil? | ||
bucket.website_main.must_be :nil? | ||
bucket.website_404.must_be :nil? | ||
|
||
bucket.cors.each do |cors| | ||
cors.must_be_kind_of Gcloud::Storage::Bucket::Cors::Rule | ||
cors.frozen?.must_equal true | ||
end | ||
bucket.cors.frozen?.must_equal true | ||
end | ||
|
||
it "sets and updates cors rules" do | ||
bucket.cors do |c| | ||
c.add_rule ["http://example.org", "https://example.org"], | ||
"*", | ||
headers: ["X-My-Custom-Header"], | ||
max_age: 300 | ||
end | ||
|
||
bucket.cors.wont_be :empty? | ||
bucket.cors.last.origin.must_equal ["http://example.org", "https://example.org"] | ||
bucket.cors.last.methods.must_equal ["*"] | ||
bucket.cors.last.headers.must_equal ["X-My-Custom-Header"] | ||
bucket.cors.last.max_age.must_equal 300 | ||
|
||
bucket.reload! | ||
|
||
bucket.cors do |c| | ||
c.last.origin << "https://example.com" | ||
c.last.methods = ["PUT"] | ||
c.last.headers << "X-Another-Custom-Header" | ||
c.last.max_age = 600 | ||
end | ||
|
||
bucket.reload! | ||
|
||
bucket.cors.last.origin.must_equal ["http://example.org", "https://example.org", "https://example.com"] | ||
bucket.cors.last.methods.must_equal ["PUT"] | ||
bucket.cors.last.headers.must_equal ["X-My-Custom-Header", "X-Another-Custom-Header"] | ||
bucket.cors.last.max_age.must_equal 600 | ||
end | ||
|
||
it "does not error when getting a file that does not exist" do | ||
random_bucket = storage.bucket "#{bucket_name}_does_not_exist" | ||
random_bucket.must_be :nil? | ||
end | ||
end |
Oops, something went wrong.