croaker-aws-s3 0.5.2.20090127001
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/COPYING +19 -0
 - data/INSTALL +55 -0
 - data/README +545 -0
 - data/Rakefile +334 -0
 - data/bin/s3sh +6 -0
 - data/bin/setup.rb +10 -0
 - data/lib/aws/s3/acl.rb +636 -0
 - data/lib/aws/s3/authentication.rb +222 -0
 - data/lib/aws/s3/base.rb +257 -0
 - data/lib/aws/s3/bittorrent.rb +58 -0
 - data/lib/aws/s3/bucket.rb +329 -0
 - data/lib/aws/s3/connection.rb +349 -0
 - data/lib/aws/s3/error.rb +69 -0
 - data/lib/aws/s3/exceptions.rb +133 -0
 - data/lib/aws/s3/extensions.rb +324 -0
 - data/lib/aws/s3/logging.rb +311 -0
 - data/lib/aws/s3/object.rb +613 -0
 - data/lib/aws/s3/owner.rb +44 -0
 - data/lib/aws/s3/parsing.rb +99 -0
 - data/lib/aws/s3/response.rb +180 -0
 - data/lib/aws/s3/service.rb +51 -0
 - data/lib/aws/s3/version.rb +12 -0
 - data/lib/aws/s3.rb +61 -0
 - data/support/faster-xml-simple/lib/faster_xml_simple.rb +187 -0
 - data/support/faster-xml-simple/test/regression_test.rb +47 -0
 - data/support/faster-xml-simple/test/test_helper.rb +17 -0
 - data/support/faster-xml-simple/test/xml_simple_comparison_test.rb +46 -0
 - data/support/rdoc/code_info.rb +211 -0
 - data/test/acl_test.rb +254 -0
 - data/test/authentication_test.rb +114 -0
 - data/test/base_test.rb +136 -0
 - data/test/bucket_test.rb +74 -0
 - data/test/connection_test.rb +217 -0
 - data/test/error_test.rb +70 -0
 - data/test/extensions_test.rb +331 -0
 - data/test/fixtures/buckets.yml +133 -0
 - data/test/fixtures/errors.yml +34 -0
 - data/test/fixtures/headers.yml +3 -0
 - data/test/fixtures/logging.yml +15 -0
 - data/test/fixtures/loglines.yml +5 -0
 - data/test/fixtures/logs.yml +7 -0
 - data/test/fixtures/policies.yml +16 -0
 - data/test/fixtures.rb +89 -0
 - data/test/logging_test.rb +89 -0
 - data/test/mocks/fake_response.rb +26 -0
 - data/test/object_test.rb +205 -0
 - data/test/parsing_test.rb +66 -0
 - data/test/remote/acl_test.rb +117 -0
 - data/test/remote/bittorrent_test.rb +45 -0
 - data/test/remote/bucket_test.rb +146 -0
 - data/test/remote/logging_test.rb +82 -0
 - data/test/remote/object_test.rb +371 -0
 - data/test/remote/test_helper.rb +30 -0
 - data/test/response_test.rb +68 -0
 - data/test/service_test.rb +23 -0
 - data/test/test_helper.rb +111 -0
 - metadata +143 -0
 
| 
         @@ -0,0 +1,89 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require File.dirname(__FILE__) + '/test_helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            class LoggingStatusReadingTest < Test::Unit::TestCase
         
     | 
| 
      
 4 
     | 
    
         
            +
              
         
     | 
| 
      
 5 
     | 
    
         
            +
              def setup
         
     | 
| 
      
 6 
     | 
    
         
            +
                @disabled   = logging_status(:logging_disabled)
         
     | 
| 
      
 7 
     | 
    
         
            +
                @enabled    = logging_status(:logging_enabled)
         
     | 
| 
      
 8 
     | 
    
         
            +
                @new_status = Logging::Status.new('target_bucket' => 'foo', 'target_prefix' => 'access-log-')
         
     | 
| 
      
 9 
     | 
    
         
            +
              end
         
     | 
| 
      
 10 
     | 
    
         
            +
              
         
     | 
| 
      
 11 
     | 
    
         
            +
              def test_logging_enabled?
         
     | 
| 
      
 12 
     | 
    
         
            +
                assert !@disabled.logging_enabled?
         
     | 
| 
      
 13 
     | 
    
         
            +
                assert !@new_status.logging_enabled?
         
     | 
| 
      
 14 
     | 
    
         
            +
                assert @enabled.logging_enabled?
         
     | 
| 
      
 15 
     | 
    
         
            +
              end
         
     | 
| 
      
 16 
     | 
    
         
            +
              
         
     | 
| 
      
 17 
     | 
    
         
            +
              def test_passing_in_prefix_and_bucket
         
     | 
| 
      
 18 
     | 
    
         
            +
                assert_equal 'foo', @new_status.target_bucket
         
     | 
| 
      
 19 
     | 
    
         
            +
                assert_equal 'access-log-', @new_status.target_prefix
         
     | 
| 
      
 20 
     | 
    
         
            +
                assert !@new_status.logging_enabled?
         
     | 
| 
      
 21 
     | 
    
         
            +
              end
         
     | 
| 
      
 22 
     | 
    
         
            +
              
         
     | 
| 
      
 23 
     | 
    
         
            +
              private
         
     | 
| 
      
 24 
     | 
    
         
            +
                def logging_status(fixture)
         
     | 
| 
      
 25 
     | 
    
         
            +
                  Logging::Status.new(Parsing::XmlParser.new(Fixtures::Logging[fixture.to_s]))
         
     | 
| 
      
 26 
     | 
    
         
            +
                end
         
     | 
| 
      
 27 
     | 
    
         
            +
            end
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
            class LoggingStatusWritingTest < LoggingStatusReadingTest
         
     | 
| 
      
 30 
     | 
    
         
            +
              def setup
         
     | 
| 
      
 31 
     | 
    
         
            +
                super
         
     | 
| 
      
 32 
     | 
    
         
            +
                @disabled = Logging::Status.new(Parsing::XmlParser.new(@disabled.to_xml))
         
     | 
| 
      
 33 
     | 
    
         
            +
                @enabled  = Logging::Status.new(Parsing::XmlParser.new(@enabled.to_xml))
         
     | 
| 
      
 34 
     | 
    
         
            +
              end
         
     | 
| 
      
 35 
     | 
    
         
            +
            end
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
            class LogTest < Test::Unit::TestCase
         
     | 
| 
      
 38 
     | 
    
         
            +
              def test_value_converted_to_log_lines
         
     | 
| 
      
 39 
     | 
    
         
            +
                log_object = S3Object.new
         
     | 
| 
      
 40 
     | 
    
         
            +
                log_object.value = Fixtures::Logs.simple_log.join
         
     | 
| 
      
 41 
     | 
    
         
            +
                log = Logging::Log.new(log_object)
         
     | 
| 
      
 42 
     | 
    
         
            +
                assert_nothing_raised do
         
     | 
| 
      
 43 
     | 
    
         
            +
                  log.lines
         
     | 
| 
      
 44 
     | 
    
         
            +
                end
         
     | 
| 
      
 45 
     | 
    
         
            +
                
         
     | 
| 
      
 46 
     | 
    
         
            +
                assert_equal 2, log.lines.size
         
     | 
| 
      
 47 
     | 
    
         
            +
                assert_kind_of Logging::Log::Line, log.lines.first
         
     | 
| 
      
 48 
     | 
    
         
            +
                assert_equal 'marcel', log.lines.first.bucket
         
     | 
| 
      
 49 
     | 
    
         
            +
              end
         
     | 
| 
      
 50 
     | 
    
         
            +
            end
         
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
      
 52 
     | 
    
         
            +
            class LogLineTest < Test::Unit::TestCase
         
     | 
| 
      
 53 
     | 
    
         
            +
              def setup
         
     | 
| 
      
 54 
     | 
    
         
            +
                @line = Logging::Log::Line.new(Fixtures::Loglines.bucket_get)
         
     | 
| 
      
 55 
     | 
    
         
            +
              end
         
     | 
| 
      
 56 
     | 
    
         
            +
              
         
     | 
| 
      
 57 
     | 
    
         
            +
              def test_field_accessors
         
     | 
| 
      
 58 
     | 
    
         
            +
                expected_results = {
         
     | 
| 
      
 59 
     | 
    
         
            +
                  :owner            => Owner.new('id' => 'bb2041a25975c3d4ce9775fe9e93e5b77a6a9fad97dc7e00686191f3790b13f1'),
         
     | 
| 
      
 60 
     | 
    
         
            +
                  :bucket           => 'marcel',
         
     | 
| 
      
 61 
     | 
    
         
            +
                  :time             => Time.parse('11/14/2006 06:36:48 +0000'),
         
     | 
| 
      
 62 
     | 
    
         
            +
                  :remote_ip        => '67.165.183.125',
         
     | 
| 
      
 63 
     | 
    
         
            +
                  :request_id       => '8B5297D428A05432',
         
     | 
| 
      
 64 
     | 
    
         
            +
                  :requestor        => Owner.new('id' => 'bb2041a25975c3d4ce9775fe9e93e5b77a6a9fad97dc7e00686191f3790b13f1'),
         
     | 
| 
      
 65 
     | 
    
         
            +
                  :operation        => 'REST.GET.BUCKET',
         
     | 
| 
      
 66 
     | 
    
         
            +
                  :key              => nil,
         
     | 
| 
      
 67 
     | 
    
         
            +
                  :request_uri      => 'GET /marcel HTTP/1.1',
         
     | 
| 
      
 68 
     | 
    
         
            +
                  :http_status      => 200,
         
     | 
| 
      
 69 
     | 
    
         
            +
                  :error_code       => nil,
         
     | 
| 
      
 70 
     | 
    
         
            +
                  :bytes_sent       => 4534,
         
     | 
| 
      
 71 
     | 
    
         
            +
                  :object_size      => nil,
         
     | 
| 
      
 72 
     | 
    
         
            +
                  :total_time       => 398,
         
     | 
| 
      
 73 
     | 
    
         
            +
                  :turn_around_time => 395,
         
     | 
| 
      
 74 
     | 
    
         
            +
                  :referrer         => nil,
         
     | 
| 
      
 75 
     | 
    
         
            +
                  :user_agent       => nil
         
     | 
| 
      
 76 
     | 
    
         
            +
                }
         
     | 
| 
      
 77 
     | 
    
         
            +
                 
         
     | 
| 
      
 78 
     | 
    
         
            +
                 expected_results.each do |field, expected|
         
     | 
| 
      
 79 
     | 
    
         
            +
                   assert_equal expected, @line.send(field)
         
     | 
| 
      
 80 
     | 
    
         
            +
                 end
         
     | 
| 
      
 81 
     | 
    
         
            +
                 
         
     | 
| 
      
 82 
     | 
    
         
            +
                 assert_equal expected_results, @line.attributes
         
     | 
| 
      
 83 
     | 
    
         
            +
               end
         
     | 
| 
      
 84 
     | 
    
         
            +
               
         
     | 
| 
      
 85 
     | 
    
         
            +
              def test_user_agent
         
     | 
| 
      
 86 
     | 
    
         
            +
                line = Logging::Log::Line.new(Fixtures::Loglines.browser_get)
         
     | 
| 
      
 87 
     | 
    
         
            +
                assert_equal 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0', line.user_agent
         
     | 
| 
      
 88 
     | 
    
         
            +
              end
         
     | 
| 
      
 89 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,26 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module AWS
         
     | 
| 
      
 2 
     | 
    
         
            +
              module S3
         
     | 
| 
      
 3 
     | 
    
         
            +
                class FakeResponse
         
     | 
| 
      
 4 
     | 
    
         
            +
                  attr_reader :code, :body, :headers
         
     | 
| 
      
 5 
     | 
    
         
            +
                  def initialize(options = {})
         
     | 
| 
      
 6 
     | 
    
         
            +
                    @code    = options.delete(:code)  || 200 
         
     | 
| 
      
 7 
     | 
    
         
            +
                    @body    = options.delete(:body)  || ''
         
     | 
| 
      
 8 
     | 
    
         
            +
                    @headers = {'content-type' => 'application/xml'}.merge(options.delete(:headers) || {})
         
     | 
| 
      
 9 
     | 
    
         
            +
                  end
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
                  # For ErrorResponse
         
     | 
| 
      
 12 
     | 
    
         
            +
                  def response
         
     | 
| 
      
 13 
     | 
    
         
            +
                    body
         
     | 
| 
      
 14 
     | 
    
         
            +
                  end
         
     | 
| 
      
 15 
     | 
    
         
            +
                  
         
     | 
| 
      
 16 
     | 
    
         
            +
                  def [](header)
         
     | 
| 
      
 17 
     | 
    
         
            +
                    headers[header]
         
     | 
| 
      
 18 
     | 
    
         
            +
                  end
         
     | 
| 
      
 19 
     | 
    
         
            +
                  
         
     | 
| 
      
 20 
     | 
    
         
            +
                  def each(&block)
         
     | 
| 
      
 21 
     | 
    
         
            +
                    headers.each(&block)
         
     | 
| 
      
 22 
     | 
    
         
            +
                  end
         
     | 
| 
      
 23 
     | 
    
         
            +
                  alias_method :each_header, :each
         
     | 
| 
      
 24 
     | 
    
         
            +
                end
         
     | 
| 
      
 25 
     | 
    
         
            +
              end
         
     | 
| 
      
 26 
     | 
    
         
            +
            end
         
     | 
    
        data/test/object_test.rb
    ADDED
    
    | 
         @@ -0,0 +1,205 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require File.dirname(__FILE__) + '/test_helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            class ObjectTest < Test::Unit::TestCase
         
     | 
| 
      
 4 
     | 
    
         
            +
              def setup
         
     | 
| 
      
 5 
     | 
    
         
            +
                bucket  = Bucket.new(Parsing::XmlParser.new(Fixtures::Buckets.bucket_with_one_key))
         
     | 
| 
      
 6 
     | 
    
         
            +
                @object = bucket.objects.first
         
     | 
| 
      
 7 
     | 
    
         
            +
              end
         
     | 
| 
      
 8 
     | 
    
         
            +
              
         
     | 
| 
      
 9 
     | 
    
         
            +
              def test_header_settings_reader_and_writer
         
     | 
| 
      
 10 
     | 
    
         
            +
                headers = {'content-type' => 'text/plain'}
         
     | 
| 
      
 11 
     | 
    
         
            +
                mock_connection_for(S3Object, :returns => {:headers => headers})
         
     | 
| 
      
 12 
     | 
    
         
            +
                
         
     | 
| 
      
 13 
     | 
    
         
            +
                assert_nothing_raised do
         
     | 
| 
      
 14 
     | 
    
         
            +
                  @object.content_type
         
     | 
| 
      
 15 
     | 
    
         
            +
                end
         
     | 
| 
      
 16 
     | 
    
         
            +
              
         
     | 
| 
      
 17 
     | 
    
         
            +
                assert_equal 'text/plain', @object.content_type
         
     | 
| 
      
 18 
     | 
    
         
            +
              
         
     | 
| 
      
 19 
     | 
    
         
            +
                assert_nothing_raised do
         
     | 
| 
      
 20 
     | 
    
         
            +
                  @object.content_type = 'image/jpg'
         
     | 
| 
      
 21 
     | 
    
         
            +
                end
         
     | 
| 
      
 22 
     | 
    
         
            +
              
         
     | 
| 
      
 23 
     | 
    
         
            +
                assert_equal 'image/jpg', @object.content_type
         
     | 
| 
      
 24 
     | 
    
         
            +
              
         
     | 
| 
      
 25 
     | 
    
         
            +
                assert_raises(NoMethodError) do
         
     | 
| 
      
 26 
     | 
    
         
            +
                  @object.non_existant_header_setting
         
     | 
| 
      
 27 
     | 
    
         
            +
                end
         
     | 
| 
      
 28 
     | 
    
         
            +
              end
         
     | 
| 
      
 29 
     | 
    
         
            +
              
         
     | 
| 
      
 30 
     | 
    
         
            +
              def test_key_name_validation
         
     | 
| 
      
 31 
     | 
    
         
            +
                assert_raises(InvalidKeyName) do
         
     | 
| 
      
 32 
     | 
    
         
            +
                  S3Object.create(nil, '', 'marcel')
         
     | 
| 
      
 33 
     | 
    
         
            +
                end
         
     | 
| 
      
 34 
     | 
    
         
            +
                
         
     | 
| 
      
 35 
     | 
    
         
            +
                assert_raises(InvalidKeyName) do
         
     | 
| 
      
 36 
     | 
    
         
            +
                  huge_name = 'a' * 1500
         
     | 
| 
      
 37 
     | 
    
         
            +
                  S3Object.create(huge_name, '', 'marcel')
         
     | 
| 
      
 38 
     | 
    
         
            +
                end
         
     | 
| 
      
 39 
     | 
    
         
            +
              end
         
     | 
| 
      
 40 
     | 
    
         
            +
              
         
     | 
| 
      
 41 
     | 
    
         
            +
              def test_content_type_inference
         
     | 
| 
      
 42 
     | 
    
         
            +
                [
         
     | 
| 
      
 43 
     | 
    
         
            +
                  ['foo.jpg',  {},                             'image/jpeg'],
         
     | 
| 
      
 44 
     | 
    
         
            +
                  ['foo.txt',  {},                             'text/plain'],
         
     | 
| 
      
 45 
     | 
    
         
            +
                  ['foo',      {},                             nil],
         
     | 
| 
      
 46 
     | 
    
         
            +
                  ['foo.asdf', {},                             nil],
         
     | 
| 
      
 47 
     | 
    
         
            +
                  ['foo.jpg',  {:content_type => nil},         nil],
         
     | 
| 
      
 48 
     | 
    
         
            +
                  ['foo',      {:content_type => 'image/jpg'}, 'image/jpg'],
         
     | 
| 
      
 49 
     | 
    
         
            +
                  ['foo.jpg',  {:content_type => 'image/png'}, 'image/png'],
         
     | 
| 
      
 50 
     | 
    
         
            +
                  ['foo.asdf', {:content_type => 'image/jpg'}, 'image/jpg']
         
     | 
| 
      
 51 
     | 
    
         
            +
                ].each do |key, options, content_type|
         
     | 
| 
      
 52 
     | 
    
         
            +
                  S3Object.send(:infer_content_type!, key, options)
         
     | 
| 
      
 53 
     | 
    
         
            +
                  assert_equal content_type, options[:content_type]
         
     | 
| 
      
 54 
     | 
    
         
            +
                end
         
     | 
| 
      
 55 
     | 
    
         
            +
              end
         
     | 
| 
      
 56 
     | 
    
         
            +
              
         
     | 
| 
      
 57 
     | 
    
         
            +
              def test_object_has_owner
         
     | 
| 
      
 58 
     | 
    
         
            +
                assert_kind_of Owner, @object.owner 
         
     | 
| 
      
 59 
     | 
    
         
            +
              end
         
     | 
| 
      
 60 
     | 
    
         
            +
              
         
     | 
| 
      
 61 
     | 
    
         
            +
              def test_owner_attributes_are_accessible
         
     | 
| 
      
 62 
     | 
    
         
            +
                owner = @object.owner
         
     | 
| 
      
 63 
     | 
    
         
            +
                assert owner.id
         
     | 
| 
      
 64 
     | 
    
         
            +
                assert owner.display_name
         
     | 
| 
      
 65 
     | 
    
         
            +
                assert_equal 'bb2041a25975c3d4ce9775fe9e93e5b77a6a9fad97dc7e00686191f3790b13f1', owner.id
         
     | 
| 
      
 66 
     | 
    
         
            +
                assert_equal 'mmolina@onramp.net', owner.display_name
         
     | 
| 
      
 67 
     | 
    
         
            +
              end
         
     | 
| 
      
 68 
     | 
    
         
            +
              
         
     | 
| 
      
 69 
     | 
    
         
            +
              def test_only_valid_attributes_accessible
         
     | 
| 
      
 70 
     | 
    
         
            +
                assert_raises(NoMethodError) do
         
     | 
| 
      
 71 
     | 
    
         
            +
                  @object.owner.foo
         
     | 
| 
      
 72 
     | 
    
         
            +
                end
         
     | 
| 
      
 73 
     | 
    
         
            +
              end
         
     | 
| 
      
 74 
     | 
    
         
            +
              
         
     | 
| 
      
 75 
     | 
    
         
            +
              def test_fetching_object_value_generates_value_object
         
     | 
| 
      
 76 
     | 
    
         
            +
                mock_connection_for(S3Object, :returns => {:body => 'hello!'})
         
     | 
| 
      
 77 
     | 
    
         
            +
                value = S3Object.value('foo', 'bar')
         
     | 
| 
      
 78 
     | 
    
         
            +
                assert_kind_of S3Object::Value, value
         
     | 
| 
      
 79 
     | 
    
         
            +
                assert_equal 'hello!', value
         
     | 
| 
      
 80 
     | 
    
         
            +
              end
         
     | 
| 
      
 81 
     | 
    
         
            +
              
         
     | 
| 
      
 82 
     | 
    
         
            +
              def test_fetching_file_by_name_raises_when_heuristic_fails
         
     | 
| 
      
 83 
     | 
    
         
            +
                mock_connection_for(Bucket, :returns => {:body => Fixtures::Buckets.bucket_with_one_key})
         
     | 
| 
      
 84 
     | 
    
         
            +
                assert_raises(NoSuchKey) do
         
     | 
| 
      
 85 
     | 
    
         
            +
                  S3Object.find('not_tongue_overload.jpg', 'marcel_molina')
         
     | 
| 
      
 86 
     | 
    
         
            +
                end
         
     | 
| 
      
 87 
     | 
    
         
            +
                
         
     | 
| 
      
 88 
     | 
    
         
            +
                object = nil # Block scoping
         
     | 
| 
      
 89 
     | 
    
         
            +
                assert_nothing_raised do
         
     | 
| 
      
 90 
     | 
    
         
            +
                  object = S3Object.find('tongue_overload.jpg', 'marcel_molina')
         
     | 
| 
      
 91 
     | 
    
         
            +
                end
         
     | 
| 
      
 92 
     | 
    
         
            +
                assert_kind_of S3Object, object
         
     | 
| 
      
 93 
     | 
    
         
            +
                assert_equal 'tongue_overload.jpg', object.key
         
     | 
| 
      
 94 
     | 
    
         
            +
              end
         
     | 
| 
      
 95 
     | 
    
         
            +
              
         
     | 
| 
      
 96 
     | 
    
         
            +
              def test_about
         
     | 
| 
      
 97 
     | 
    
         
            +
                headers = {'content-size' => '12345', 'date' => Time.now.httpdate, 'content-type' => 'application/xml'}
         
     | 
| 
      
 98 
     | 
    
         
            +
                mock_connection_for(S3Object, :returns => [
         
     | 
| 
      
 99 
     | 
    
         
            +
                  {:headers => headers},
         
     | 
| 
      
 100 
     | 
    
         
            +
                  {:code    => 404}
         
     | 
| 
      
 101 
     | 
    
         
            +
                  ]
         
     | 
| 
      
 102 
     | 
    
         
            +
                )
         
     | 
| 
      
 103 
     | 
    
         
            +
                about = S3Object.about('foo', 'bar')
         
     | 
| 
      
 104 
     | 
    
         
            +
                assert_kind_of S3Object::About, about
         
     | 
| 
      
 105 
     | 
    
         
            +
                assert_equal headers, about
         
     | 
| 
      
 106 
     | 
    
         
            +
                
         
     | 
| 
      
 107 
     | 
    
         
            +
                assert_raises(NoSuchKey) do
         
     | 
| 
      
 108 
     | 
    
         
            +
                  S3Object.about('foo', 'bar')
         
     | 
| 
      
 109 
     | 
    
         
            +
                end
         
     | 
| 
      
 110 
     | 
    
         
            +
              end
         
     | 
| 
      
 111 
     | 
    
         
            +
              
         
     | 
| 
      
 112 
     | 
    
         
            +
              def test_can_tell_that_an_s3object_does_not_exist
         
     | 
| 
      
 113 
     | 
    
         
            +
                mock_connection_for(S3Object, :returns => {:code => 404})
         
     | 
| 
      
 114 
     | 
    
         
            +
                assert_equal false, S3Object.exists?('foo', 'bar')
         
     | 
| 
      
 115 
     | 
    
         
            +
              end
         
     | 
| 
      
 116 
     | 
    
         
            +
              
         
     | 
| 
      
 117 
     | 
    
         
            +
              def test_can_tell_that_an_s3object_exists
         
     | 
| 
      
 118 
     | 
    
         
            +
                mock_connection_for(S3Object, :returns => {:code => 200})
         
     | 
| 
      
 119 
     | 
    
         
            +
                assert_equal true, S3Object.exists?('foo', 'bar')
         
     | 
| 
      
 120 
     | 
    
         
            +
              end
         
     | 
| 
      
 121 
     | 
    
         
            +
              
         
     | 
| 
      
 122 
     | 
    
         
            +
              def test_s3object_equality
         
     | 
| 
      
 123 
     | 
    
         
            +
                mock_connection_for(Bucket, :returns => {:body => Fixtures::Buckets.bucket_with_more_than_one_key})
         
     | 
| 
      
 124 
     | 
    
         
            +
                file1, file2 = Bucket.objects('does not matter')
         
     | 
| 
      
 125 
     | 
    
         
            +
                assert file1 == file1
         
     | 
| 
      
 126 
     | 
    
         
            +
                assert file2 == file2
         
     | 
| 
      
 127 
     | 
    
         
            +
                assert !(file1 == file2) # /!\ Parens required /!\
         
     | 
| 
      
 128 
     | 
    
         
            +
              end
         
     | 
| 
      
 129 
     | 
    
         
            +
              
         
     | 
| 
      
 130 
     | 
    
         
            +
              def test_inspect
         
     | 
| 
      
 131 
     | 
    
         
            +
                mock_connection_for(Bucket, :returns => {:body => Fixtures::Buckets.bucket_with_one_key})
         
     | 
| 
      
 132 
     | 
    
         
            +
                object = S3Object.find('tongue_overload.jpg', 'bucket does not matter')
         
     | 
| 
      
 133 
     | 
    
         
            +
                assert object.path
         
     | 
| 
      
 134 
     | 
    
         
            +
                assert_nothing_raised { object.inspect }
         
     | 
| 
      
 135 
     | 
    
         
            +
                assert object.inspect[object.path]
         
     | 
| 
      
 136 
     | 
    
         
            +
              end
         
     | 
| 
      
 137 
     | 
    
         
            +
             
         
     | 
| 
      
 138 
     | 
    
         
            +
              def test_etag
         
     | 
| 
      
 139 
     | 
    
         
            +
                mock_connection_for(Bucket, :returns => {:body => Fixtures::Buckets.bucket_with_one_key})
         
     | 
| 
      
 140 
     | 
    
         
            +
                file = S3Object.find('tongue_overload.jpg', 'bucket does not matter')
         
     | 
| 
      
 141 
     | 
    
         
            +
                assert file.etag
         
     | 
| 
      
 142 
     | 
    
         
            +
                assert_equal 'f21f7c4e8ea6e34b268887b07d6da745', file.etag
         
     | 
| 
      
 143 
     | 
    
         
            +
              end
         
     | 
| 
      
 144 
     | 
    
         
            +
             
         
     | 
| 
      
 145 
     | 
    
         
            +
              def test_fetching_information_about_an_object_that_does_not_exist_raises_no_such_key
         
     | 
| 
      
 146 
     | 
    
         
            +
                mock_connection_for(S3Object, :returns => {:body => '', :code => 404})
         
     | 
| 
      
 147 
     | 
    
         
            +
                assert_raises(NoSuchKey) do
         
     | 
| 
      
 148 
     | 
    
         
            +
                  S3Object.about('asdfasdfasdfas-this-does-not-exist', 'bucket does not matter')
         
     | 
| 
      
 149 
     | 
    
         
            +
                end
         
     | 
| 
      
 150 
     | 
    
         
            +
              end
         
     | 
| 
      
 151 
     | 
    
         
            +
            end
         
     | 
| 
      
 152 
     | 
    
         
            +
             
     | 
| 
      
 153 
     | 
    
         
            +
            class MetadataTest < Test::Unit::TestCase
         
     | 
| 
      
 154 
     | 
    
         
            +
              def setup
         
     | 
| 
      
 155 
     | 
    
         
            +
                @metadata = S3Object::Metadata.new(Fixtures::Headers.headers_including_one_piece_of_metadata)
         
     | 
| 
      
 156 
     | 
    
         
            +
              end
         
     | 
| 
      
 157 
     | 
    
         
            +
                
         
     | 
| 
      
 158 
     | 
    
         
            +
              def test_only_metadata_is_extracted
         
     | 
| 
      
 159 
     | 
    
         
            +
                assert @metadata.to_headers.size == 1
         
     | 
| 
      
 160 
     | 
    
         
            +
                assert @metadata.to_headers['x-amz-meta-test']
         
     | 
| 
      
 161 
     | 
    
         
            +
                assert_equal 'foo', @metadata.to_headers['x-amz-meta-test']
         
     | 
| 
      
 162 
     | 
    
         
            +
              end
         
     | 
| 
      
 163 
     | 
    
         
            +
              
         
     | 
| 
      
 164 
     | 
    
         
            +
              def test_setting_new_metadata_normalizes_name
         
     | 
| 
      
 165 
     | 
    
         
            +
                @metadata[:bar] = 'baz'
         
     | 
| 
      
 166 
     | 
    
         
            +
                assert @metadata.to_headers.include?('x-amz-meta-bar')
         
     | 
| 
      
 167 
     | 
    
         
            +
                @metadata['baz'] = 'quux'
         
     | 
| 
      
 168 
     | 
    
         
            +
                assert @metadata.to_headers.include?('x-amz-meta-baz')
         
     | 
| 
      
 169 
     | 
    
         
            +
                @metadata['x-amz-meta-quux'] = 'whatever'
         
     | 
| 
      
 170 
     | 
    
         
            +
                assert @metadata.to_headers.include?('x-amz-meta-quux')
         
     | 
| 
      
 171 
     | 
    
         
            +
              end
         
     | 
| 
      
 172 
     | 
    
         
            +
              
         
     | 
| 
      
 173 
     | 
    
         
            +
              def test_clobbering_existing_header
         
     | 
| 
      
 174 
     | 
    
         
            +
                @metadata[:bar] = 'baz'
         
     | 
| 
      
 175 
     | 
    
         
            +
                assert_equal 'baz', @metadata.to_headers['x-amz-meta-bar']
         
     | 
| 
      
 176 
     | 
    
         
            +
                @metadata[:bar] = 'quux'
         
     | 
| 
      
 177 
     | 
    
         
            +
                assert_equal 'quux', @metadata.to_headers['x-amz-meta-bar']
         
     | 
| 
      
 178 
     | 
    
         
            +
                @metadata['bar'] = 'foo'
         
     | 
| 
      
 179 
     | 
    
         
            +
                assert_equal 'foo', @metadata.to_headers['x-amz-meta-bar']
         
     | 
| 
      
 180 
     | 
    
         
            +
                @metadata['x-amz-meta-bar'] = 'bar'
         
     | 
| 
      
 181 
     | 
    
         
            +
                assert_equal 'bar', @metadata.to_headers['x-amz-meta-bar']
         
     | 
| 
      
 182 
     | 
    
         
            +
              end
         
     | 
| 
      
 183 
     | 
    
         
            +
              
         
     | 
| 
      
 184 
     | 
    
         
            +
              def test_invalid_metadata
         
     | 
| 
      
 185 
     | 
    
         
            +
                @metadata[:invalid_header] = ' ' * (S3Object::Metadata::SIZE_LIMIT + 1)
         
     | 
| 
      
 186 
     | 
    
         
            +
                assert_raises InvalidMetadataValue do
         
     | 
| 
      
 187 
     | 
    
         
            +
                  @metadata.to_headers
         
     | 
| 
      
 188 
     | 
    
         
            +
                end
         
     | 
| 
      
 189 
     | 
    
         
            +
              end
         
     | 
| 
      
 190 
     | 
    
         
            +
            end
         
     | 
| 
      
 191 
     | 
    
         
            +
             
     | 
| 
      
 192 
     | 
    
         
            +
            class ValueTest < Test::Unit::TestCase
         
     | 
| 
      
 193 
     | 
    
         
            +
              def setup
         
     | 
| 
      
 194 
     | 
    
         
            +
                @response = FakeResponse.new(:body => 'hello there')
         
     | 
| 
      
 195 
     | 
    
         
            +
                @value    = S3Object::Value.new(@response)
         
     | 
| 
      
 196 
     | 
    
         
            +
              end
         
     | 
| 
      
 197 
     | 
    
         
            +
              
         
     | 
| 
      
 198 
     | 
    
         
            +
              def test_value_is_set_to_response_body
         
     | 
| 
      
 199 
     | 
    
         
            +
                assert_equal @response.body, @value
         
     | 
| 
      
 200 
     | 
    
         
            +
              end
         
     | 
| 
      
 201 
     | 
    
         
            +
              
         
     | 
| 
      
 202 
     | 
    
         
            +
              def test_response_is_accessible_from_value_object
         
     | 
| 
      
 203 
     | 
    
         
            +
                assert_equal @response, @value.response
         
     | 
| 
      
 204 
     | 
    
         
            +
              end
         
     | 
| 
      
 205 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,66 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require File.dirname(__FILE__) + '/test_helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            class TypecastingTest < Test::Unit::TestCase
         
     | 
| 
      
 4 
     | 
    
         
            +
              # Make it easier to call methods in tests
         
     | 
| 
      
 5 
     | 
    
         
            +
              Parsing::Typecasting.public_instance_methods.each do |method|
         
     | 
| 
      
 6 
     | 
    
         
            +
                Parsing::Typecasting.send(:module_function, method)
         
     | 
| 
      
 7 
     | 
    
         
            +
              end
         
     | 
| 
      
 8 
     | 
    
         
            +
              
         
     | 
| 
      
 9 
     | 
    
         
            +
              def test_array_with_one_element_that_is_a_hash
         
     | 
| 
      
 10 
     | 
    
         
            +
                value = [{'Available' => 'true'}]
         
     | 
| 
      
 11 
     | 
    
         
            +
                assert_equal [{'available' => true}], Parsing::Typecasting.typecast(value)
         
     | 
| 
      
 12 
     | 
    
         
            +
              end
         
     | 
| 
      
 13 
     | 
    
         
            +
              
         
     | 
| 
      
 14 
     | 
    
         
            +
              def test_hash_with_one_key_whose_value_is_an_array
         
     | 
| 
      
 15 
     | 
    
         
            +
                value = {
         
     | 
| 
      
 16 
     | 
    
         
            +
                  'Bucket' => 
         
     | 
| 
      
 17 
     | 
    
         
            +
                    [ 
         
     | 
| 
      
 18 
     | 
    
         
            +
                      {'Available' => 'true'} 
         
     | 
| 
      
 19 
     | 
    
         
            +
                    ] 
         
     | 
| 
      
 20 
     | 
    
         
            +
                }
         
     | 
| 
      
 21 
     | 
    
         
            +
                
         
     | 
| 
      
 22 
     | 
    
         
            +
                expected = {
         
     | 
| 
      
 23 
     | 
    
         
            +
                  'bucket' => 
         
     | 
| 
      
 24 
     | 
    
         
            +
                    [
         
     | 
| 
      
 25 
     | 
    
         
            +
                      {'available' => true}
         
     | 
| 
      
 26 
     | 
    
         
            +
                    ]
         
     | 
| 
      
 27 
     | 
    
         
            +
                }
         
     | 
| 
      
 28 
     | 
    
         
            +
                assert_equal expected, Parsing::Typecasting.typecast(value)
         
     | 
| 
      
 29 
     | 
    
         
            +
              end
         
     | 
| 
      
 30 
     | 
    
         
            +
              
         
     | 
| 
      
 31 
     | 
    
         
            +
            end
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
            class XmlParserTest < Test::Unit::TestCase
         
     | 
| 
      
 34 
     | 
    
         
            +
              def test_bucket_is_always_forced_to_be_an_array_unless_empty
         
     | 
| 
      
 35 
     | 
    
         
            +
                one_bucket    = Parsing::XmlParser.new(Fixtures::Buckets.bucket_list_with_one_bucket)
         
     | 
| 
      
 36 
     | 
    
         
            +
                more_than_one = Parsing::XmlParser.new(Fixtures::Buckets.bucket_list_with_more_than_one_bucket)
         
     | 
| 
      
 37 
     | 
    
         
            +
                
         
     | 
| 
      
 38 
     | 
    
         
            +
                [one_bucket, more_than_one].each do |bucket_list|
         
     | 
| 
      
 39 
     | 
    
         
            +
                  assert_kind_of Array, bucket_list['buckets']['bucket']
         
     | 
| 
      
 40 
     | 
    
         
            +
                end
         
     | 
| 
      
 41 
     | 
    
         
            +
                
         
     | 
| 
      
 42 
     | 
    
         
            +
                no_buckets    = Parsing::XmlParser.new(Fixtures::Buckets.empty_bucket_list)
         
     | 
| 
      
 43 
     | 
    
         
            +
                assert no_buckets.has_key?('buckets')
         
     | 
| 
      
 44 
     | 
    
         
            +
                assert_nil no_buckets['buckets']
         
     | 
| 
      
 45 
     | 
    
         
            +
              end
         
     | 
| 
      
 46 
     | 
    
         
            +
              
         
     | 
| 
      
 47 
     | 
    
         
            +
              def test_bucket_contents_are_forced_to_be_an_array_unless_empty
         
     | 
| 
      
 48 
     | 
    
         
            +
                one_key       = Parsing::XmlParser.new(Fixtures::Buckets.bucket_with_one_key)
         
     | 
| 
      
 49 
     | 
    
         
            +
                more_than_one = Parsing::XmlParser.new(Fixtures::Buckets.bucket_with_more_than_one_key)
         
     | 
| 
      
 50 
     | 
    
         
            +
                [one_key, more_than_one].each do |bucket_with_contents|
         
     | 
| 
      
 51 
     | 
    
         
            +
                  assert_kind_of Array, bucket_with_contents['contents']
         
     | 
| 
      
 52 
     | 
    
         
            +
                end
         
     | 
| 
      
 53 
     | 
    
         
            +
                
         
     | 
| 
      
 54 
     | 
    
         
            +
                no_keys = Parsing::XmlParser.new(Fixtures::Buckets.empty_bucket)
         
     | 
| 
      
 55 
     | 
    
         
            +
                assert !no_keys.has_key?('contents')
         
     | 
| 
      
 56 
     | 
    
         
            +
              end
         
     | 
| 
      
 57 
     | 
    
         
            +
              
         
     | 
| 
      
 58 
     | 
    
         
            +
              def test_policy_grants_are_always_an_array
         
     | 
| 
      
 59 
     | 
    
         
            +
                policy = Parsing::XmlParser.new(Fixtures::Policies.policy_with_one_grant)
         
     | 
| 
      
 60 
     | 
    
         
            +
                assert_kind_of Array, policy['access_control_list']['grant']
         
     | 
| 
      
 61 
     | 
    
         
            +
              end
         
     | 
| 
      
 62 
     | 
    
         
            +
              
         
     | 
| 
      
 63 
     | 
    
         
            +
              def test_empty_xml_response_is_not_parsed
         
     | 
| 
      
 64 
     | 
    
         
            +
                assert_equal({}, Parsing::XmlParser.new(''))
         
     | 
| 
      
 65 
     | 
    
         
            +
              end
         
     | 
| 
      
 66 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,117 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require File.dirname(__FILE__) + '/test_helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            class RemoteACLTest < Test::Unit::TestCase
         
     | 
| 
      
 4 
     | 
    
         
            +
              
         
     | 
| 
      
 5 
     | 
    
         
            +
              def setup
         
     | 
| 
      
 6 
     | 
    
         
            +
                establish_real_connection
         
     | 
| 
      
 7 
     | 
    
         
            +
              end
         
     | 
| 
      
 8 
     | 
    
         
            +
              
         
     | 
| 
      
 9 
     | 
    
         
            +
              def teardown
         
     | 
| 
      
 10 
     | 
    
         
            +
                disconnect!
         
     | 
| 
      
 11 
     | 
    
         
            +
              end
         
     | 
| 
      
 12 
     | 
    
         
            +
              
         
     | 
| 
      
 13 
     | 
    
         
            +
              def test_acl
         
     | 
| 
      
 14 
     | 
    
         
            +
                Bucket.create(TEST_BUCKET) # Wipe out the existing bucket's ACL
         
     | 
| 
      
 15 
     | 
    
         
            +
                  
         
     | 
| 
      
 16 
     | 
    
         
            +
                bucket_policy = Bucket.acl(TEST_BUCKET)
         
     | 
| 
      
 17 
     | 
    
         
            +
                assert_equal 1, bucket_policy.grants.size
         
     | 
| 
      
 18 
     | 
    
         
            +
                assert !bucket_policy.grants.include?(:public_read_acp)
         
     | 
| 
      
 19 
     | 
    
         
            +
                
         
     | 
| 
      
 20 
     | 
    
         
            +
                bucket_policy.grants << ACL::Grant.grant(:public_read_acp)
         
     | 
| 
      
 21 
     | 
    
         
            +
                
         
     | 
| 
      
 22 
     | 
    
         
            +
                assert_nothing_raised do
         
     | 
| 
      
 23 
     | 
    
         
            +
                  Bucket.acl(TEST_BUCKET, bucket_policy)
         
     | 
| 
      
 24 
     | 
    
         
            +
                end
         
     | 
| 
      
 25 
     | 
    
         
            +
                
         
     | 
| 
      
 26 
     | 
    
         
            +
                bucket = Bucket.find(TEST_BUCKET)
         
     | 
| 
      
 27 
     | 
    
         
            +
                assert bucket.acl.grants.include?(:public_read_acp)
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
                bucket.acl.grants.pop # Get rid of the newly added grant
         
     | 
| 
      
 30 
     | 
    
         
            +
                
         
     | 
| 
      
 31 
     | 
    
         
            +
                assert !bucket.acl.grants.include?(:public_read_acp)
         
     | 
| 
      
 32 
     | 
    
         
            +
                bucket.acl(bucket.acl) # Update its acl
         
     | 
| 
      
 33 
     | 
    
         
            +
                assert Service.response.success?
         
     | 
| 
      
 34 
     | 
    
         
            +
                
         
     | 
| 
      
 35 
     | 
    
         
            +
                bucket_policy = Bucket.acl(TEST_BUCKET)
         
     | 
| 
      
 36 
     | 
    
         
            +
                assert_equal 1, bucket_policy.grants.size
         
     | 
| 
      
 37 
     | 
    
         
            +
                assert !bucket_policy.grants.include?(:public_read_acp)
         
     | 
| 
      
 38 
     | 
    
         
            +
                
         
     | 
| 
      
 39 
     | 
    
         
            +
                S3Object.store('testing-acls', 'the test data', TEST_BUCKET, :content_type => 'text/plain')
         
     | 
| 
      
 40 
     | 
    
         
            +
                acl = S3Object.acl('testing-acls', TEST_BUCKET)
         
     | 
| 
      
 41 
     | 
    
         
            +
                
         
     | 
| 
      
 42 
     | 
    
         
            +
                # Confirm object has the default policy 
         
     | 
| 
      
 43 
     | 
    
         
            +
                
         
     | 
| 
      
 44 
     | 
    
         
            +
                assert !acl.grants.empty?
         
     | 
| 
      
 45 
     | 
    
         
            +
                assert_equal 1, acl.grants.size
         
     | 
| 
      
 46 
     | 
    
         
            +
                grant = acl.grants.first
         
     | 
| 
      
 47 
     | 
    
         
            +
                
         
     | 
| 
      
 48 
     | 
    
         
            +
                assert_equal 'FULL_CONTROL', grant.permission
         
     | 
| 
      
 49 
     | 
    
         
            +
                
         
     | 
| 
      
 50 
     | 
    
         
            +
                grantee = grant.grantee
         
     | 
| 
      
 51 
     | 
    
         
            +
                
         
     | 
| 
      
 52 
     | 
    
         
            +
                assert acl.owner.id
         
     | 
| 
      
 53 
     | 
    
         
            +
                assert acl.owner.display_name
         
     | 
| 
      
 54 
     | 
    
         
            +
                assert grantee.id
         
     | 
| 
      
 55 
     | 
    
         
            +
                assert grantee.display_name
         
     | 
| 
      
 56 
     | 
    
         
            +
                
         
     | 
| 
      
 57 
     | 
    
         
            +
                assert_equal acl.owner.id, grantee.id
         
     | 
| 
      
 58 
     | 
    
         
            +
                assert_equal acl.owner.display_name, grantee.display_name
         
     | 
| 
      
 59 
     | 
    
         
            +
                
         
     | 
| 
      
 60 
     | 
    
         
            +
                assert_equal Owner.current, acl.owner
         
     | 
| 
      
 61 
     | 
    
         
            +
                
         
     | 
| 
      
 62 
     | 
    
         
            +
                
         
     | 
| 
      
 63 
     | 
    
         
            +
                # Manually add read access to an Amazon customer by email address
         
     | 
| 
      
 64 
     | 
    
         
            +
                
         
     | 
| 
      
 65 
     | 
    
         
            +
                new_grant                       = ACL::Grant.new
         
     | 
| 
      
 66 
     | 
    
         
            +
                new_grant.permission            = 'READ'
         
     | 
| 
      
 67 
     | 
    
         
            +
                new_grant_grantee               = ACL::Grantee.new
         
     | 
| 
      
 68 
     | 
    
         
            +
                new_grant_grantee.email_address = 'marcel@vernix.org'
         
     | 
| 
      
 69 
     | 
    
         
            +
                new_grant.grantee = new_grant_grantee
         
     | 
| 
      
 70 
     | 
    
         
            +
                acl.grants << new_grant
         
     | 
| 
      
 71 
     | 
    
         
            +
                
         
     | 
| 
      
 72 
     | 
    
         
            +
                assert_nothing_raised do
         
     | 
| 
      
 73 
     | 
    
         
            +
                  S3Object.acl('testing-acls', TEST_BUCKET, acl)
         
     | 
| 
      
 74 
     | 
    
         
            +
                end
         
     | 
| 
      
 75 
     | 
    
         
            +
                
         
     | 
| 
      
 76 
     | 
    
         
            +
                # Confirm the acl was updated successfully
         
     | 
| 
      
 77 
     | 
    
         
            +
                
         
     | 
| 
      
 78 
     | 
    
         
            +
                assert Service.response.success?
         
     | 
| 
      
 79 
     | 
    
         
            +
                
         
     | 
| 
      
 80 
     | 
    
         
            +
                acl = S3Object.acl('testing-acls', TEST_BUCKET)
         
     | 
| 
      
 81 
     | 
    
         
            +
                assert !acl.grants.empty?
         
     | 
| 
      
 82 
     | 
    
         
            +
                assert_equal 2, acl.grants.size
         
     | 
| 
      
 83 
     | 
    
         
            +
                new_grant = acl.grants.last
         
     | 
| 
      
 84 
     | 
    
         
            +
                assert_equal 'READ', new_grant.permission
         
     | 
| 
      
 85 
     | 
    
         
            +
                
         
     | 
| 
      
 86 
     | 
    
         
            +
                # Confirm instance method has same result
         
     | 
| 
      
 87 
     | 
    
         
            +
                
         
     | 
| 
      
 88 
     | 
    
         
            +
                assert_equal acl.grants, S3Object.find('testing-acls', TEST_BUCKET).acl.grants
         
     | 
| 
      
 89 
     | 
    
         
            +
                
         
     | 
| 
      
 90 
     | 
    
         
            +
                # Get rid of the grant we just added
         
     | 
| 
      
 91 
     | 
    
         
            +
                
         
     | 
| 
      
 92 
     | 
    
         
            +
                acl.grants.pop
         
     | 
| 
      
 93 
     | 
    
         
            +
                
         
     | 
| 
      
 94 
     | 
    
         
            +
                # Confirm acl class method sees that the bucket option is being used to put a new acl
         
     | 
| 
      
 95 
     | 
    
         
            +
                
         
     | 
| 
      
 96 
     | 
    
         
            +
                assert_nothing_raised do
         
     | 
| 
      
 97 
     | 
    
         
            +
                  TestS3Object.acl('testing-acls', acl)
         
     | 
| 
      
 98 
     | 
    
         
            +
                end
         
     | 
| 
      
 99 
     | 
    
         
            +
                
         
     | 
| 
      
 100 
     | 
    
         
            +
                assert Service.response.success?
         
     | 
| 
      
 101 
     | 
    
         
            +
                
         
     | 
| 
      
 102 
     | 
    
         
            +
                acl = TestS3Object.acl('testing-acls')
         
     | 
| 
      
 103 
     | 
    
         
            +
                
         
     | 
| 
      
 104 
     | 
    
         
            +
                # Confirm added grant was removed from the policy
         
     | 
| 
      
 105 
     | 
    
         
            +
                
         
     | 
| 
      
 106 
     | 
    
         
            +
                assert !acl.grants.empty?
         
     | 
| 
      
 107 
     | 
    
         
            +
                assert_equal 1, acl.grants.size
         
     | 
| 
      
 108 
     | 
    
         
            +
                grant = acl.grants.first
         
     | 
| 
      
 109 
     | 
    
         
            +
                assert_equal 'FULL_CONTROL', grant.permission
         
     | 
| 
      
 110 
     | 
    
         
            +
                
         
     | 
| 
      
 111 
     | 
    
         
            +
                assert_nothing_raised do
         
     | 
| 
      
 112 
     | 
    
         
            +
                  S3Object.delete('testing-acls', TEST_BUCKET)
         
     | 
| 
      
 113 
     | 
    
         
            +
                end
         
     | 
| 
      
 114 
     | 
    
         
            +
                
         
     | 
| 
      
 115 
     | 
    
         
            +
                assert Service.response.success?
         
     | 
| 
      
 116 
     | 
    
         
            +
              end
         
     | 
| 
      
 117 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,45 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require File.dirname(__FILE__) + '/test_helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            class RemoteBittorrentTest < Test::Unit::TestCase
         
     | 
| 
      
 4 
     | 
    
         
            +
              def setup
         
     | 
| 
      
 5 
     | 
    
         
            +
                establish_real_connection
         
     | 
| 
      
 6 
     | 
    
         
            +
              end
         
     | 
| 
      
 7 
     | 
    
         
            +
              
         
     | 
| 
      
 8 
     | 
    
         
            +
              def teardown
         
     | 
| 
      
 9 
     | 
    
         
            +
                disconnect!
         
     | 
| 
      
 10 
     | 
    
         
            +
              end
         
     | 
| 
      
 11 
     | 
    
         
            +
              
         
     | 
| 
      
 12 
     | 
    
         
            +
              def test_bittorrent
         
     | 
| 
      
 13 
     | 
    
         
            +
                bt_test_key = 'testing-bittorrent'
         
     | 
| 
      
 14 
     | 
    
         
            +
                S3Object.create(bt_test_key, 'foo', TEST_BUCKET)
         
     | 
| 
      
 15 
     | 
    
         
            +
                
         
     | 
| 
      
 16 
     | 
    
         
            +
                # Confirm we can fetch a bittorrent file for this object
         
     | 
| 
      
 17 
     | 
    
         
            +
                
         
     | 
| 
      
 18 
     | 
    
         
            +
                torrent_file = nil
         
     | 
| 
      
 19 
     | 
    
         
            +
                assert_nothing_raised do
         
     | 
| 
      
 20 
     | 
    
         
            +
                  torrent_file = S3Object.torrent_for(bt_test_key, TEST_BUCKET)
         
     | 
| 
      
 21 
     | 
    
         
            +
                end
         
     | 
| 
      
 22 
     | 
    
         
            +
                assert torrent_file
         
     | 
| 
      
 23 
     | 
    
         
            +
                assert torrent_file['tracker']
         
     | 
| 
      
 24 
     | 
    
         
            +
                
         
     | 
| 
      
 25 
     | 
    
         
            +
                # Make object accessible to the public via a torrent
         
     | 
| 
      
 26 
     | 
    
         
            +
                
         
     | 
| 
      
 27 
     | 
    
         
            +
                policy = S3Object.acl(bt_test_key, TEST_BUCKET)
         
     | 
| 
      
 28 
     | 
    
         
            +
                
         
     | 
| 
      
 29 
     | 
    
         
            +
                assert !policy.grants.include?(:public_read)
         
     | 
| 
      
 30 
     | 
    
         
            +
                
         
     | 
| 
      
 31 
     | 
    
         
            +
                assert_nothing_raised do
         
     | 
| 
      
 32 
     | 
    
         
            +
                  S3Object.grant_torrent_access_to(bt_test_key, TEST_BUCKET)
         
     | 
| 
      
 33 
     | 
    
         
            +
                end
         
     | 
| 
      
 34 
     | 
    
         
            +
                
         
     | 
| 
      
 35 
     | 
    
         
            +
                policy = S3Object.acl(bt_test_key, TEST_BUCKET)
         
     | 
| 
      
 36 
     | 
    
         
            +
                
         
     | 
| 
      
 37 
     | 
    
         
            +
                assert policy.grants.include?(:public_read)
         
     | 
| 
      
 38 
     | 
    
         
            +
                
         
     | 
| 
      
 39 
     | 
    
         
            +
                # Confirm instance method wraps class method
         
     | 
| 
      
 40 
     | 
    
         
            +
                
         
     | 
| 
      
 41 
     | 
    
         
            +
                assert_equal torrent_file, S3Object.find(bt_test_key, TEST_BUCKET).torrent 
         
     | 
| 
      
 42 
     | 
    
         
            +
                
         
     | 
| 
      
 43 
     | 
    
         
            +
                S3Object.delete(bt_test_key, TEST_BUCKET)
         
     | 
| 
      
 44 
     | 
    
         
            +
              end
         
     | 
| 
      
 45 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,146 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require File.dirname(__FILE__) + '/test_helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            class RemoteBucketTest < Test::Unit::TestCase
         
     | 
| 
      
 4 
     | 
    
         
            +
              
         
     | 
| 
      
 5 
     | 
    
         
            +
              def setup
         
     | 
| 
      
 6 
     | 
    
         
            +
                establish_real_connection
         
     | 
| 
      
 7 
     | 
    
         
            +
                assert Bucket.find(TEST_BUCKET).delete_all
         
     | 
| 
      
 8 
     | 
    
         
            +
              end
         
     | 
| 
      
 9 
     | 
    
         
            +
              
         
     | 
| 
      
 10 
     | 
    
         
            +
              def teardown
         
     | 
| 
      
 11 
     | 
    
         
            +
                disconnect!
         
     | 
| 
      
 12 
     | 
    
         
            +
              end
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
              def test_bucket
         
     | 
| 
      
 15 
     | 
    
         
            +
                # Fetch the testing bucket
         
     | 
| 
      
 16 
     | 
    
         
            +
                
         
     | 
| 
      
 17 
     | 
    
         
            +
                bucket = nil
         
     | 
| 
      
 18 
     | 
    
         
            +
                assert_nothing_raised do
         
     | 
| 
      
 19 
     | 
    
         
            +
                  bucket = Bucket.find(TEST_BUCKET)
         
     | 
| 
      
 20 
     | 
    
         
            +
                end
         
     | 
| 
      
 21 
     | 
    
         
            +
                
         
     | 
| 
      
 22 
     | 
    
         
            +
                assert bucket
         
     | 
| 
      
 23 
     | 
    
         
            +
                
         
     | 
| 
      
 24 
     | 
    
         
            +
                # Confirm we can fetch the bucket implicitly
         
     | 
| 
      
 25 
     | 
    
         
            +
                
         
     | 
| 
      
 26 
     | 
    
         
            +
                bucket = nil
         
     | 
| 
      
 27 
     | 
    
         
            +
                assert_nothing_raised do
         
     | 
| 
      
 28 
     | 
    
         
            +
                  bucket = TestBucket.find
         
     | 
| 
      
 29 
     | 
    
         
            +
                end
         
     | 
| 
      
 30 
     | 
    
         
            +
                
         
     | 
| 
      
 31 
     | 
    
         
            +
                assert bucket
         
     | 
| 
      
 32 
     | 
    
         
            +
                
         
     | 
| 
      
 33 
     | 
    
         
            +
                # Confirm the bucket has the right name
         
     | 
| 
      
 34 
     | 
    
         
            +
                
         
     | 
| 
      
 35 
     | 
    
         
            +
                assert_equal TEST_BUCKET, bucket.name
         
     | 
| 
      
 36 
     | 
    
         
            +
                
         
     | 
| 
      
 37 
     | 
    
         
            +
                assert bucket.empty?
         
     | 
| 
      
 38 
     | 
    
         
            +
                assert_equal 0, bucket.size
         
     | 
| 
      
 39 
     | 
    
         
            +
                
         
     | 
| 
      
 40 
     | 
    
         
            +
                # Add some files to the bucket
         
     | 
| 
      
 41 
     | 
    
         
            +
                
         
     | 
| 
      
 42 
     | 
    
         
            +
                assert_nothing_raised do
         
     | 
| 
      
 43 
     | 
    
         
            +
                  %w(a m z).each do |file_name|
         
     | 
| 
      
 44 
     | 
    
         
            +
                    S3Object.create(file_name, file_name, bucket.name, :content_type => 'text/plain')
         
     | 
| 
      
 45 
     | 
    
         
            +
                  end
         
     | 
| 
      
 46 
     | 
    
         
            +
                end
         
     | 
| 
      
 47 
     | 
    
         
            +
                
         
     | 
| 
      
 48 
     | 
    
         
            +
                # Confirm that we can reload the objects
         
     | 
| 
      
 49 
     | 
    
         
            +
                
         
     | 
| 
      
 50 
     | 
    
         
            +
                assert_nothing_raised do
         
     | 
| 
      
 51 
     | 
    
         
            +
                  bucket.objects(:reload)
         
     | 
| 
      
 52 
     | 
    
         
            +
                end
         
     | 
| 
      
 53 
     | 
    
         
            +
                
         
     | 
| 
      
 54 
     | 
    
         
            +
                assert !bucket.empty?
         
     | 
| 
      
 55 
     | 
    
         
            +
                assert_equal 3, bucket.size
         
     | 
| 
      
 56 
     | 
    
         
            +
                
         
     | 
| 
      
 57 
     | 
    
         
            +
                assert_nothing_raised do
         
     | 
| 
      
 58 
     | 
    
         
            +
                  bucket.objects(:marker => 'm')
         
     | 
| 
      
 59 
     | 
    
         
            +
                end
         
     | 
| 
      
 60 
     | 
    
         
            +
             
     | 
| 
      
 61 
     | 
    
         
            +
                assert_equal 1, bucket.size
         
     | 
| 
      
 62 
     | 
    
         
            +
                assert bucket['z']
         
     | 
| 
      
 63 
     | 
    
         
            +
                
         
     | 
| 
      
 64 
     | 
    
         
            +
                assert_equal 1, Bucket.find(TEST_BUCKET, :max_keys => 1).size
         
     | 
| 
      
 65 
     | 
    
         
            +
                
         
     | 
| 
      
 66 
     | 
    
         
            +
                assert_nothing_raised do
         
     | 
| 
      
 67 
     | 
    
         
            +
                  bucket.objects(:reload)
         
     | 
| 
      
 68 
     | 
    
         
            +
                end
         
     | 
| 
      
 69 
     | 
    
         
            +
                
         
     | 
| 
      
 70 
     | 
    
         
            +
                assert_equal 3, bucket.size
         
     | 
| 
      
 71 
     | 
    
         
            +
                
         
     | 
| 
      
 72 
     | 
    
         
            +
                # Ensure the reloaded buckets have been repatriated
         
     | 
| 
      
 73 
     | 
    
         
            +
                
         
     | 
| 
      
 74 
     | 
    
         
            +
                assert_equal bucket, bucket.objects.first.bucket
         
     | 
| 
      
 75 
     | 
    
         
            +
                
         
     | 
| 
      
 76 
     | 
    
         
            +
                # Confirm that we can delete one of the objects and it will be removed
         
     | 
| 
      
 77 
     | 
    
         
            +
                
         
     | 
| 
      
 78 
     | 
    
         
            +
                object_to_be_deleted = bucket.objects.last
         
     | 
| 
      
 79 
     | 
    
         
            +
                assert_nothing_raised do
         
     | 
| 
      
 80 
     | 
    
         
            +
                  object_to_be_deleted.delete
         
     | 
| 
      
 81 
     | 
    
         
            +
                end
         
     | 
| 
      
 82 
     | 
    
         
            +
                
         
     | 
| 
      
 83 
     | 
    
         
            +
                assert !bucket.objects.include?(object_to_be_deleted)
         
     | 
| 
      
 84 
     | 
    
         
            +
                
         
     | 
| 
      
 85 
     | 
    
         
            +
                # Confirm that we can add an object
         
     | 
| 
      
 86 
     | 
    
         
            +
                
         
     | 
| 
      
 87 
     | 
    
         
            +
                object = bucket.new_object(:value => 'hello')
         
     | 
| 
      
 88 
     | 
    
         
            +
                
         
     | 
| 
      
 89 
     | 
    
         
            +
                assert_raises(NoKeySpecified) do
         
     | 
| 
      
 90 
     | 
    
         
            +
                  object.store
         
     | 
| 
      
 91 
     | 
    
         
            +
                end
         
     | 
| 
      
 92 
     | 
    
         
            +
                
         
     | 
| 
      
 93 
     | 
    
         
            +
                object.key = 'abc'
         
     | 
| 
      
 94 
     | 
    
         
            +
                assert_nothing_raised do
         
     | 
| 
      
 95 
     | 
    
         
            +
                  object.store
         
     | 
| 
      
 96 
     | 
    
         
            +
                end
         
     | 
| 
      
 97 
     | 
    
         
            +
                
         
     | 
| 
      
 98 
     | 
    
         
            +
                assert bucket.objects.include?(object)
         
     | 
| 
      
 99 
     | 
    
         
            +
                
         
     | 
| 
      
 100 
     | 
    
         
            +
                # Confirm that the object is still there after reloading its objects
         
     | 
| 
      
 101 
     | 
    
         
            +
                
         
     | 
| 
      
 102 
     | 
    
         
            +
                assert_nothing_raised do
         
     | 
| 
      
 103 
     | 
    
         
            +
                  bucket.objects(:reload)
         
     | 
| 
      
 104 
     | 
    
         
            +
                end 
         
     | 
| 
      
 105 
     | 
    
         
            +
                assert bucket.objects.include?(object)
         
     | 
| 
      
 106 
     | 
    
         
            +
                
         
     | 
| 
      
 107 
     | 
    
         
            +
                # Check that TestBucket has the same objects fetched implicitly
         
     | 
| 
      
 108 
     | 
    
         
            +
                
         
     | 
| 
      
 109 
     | 
    
         
            +
                assert_equal bucket.objects, TestBucket.objects
         
     | 
| 
      
 110 
     | 
    
         
            +
                
         
     | 
| 
      
 111 
     | 
    
         
            +
                # Empty out bucket
         
     | 
| 
      
 112 
     | 
    
         
            +
                
         
     | 
| 
      
 113 
     | 
    
         
            +
                assert_nothing_raised do
         
     | 
| 
      
 114 
     | 
    
         
            +
                  bucket.delete_all
         
     | 
| 
      
 115 
     | 
    
         
            +
                end
         
     | 
| 
      
 116 
     | 
    
         
            +
                
         
     | 
| 
      
 117 
     | 
    
         
            +
                assert bucket.empty?
         
     | 
| 
      
 118 
     | 
    
         
            +
                
         
     | 
| 
      
 119 
     | 
    
         
            +
                bucket = nil
         
     | 
| 
      
 120 
     | 
    
         
            +
                assert_nothing_raised do
         
     | 
| 
      
 121 
     | 
    
         
            +
                  bucket = Bucket.find(TEST_BUCKET)
         
     | 
| 
      
 122 
     | 
    
         
            +
                end
         
     | 
| 
      
 123 
     | 
    
         
            +
                
         
     | 
| 
      
 124 
     | 
    
         
            +
                assert bucket.empty?    
         
     | 
| 
      
 125 
     | 
    
         
            +
              end
         
     | 
| 
      
 126 
     | 
    
         
            +
              
         
     | 
| 
      
 127 
     | 
    
         
            +
              def test_bucket_name_is_switched_with_options_when_bucket_is_implicit_and_options_are_passed
         
     | 
| 
      
 128 
     | 
    
         
            +
                Object.const_set(:ImplicitlyNamedBucket, Class.new(Bucket))
         
     | 
| 
      
 129 
     | 
    
         
            +
                ImplicitlyNamedBucket.current_bucket = TEST_BUCKET
         
     | 
| 
      
 130 
     | 
    
         
            +
                assert ImplicitlyNamedBucket.objects.empty?
         
     | 
| 
      
 131 
     | 
    
         
            +
                
         
     | 
| 
      
 132 
     | 
    
         
            +
                %w(a b c).each {|key| S3Object.store(key, 'value does not matter', TEST_BUCKET)}
         
     | 
| 
      
 133 
     | 
    
         
            +
                
         
     | 
| 
      
 134 
     | 
    
         
            +
                assert_equal 3, ImplicitlyNamedBucket.objects.size
         
     | 
| 
      
 135 
     | 
    
         
            +
                
         
     | 
| 
      
 136 
     | 
    
         
            +
                objects = nil
         
     | 
| 
      
 137 
     | 
    
         
            +
                assert_nothing_raised do
         
     | 
| 
      
 138 
     | 
    
         
            +
                  objects = ImplicitlyNamedBucket.objects(:max_keys => 1)
         
     | 
| 
      
 139 
     | 
    
         
            +
                end
         
     | 
| 
      
 140 
     | 
    
         
            +
                
         
     | 
| 
      
 141 
     | 
    
         
            +
                assert objects
         
     | 
| 
      
 142 
     | 
    
         
            +
                assert_equal 1, objects.size
         
     | 
| 
      
 143 
     | 
    
         
            +
              ensure
         
     | 
| 
      
 144 
     | 
    
         
            +
                %w(a b c).each {|key| S3Object.delete(key, TEST_BUCKET)}
         
     | 
| 
      
 145 
     | 
    
         
            +
              end
         
     | 
| 
      
 146 
     | 
    
         
            +
            end
         
     |