fakes3 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1ac47d99abf4623ccf2a5a740d3eaf13c399de93
4
- data.tar.gz: fc625c2b3ef6c954b81ac3002477abd61fa0e378
3
+ metadata.gz: d257019492e12513dd0de611fd983d31277420ee
4
+ data.tar.gz: fb8546e21de97909554805fc6082b07e7f43db48
5
5
  SHA512:
6
- metadata.gz: 78738e022fbdc49460e9abeb3f9b65c66ecf18de3d7f8b336aeb259f5e791c5653ce86200748e0c8d7d74f54ef33ed01d59880a7f6f07c25543bdfe0f183466f
7
- data.tar.gz: 6f2e4df7a1d351315f59595a5c94605deebbc5346add671a47ef3503dda69533111cee1a8b662e639e529c23b9980267412fc63010423856ce2e4a4ffbcfc0a0
6
+ metadata.gz: 2d2cad4af718747f5b93ab6f6831c6230a209221c0d5950b8ba6b3976f78982edf7ddda23a33b144cd671bb661b3baec887c7a30eaa9af422473883d46e7397d
7
+ data.tar.gz: 125638e4c8b6d312cf34a26ebaa724dab1a87f70d2d61007f2e86f76e838a406731deba8f8fb50c2eac7ea54112b2cb8c01759a265ec9be5e21ac19e26976b45
@@ -9,7 +9,7 @@ module FakeS3
9
9
  desc "server", "Run a server on a particular hostname"
10
10
  method_option :root, :type => :string, :aliases => '-r', :required => true
11
11
  method_option :port, :type => :numeric, :aliases => '-p', :required => true
12
- method_option :address, :type => :string, :aliases => '-a', :required => false, :desc => "Bind to this address. Defaults to 0.0.0.0"
12
+ method_option :address, :type => :string, :aliases => '-a', :required => false, :desc => "Bind to this address. Defaults to all IP addresses of the machine."
13
13
  method_option :hostname, :type => :string, :aliases => '-H', :desc => "The root name of the host. Defaults to s3.amazonaws.com."
14
14
  method_option :quiet, :type => :boolean, :aliases => '-q', :desc => "Quiet; do not write anything to standard output."
15
15
  method_option :limit, :aliases => '-l', :type => :string, :desc => 'Rate limit for serving (ie. 50K, 1.0M)'
@@ -45,7 +45,7 @@ module FakeS3
45
45
  end
46
46
  end
47
47
 
48
- address = options[:address] || '0.0.0.0'
48
+ address = options[:address]
49
49
  ssl_cert_path = options[:sslcert]
50
50
  ssl_key_path = options[:sslkey]
51
51
 
@@ -85,7 +85,10 @@ module FakeS3
85
85
  metadata = File.open(File.join(obj_root, "metadata")) { |file| YAML::load(file) }
86
86
  real_obj.name = object_name
87
87
  real_obj.md5 = metadata[:md5]
88
- real_obj.content_type = metadata.fetch(:content_type) { "application/octet-stream" }
88
+ real_obj.content_type = request.query['response-content-type'] ||
89
+ metadata.fetch(:content_type) { "application/octet-stream" }
90
+ real_obj.content_disposition = request.query['response-content-disposition'] ||
91
+ metadata[:content_disposition]
89
92
  real_obj.content_encoding = metadata.fetch(:content_encoding) # if metadata.fetch(:content_encoding)
90
93
  real_obj.io = RateLimitableFile.open(File.join(obj_root, "content"), 'rb')
91
94
  real_obj.size = metadata.fetch(:size) { 0 }
@@ -151,6 +154,7 @@ module FakeS3
151
154
  obj.name = dst_name
152
155
  obj.md5 = src_metadata[:md5]
153
156
  obj.content_type = src_metadata[:content_type]
157
+ obj.content_disposition = src_metadata[:content_disposition]
154
158
  obj.content_encoding = src_metadata[:content_encoding] # if src_metadata[:content_encoding]
155
159
  obj.size = src_metadata[:size]
156
160
  obj.modified_date = src_metadata[:modified_date]
@@ -206,6 +210,7 @@ module FakeS3
206
210
  obj.name = object_name
207
211
  obj.md5 = metadata_struct[:md5]
208
212
  obj.content_type = metadata_struct[:content_type]
213
+ obj.content_disposition = metadata_struct[:content_disposition]
209
214
  obj.content_encoding = metadata_struct[:content_encoding] # if metadata_struct[:content_encoding]
210
215
  obj.size = metadata_struct[:size]
211
216
  obj.modified_date = metadata_struct[:modified_date]
@@ -269,6 +274,9 @@ module FakeS3
269
274
  metadata = {}
270
275
  metadata[:md5] = Digest::MD5.file(content).hexdigest
271
276
  metadata[:content_type] = request.header["content-type"].first
277
+ if request.header['content-disposition']
278
+ metadata[:content_disposition] = request.header['content-disposition'].first
279
+ end
272
280
  content_encoding = request.header["content-encoding"].first
273
281
  metadata[:content_encoding] = content_encoding
274
282
  #if content_encoding
@@ -1,7 +1,7 @@
1
1
  module FakeS3
2
2
  class S3Object
3
3
  include Comparable
4
- attr_accessor :name,:size,:creation_date,:modified_date,:md5,:io,:content_type,:content_encoding,:custom_metadata
4
+ attr_accessor :name,:size,:creation_date,:modified_date,:md5,:io,:content_type,:content_disposition,:content_encoding,:custom_metadata
5
5
 
6
6
  def hash
7
7
  @name.hash
@@ -124,6 +124,7 @@ module FakeS3
124
124
  response.header['Content-Encoding'] = real_obj.content_encoding
125
125
  end
126
126
 
127
+ response['Content-Disposition'] = real_obj.content_disposition if real_obj.content_disposition
127
128
  stat = File::Stat.new(real_obj.io.path)
128
129
 
129
130
  response['Last-Modified'] = Time.iso8601(real_obj.modified_date).httpdate
@@ -334,7 +335,7 @@ module FakeS3
334
335
 
335
336
  response['Access-Control-Allow-Origin'] = '*'
336
337
  response['Access-Control-Allow-Methods'] = 'PUT, POST, HEAD, GET, OPTIONS'
337
- response['Access-Control-Allow-Headers'] = 'Accept, Content-Type, Authorization, Content-Length, ETag, X-CSRF-Token'
338
+ response['Access-Control-Allow-Headers'] = 'Accept, Content-Type, Authorization, Content-Length, ETag, X-CSRF-Token, Content-Disposition'
338
339
  response['Access-Control-Expose-Headers'] = 'ETag'
339
340
  end
340
341
 
@@ -1,3 +1,3 @@
1
1
  module FakeS3
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -1,5 +1,6 @@
1
1
  require 'test/test_helper'
2
2
  require 'aws-sdk-v1'
3
+ require 'rest-client'
3
4
 
4
5
  class AwsSdkCommandsTest < Test::Unit::TestCase
5
6
  def setup
@@ -55,4 +56,43 @@ class AwsSdkCommandsTest < Test::Unit::TestCase
55
56
  assert metadata_file[:amazon_metadata].has_key?('storage-class'), ':amazon_metadata does not contain field "storage-class"'
56
57
  assert_equal 'REDUCED_REDUNDANCY', metadata_file[:amazon_metadata]['storage-class'], '"storage-class" does not equal expected value "REDUCED_REDUNDANCY"'
57
58
  end
59
+
60
+ def test_content_disposition
61
+ bucket = @s3.buckets["test_bucket"]
62
+ bucket.objects.create("test_object", "asdf", :content_disposition => "application/test")
63
+ assert_equal "application/test", content_disposition("test_bucket", "test_object")
64
+ end
65
+
66
+ def test_content_disposition_copy
67
+ bucket = @s3.buckets["test_bucket"]
68
+ object = bucket.objects.create("test_object", "asdf", :content_disposition => "application/test")
69
+ object.copy_to("test_copy_object")
70
+ assert_equal "application/test", content_disposition("test_bucket", "test_copy_object")
71
+ end
72
+
73
+ def test_content_disposition_request_parameter
74
+ bucket = @s3.buckets["test_bucket"]
75
+ object = bucket.objects.create("test_object", "asdf")
76
+ url = object.url_for(:read, :response_content_disposition => "application/test", :signature_version => :v4)
77
+ assert_equal "application/test", response_header(url, :content_disposition)
78
+ end
79
+
80
+ def test_content_type_request_parameter
81
+ bucket = @s3.buckets["test_bucket"]
82
+ object = bucket.objects.create("test_object", "asdf")
83
+ url = object.url_for(:read, :response_content_type => "application/test", :signature_version => :v4)
84
+ assert_equal "application/test", response_header(url, :content_type)
85
+ end
86
+
87
+ # Unfortunately v1 of the AWS SDK doesn't support reading the content_disposition of an object
88
+ def content_disposition(bucket_name, key)
89
+ url = "http://localhost:#{@s3.client.port}/#{bucket_name}/#{key}"
90
+ response_header(url, :content_disposition)
91
+ end
92
+
93
+ def response_header(url, header_name)
94
+ RestClient.head(url.to_s) do |response|
95
+ response.headers[header_name]
96
+ end
97
+ end
58
98
  end
@@ -15,7 +15,7 @@ class PostTest < Test::Unit::TestCase
15
15
  assert_equal(response.code, 200)
16
16
  assert_equal(response.headers[:access_control_allow_origin],"*")
17
17
  assert_equal(response.headers[:access_control_allow_methods], "PUT, POST, HEAD, GET, OPTIONS")
18
- assert_equal(response.headers[:access_control_allow_headers], "Accept, Content-Type, Authorization, Content-Length, ETag, X-CSRF-Token")
18
+ assert_equal(response.headers[:access_control_allow_headers], "Accept, Content-Type, Authorization, Content-Length, ETag, X-CSRF-Token, Content-Disposition")
19
19
  assert_equal(response.headers[:access_control_expose_headers], "ETag")
20
20
  end
21
21
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fakes3
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Curtis Spencer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-30 00:00:00.000000000 Z
11
+ date: 2017-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler