awsraw 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -14,16 +14,16 @@ module AWSRaw
14
14
  # curl, wget, etc) about all the special AWS headers. The query string
15
15
  # authentication method is useful in those cases.
16
16
  class QueryStringSigner < Signer
17
- def sign_with_query_string(url, expires)
18
- query_string_hash = query_string_hash(url, expires)
17
+ def sign_with_query_string(url, expires, headers = {})
18
+ query_string_hash = query_string_hash(url, expires, headers)
19
19
 
20
20
  uri = URI.parse(url)
21
21
  uri.query = query_string_hash.map { |k,v| "#{k}=#{v}" }.join("&")
22
22
  uri.to_s
23
23
  end
24
24
 
25
- def query_string_hash(url, expires)
26
- string_to_sign = string_to_sign(url, expires)
25
+ def query_string_hash(url, expires, headers = {})
26
+ string_to_sign = string_to_sign(url, expires, headers)
27
27
  signature = encoded_signature(string_to_sign)
28
28
 
29
29
  {
@@ -33,16 +33,13 @@ module AWSRaw
33
33
  }
34
34
  end
35
35
 
36
- def string_to_sign(url, expires)
36
+ def string_to_sign(url, expires, headers)
37
37
  [
38
38
  "GET",
39
- # Assume user-agent won't send Content-MD5 header
40
- "",
41
- # Assume user-agent won't send Content-Type header
42
- "",
39
+ headers["Content-MD5"],
40
+ headers["Content-Type"],
43
41
  expires.to_s,
44
- # Assume user-agent won't send any amz headers
45
- canonicalized_amz_headers({}),
42
+ canonicalized_amz_headers(headers),
46
43
  canonicalized_resource(URI.parse(url))
47
44
  ].flatten.join("\n")
48
45
  end
@@ -1,3 +1,3 @@
1
1
  module Awsraw
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
@@ -10,8 +10,9 @@ describe AWSRaw::S3::QueryStringSigner do
10
10
  it "signs a get request correctly" do
11
11
  url = "http://s3.amazonaws.com/johnsmith/photos/puppy.jpg"
12
12
  expiry = 1175139620
13
+ headers = {}
13
14
 
14
- subject.string_to_sign(url, expiry).should ==
15
+ subject.string_to_sign(url, expiry, {}).should ==
15
16
  "GET\n\n\n#{expiry}\n/johnsmith/photos/puppy.jpg"
16
17
 
17
18
  subject.query_string_hash(url, expiry).should == {
@@ -27,8 +28,9 @@ describe AWSRaw::S3::QueryStringSigner do
27
28
  it "signs a get request to a non-us-east bucket" do
28
29
  url = "http://johnsmith.s3.amazonaws.com/photos/puppy.jpg"
29
30
  expiry = 1175139620
31
+ headers = {}
30
32
 
31
- subject.string_to_sign(url, expiry).should ==
33
+ subject.string_to_sign(url, expiry, headers).should ==
32
34
  "GET\n\n\n#{expiry}\n/johnsmith/photos/puppy.jpg"
33
35
 
34
36
  subject.query_string_hash(url, expiry).should == {
@@ -41,5 +43,25 @@ describe AWSRaw::S3::QueryStringSigner do
41
43
  "http://johnsmith.s3.amazonaws.com/photos/puppy.jpg?AWSAccessKeyId=#{access_key_id}&Expires=#{expiry}&Signature=NpgCjnDzrM%2BWFzoENXmpNDUsSn8%3D"
42
44
  end
43
45
  end
46
+
47
+ context "custom headers" do
48
+ let(:url) { "http://s3.amazonaws.com/johnsmith/" }
49
+ let(:expiry) { 1175139620 }
50
+
51
+ it "changes the signature based on the Content-MD5 header" do
52
+ subject.string_to_sign(url, expiry, "Content-MD5" => "deadbeef").should ==
53
+ "GET\ndeadbeef\n\n#{expiry}\n/johnsmith/"
54
+ end
55
+
56
+ it "changes the signature based on the Content-Type header" do
57
+ subject.string_to_sign(url, expiry, "Content-Type" => "image/png").should ==
58
+ "GET\n\nimage/png\n#{expiry}\n/johnsmith/"
59
+ end
60
+
61
+ it "changes the signature based on x-amz-* headers" do
62
+ subject.string_to_sign(url, expiry, "x-amz-acl" => "public-read").should ==
63
+ "GET\n\n\n#{expiry}\nx-amz-acl:public-read\n/johnsmith/"
64
+ end
65
+ end
44
66
  end
45
67
 
metadata CHANGED
@@ -1,7 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awsraw
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Pete Yandell
@@ -10,34 +11,38 @@ authors:
10
11
  autorequire:
11
12
  bindir: bin
12
13
  cert_chain: []
13
- date: 2013-06-04 00:00:00.000000000 Z
14
+ date: 2013-06-06 00:00:00.000000000 Z
14
15
  dependencies:
15
16
  - !ruby/object:Gem::Dependency
16
17
  name: rake
17
18
  requirement: !ruby/object:Gem::Requirement
19
+ none: false
18
20
  requirements:
19
- - - '>='
21
+ - - ! '>='
20
22
  - !ruby/object:Gem::Version
21
23
  version: '0'
22
24
  type: :development
23
25
  prerelease: false
24
26
  version_requirements: !ruby/object:Gem::Requirement
27
+ none: false
25
28
  requirements:
26
- - - '>='
29
+ - - ! '>='
27
30
  - !ruby/object:Gem::Version
28
31
  version: '0'
29
32
  - !ruby/object:Gem::Dependency
30
33
  name: rspec
31
34
  requirement: !ruby/object:Gem::Requirement
35
+ none: false
32
36
  requirements:
33
- - - '>='
37
+ - - ! '>='
34
38
  - !ruby/object:Gem::Version
35
39
  version: '0'
36
40
  type: :development
37
41
  prerelease: false
38
42
  version_requirements: !ruby/object:Gem::Requirement
43
+ none: false
39
44
  requirements:
40
- - - '>='
45
+ - - ! '>='
41
46
  - !ruby/object:Gem::Version
42
47
  version: '0'
43
48
  description: A client for Amazon Web Services in the style of FlickRaw
@@ -73,26 +78,27 @@ files:
73
78
  homepage: http://github.com/envato/awsraw
74
79
  licenses:
75
80
  - MIT
76
- metadata: {}
77
81
  post_install_message:
78
82
  rdoc_options: []
79
83
  require_paths:
80
84
  - lib
81
85
  required_ruby_version: !ruby/object:Gem::Requirement
86
+ none: false
82
87
  requirements:
83
- - - '>='
88
+ - - ! '>='
84
89
  - !ruby/object:Gem::Version
85
90
  version: '0'
86
91
  required_rubygems_version: !ruby/object:Gem::Requirement
92
+ none: false
87
93
  requirements:
88
- - - '>='
94
+ - - ! '>='
89
95
  - !ruby/object:Gem::Version
90
96
  version: '0'
91
97
  requirements: []
92
98
  rubyforge_project: awsraw
93
- rubygems_version: 2.0.3
99
+ rubygems_version: 1.8.23
94
100
  signing_key:
95
- specification_version: 4
101
+ specification_version: 3
96
102
  summary: Minimal AWS client
97
103
  test_files:
98
104
  - spec/s3/client_spec.rb
@@ -101,3 +107,4 @@ test_files:
101
107
  - spec/s3/query_string_signer_spec.rb
102
108
  - spec/s3/request_spec.rb
103
109
  - spec/s3/signer_spec.rb
110
+ has_rdoc:
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 87374bc9711ba8212767836856d7e090f5c3893b
4
- data.tar.gz: 65d1a59bfcc0b37ab7a6fb55e2eb5bf789476206
5
- SHA512:
6
- metadata.gz: 7b578a0265a94387760fc5a371f8b77a002449b6f357200c0375bced4b996dd5db4b1963c84ab565facd3a87972d34aae983f391828297eada924c2bd777e9d2
7
- data.tar.gz: 6feb80ffd5a50cbe3c6ebdb9de051f8512b9aa44d54a0f2e8506ef4422c379841df7a4cee702d81f37b6d4b394d17ba66a4db51b52c7164b7aba4fb841124a8a