awsraw 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,6 +10,7 @@ module AWSRaw
10
10
  #
11
11
  # See http://docs.amazonwebservices.com/AmazonS3/latest/dev/RESTAuthentication.html
12
12
  class Signer
13
+ SUBRESOURCES = %w(acl lifecycle location logging notification partNumber policy requestPayment torrent uploadId uploads versionId versioning versions website)
13
14
 
14
15
  def initialize(access_key_id, secret_access_key)
15
16
  @access_key_id = access_key_id
@@ -56,12 +57,26 @@ module AWSRaw
56
57
  end
57
58
 
58
59
  def canonicalized_resource(request)
59
- # TODO: Should also append the sub-resource.
60
60
  if request.host =~ /^(.+)\.s3\.amazonaws\.com/
61
61
  bucket = request.host.split(/\./).first
62
- '/' + bucket + request.path
62
+ resource = '/' + bucket + request.path
63
63
  else
64
- request.path
64
+ resource = request.path
65
+ end
66
+ resource + canonicalized_subresource(request)
67
+ end
68
+
69
+ def canonicalized_subresource(request)
70
+ return "" unless request.query
71
+ subresources =
72
+ request.query.split('&')
73
+ .map { |s| s.split('=') }
74
+ .select { |k,v| SUBRESOURCES.include? k }
75
+ .map { |k,v| k + (v ? "=#{v}" : "") }
76
+ if subresources.any?
77
+ "?" + subresources.join("&")
78
+ else
79
+ ""
65
80
  end
66
81
  end
67
82
 
@@ -1,3 +1,3 @@
1
1
  module Awsraw
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -7,45 +7,67 @@ describe AWSRaw::S3::Signer do
7
7
  subject { AWSRaw::S3::Signer.new(access_key_id, secret_access_key) }
8
8
 
9
9
  context "examples from Amazon docs" do
10
- it "signs a get request correctly" do
11
- request = stub(
12
- :method => "GET",
13
- :host => "s3.amazonaws.com",
14
- :path => "/johnsmith/photos/puppy.jpg",
15
- :headers => { "Date" => "Tue, 27 Mar 2007 19:36:42 +0000" }
16
- )
10
+ context "Example Object GET" do
11
+ it "signs a get request correctly" do
12
+ request = stub(
13
+ :method => "GET",
14
+ :host => "s3.amazonaws.com",
15
+ :path => "/johnsmith/photos/puppy.jpg",
16
+ :query => nil,
17
+ :headers => { "Date" => "Tue, 27 Mar 2007 19:36:42 +0000" }
18
+ )
17
19
 
18
- subject.string_to_sign(request).should ==
19
- "GET\n\n\nTue, 27 Mar 2007 19:36:42 +0000\n/johnsmith/photos/puppy.jpg"
20
+ subject.string_to_sign(request).should ==
21
+ "GET\n\n\nTue, 27 Mar 2007 19:36:42 +0000\n/johnsmith/photos/puppy.jpg"
20
22
 
21
- subject.signature(request).should == "AWS #{access_key_id}:bWq2s1WEIj+Ydj0vQ697zp+IXMU="
22
- end
23
+ subject.signature(request).should == "AWS #{access_key_id}:bWq2s1WEIj+Ydj0vQ697zp+IXMU="
24
+ end
25
+
26
+ it "signs an upload correctly" do
27
+ request = stub(
28
+ :method => "PUT",
29
+ :host => "s3.amazonaws.com",
30
+ :path => "/static.johnsmith.net/db-backup.dat.gz",
31
+ :query => nil,
32
+ :headers => {
33
+ "User-Agent" => "curl/7.15.5",
34
+ "Date" => "Tue, 27 Mar 2007 21:06:08 +0000",
35
+ "x-amz-acl" => "public-read",
36
+ "Content-Type" => "application/x-download",
37
+ "Content-MD5" => "4gJE4saaMU4BqNR0kLY+lw==",
38
+ "X-Amz-Meta-ReviewedBy" => "joe@johnsmith.net,jane@johnsmith.net",
39
+ "X-Amz-Meta-FileChecksum" => "0x02661779",
40
+ "X-Amz-Meta-ChecksumAlgorithm" => "crc32",
41
+ "Content-Disposition" => "attachment; filename=database.dat",
42
+ "Content-Encoding" => "gzip",
43
+ "Content-Length" => "5913339"
44
+ }
45
+ )
46
+
47
+ subject.string_to_sign(request).should ==
48
+ "PUT\n4gJE4saaMU4BqNR0kLY+lw==\napplication/x-download\nTue, 27 Mar 2007 21:06:08 +0000\nx-amz-acl:public-read\nx-amz-meta-checksumalgorithm:crc32\nx-amz-meta-filechecksum:0x02661779\nx-amz-meta-reviewedby:joe@johnsmith.net,jane@johnsmith.net\n/static.johnsmith.net/db-backup.dat.gz"
23
49
 
24
- it "signs an upload correctly" do
25
- request = stub(
26
- :method => "PUT",
27
- :host => "s3.amazonaws.com",
28
- :path => "/static.johnsmith.net/db-backup.dat.gz",
29
- :headers => {
30
- "User-Agent" => "curl/7.15.5",
31
- "Date" => "Tue, 27 Mar 2007 21:06:08 +0000",
32
- "x-amz-acl" => "public-read",
33
- "Content-Type" => "application/x-download",
34
- "Content-MD5" => "4gJE4saaMU4BqNR0kLY+lw==",
35
- "X-Amz-Meta-ReviewedBy" => "joe@johnsmith.net,jane@johnsmith.net",
36
- "X-Amz-Meta-FileChecksum" => "0x02661779",
37
- "X-Amz-Meta-ChecksumAlgorithm" => "crc32",
38
- "Content-Disposition" => "attachment; filename=database.dat",
39
- "Content-Encoding" => "gzip",
40
- "Content-Length" => "5913339"
41
- }
42
- )
43
-
44
- subject.string_to_sign(request).should ==
45
- "PUT\n4gJE4saaMU4BqNR0kLY+lw==\napplication/x-download\nTue, 27 Mar 2007 21:06:08 +0000\nx-amz-acl:public-read\nx-amz-meta-checksumalgorithm:crc32\nx-amz-meta-filechecksum:0x02661779\nx-amz-meta-reviewedby:joe@johnsmith.net,jane@johnsmith.net\n/static.johnsmith.net/db-backup.dat.gz"
46
-
47
- subject.signature(request).should == "AWS #{access_key_id}:ilyl83RwaSoYIEdixDQcA4OnAnc="
50
+ subject.signature(request).should == "AWS #{access_key_id}:ilyl83RwaSoYIEdixDQcA4OnAnc="
51
+ end
48
52
  end
49
53
 
54
+ context "Example Fetch" do
55
+ let(:request) { stub(
56
+ :method => "GET",
57
+ :host => "johnsmith.s3.amazonaws.com",
58
+ :path => "/",
59
+ :query => "acl",
60
+ :headers => { "Date" => "Tue, 27 Mar 2007 19:44:46 +0000" }
61
+ )}
62
+
63
+ it "generates the correct string to sign" do
64
+ subject.string_to_sign(request).should ==
65
+ "GET\n\n\nTue, 27 Mar 2007 19:44:46 +0000\n/johnsmith/?acl"
66
+ end
67
+
68
+ it "signs the request correctly" do
69
+ subject.signature(request).should == "AWS #{access_key_id}:c2WLPFtWHVgbEmeEG93a4cG37dM="
70
+ end
71
+ end
50
72
  end
51
73
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awsraw
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2013-04-23 00:00:00.000000000 Z
14
+ date: 2013-06-04 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rake
@@ -87,18 +87,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
87
87
  - - ! '>='
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
- segments:
91
- - 0
92
- hash: -2102654929379621144
93
90
  required_rubygems_version: !ruby/object:Gem::Requirement
94
91
  none: false
95
92
  requirements:
96
93
  - - ! '>='
97
94
  - !ruby/object:Gem::Version
98
95
  version: '0'
99
- segments:
100
- - 0
101
- hash: -2102654929379621144
102
96
  requirements: []
103
97
  rubyforge_project: awsraw
104
98
  rubygems_version: 1.8.23
@@ -111,3 +105,4 @@ test_files:
111
105
  - spec/s3/md5_digester_spec.rb
112
106
  - spec/s3/query_string_signer_spec.rb
113
107
  - spec/s3/signer_spec.rb
108
+ has_rdoc: