fake_aws 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/fake_aws.gemspec +1 -0
- data/lib/fake_aws/error.rb +7 -0
- data/lib/fake_aws/s3/object_on_disk.rb +3 -7
- data/lib/fake_aws/s3/operations/put_object.rb +1 -1
- data/lib/fake_aws/s3/rack_app.rb +14 -9
- data/lib/fake_aws/s3/request.rb +13 -37
- data/lib/fake_aws/s3/responses/empty.rb +1 -1
- data/lib/fake_aws/version.rb +1 -1
- data/spec/integration/s3/unsupported_request_spec.rb +12 -0
- data/spec/unit/s3/object_on_disk_spec.rb +0 -6
- data/spec/unit/s3/request_spec.rb +3 -28
- data/spec/unit/s3/responses/empty_spec.rb +1 -1
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 97d179757822dc322dbb1546a8a009fdbdf58246
|
4
|
+
data.tar.gz: 899598101f6b165db67453d1bd5a47166a6f2c02
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/lib/fake_aws/error.rb
CHANGED
@@ -5,7 +5,7 @@ module FakeAWS
|
|
5
5
|
|
6
6
|
class ObjectOnDisk
|
7
7
|
|
8
|
-
def initialize(bucket_on_disk, key
|
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(
|
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 ||=
|
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
|
data/lib/fake_aws/s3/rack_app.rb
CHANGED
@@ -18,17 +18,22 @@ module FakeAWS
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def operation_class(request)
|
21
|
-
case
|
22
|
-
when
|
23
|
-
|
24
|
-
|
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
|
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
|
|
data/lib/fake_aws/s3/request.rb
CHANGED
@@ -1,28 +1,12 @@
|
|
1
|
+
require "rack/request"
|
2
|
+
|
1
3
|
module FakeAWS
|
2
4
|
module S3
|
3
5
|
|
4
|
-
# Extract
|
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
|
-
|
20
|
+
host_name_components[0..-4].join(".")
|
37
21
|
when :cname
|
38
|
-
|
22
|
+
host
|
39
23
|
else
|
40
|
-
raise
|
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
|
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
|
62
|
-
@
|
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 ||=
|
50
|
+
@path_components ||= path.split("/").drop(1)
|
75
51
|
end
|
76
52
|
|
77
53
|
def request_style
|
78
|
-
@request_style ||= if
|
79
|
-
if
|
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
|
data/lib/fake_aws/version.rb
CHANGED
@@ -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
|
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.
|
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:
|
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:
|