rack-s3 0.0.2 → 0.0.3
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/Gemfile.lock +1 -1
- data/lib/rack/s3/version.rb +1 -1
- data/lib/rack/s3.rb +10 -4
- data/test/rack_s3_test.rb +33 -20
- metadata +4 -4
data/Gemfile.lock
CHANGED
data/lib/rack/s3/version.rb
CHANGED
data/lib/rack/s3.rb
CHANGED
@@ -4,13 +4,19 @@ require 'aws/s3'
|
|
4
4
|
module Rack
|
5
5
|
class S3
|
6
6
|
|
7
|
-
def initialize(
|
8
|
-
@app = app
|
7
|
+
def initialize(options={})
|
9
8
|
@bucket = options[:bucket]
|
10
9
|
|
10
|
+
establish_aws_connection(options[:access_key_id],
|
11
|
+
options[:secret_access_key])
|
12
|
+
end
|
13
|
+
|
14
|
+
def establish_aws_connection(access_key_id, secret_access_key)
|
15
|
+
return unless access_key_id && secret_access_key
|
16
|
+
|
11
17
|
AWS::S3::Base.establish_connection!(
|
12
|
-
:access_key_id =>
|
13
|
-
:secret_access_key =>
|
18
|
+
:access_key_id => access_key_id,
|
19
|
+
:secret_access_key => secret_access_key)
|
14
20
|
end
|
15
21
|
|
16
22
|
def call(env)
|
data/test/rack_s3_test.rb
CHANGED
@@ -2,33 +2,25 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class RackS3Test < Test::Unit::TestCase
|
4
4
|
|
5
|
-
def
|
6
|
-
|
7
|
-
:access_key_id => 'abc123',
|
8
|
-
:secret_access_key => 'abc123' }
|
9
|
-
|
10
|
-
Rack::Builder.new do
|
11
|
-
use Rack::S3, options
|
12
|
-
run lambda { [ 200, {}, [ "Hello World" ]] }
|
13
|
-
end
|
5
|
+
def mock_request(path)
|
6
|
+
Rack::MockRequest.new(app).get path, :lint => true
|
14
7
|
end
|
15
8
|
|
16
|
-
def
|
17
|
-
|
18
|
-
|
9
|
+
def app
|
10
|
+
Rack::S3.new :bucket => 'rack-s3',
|
11
|
+
:access_key_id => 'abc123',
|
12
|
+
:secret_access_key => 'abc123'
|
13
|
+
end
|
19
14
|
|
20
|
-
|
21
|
-
|
22
|
-
run unmapped_app
|
23
|
-
end
|
24
|
-
end
|
15
|
+
def teardown
|
16
|
+
AWS::S3::Base.disconnect!
|
25
17
|
end
|
26
18
|
|
27
19
|
|
28
20
|
context 'A request for a nonexistent key' do
|
29
21
|
subject do
|
30
22
|
VCR.use_cassette 'not_found' do
|
31
|
-
|
23
|
+
mock_request '/not_found.png'
|
32
24
|
end
|
33
25
|
end
|
34
26
|
|
@@ -44,7 +36,7 @@ class RackS3Test < Test::Unit::TestCase
|
|
44
36
|
context 'A request for a key' do
|
45
37
|
subject do
|
46
38
|
VCR.use_cassette 'clear' do
|
47
|
-
|
39
|
+
mock_request '/clear.png'
|
48
40
|
end
|
49
41
|
end
|
50
42
|
|
@@ -62,7 +54,7 @@ class RackS3Test < Test::Unit::TestCase
|
|
62
54
|
context 'A request for a nested key' do
|
63
55
|
subject do
|
64
56
|
VCR.use_cassette 'nested_clear' do
|
65
|
-
|
57
|
+
mock_request '/very/important/files/clear.png'
|
66
58
|
end
|
67
59
|
end
|
68
60
|
|
@@ -80,6 +72,13 @@ class RackS3Test < Test::Unit::TestCase
|
|
80
72
|
context 'A request to a mapped app' do
|
81
73
|
subject do
|
82
74
|
VCR.use_cassette 'clear' do
|
75
|
+
unmapped_app = app
|
76
|
+
mapped_app = Rack::Builder.new do
|
77
|
+
map '/mapped/app' do
|
78
|
+
run unmapped_app
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
83
82
|
Rack::MockRequest.new(mapped_app).get '/mapped/app/clear.png'
|
84
83
|
end
|
85
84
|
end
|
@@ -89,4 +88,18 @@ class RackS3Test < Test::Unit::TestCase
|
|
89
88
|
end
|
90
89
|
end
|
91
90
|
|
91
|
+
context 'Without AWS credentials' do
|
92
|
+
subject do
|
93
|
+
app = Rack::S3.new :bucket => 'rack-s3'
|
94
|
+
|
95
|
+
Rack::MockRequest.new(app).get '/clear.png'
|
96
|
+
end
|
97
|
+
|
98
|
+
should 'not attempt to establish a connection to AWS' do
|
99
|
+
assert_raise AWS::S3::NoConnectionEstablished do
|
100
|
+
subject
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
92
105
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-s3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Larry Marburger
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-01-
|
18
|
+
date: 2011-01-27 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|