s3 0.3.0.beta → 0.3.0.beta2
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/extra/s3_paperclip.rb +28 -16
- data/lib/s3.rb +1 -0
- metadata +21 -40
- data/.document +0 -6
- data/.gitignore +0 -6
- data/Rakefile +0 -62
- data/VERSION +0 -1
- data/s3.gemspec +0 -85
- data/test/bucket_test.rb +0 -215
- data/test/connection_test.rb +0 -170
- data/test/object_test.rb +0 -155
- data/test/service_test.rb +0 -111
- data/test/signature_test.rb +0 -143
- data/test/test_helper.rb +0 -8
data/extra/s3_paperclip.rb
CHANGED
|
@@ -17,11 +17,10 @@
|
|
|
17
17
|
# },
|
|
18
18
|
# :bucket => "bucket.domain.tld",
|
|
19
19
|
# :path => ":attachment/:id/:style.:extension"
|
|
20
|
-
|
|
21
20
|
module Paperclip
|
|
22
21
|
module Storage
|
|
23
22
|
module S3
|
|
24
|
-
def self.extended
|
|
23
|
+
def self.extended base
|
|
25
24
|
begin
|
|
26
25
|
require "s3"
|
|
27
26
|
rescue LoadError => e
|
|
@@ -39,9 +38,11 @@ module Paperclip
|
|
|
39
38
|
@s3_headers = @options[:s3_headers] || {}
|
|
40
39
|
@s3_host_alias = @options[:s3_host_alias]
|
|
41
40
|
@url = ":s3_path_url" unless @url.to_s.match(/^:s3.*url$/)
|
|
42
|
-
@service = ::S3::Service.new(@s3_options.merge(
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
@service = ::S3::Service.new(@s3_options.merge(
|
|
42
|
+
:access_key_id => @s3_credentials[:access_key_id],
|
|
43
|
+
:secret_access_key => @s3_credentials[:secret_access_key],
|
|
44
|
+
:use_ssl => @s3_protocol == "https"
|
|
45
|
+
))
|
|
45
46
|
@bucket = @service.buckets.build(@bucket_name)
|
|
46
47
|
end
|
|
47
48
|
Paperclip.interpolates(:s3_alias_url) do |attachment, style|
|
|
@@ -55,19 +56,23 @@ module Paperclip
|
|
|
55
56
|
end
|
|
56
57
|
end
|
|
57
58
|
|
|
58
|
-
def
|
|
59
|
-
|
|
59
|
+
def expiring_url(style_name = default_style, time = 3600)
|
|
60
|
+
bucket.objects.build(path(style_name)).temporary_url(Time.now + time)
|
|
60
61
|
end
|
|
61
62
|
|
|
62
63
|
def bucket_name
|
|
63
|
-
@
|
|
64
|
+
@bucket_name
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def bucket
|
|
68
|
+
@bucket
|
|
64
69
|
end
|
|
65
70
|
|
|
66
71
|
def s3_host_alias
|
|
67
72
|
@s3_host_alias
|
|
68
73
|
end
|
|
69
74
|
|
|
70
|
-
def parse_credentials
|
|
75
|
+
def parse_credentials creds
|
|
71
76
|
creds = find_credentials(creds).stringify_keys
|
|
72
77
|
(creds[RAILS_ENV] || creds).symbolize_keys
|
|
73
78
|
end
|
|
@@ -86,12 +91,18 @@ module Paperclip
|
|
|
86
91
|
|
|
87
92
|
# Returns representation of the data of the file assigned to the given
|
|
88
93
|
# style, in the format most representative of the current storage.
|
|
89
|
-
def to_file
|
|
94
|
+
def to_file style = default_style
|
|
90
95
|
return @queued_for_write[style] if @queued_for_write[style]
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
96
|
+
begin
|
|
97
|
+
file = Tempfile.new(path(style))
|
|
98
|
+
file.binmode if file.respond_to?(:binmode)
|
|
99
|
+
file.write(bucket.objects.find(path(style)).content)
|
|
100
|
+
file.rewind
|
|
101
|
+
rescue ::S3::Error::NoSuchKey
|
|
102
|
+
file.close if file.respond_to?(:close)
|
|
103
|
+
file = nil
|
|
104
|
+
end
|
|
105
|
+
file
|
|
95
106
|
end
|
|
96
107
|
|
|
97
108
|
def flush_writes #:nodoc:
|
|
@@ -100,7 +111,7 @@ module Paperclip
|
|
|
100
111
|
log("saving #{path(style)}")
|
|
101
112
|
object = bucket.objects.build(path(style))
|
|
102
113
|
object.content = file.read
|
|
103
|
-
object.acl = @
|
|
114
|
+
object.acl = @s3_permissions
|
|
104
115
|
object.content_type = instance_read(:content_type)
|
|
105
116
|
object.content_disposition = @s3_headers[:content_disposition]
|
|
106
117
|
object.content_encoding = @s3_headers[:content_encoding]
|
|
@@ -124,7 +135,7 @@ module Paperclip
|
|
|
124
135
|
@queued_for_delete = []
|
|
125
136
|
end
|
|
126
137
|
|
|
127
|
-
def find_credentials
|
|
138
|
+
def find_credentials creds
|
|
128
139
|
case creds
|
|
129
140
|
when File
|
|
130
141
|
YAML::load(ERB.new(File.read(creds.path)).result)
|
|
@@ -137,6 +148,7 @@ module Paperclip
|
|
|
137
148
|
end
|
|
138
149
|
end
|
|
139
150
|
private :find_credentials
|
|
151
|
+
|
|
140
152
|
end
|
|
141
153
|
end
|
|
142
154
|
end
|
data/lib/s3.rb
CHANGED
metadata
CHANGED
|
@@ -6,18 +6,17 @@ version: !ruby/object:Gem::Version
|
|
|
6
6
|
- 0
|
|
7
7
|
- 3
|
|
8
8
|
- 0
|
|
9
|
-
-
|
|
10
|
-
version: 0.3.0.
|
|
9
|
+
- beta2
|
|
10
|
+
version: 0.3.0.beta2
|
|
11
11
|
platform: ruby
|
|
12
12
|
authors:
|
|
13
13
|
- "Jakub Ku\xC5\xBAma"
|
|
14
|
-
- "Miros\xC5\x82aw Boruta"
|
|
15
14
|
autorequire:
|
|
16
15
|
bindir: bin
|
|
17
16
|
cert_chain: []
|
|
18
17
|
|
|
19
|
-
date: 2010-04-
|
|
20
|
-
default_executable:
|
|
18
|
+
date: 2010-04-20 00:00:00 +02:00
|
|
19
|
+
default_executable:
|
|
21
20
|
dependencies:
|
|
22
21
|
- !ruby/object:Gem::Dependency
|
|
23
22
|
name: trollop
|
|
@@ -27,9 +26,8 @@ dependencies:
|
|
|
27
26
|
- - ">="
|
|
28
27
|
- !ruby/object:Gem::Version
|
|
29
28
|
segments:
|
|
30
|
-
-
|
|
31
|
-
|
|
32
|
-
version: "1.14"
|
|
29
|
+
- 0
|
|
30
|
+
version: "0"
|
|
33
31
|
type: :runtime
|
|
34
32
|
version_requirements: *id001
|
|
35
33
|
- !ruby/object:Gem::Dependency
|
|
@@ -75,43 +73,31 @@ executables:
|
|
|
75
73
|
- s3
|
|
76
74
|
extensions: []
|
|
77
75
|
|
|
78
|
-
extra_rdoc_files:
|
|
79
|
-
|
|
80
|
-
- README.rdoc
|
|
76
|
+
extra_rdoc_files: []
|
|
77
|
+
|
|
81
78
|
files:
|
|
82
|
-
- .document
|
|
83
|
-
- .gitignore
|
|
84
|
-
- LICENSE
|
|
85
|
-
- README.rdoc
|
|
86
|
-
- Rakefile
|
|
87
|
-
- VERSION
|
|
88
79
|
- bin/s3
|
|
89
80
|
- extra/s3_attachment_fu.rb
|
|
90
81
|
- extra/s3_paperclip.rb
|
|
91
|
-
- lib/s3.rb
|
|
92
|
-
- lib/s3/bucket.rb
|
|
82
|
+
- lib/s3/parser.rb
|
|
93
83
|
- lib/s3/buckets_extension.rb
|
|
94
84
|
- lib/s3/connection.rb
|
|
95
85
|
- lib/s3/exceptions.rb
|
|
96
|
-
- lib/s3/
|
|
86
|
+
- lib/s3/bucket.rb
|
|
97
87
|
- lib/s3/objects_extension.rb
|
|
98
|
-
- lib/s3/
|
|
88
|
+
- lib/s3/object.rb
|
|
99
89
|
- lib/s3/service.rb
|
|
100
90
|
- lib/s3/signature.rb
|
|
101
|
-
- s3.
|
|
102
|
-
-
|
|
103
|
-
-
|
|
104
|
-
- test/object_test.rb
|
|
105
|
-
- test/service_test.rb
|
|
106
|
-
- test/signature_test.rb
|
|
107
|
-
- test/test_helper.rb
|
|
91
|
+
- lib/s3.rb
|
|
92
|
+
- LICENSE
|
|
93
|
+
- README.rdoc
|
|
108
94
|
has_rdoc: true
|
|
109
95
|
homepage: http://jah.pl/projects/s3.html
|
|
110
96
|
licenses: []
|
|
111
97
|
|
|
112
98
|
post_install_message:
|
|
113
|
-
rdoc_options:
|
|
114
|
-
|
|
99
|
+
rdoc_options: []
|
|
100
|
+
|
|
115
101
|
require_paths:
|
|
116
102
|
- lib
|
|
117
103
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
@@ -123,13 +109,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
123
109
|
version: "0"
|
|
124
110
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
111
|
requirements:
|
|
126
|
-
- - "
|
|
112
|
+
- - ">="
|
|
127
113
|
- !ruby/object:Gem::Version
|
|
128
114
|
segments:
|
|
129
115
|
- 1
|
|
130
116
|
- 3
|
|
131
|
-
-
|
|
132
|
-
version: 1.3.
|
|
117
|
+
- 6
|
|
118
|
+
version: 1.3.6
|
|
133
119
|
requirements: []
|
|
134
120
|
|
|
135
121
|
rubyforge_project:
|
|
@@ -137,10 +123,5 @@ rubygems_version: 1.3.6
|
|
|
137
123
|
signing_key:
|
|
138
124
|
specification_version: 3
|
|
139
125
|
summary: Library for accessing S3 objects and buckets, with command line tool
|
|
140
|
-
test_files:
|
|
141
|
-
|
|
142
|
-
- test/test_helper.rb
|
|
143
|
-
- test/bucket_test.rb
|
|
144
|
-
- test/connection_test.rb
|
|
145
|
-
- test/service_test.rb
|
|
146
|
-
- test/signature_test.rb
|
|
126
|
+
test_files: []
|
|
127
|
+
|
data/.document
DELETED
data/.gitignore
DELETED
data/Rakefile
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
# encoding: UTF-8
|
|
2
|
-
|
|
3
|
-
require 'rubygems'
|
|
4
|
-
require 'rake'
|
|
5
|
-
|
|
6
|
-
begin
|
|
7
|
-
require 'jeweler'
|
|
8
|
-
Jeweler::Tasks.new do |gem|
|
|
9
|
-
gem.name = "s3"
|
|
10
|
-
gem.summary = %Q{Library for accessing S3 objects and buckets, with command line tool}
|
|
11
|
-
gem.description = %Q{S3 library provides access to Amazon's Simple Storage Service. It supports both: European and US buckets through REST API.}
|
|
12
|
-
gem.email = "qoobaa@gmail.com"
|
|
13
|
-
gem.homepage = "http://jah.pl/projects/s3.html"
|
|
14
|
-
gem.authors = ["Jakub Kuźma", "Mirosław Boruta"]
|
|
15
|
-
gem.add_dependency "trollop", ">=1.14"
|
|
16
|
-
gem.add_dependency "proxies"
|
|
17
|
-
gem.add_development_dependency "test-unit", ">= 2.0"
|
|
18
|
-
gem.add_development_dependency "mocha"
|
|
19
|
-
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
rescue LoadError
|
|
23
|
-
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
require 'rake/testtask'
|
|
27
|
-
Rake::TestTask.new(:test) do |test|
|
|
28
|
-
test.libs << 'lib' << 'test'
|
|
29
|
-
test.pattern = 'test/**/*_test.rb'
|
|
30
|
-
test.verbose = true
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
begin
|
|
34
|
-
require 'rcov/rcovtask'
|
|
35
|
-
Rcov::RcovTask.new do |test|
|
|
36
|
-
test.libs << 'test'
|
|
37
|
-
test.pattern = 'test/**/*_test.rb'
|
|
38
|
-
test.verbose = true
|
|
39
|
-
end
|
|
40
|
-
rescue LoadError
|
|
41
|
-
task :rcov do
|
|
42
|
-
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
task :default => :test
|
|
47
|
-
|
|
48
|
-
require 'rake/rdoctask'
|
|
49
|
-
Rake::RDocTask.new do |rdoc|
|
|
50
|
-
if File.exist?('VERSION.yml')
|
|
51
|
-
config = YAML.load(File.read('VERSION.yml'))
|
|
52
|
-
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
|
53
|
-
else
|
|
54
|
-
version = ""
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
rdoc.rdoc_dir = 'rdoc'
|
|
58
|
-
rdoc.title = "s3 #{version}"
|
|
59
|
-
rdoc.rdoc_files.include('README*')
|
|
60
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
61
|
-
end
|
|
62
|
-
|
data/VERSION
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
0.3.0.beta
|
data/s3.gemspec
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
# Generated by jeweler
|
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
|
4
|
-
# -*- encoding: utf-8 -*-
|
|
5
|
-
|
|
6
|
-
Gem::Specification.new do |s|
|
|
7
|
-
s.name = %q{s3}
|
|
8
|
-
s.version = "0.3.0.beta"
|
|
9
|
-
|
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
|
|
11
|
-
s.authors = ["Jakub Kuźma", "Mirosław Boruta"]
|
|
12
|
-
s.date = %q{2010-04-01}
|
|
13
|
-
s.default_executable = %q{s3}
|
|
14
|
-
s.description = %q{S3 library provides access to Amazon's Simple Storage Service. It supports both: European and US buckets through REST API.}
|
|
15
|
-
s.email = %q{qoobaa@gmail.com}
|
|
16
|
-
s.executables = ["s3"]
|
|
17
|
-
s.extra_rdoc_files = [
|
|
18
|
-
"LICENSE",
|
|
19
|
-
"README.rdoc"
|
|
20
|
-
]
|
|
21
|
-
s.files = [
|
|
22
|
-
".document",
|
|
23
|
-
".gitignore",
|
|
24
|
-
"LICENSE",
|
|
25
|
-
"README.rdoc",
|
|
26
|
-
"Rakefile",
|
|
27
|
-
"VERSION",
|
|
28
|
-
"bin/s3",
|
|
29
|
-
"extra/s3_attachment_fu.rb",
|
|
30
|
-
"extra/s3_paperclip.rb",
|
|
31
|
-
"lib/s3.rb",
|
|
32
|
-
"lib/s3/bucket.rb",
|
|
33
|
-
"lib/s3/buckets_extension.rb",
|
|
34
|
-
"lib/s3/connection.rb",
|
|
35
|
-
"lib/s3/exceptions.rb",
|
|
36
|
-
"lib/s3/object.rb",
|
|
37
|
-
"lib/s3/objects_extension.rb",
|
|
38
|
-
"lib/s3/parser.rb",
|
|
39
|
-
"lib/s3/service.rb",
|
|
40
|
-
"lib/s3/signature.rb",
|
|
41
|
-
"s3.gemspec",
|
|
42
|
-
"test/bucket_test.rb",
|
|
43
|
-
"test/connection_test.rb",
|
|
44
|
-
"test/object_test.rb",
|
|
45
|
-
"test/service_test.rb",
|
|
46
|
-
"test/signature_test.rb",
|
|
47
|
-
"test/test_helper.rb"
|
|
48
|
-
]
|
|
49
|
-
s.homepage = %q{http://jah.pl/projects/s3.html}
|
|
50
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
|
51
|
-
s.require_paths = ["lib"]
|
|
52
|
-
s.rubygems_version = %q{1.3.6}
|
|
53
|
-
s.summary = %q{Library for accessing S3 objects and buckets, with command line tool}
|
|
54
|
-
s.test_files = [
|
|
55
|
-
"test/object_test.rb",
|
|
56
|
-
"test/test_helper.rb",
|
|
57
|
-
"test/bucket_test.rb",
|
|
58
|
-
"test/connection_test.rb",
|
|
59
|
-
"test/service_test.rb",
|
|
60
|
-
"test/signature_test.rb"
|
|
61
|
-
]
|
|
62
|
-
|
|
63
|
-
if s.respond_to? :specification_version then
|
|
64
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
|
65
|
-
s.specification_version = 3
|
|
66
|
-
|
|
67
|
-
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
|
68
|
-
s.add_runtime_dependency(%q<trollop>, [">= 1.14"])
|
|
69
|
-
s.add_runtime_dependency(%q<proxies>, [">= 0"])
|
|
70
|
-
s.add_development_dependency(%q<test-unit>, [">= 2.0"])
|
|
71
|
-
s.add_development_dependency(%q<mocha>, [">= 0"])
|
|
72
|
-
else
|
|
73
|
-
s.add_dependency(%q<trollop>, [">= 1.14"])
|
|
74
|
-
s.add_dependency(%q<proxies>, [">= 0"])
|
|
75
|
-
s.add_dependency(%q<test-unit>, [">= 2.0"])
|
|
76
|
-
s.add_dependency(%q<mocha>, [">= 0"])
|
|
77
|
-
end
|
|
78
|
-
else
|
|
79
|
-
s.add_dependency(%q<trollop>, [">= 1.14"])
|
|
80
|
-
s.add_dependency(%q<proxies>, [">= 0"])
|
|
81
|
-
s.add_dependency(%q<test-unit>, [">= 2.0"])
|
|
82
|
-
s.add_dependency(%q<mocha>, [">= 0"])
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
|
data/test/bucket_test.rb
DELETED
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
require "test_helper"
|
|
2
|
-
|
|
3
|
-
class BucketTest < Test::Unit::TestCase
|
|
4
|
-
def setup
|
|
5
|
-
@bucket_vhost = S3::Bucket.send(:new, nil, "Data-Bucket")
|
|
6
|
-
@bucket_path = S3::Bucket.send(:new, nil, "Data_Bucket")
|
|
7
|
-
@bucket = @bucket_vhost
|
|
8
|
-
|
|
9
|
-
@bucket_location = "EU"
|
|
10
|
-
@bucket_location_body = <<-EOLocation
|
|
11
|
-
<?xml version="1.0" encoding="UTF-8"?>\n<LocationConstraint xmlns="http://s3.amazonaws.com/doc/2006-03-01/">EU</LocationConstraint>
|
|
12
|
-
EOLocation
|
|
13
|
-
|
|
14
|
-
@response_location = Net::HTTPOK.new("1.1", "200", "OK")
|
|
15
|
-
@response_location.stubs(:body).returns(@bucket_location_body)
|
|
16
|
-
|
|
17
|
-
@bucket_owned_by_you_body = <<-EOOwnedByYou
|
|
18
|
-
<?xml version="1.0" encoding="UTF-8"?>\n<Error> <Code>BucketAlreadyOwnedByYou</Code> <Message>Your previous request to create the named bucket succeeded and you already own it.</Message> <BucketName>bucket</BucketName> <RequestId>117D08EA0EC6E860</RequestId> <HostId>4VpMSvmJ+G5+DLtVox6O5cZNgdPlYcjCu3l0n4HjDe01vPxxuk5eTAtcAkUynRyV</HostId> </Error>
|
|
19
|
-
EOOwnedByYou
|
|
20
|
-
|
|
21
|
-
@reponse_owned_by_you = Net::HTTPConflict.new("1.1", "409", "Conflict")
|
|
22
|
-
@reponse_owned_by_you.stubs(:body).returns(@bucket_owned_by_you_body)
|
|
23
|
-
|
|
24
|
-
@bucket_already_exists_body = <<-EOAlreadyExists
|
|
25
|
-
<?xml version="1.0" encoding="UTF-8"?>\n<Error> <Code>BucketAlreadyExists</Code> <Message>The requested bucket name is not available. The bucket namespace is shared by all users of the system. Please select a different name and try again.</Message> <BucketName>bucket</BucketName> <RequestId>4C154D32807C92BD</RequestId> <HostId>/xyHQgXcUXTZQhoO+NUBzbaxbFrIhKlyuaRHFnmcId0bMePvY9Zwg+dyk2LYE4g5</HostId> </Error>
|
|
26
|
-
EOAlreadyExists
|
|
27
|
-
|
|
28
|
-
@reponse_already_exists = Net::HTTPConflict.new("1.1", "409", "Conflict")
|
|
29
|
-
@response_already_exists.stubs(:body).returns(@bucket_already_exists_body)
|
|
30
|
-
|
|
31
|
-
@objects_list_empty = []
|
|
32
|
-
@objects_list = [
|
|
33
|
-
S3::Object.send(:new, @bucket, :key => "obj1"),
|
|
34
|
-
S3::Object.send(:new, @bucket, :key => "obj2")
|
|
35
|
-
]
|
|
36
|
-
|
|
37
|
-
@response_objects_list_empty_body = <<-EOEmpty
|
|
38
|
-
<?xml version="1.0" encoding="UTF-8"?>\n<ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> <Name>bucket</Name> <Prefix></Prefix> <Marker></Marker> <MaxKeys>1000</MaxKeys> <IsTruncated>false</IsTruncated> </ListBucketResult>
|
|
39
|
-
EOEmpty
|
|
40
|
-
|
|
41
|
-
@response_objects_list_empty = Net::HTTPOK.new("1.1", "200", "OK")
|
|
42
|
-
@response_objects_list_empty.stubs(:body).returns(@response_objects_list_empty_body)
|
|
43
|
-
|
|
44
|
-
@response_objects_list_body = <<-EOObjects
|
|
45
|
-
<?xml version="1.0" encoding="UTF-8"?>\n<ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> <Name>bucket</Name> <Prefix></Prefix> <Marker></Marker> <MaxKeys>1000</MaxKeys> <IsTruncated>false</IsTruncated> <Contents> <Key>obj1</Key> <LastModified>2009-07-03T10:17:33.000Z</LastModified> <ETag>"99519cdf14c255e580e1b7bca85a458c"</ETag> <Size>1729</Size> <Owner> <ID>df864aeb6f42be43f1d9e60aaabe3f15e245b035a4b79d1cfe36c4deaec67205</ID> <DisplayName>owner</DisplayName> </Owner> <StorageClass>STANDARD</StorageClass> </Contents> <Contents> <Key>obj2</Key> <LastModified>2009-07-03T11:17:33.000Z</LastModified> <ETag>"99519cdf14c255e586e1b12bca85a458c"</ETag> <Size>179</Size> <Owner> <ID>df864aeb6f42be43f1d9e60aaabe3f17e247b037a4b79d1cfe36c4deaec67205</ID> <DisplayName>owner</DisplayName> </Owner> <StorageClass>STANDARD</StorageClass> </Contents> </ListBucketResult>
|
|
46
|
-
EOObjects
|
|
47
|
-
|
|
48
|
-
@response_objects_list = Net::HTTPOK.new("1.1", "200", "OK")
|
|
49
|
-
@response_objects_list.stubs(:body).returns(@response_objects_list_body)
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
test "name valid" do
|
|
53
|
-
assert_raise ArgumentError do S3::Bucket.send(:new, nil, "") end # should not be valid with empty name
|
|
54
|
-
assert_raise ArgumentError do S3::Bucket.send(:new, nil, "10.0.0.1") end # should not be valid with IP as name
|
|
55
|
-
assert_raise ArgumentError do S3::Bucket.send(:new, nil, "as") end # should not be valid with name shorter than 3 characters
|
|
56
|
-
assert_raise ArgumentError do S3::Bucket.send(:new, nil, "a" * 256) end # should not be valid with name longer than 255 characters
|
|
57
|
-
assert_raise ArgumentError do S3::Bucket.send(:new, nil, ".asdf") end # should not allow special characters as first character
|
|
58
|
-
assert_raise ArgumentError do S3::Bucket.send(:new, nil, "-asdf") end # should not allow special characters as first character
|
|
59
|
-
assert_raise ArgumentError do S3::Bucket.send(:new, nil, "_asdf") end # should not allow special characters as first character
|
|
60
|
-
|
|
61
|
-
assert_nothing_raised do
|
|
62
|
-
S3::Bucket.send(:new, nil, "a-a-")
|
|
63
|
-
S3::Bucket.send(:new, nil, "a.a.")
|
|
64
|
-
S3::Bucket.send(:new, nil, "a_a_")
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
test "path prefix" do
|
|
69
|
-
expected = ""
|
|
70
|
-
actual = @bucket_vhost.path_prefix
|
|
71
|
-
assert_equal expected, actual
|
|
72
|
-
|
|
73
|
-
expected = "Data_Bucket/"
|
|
74
|
-
actual = @bucket_path.path_prefix
|
|
75
|
-
assert_equal expected, actual
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
test "host" do
|
|
79
|
-
expected = "Data-Bucket.s3.amazonaws.com"
|
|
80
|
-
actual = @bucket_vhost.host
|
|
81
|
-
assert_equal expected, actual
|
|
82
|
-
|
|
83
|
-
expected = "s3.amazonaws.com"
|
|
84
|
-
actual = @bucket_path.host
|
|
85
|
-
assert_equal expected, actual
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
test "vhost" do
|
|
89
|
-
assert @bucket_vhost.vhost?
|
|
90
|
-
assert ! @bucket_path.vhost?
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
test "exists" do
|
|
94
|
-
@bucket.expects(:retrieve).returns(@bucket_vhost)
|
|
95
|
-
assert @bucket.exists?
|
|
96
|
-
|
|
97
|
-
@bucket.expects(:retrieve).raises(S3::Error::NoSuchBucket.new(nil, nil))
|
|
98
|
-
assert ! @bucket.exists?
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
test "location and parse location" do
|
|
102
|
-
@bucket.expects(:bucket_request).with(:get, { :params => { :location => nil } }).returns(@response_location)
|
|
103
|
-
|
|
104
|
-
expected = @bucket_location
|
|
105
|
-
actual = @bucket.location
|
|
106
|
-
assert_equal expected, actual
|
|
107
|
-
|
|
108
|
-
@bucket.stubs(:bucket_request).with(:get, { :params => { :location => nil } })
|
|
109
|
-
actual = @bucket.location
|
|
110
|
-
assert_equal expected, actual
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
test "save" do
|
|
114
|
-
@bucket.expects(:bucket_request).with(:put, { :headers => {} })
|
|
115
|
-
assert @bucket.save
|
|
116
|
-
# mock ensures that bucket_request was called
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
test "save failure owned by you" do
|
|
120
|
-
@bucket.expects(:bucket_request).with(:put, { :headers => {} }).raises(S3::Error::BucketAlreadyOwnedByYou.new(409, @response_owned_by_you))
|
|
121
|
-
assert_raise S3::Error::BucketAlreadyOwnedByYou do
|
|
122
|
-
@bucket.save
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
@bucket.expects(:bucket_request).with(:put, { :headers => {} }).raises(S3::Error::BucketAlreadyExists.new(409, @response_already_exists))
|
|
126
|
-
assert_raise S3::Error::BucketAlreadyExists do
|
|
127
|
-
@bucket.save
|
|
128
|
-
end
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
test "objects" do
|
|
132
|
-
@bucket.expects(:list_bucket).returns(@objects_list_empty)
|
|
133
|
-
expected = @objects_list_empty
|
|
134
|
-
actual = @bucket.objects
|
|
135
|
-
assert_equal expected, actual
|
|
136
|
-
|
|
137
|
-
@bucket.stubs(:list_bucket).returns(@objects_list_empty)
|
|
138
|
-
actual = @bucket.objects
|
|
139
|
-
assert_equal expected, actual
|
|
140
|
-
|
|
141
|
-
@bucket.stubs(:list_bucket).returns(@objects_list)
|
|
142
|
-
|
|
143
|
-
expected = @objects_list
|
|
144
|
-
actual = @bucket.objects
|
|
145
|
-
assert_equal expected, actual
|
|
146
|
-
end
|
|
147
|
-
|
|
148
|
-
test "list bucket and parse objects" do
|
|
149
|
-
@bucket.expects(:bucket_request).with(:get, :params => { :test=>true }).returns(@response_objects_list_empty)
|
|
150
|
-
expected = @objects_list_empty
|
|
151
|
-
actual = @bucket.objects.find_all(:test => true)
|
|
152
|
-
assert_equal expected, actual
|
|
153
|
-
|
|
154
|
-
@bucket.expects(:bucket_request).with(:get, :params => { :test => true }).returns(@response_objects_list)
|
|
155
|
-
expected = @objects_list
|
|
156
|
-
actual = @bucket.objects.find_all(:test => true)
|
|
157
|
-
assert_equal expected, actual
|
|
158
|
-
end
|
|
159
|
-
|
|
160
|
-
test "destroy" do
|
|
161
|
-
@bucket.expects(:bucket_request).with(:delete)
|
|
162
|
-
assert @bucket.destroy
|
|
163
|
-
end
|
|
164
|
-
|
|
165
|
-
test "objects build" do
|
|
166
|
-
@bucket.stubs(:bucket_request)
|
|
167
|
-
|
|
168
|
-
expected = "object_name"
|
|
169
|
-
actual = @bucket.objects.build("object_name")
|
|
170
|
-
assert_kind_of S3::Object, actual
|
|
171
|
-
assert_equal expected, actual.key
|
|
172
|
-
end
|
|
173
|
-
|
|
174
|
-
test "objects find first" do
|
|
175
|
-
assert_nothing_raised do
|
|
176
|
-
S3::Object.any_instance.stubs(:retrieve).returns(S3::Object.send(:new, nil, :key => "obj2"))
|
|
177
|
-
expected = "obj2"
|
|
178
|
-
actual = @bucket.objects.find_first("obj2")
|
|
179
|
-
assert_equal "obj2", actual.key
|
|
180
|
-
end
|
|
181
|
-
end
|
|
182
|
-
|
|
183
|
-
test "objects find first fail" do
|
|
184
|
-
assert_raise S3::Error::NoSuchKey do
|
|
185
|
-
S3::Object.any_instance.stubs(:retrieve).raises(S3::Error::NoSuchKey.new(404, nil))
|
|
186
|
-
@bucket.objects.find_first("obj3")
|
|
187
|
-
end
|
|
188
|
-
end
|
|
189
|
-
|
|
190
|
-
test "objects find all on empty list" do
|
|
191
|
-
@bucket.stubs(:list_bucket).returns(@objects_list_empty)
|
|
192
|
-
assert_nothing_raised do
|
|
193
|
-
expected = @objects_list_empty
|
|
194
|
-
actual = @bucket.objects.find_all
|
|
195
|
-
assert_equal expected, actual
|
|
196
|
-
end
|
|
197
|
-
end
|
|
198
|
-
|
|
199
|
-
test "objects find all" do
|
|
200
|
-
@bucket.stubs(:list_bucket).returns(@objects_list)
|
|
201
|
-
assert_nothing_raised do
|
|
202
|
-
expected = @objects_list
|
|
203
|
-
actual = @bucket.objects.find_all
|
|
204
|
-
assert_equal expected, actual
|
|
205
|
-
end
|
|
206
|
-
end
|
|
207
|
-
|
|
208
|
-
test "objects destroy all" do
|
|
209
|
-
@bucket.stubs(:list_bucket).returns(@objects_list)
|
|
210
|
-
@bucket.objects.each do |obj|
|
|
211
|
-
obj.expects(:destroy)
|
|
212
|
-
end
|
|
213
|
-
@bucket.objects.destroy_all
|
|
214
|
-
end
|
|
215
|
-
end
|
data/test/connection_test.rb
DELETED
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
require "test_helper"
|
|
2
|
-
|
|
3
|
-
class ConnectionTest < Test::Unit::TestCase
|
|
4
|
-
def setup
|
|
5
|
-
@connection = S3::Connection.new(
|
|
6
|
-
:access_key_id => "12345678901234567890",
|
|
7
|
-
:secret_access_key => "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDF"
|
|
8
|
-
)
|
|
9
|
-
@http_request = Net::HTTP.new("")
|
|
10
|
-
@response_ok = Net::HTTPOK.new("1.1", "200", "OK")
|
|
11
|
-
@response_not_found = Net::HTTPNotFound.new("1.1", "404", "Not Found")
|
|
12
|
-
@response_error = Net::HTTPInternalServerError.new("1.1", "500", "Internal Server Error")
|
|
13
|
-
@connection.stubs(:http).returns(@http_request)
|
|
14
|
-
|
|
15
|
-
@http_request.stubs(:start).returns(@response_ok)
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
test "handle response not modify response when ok" do
|
|
19
|
-
assert_nothing_raised do
|
|
20
|
-
response = @connection.request(
|
|
21
|
-
:get,
|
|
22
|
-
:host => "s3.amazonaws.com",
|
|
23
|
-
:path => "/"
|
|
24
|
-
)
|
|
25
|
-
assert_equal @response_ok, response
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
test "handle response throws exception when error" do
|
|
30
|
-
response_body = <<-EOFakeBody
|
|
31
|
-
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
|
|
32
|
-
<Error>
|
|
33
|
-
<Code>NoSuchBucket</Code>
|
|
34
|
-
<Message>The specified bucket does not exist</Message>
|
|
35
|
-
</Error>
|
|
36
|
-
EOFakeBody
|
|
37
|
-
|
|
38
|
-
@http_request.stubs(:start).returns(@response_not_found)
|
|
39
|
-
@response_not_found.stubs(:body).returns(response_body)
|
|
40
|
-
|
|
41
|
-
assert_raise S3::Error::NoSuchBucket do
|
|
42
|
-
response = @connection.request(
|
|
43
|
-
:get,
|
|
44
|
-
:host => "data.example.com.s3.amazonaws.com",
|
|
45
|
-
:path => "/"
|
|
46
|
-
)
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
test "handle response throws standard exception when error" do
|
|
51
|
-
@http_request.stubs(:start).returns(@response_error)
|
|
52
|
-
@response_error.stubs(:body)
|
|
53
|
-
assert_raise S3::Error::ResponseError do
|
|
54
|
-
response = @connection.request(
|
|
55
|
-
:get,
|
|
56
|
-
:host => "data.example.com.s3.amazonaws.com",
|
|
57
|
-
:path => "/"
|
|
58
|
-
)
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
@response_error.stubs(:body).returns("")
|
|
62
|
-
assert_raise S3::Error::ResponseError do
|
|
63
|
-
response = @connection.request(
|
|
64
|
-
:get,
|
|
65
|
-
:host => "data.example.com.s3.amazonaws.com",
|
|
66
|
-
:path => "/"
|
|
67
|
-
)
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
test "parse params empty" do
|
|
72
|
-
expected = ""
|
|
73
|
-
actual = S3::Connection.parse_params({})
|
|
74
|
-
assert_equal expected, actual
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
test "parse params only interesting params" do
|
|
78
|
-
expected = ""
|
|
79
|
-
actual = S3::Connection.parse_params(:param1 => "1", :maxkeys => "2")
|
|
80
|
-
assert_equal expected, actual
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
test "parse params remove underscore" do
|
|
84
|
-
expected = "max-keys=100"
|
|
85
|
-
actual = S3::Connection.parse_params(:max_keys => 100)
|
|
86
|
-
assert_equal expected, actual
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
test "parse params with and without values" do
|
|
90
|
-
params = S3::Connection.parse_params(:max_keys => 100, :prefix => nil)
|
|
91
|
-
|
|
92
|
-
splitted_params = params.split("&")
|
|
93
|
-
assert_equal 2, splitted_params.length
|
|
94
|
-
assert splitted_params.include?("max-keys=100")
|
|
95
|
-
assert splitted_params.include?("prefix")
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
test "headers empty" do
|
|
99
|
-
expected = {}
|
|
100
|
-
actual = S3::Connection.parse_headers({})
|
|
101
|
-
assert_equal expected, actual
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
test "parse only interesting headers" do
|
|
105
|
-
expected = {}
|
|
106
|
-
actual = S3::Connection.parse_headers(
|
|
107
|
-
:accept => "text/*, text/html, text/html;level=1, */*",
|
|
108
|
-
:accept_charset => "iso-8859-2, unicode-1-1;q=0.8"
|
|
109
|
-
)
|
|
110
|
-
assert_equal expected, actual
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
test "parse headers remove underscore" do
|
|
114
|
-
expected = {
|
|
115
|
-
"content-type" => nil,
|
|
116
|
-
"x-amz-acl" => nil,
|
|
117
|
-
"if-modified-since" => nil,
|
|
118
|
-
"if-unmodified-since" => nil,
|
|
119
|
-
"if-match" => nil,
|
|
120
|
-
"if-none-match" => nil,
|
|
121
|
-
"content-disposition" => nil,
|
|
122
|
-
"content-encoding" => nil
|
|
123
|
-
}
|
|
124
|
-
actual = S3::Connection.parse_headers(
|
|
125
|
-
:content_type => nil,
|
|
126
|
-
:x_amz_acl => nil,
|
|
127
|
-
:if_modified_since => nil,
|
|
128
|
-
:if_unmodified_since => nil,
|
|
129
|
-
:if_match => nil,
|
|
130
|
-
:if_none_match => nil,
|
|
131
|
-
:content_disposition => nil,
|
|
132
|
-
:content_encoding => nil
|
|
133
|
-
)
|
|
134
|
-
assert_equal expected, actual
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
test "parse headers with values" do
|
|
138
|
-
expected = {
|
|
139
|
-
"content-type" => "text/html",
|
|
140
|
-
"x-amz-acl" => "public-read",
|
|
141
|
-
"if-modified-since" => "today",
|
|
142
|
-
"if-unmodified-since" => "tomorrow",
|
|
143
|
-
"if-match" => "1234",
|
|
144
|
-
"if-none-match" => "1243",
|
|
145
|
-
"content-disposition" => "inline",
|
|
146
|
-
"content-encoding" => "gzip"
|
|
147
|
-
}
|
|
148
|
-
actual = S3::Connection.parse_headers(
|
|
149
|
-
:content_type => "text/html",
|
|
150
|
-
:x_amz_acl => "public-read",
|
|
151
|
-
:if_modified_since => "today",
|
|
152
|
-
:if_unmodified_since => "tomorrow",
|
|
153
|
-
:if_match => "1234",
|
|
154
|
-
:if_none_match => "1243",
|
|
155
|
-
:content_disposition => "inline",
|
|
156
|
-
:content_encoding => "gzip"
|
|
157
|
-
)
|
|
158
|
-
assert_equal expected, actual
|
|
159
|
-
end
|
|
160
|
-
|
|
161
|
-
test "parse headers with range" do
|
|
162
|
-
expected = {
|
|
163
|
-
"range" => "bytes=0-100"
|
|
164
|
-
}
|
|
165
|
-
actual = S3::Connection.parse_headers(
|
|
166
|
-
:range => 0..100
|
|
167
|
-
)
|
|
168
|
-
assert_equal expected, actual
|
|
169
|
-
end
|
|
170
|
-
end
|
data/test/object_test.rb
DELETED
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
require "test_helper"
|
|
3
|
-
|
|
4
|
-
class ObjectTest < Test::Unit::TestCase
|
|
5
|
-
def setup
|
|
6
|
-
@service = S3::Service.new(
|
|
7
|
-
:access_key_id => "1234",
|
|
8
|
-
:secret_access_key => "1337"
|
|
9
|
-
)
|
|
10
|
-
@bucket_images = S3::Bucket.send(:new, @service, "images")
|
|
11
|
-
@object_lena = S3::Object.send(:new, @bucket_images, :key => "Lena.png")
|
|
12
|
-
@object_lena.content = "test"
|
|
13
|
-
@object_carmen = S3::Object.send(:new, @bucket_images, :key => "Carmen.png")
|
|
14
|
-
|
|
15
|
-
@response_binary = Net::HTTPOK.new("1.1", "200", "OK")
|
|
16
|
-
@response_binary.stubs(:body).returns("test".respond_to?(:force_encoding) ? "test".force_encoding(Encoding::BINARY) : "test")
|
|
17
|
-
@response_binary["etag"] = ""
|
|
18
|
-
@response_binary["content-type"] = "image/png"
|
|
19
|
-
@response_binary["content-disposition"] = "inline"
|
|
20
|
-
@response_binary["content-encoding"] = nil
|
|
21
|
-
@response_binary["last-modified"] = Time.now.httpdate
|
|
22
|
-
@response_binary["content-length"] = 20
|
|
23
|
-
|
|
24
|
-
@xml_body = <<-EOXML
|
|
25
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
26
|
-
<CopyObjectResult> <LastModified>timestamp</LastModified> <ETag>"etag"</ETag> </CopyObjectResult>
|
|
27
|
-
EOXML
|
|
28
|
-
@response_xml = Net::HTTPOK.new("1.1", "200", "OK")
|
|
29
|
-
@response_xml.stubs(:body).returns(@xml_body)
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
test "initializing" do
|
|
33
|
-
assert_raise ArgumentError do S3::Object.send(:new, nil, :key => "") end # should not allow empty key
|
|
34
|
-
assert_raise ArgumentError do S3::Object.send(:new, nil, :key => "//") end # should not allow key with double slash
|
|
35
|
-
|
|
36
|
-
assert_nothing_raised do
|
|
37
|
-
S3::Object.send(:new, nil, :key => "Lena.png")
|
|
38
|
-
S3::Object.send(:new, nil, :key => "Lena playboy.png")
|
|
39
|
-
S3::Object.send(:new, nil, :key => "Lena Söderberg.png")
|
|
40
|
-
S3::Object.send(:new, nil, :key => "/images/pictures/test images/Lena not full.png")
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
test "full key" do
|
|
45
|
-
expected = "images/Lena.png"
|
|
46
|
-
actual = @object_lena.full_key
|
|
47
|
-
assert_equal expected, actual
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
test "url" do
|
|
51
|
-
bucket1 = S3::Bucket.send(:new, @service, "images")
|
|
52
|
-
|
|
53
|
-
object11 = S3::Object.send(:new, bucket1, :key => "Lena.png")
|
|
54
|
-
expected = "http://images.s3.amazonaws.com/Lena.png"
|
|
55
|
-
actual = object11.url
|
|
56
|
-
assert_equal expected, actual
|
|
57
|
-
|
|
58
|
-
object12 = S3::Object.send(:new, bucket1, :key => "Lena Söderberg.png")
|
|
59
|
-
expected = "http://images.s3.amazonaws.com/Lena%20S%C3%B6derberg.png"
|
|
60
|
-
actual = object12.url
|
|
61
|
-
assert_equal expected, actual
|
|
62
|
-
|
|
63
|
-
bucket2 = S3::Bucket.send(:new, @service, "images_new")
|
|
64
|
-
|
|
65
|
-
object21 = S3::Object.send(:new, bucket2, :key => "Lena.png")
|
|
66
|
-
expected = "http://s3.amazonaws.com/images_new/Lena.png"
|
|
67
|
-
actual = object21.url
|
|
68
|
-
assert_equal expected, actual
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
test "cname url" do
|
|
72
|
-
bucket1 = S3::Bucket.send(:new, @service, "images.example.com")
|
|
73
|
-
|
|
74
|
-
object11 = S3::Object.send(:new, bucket1, :key => "Lena.png")
|
|
75
|
-
expected = "http://images.example.com/Lena.png"
|
|
76
|
-
actual = object11.cname_url
|
|
77
|
-
assert_equal expected, actual
|
|
78
|
-
|
|
79
|
-
object12 = S3::Object.send(:new, bucket1, :key => "Lena Söderberg.png")
|
|
80
|
-
expected = "http://images.example.com/Lena%20S%C3%B6derberg.png"
|
|
81
|
-
actual = object12.cname_url
|
|
82
|
-
assert_equal expected, actual
|
|
83
|
-
|
|
84
|
-
bucket2 = S3::Bucket.send(:new, @service, "images_new")
|
|
85
|
-
|
|
86
|
-
object21 = S3::Object.send(:new, bucket2, :key => "Lena.png")
|
|
87
|
-
expected = nil
|
|
88
|
-
actual = object21.cname_url
|
|
89
|
-
assert_equal expected, actual
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
test "destroy" do
|
|
93
|
-
@object_lena.expects(:object_request).with(:delete)
|
|
94
|
-
assert @object_lena.destroy
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
test "save" do
|
|
98
|
-
@object_lena.expects(:object_request).with(:put, :body=>"test", :headers=>{ :x_amz_acl=>"public-read", :content_type=>"application/octet-stream" }).returns(@response_binary)
|
|
99
|
-
assert @object_lena.save
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
test "content and parse headers" do
|
|
103
|
-
@object_lena.expects(:object_request).with(:get, {}).returns(@response_binary)
|
|
104
|
-
|
|
105
|
-
expected = /test/n
|
|
106
|
-
actual = @object_lena.content(true)
|
|
107
|
-
assert_match expected, actual
|
|
108
|
-
assert_equal "image/png", @object_lena.content_type
|
|
109
|
-
|
|
110
|
-
assert @object_lena.content
|
|
111
|
-
|
|
112
|
-
@object_lena.expects(:object_request).with(:get, {}).returns(@response_binary)
|
|
113
|
-
assert @object_lena.content(true)
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
test "retrieve" do
|
|
117
|
-
@object_lena.expects(:object_request).with(:head, {}).returns(@response_binary)
|
|
118
|
-
assert @object_lena.retrieve
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
test "exists" do
|
|
122
|
-
@object_lena.expects(:retrieve).returns(true)
|
|
123
|
-
assert @object_lena.exists?
|
|
124
|
-
|
|
125
|
-
@object_carmen.expects(:retrieve).raises(S3::Error::NoSuchKey.new(nil, nil))
|
|
126
|
-
assert ! @object_carmen.exists?
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
test "ACL writer" do
|
|
130
|
-
expected = nil
|
|
131
|
-
actual = @object_lena.acl
|
|
132
|
-
assert_equal expected, actual
|
|
133
|
-
|
|
134
|
-
assert @object_lena.acl = :public_read
|
|
135
|
-
|
|
136
|
-
expected = "public-read"
|
|
137
|
-
actual = @object_lena.acl
|
|
138
|
-
assert_equal expected, actual
|
|
139
|
-
|
|
140
|
-
assert @object_lena.acl = :private
|
|
141
|
-
|
|
142
|
-
expected = "private"
|
|
143
|
-
actual = @object_lena.acl
|
|
144
|
-
assert_equal expected, actual
|
|
145
|
-
end
|
|
146
|
-
|
|
147
|
-
test "copy" do
|
|
148
|
-
@bucket_images.expects(:bucket_request).with(:put, :path => "Lena-copy.png", :headers => { :x_amz_acl => "public-read", :content_type => "application/octet-stream", :x_amz_copy_source => "images/Lena.png", :x_amz_metadata_directive => "REPLACE" }).returns(@response_xml)
|
|
149
|
-
|
|
150
|
-
new_object = @object_lena.copy(:key => "Lena-copy.png")
|
|
151
|
-
|
|
152
|
-
assert_equal "Lena-copy.png", new_object.key
|
|
153
|
-
assert_equal "Lena.png", @object_lena.key
|
|
154
|
-
end
|
|
155
|
-
end
|
data/test/service_test.rb
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
require "test_helper"
|
|
2
|
-
|
|
3
|
-
class ServiceTest < Test::Unit::TestCase
|
|
4
|
-
def setup
|
|
5
|
-
@buckets_list_body = <<-EOBuckets
|
|
6
|
-
<?xml version="1.0" encoding="UTF-8"?>\n<ListAllMyBucketsResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> <Owner> <ID>123u1odhkhfoadf</ID> <DisplayName>JohnDoe</DisplayName> </Owner> <Buckets> <Bucket> <Name>data.example.com</Name> <CreationDate>2009-07-02T11:56:58.000Z</CreationDate> </Bucket> <Bucket> <Name>images</Name> <CreationDate>2009-06-05T12:26:33.000Z</CreationDate> </Bucket> </Buckets> </ListAllMyBucketsResult>
|
|
7
|
-
EOBuckets
|
|
8
|
-
|
|
9
|
-
@bucket_not_exists = <<-EOBucketNoexists
|
|
10
|
-
<?xml version="1.0" encoding="UTF-8"?>\n<Error> <Code>NoSuchBucket</Code> <Message>The specified bucket does not exists</Message> <BucketName>data2.example.com</BucketName> <RequestId>8D7519AAE74E9E99</RequestId> <HostId>DvKnnNSMnPHd1oXukyRaFNv8Lg/bpwhuUtY8Kj7eDLbaIrIT8JebSnHwi89AK1P+</HostId> </Error>
|
|
11
|
-
EOBucketNoexists
|
|
12
|
-
|
|
13
|
-
@bucket_exists = <<-EOBucketexists
|
|
14
|
-
<?xml version="1.0" encoding="UTF-8"?>\n<ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> <Name>data.synergypeople.net</Name> <Prefix></Prefix> <Marker></Marker> <MaxKeys>1000</MaxKeys> <IsTruncated>false</IsTruncated> </ListBucketResult>
|
|
15
|
-
EOBucketexists
|
|
16
|
-
|
|
17
|
-
@service_empty_buckets_list = S3::Service.new(
|
|
18
|
-
:access_key_id => "12345678901234567890",
|
|
19
|
-
:secret_access_key => "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDF"
|
|
20
|
-
)
|
|
21
|
-
@response_empty_buckets_list = Net::HTTPOK.new("1.1", "200", "OK")
|
|
22
|
-
@service_empty_buckets_list.stubs(:service_request).returns(@response_empty_buckets_list)
|
|
23
|
-
@response_empty_buckets_list.stubs(:body).returns(@buckets_empty_list_body)
|
|
24
|
-
|
|
25
|
-
@service_buckets_list = S3::Service.new(
|
|
26
|
-
:access_key_id => "12345678901234567890",
|
|
27
|
-
:secret_access_key => "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDF"
|
|
28
|
-
)
|
|
29
|
-
@response_buckets_list = Net::HTTPOK.new("1.1", "200", "OK")
|
|
30
|
-
@service_buckets_list.stubs(:service_request).returns(@response_buckets_list)
|
|
31
|
-
@response_buckets_list.stubs(:body).returns(@buckets_list_body)
|
|
32
|
-
|
|
33
|
-
@service_bucket_exists = S3::Service.new(
|
|
34
|
-
:access_key_id => "12345678901234567890",
|
|
35
|
-
:secret_access_key => "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDF"
|
|
36
|
-
)
|
|
37
|
-
@response_bucket_exists = Net::HTTPNotFound.new("1.1", "200", "OK")
|
|
38
|
-
@service_bucket_exists.stubs(:service_request).returns(@response_bucket_exists)
|
|
39
|
-
@response_bucket_exists.stubs(:body).returns(@bucket_exists)
|
|
40
|
-
|
|
41
|
-
@service_bucket_not_exists = S3::Service.new(
|
|
42
|
-
:access_key_id => "12345678901234567890",
|
|
43
|
-
:secret_access_key => "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDF"
|
|
44
|
-
)
|
|
45
|
-
@response_bucket_not_exists = Net::HTTPNotFound.new("1.1", "404", "Not Found")
|
|
46
|
-
@service_bucket_not_exists.stubs(:service_request).raises(S3::Error::NoSuchBucket.new(404, @response_bucket_not_exists))
|
|
47
|
-
@response_bucket_not_exists.stubs(:body).returns(@bucket_not_exists)
|
|
48
|
-
|
|
49
|
-
@buckets_empty_list = []
|
|
50
|
-
@buckets_empty_list_body = <<-EOEmptyBuckets
|
|
51
|
-
<?xml version="1.0" encoding="UTF-8"?>\n<ListAllMyBucketsResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> <Owner> <ID>123u1odhkhfoadf</ID> <DisplayName>JohnDoe</DisplayName> </Owner> <Buckets> </Buckets> </ListAllMyBucketsResult>
|
|
52
|
-
EOEmptyBuckets
|
|
53
|
-
|
|
54
|
-
@buckets_list = [
|
|
55
|
-
S3::Bucket.send(:new, @service_buckets_list, "data.example.com"),
|
|
56
|
-
S3::Bucket.send(:new, @service_buckets_list, "images")
|
|
57
|
-
]
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
test "buckets and parse buckets empty" do
|
|
61
|
-
expected = @buckets_empty_list
|
|
62
|
-
actual = @service_empty_buckets_list.buckets
|
|
63
|
-
assert_equal expected.length, actual.length
|
|
64
|
-
assert_equal expected, actual
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
test "buckets and parse buckets" do
|
|
68
|
-
expected = @buckets_list
|
|
69
|
-
# ugly hack
|
|
70
|
-
actual = @service_buckets_list.buckets.map { |obj| obj }
|
|
71
|
-
assert_equal expected, actual
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
test "buckets build" do
|
|
75
|
-
@service_empty_buckets_list.stubs(:service_request)
|
|
76
|
-
|
|
77
|
-
expected = "bucket_name"
|
|
78
|
-
actual = @service_empty_buckets_list.buckets.build("bucket_name")
|
|
79
|
-
assert_kind_of S3::Bucket, actual
|
|
80
|
-
assert_equal expected, actual.name
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
test "buckets find first" do
|
|
84
|
-
assert_nothing_raised do
|
|
85
|
-
actual = @service_buckets_list.buckets.find_first("data.example.com")
|
|
86
|
-
assert_equal "data.example.com", actual.name
|
|
87
|
-
end
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
test "buckets find first fail" do
|
|
91
|
-
assert_raise S3::Error::NoSuchBucket do
|
|
92
|
-
@service_bucket_not_exists.buckets.find_first("data2.example.com")
|
|
93
|
-
end
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
test "buckets find all on empty list" do
|
|
97
|
-
assert_nothing_raised do
|
|
98
|
-
expected = @buckets_empty_list
|
|
99
|
-
actual = @service_empty_buckets_list.buckets.find_all
|
|
100
|
-
assert_equal expected, actual
|
|
101
|
-
end
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
test "buckets find all" do
|
|
105
|
-
assert_nothing_raised do
|
|
106
|
-
expected = @buckets_list
|
|
107
|
-
actual = @service_buckets_list.buckets.find_all
|
|
108
|
-
assert_equal expected, actual
|
|
109
|
-
end
|
|
110
|
-
end
|
|
111
|
-
end
|
data/test/signature_test.rb
DELETED
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
require "test_helper"
|
|
2
|
-
|
|
3
|
-
class SignatureTest < Test::Unit::TestCase
|
|
4
|
-
# from http://docs.amazonwebservices.com/AmazonS3/latest/RESTAuthentication.html
|
|
5
|
-
test "signature for object get" do
|
|
6
|
-
request = Net::HTTP::Get.new("/photos/puppy.jpg")
|
|
7
|
-
request["host"] = "johnsmith.s3.amazonaws.com"
|
|
8
|
-
request["date"] = "Tue, 27 Mar 2007 19:36:42 +0000"
|
|
9
|
-
|
|
10
|
-
actual = S3::Signature.generate(
|
|
11
|
-
:host => request["host"],
|
|
12
|
-
:request => request,
|
|
13
|
-
:access_key_id => "0PN5J17HBGZHT7JJ3X82",
|
|
14
|
-
:secret_access_key => "uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o"
|
|
15
|
-
)
|
|
16
|
-
expected = "AWS 0PN5J17HBGZHT7JJ3X82:xXjDGYUmKxnwqr5KXNPGldn5LbA="
|
|
17
|
-
assert_equal expected, actual
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
test "signature for object put" do
|
|
21
|
-
request = Net::HTTP::Put.new("/photos/puppy.jpg");
|
|
22
|
-
request["content-type"] = "image/jpeg"
|
|
23
|
-
request["content-length"] = "94328"
|
|
24
|
-
request["host"] = "johnsmith.s3.amazonaws.com"
|
|
25
|
-
request["date"] = "Tue, 27 Mar 2007 21:15:45 +0000"
|
|
26
|
-
|
|
27
|
-
actual = S3::Signature.generate(
|
|
28
|
-
:host => request["host"],
|
|
29
|
-
:request => request,
|
|
30
|
-
:access_key_id => "0PN5J17HBGZHT7JJ3X82",
|
|
31
|
-
:secret_access_key => "uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o"
|
|
32
|
-
)
|
|
33
|
-
expected = "AWS 0PN5J17HBGZHT7JJ3X82:hcicpDDvL9SsO6AkvxqmIWkmOuQ="
|
|
34
|
-
assert_equal expected, actual
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
test "signature for list" do
|
|
38
|
-
request = Net::HTTP::Get.new("/?prefix=photos&max-keys=50&marker=puppy");
|
|
39
|
-
request["user-agent"] = "Mozilla/5.0"
|
|
40
|
-
request["host"] = "johnsmith.s3.amazonaws.com"
|
|
41
|
-
request["date"] = "Tue, 27 Mar 2007 19:42:41 +0000"
|
|
42
|
-
|
|
43
|
-
actual = S3::Signature.generate(
|
|
44
|
-
:host => request["host"],
|
|
45
|
-
:request => request,
|
|
46
|
-
:access_key_id => "0PN5J17HBGZHT7JJ3X82",
|
|
47
|
-
:secret_access_key => "uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o"
|
|
48
|
-
)
|
|
49
|
-
expected = "AWS 0PN5J17HBGZHT7JJ3X82:jsRt/rhG+Vtp88HrYL706QhE4w4="
|
|
50
|
-
assert_equal expected, actual
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
test "signature for fetch" do
|
|
54
|
-
request = Net::HTTP::Get.new("/?acl");
|
|
55
|
-
request["host"] = "johnsmith.s3.amazonaws.com"
|
|
56
|
-
request["date"] = "Tue, 27 Mar 2007 19:44:46 +0000"
|
|
57
|
-
|
|
58
|
-
actual = S3::Signature.generate(
|
|
59
|
-
:host => request["host"],
|
|
60
|
-
:request => request,
|
|
61
|
-
:access_key_id => "0PN5J17HBGZHT7JJ3X82",
|
|
62
|
-
:secret_access_key => "uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o"
|
|
63
|
-
)
|
|
64
|
-
expected = "AWS 0PN5J17HBGZHT7JJ3X82:thdUi9VAkzhkniLj96JIrOPGi0g="
|
|
65
|
-
assert_equal expected, actual
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
test "signature for delete" do
|
|
69
|
-
request = Net::HTTP::Delete.new("/johnsmith/photos/puppy.jpg");
|
|
70
|
-
request["user-agent"] = "dotnet"
|
|
71
|
-
request["host"] = "s3.amazonaws.com"
|
|
72
|
-
request["date"] = "Tue, 27 Mar 2007 21:20:27 +0000"
|
|
73
|
-
request["x-amz-date"] = "Tue, 27 Mar 2007 21:20:26 +0000"
|
|
74
|
-
|
|
75
|
-
actual = S3::Signature.generate(
|
|
76
|
-
:host => request["host"],
|
|
77
|
-
:request => request,
|
|
78
|
-
:access_key_id => "0PN5J17HBGZHT7JJ3X82",
|
|
79
|
-
:secret_access_key => "uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o"
|
|
80
|
-
)
|
|
81
|
-
expected = "AWS 0PN5J17HBGZHT7JJ3X82:k3nL7gH3+PadhTEVn5Ip83xlYzk="
|
|
82
|
-
assert_equal expected, actual
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
test "signature for upload" do
|
|
86
|
-
request = Net::HTTP::Put.new("/db-backup.dat.gz");
|
|
87
|
-
request["user-agent"] = "curl/7.15.5"
|
|
88
|
-
request["host"] = "static.johnsmith.net:8080"
|
|
89
|
-
request["date"] = "Tue, 27 Mar 2007 21:06:08 +0000"
|
|
90
|
-
request["x-amz-acl"] = "public-read"
|
|
91
|
-
request["content-type"] = "application/x-download"
|
|
92
|
-
request["content-md5"] = "4gJE4saaMU4BqNR0kLY+lw=="
|
|
93
|
-
# FIXME: Net::HTTP doesn't allow to have multiple headers with the same name
|
|
94
|
-
# request.add_field add additional spaces (breaks signature)
|
|
95
|
-
#request["x-amz-meta-reviewedby"] = "joe@johnsmith.net"
|
|
96
|
-
#request["x-amz-meta-reviewedby"] = "jane@johnsmith.net"
|
|
97
|
-
request["x-amz-meta-reviewedby"] = "joe@johnsmith.net,jane@johnsmith.net"
|
|
98
|
-
request["x-amz-meta-filechecksum"] = "0x02661779"
|
|
99
|
-
request["x-amz-meta-checksumalgorithm"] = "crc32"
|
|
100
|
-
request["content-disposition"] = "attachment; filename=database.dat"
|
|
101
|
-
request["content-encoding"] = "gzip"
|
|
102
|
-
request["content-length"] = "5913339"
|
|
103
|
-
|
|
104
|
-
actual = S3::Signature.generate(
|
|
105
|
-
:host => "static.johnsmith.net",
|
|
106
|
-
:request => request,
|
|
107
|
-
:access_key_id => "0PN5J17HBGZHT7JJ3X82",
|
|
108
|
-
:secret_access_key => "uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o"
|
|
109
|
-
)
|
|
110
|
-
expected = "AWS 0PN5J17HBGZHT7JJ3X82:C0FlOtU8Ylb9KDTpZqYkZPX91iI="
|
|
111
|
-
assert_equal expected, actual
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
test "signature for list all my buckets" do
|
|
115
|
-
request = Net::HTTP::Get.new("/");
|
|
116
|
-
request["host"] = "s3.amazonaws.com"
|
|
117
|
-
request["date"] = "Wed, 28 Mar 2007 01:29:59 +0000"
|
|
118
|
-
|
|
119
|
-
actual = S3::Signature.generate(
|
|
120
|
-
:host => request["host"],
|
|
121
|
-
:request => request,
|
|
122
|
-
:access_key_id => "0PN5J17HBGZHT7JJ3X82",
|
|
123
|
-
:secret_access_key => "uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o"
|
|
124
|
-
)
|
|
125
|
-
expected = "AWS 0PN5J17HBGZHT7JJ3X82:Db+gepJSUbZKwpx1FR0DLtEYoZA="
|
|
126
|
-
assert_equal expected, actual
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
test "signature for unicode keys" do
|
|
130
|
-
request = Net::HTTP::Get.new("/dictionary/fran%C3%A7ais/pr%c3%a9f%c3%a8re");
|
|
131
|
-
request["host"] = "s3.amazonaws.com"
|
|
132
|
-
request["date"] = "Wed, 28 Mar 2007 01:49:49 +0000"
|
|
133
|
-
|
|
134
|
-
actual = S3::Signature.generate(
|
|
135
|
-
:host => request["host"],
|
|
136
|
-
:request => request,
|
|
137
|
-
:access_key_id => "0PN5J17HBGZHT7JJ3X82",
|
|
138
|
-
:secret_access_key => "uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o"
|
|
139
|
-
)
|
|
140
|
-
expected = "AWS 0PN5J17HBGZHT7JJ3X82:dxhSBHoI6eVSPcXJqEghlUzZMnY="
|
|
141
|
-
assert_equal expected, actual
|
|
142
|
-
end
|
|
143
|
-
end
|