fake_aws 0.0.3 → 0.0.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fcacd66d77b727c137301c6de05fa146cb88a507
4
- data.tar.gz: 614b3b3159d8b544a7826d224bf444c35383db95
3
+ metadata.gz: 97d179757822dc322dbb1546a8a009fdbdf58246
4
+ data.tar.gz: 899598101f6b165db67453d1bd5a47166a6f2c02
5
5
  SHA512:
6
- metadata.gz: 9213550b7d286db1f0f7a62efc0488aa17d637a1e0a20f08c283854dbcb8a2c4a0a9fa31e13f1b288260deaaab9ed6d42930ba604199191f2287e5b91b80f5b7
7
- data.tar.gz: d20fed38db8168dbf9c9588c3d4ecb198547a74f503f04ce856031b85c9c17e40e8c8d8cafa752cb2dcf91b7d87ae9d4e75d3aa80585f1413492e6a7d1c01151
6
+ metadata.gz: 6d071767cae22f34d7b37e3a8a8b905897a836db641fcb7f67617a4c2364afffc65a16bcdcf3214464f553b2e2142494a70d5666b5f77b4c3ec18cf20d3dfc0f
7
+ data.tar.gz: 1fe896cc79603bc19c15885ddfc028ab1045acc5dd2c6aa5ee21ab9189d8e98386a0752bc4efdab2d64b6be55d6ad8b2e493bbb0e8671748706991bef7dd350d
data/fake_aws.gemspec CHANGED
@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency "rake"
25
25
  spec.add_development_dependency "rspec", "~> 3.0.0"
26
26
  spec.add_development_dependency "faraday"
27
+ spec.add_development_dependency "rack"
27
28
  spec.add_development_dependency "rack-test"
28
29
  spec.add_development_dependency "nori", "~> 2.3.0"
29
30
  end
@@ -13,4 +13,11 @@ module FakeAWS
13
13
  super("FakeAWS doesn't (yet) support this type of AWS request.")
14
14
  end
15
15
  end
16
+
17
+ class InternalError < Error
18
+ def initialize
19
+ super("Shouldn't ever get here! Looks like a bug in FakeAWS.")
20
+ end
21
+ end
22
+
16
23
  end
@@ -5,7 +5,7 @@ module FakeAWS
5
5
 
6
6
  class ObjectOnDisk
7
7
 
8
- def initialize(bucket_on_disk, key = nil)
8
+ def initialize(bucket_on_disk, key)
9
9
  @bucket_on_disk = bucket_on_disk
10
10
  @key = key
11
11
  end
@@ -15,7 +15,7 @@ module FakeAWS
15
15
  end
16
16
 
17
17
  def write(content, metadata)
18
- FileUtils.mkdir_p(directory_path)
18
+ FileUtils.mkdir_p(File.dirname(object_path))
19
19
  File.write(object_path, content)
20
20
  File.write(metadata_path, metadata.to_json)
21
21
  end
@@ -37,11 +37,7 @@ module FakeAWS
37
37
  end
38
38
 
39
39
  def metadata_path
40
- @metadata_path ||= File.join("#{object_path}.metadata.json")
41
- end
42
-
43
- def directory_path
44
- @directory_path ||= File.dirname(object_path)
40
+ @metadata_path ||= "#{object_path}.metadata.json"
45
41
  end
46
42
 
47
43
  end
@@ -12,7 +12,7 @@ module FakeAWS
12
12
  def call
13
13
  return no_such_bucket_response unless bucket_on_disk.exists?
14
14
 
15
- object_on_disk.write(@request.content, metadata)
15
+ object_on_disk.write(@request.body.read, metadata)
16
16
  success_response
17
17
  end
18
18
 
@@ -18,17 +18,22 @@ module FakeAWS
18
18
  end
19
19
 
20
20
  def operation_class(request)
21
- case request.method
22
- when "PUT"
23
- if request.has_key?
24
- Operations::PutObject
25
- else
26
- Operations::PutBucket
27
- end
28
- when "GET"
21
+ case
22
+ when request.put?
23
+ get_put_operation_class(request)
24
+ when request.get?
29
25
  Operations::GetObject
30
26
  else
31
- raise FakeAWS::UnsupportedRequestError # TODO: This needs a spec.
27
+ raise FakeAWS::UnsupportedRequestError
28
+ end
29
+ end
30
+
31
+ def get_put_operation_class(request)
32
+ case
33
+ when request.has_key?
34
+ Operations::PutObject
35
+ else
36
+ Operations::PutBucket
32
37
  end
33
38
  end
34
39
 
@@ -1,28 +1,12 @@
1
+ require "rack/request"
2
+
1
3
  module FakeAWS
2
4
  module S3
3
5
 
4
- # Extract the bucket and key from the various different styles of S3 request.
6
+ # Extract information from an incoming S3 request.
5
7
  #
6
8
  # See http://docs.aws.amazon.com/AmazonS3/latest/dev/VirtualHosting.html
7
- class Request
8
- def initialize(env)
9
- @env = env
10
- @server_name = env["SERVER_NAME"]
11
- @path_info = env["PATH_INFO"]
12
- end
13
-
14
- def method
15
- @env["REQUEST_METHOD"]
16
- end
17
-
18
- def content_type
19
- @env["CONTENT_TYPE"]
20
- end
21
-
22
- def content
23
- @env["rack.input"].read
24
- end
25
-
9
+ class Request < Rack::Request
26
10
  def http_headers
27
11
  http_headers = env_headers.map {|key, value| [header_key_for_env_key(key), value] }
28
12
  Hash[http_headers]
@@ -33,11 +17,11 @@ module FakeAWS
33
17
  when :path
34
18
  path_components.first
35
19
  when :virtual_hosted
36
- server_name_components[0..-4].join(".")
20
+ host_name_components[0..-4].join(".")
37
21
  when :cname
38
- @server_name
22
+ host
39
23
  else
40
- raise "Uh oh"
24
+ raise FakeAWS::InternalError
41
25
  end
42
26
  end
43
27
 
@@ -48,7 +32,7 @@ module FakeAWS
48
32
  when :virtual_hosted, :cname
49
33
  path_components.join("/")
50
34
  else
51
- raise "Uh oh"
35
+ raise FakeAWS::InternalError
52
36
  end
53
37
  end
54
38
 
@@ -58,25 +42,17 @@ module FakeAWS
58
42
 
59
43
  private
60
44
 
61
- def server_name
62
- @server_name ||= @env["SERVER_NAME"]
63
- end
64
-
65
- def path_info
66
- @path_info ||= @env["PATH_INFO"]
67
- end
68
-
69
- def server_name_components
70
- @server_name_components ||= server_name.split(".")
45
+ def host_name_components
46
+ @host_name_components ||= host.split(".")
71
47
  end
72
48
 
73
49
  def path_components
74
- @path_components ||= path_info.split("/").drop(1)
50
+ @path_components ||= path.split("/").drop(1)
75
51
  end
76
52
 
77
53
  def request_style
78
- @request_style ||= if server_name =~ %r{s3[-\w\d]*\.amazonaws\.com$}
79
- if server_name_components.length > 3
54
+ @request_style ||= if host =~ %r{s3[-\w\d]*}
55
+ if host_name_components.length > 3
80
56
  :virtual_hosted
81
57
  else
82
58
  :path
@@ -14,7 +14,7 @@ module FakeAWS
14
14
  end
15
15
 
16
16
  def body
17
- ""
17
+ [""]
18
18
  end
19
19
  end
20
20
 
@@ -1,3 +1,3 @@
1
1
  module FakeAWS
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe "An unsupported ooperation" do
4
+ include S3IntegrationHelpers
5
+
6
+ it "raises an unsupported request exception" do
7
+ expect {
8
+ connection.delete("/")
9
+ }.to raise_error(FakeAWS::UnsupportedRequestError)
10
+ end
11
+ end
12
+
@@ -73,10 +73,4 @@ describe FakeAWS::S3::ObjectOnDisk do
73
73
  end
74
74
  end
75
75
 
76
- describe "#directory_path" do
77
- it "returns the path to the directory containing the object" do
78
- expect(subject.directory_path).to eq(bucket_path)
79
- end
80
- end
81
-
82
76
  end
@@ -1,31 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe FakeAWS::S3::Request do
4
- subject { described_class.new(env) }
5
-
6
- context "#method" do
7
- it "returns the request method" do
8
- request = described_class.new("REQUEST_METHOD" => "GET")
9
- expect(request.method).to eq("GET")
10
- end
11
- end
12
-
13
- context "#content_type" do
14
- it "returns the content type" do
15
- request = described_class.new("CONTENT_TYPE" => "text/plain")
16
- expect(request.content_type).to eq("text/plain")
17
- end
18
- end
19
-
20
- context "#content" do
21
- it "reads and returns the Rack input" do
22
- rack_input = double("rack.input")
23
- expect(rack_input).to receive(:read) { "foo" }
24
- request = described_class.new("rack.input" => rack_input)
25
- expect(request.content).to eq("foo")
26
- end
27
- end
28
-
29
4
  context "#http_headers" do
30
5
  it "returns the HTTP headers" do
31
6
  request = described_class.new("HTTP_X_FOO" => "foo", "HTTP_X_BAR" => "bar")
@@ -70,21 +45,21 @@ describe FakeAWS::S3::Request do
70
45
 
71
46
  context "path-style" do
72
47
  let(:bucket) { "mah-bucket" }
73
- subject(:request) { described_class.new("SERVER_NAME" => "s3.amazonaws.com", "PATH_INFO" => "/#{bucket}#{key}") }
48
+ subject(:request) { described_class.new("SERVER_PORT" => "80", "SERVER_NAME" => "s3.amazonaws.com", "PATH_INFO" => "/#{bucket}#{key}") }
74
49
 
75
50
  include_examples "request parsing"
76
51
  end
77
52
 
78
53
  context "virtual hosted-style" do
79
54
  let(:bucket) { "mah-bucket" }
80
- subject(:request) { described_class.new("SERVER_NAME" => "#{bucket}.s3.amazonaws.com", "PATH_INFO" => key) }
55
+ subject(:request) { described_class.new("SERVER_PORT" => "80", "SERVER_NAME" => "#{bucket}.s3.amazonaws.com", "PATH_INFO" => key) }
81
56
 
82
57
  include_examples "request parsing"
83
58
  end
84
59
 
85
60
  context "CNAME-style" do
86
61
  let(:bucket) { "mah-bucket.mah-domain.com" }
87
- subject(:request) { described_class.new("SERVER_NAME" => bucket, "PATH_INFO" => key) }
62
+ subject(:request) { described_class.new("SERVER_PORT" => "80", "SERVER_NAME" => bucket, "PATH_INFO" => key) }
88
63
 
89
64
  include_examples "request parsing"
90
65
  end
@@ -8,7 +8,7 @@ describe FakeAWS::S3::Responses::Empty do
8
8
  end
9
9
 
10
10
  it "has an empty body" do
11
- expect(subject.body).to be_empty
11
+ expect(subject.body).to eq([''])
12
12
  end
13
13
 
14
14
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fake_aws
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pete Yandell
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-07-29 00:00:00.000000000 Z
12
+ date: 2015-01-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: finer_struct
@@ -81,6 +81,20 @@ dependencies:
81
81
  - - ">="
82
82
  - !ruby/object:Gem::Version
83
83
  version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: rack
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
84
98
  - !ruby/object:Gem::Dependency
85
99
  name: rack-test
86
100
  requirement: !ruby/object:Gem::Requirement
@@ -144,6 +158,7 @@ files:
144
158
  - spec/integration/s3/put_bucket_spec.rb
145
159
  - spec/integration/s3/put_object_spec.rb
146
160
  - spec/integration/s3/request_styles_spec.rb
161
+ - spec/integration/s3/unsupported_request_spec.rb
147
162
  - spec/spec_helper.rb
148
163
  - spec/support/common_header_examples.rb
149
164
  - spec/support/s3_integration_helpers.rb
@@ -185,6 +200,7 @@ test_files:
185
200
  - spec/integration/s3/put_bucket_spec.rb
186
201
  - spec/integration/s3/put_object_spec.rb
187
202
  - spec/integration/s3/request_styles_spec.rb
203
+ - spec/integration/s3/unsupported_request_spec.rb
188
204
  - spec/spec_helper.rb
189
205
  - spec/support/common_header_examples.rb
190
206
  - spec/support/s3_integration_helpers.rb
@@ -196,3 +212,4 @@ test_files:
196
212
  - spec/unit/s3/responses/empty_spec.rb
197
213
  - spec/unit/s3/responses/error_spec.rb
198
214
  - spec/unit/s3/responses/success_spec.rb
215
+ has_rdoc: