awsraw 0.1.9 → 1.0.0.alpha.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,107 @@
1
+ require 'awsraw/s3/signature'
2
+ require 'ostruct'
3
+ require 'json'
4
+
5
+ describe AWSRaw::S3::Signature do
6
+
7
+ let(:credentials) do
8
+ OpenStruct.new(
9
+ :access_key_id => "AKIAIOSFODNN7EXAMPLE",
10
+ :secret_access_key => "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
11
+ )
12
+ end
13
+
14
+ context ".signature" do
15
+ context "AWS example tests:" do
16
+ # Examples are pulled from the AWS docs:
17
+ # http://docs.aws.amazon.com/AmazonS3/latest/dev/RESTAuthentication.html
18
+
19
+ def self.test_example(title, string_to_sign, signature)
20
+ it "#{title} works" do
21
+ header = described_class.signature(string_to_sign, credentials)
22
+ expect(header).to eq(signature)
23
+ end
24
+ end
25
+
26
+ test_example "Object GET",
27
+ "GET\n\n\nTue, 27 Mar 2007 19:36:42 +0000\n/johnsmith/photos/puppy.jpg",
28
+ "bWq2s1WEIj+Ydj0vQ697zp+IXMU="
29
+
30
+ test_example "Object PUT",
31
+ "PUT\n\nimage/jpeg\nTue, 27 Mar 2007 21:15:45 +0000\n/johnsmith/photos/puppy.jpg",
32
+ "MyyxeRY7whkBe+bq8fHCL/2kKUg="
33
+
34
+ test_example "List",
35
+ "GET\n\n\nTue, 27 Mar 2007 19:42:41 +0000\n/johnsmith/",
36
+ "htDYFYduRNen8P9ZfE/s9SuKy0U="
37
+
38
+ test_example "Fetch",
39
+ "GET\n\n\nTue, 27 Mar 2007 19:44:46 +0000\n/johnsmith/?acl",
40
+ "c2WLPFtWHVgbEmeEG93a4cG37dM="
41
+
42
+ test_example "Delete",
43
+ "DELETE\n\n\nTue, 27 Mar 2007 21:20:26 +0000\n/johnsmith/photos/puppy.jpg",
44
+ "lx3byBScXR6KzyMaifNkardMwNk="
45
+
46
+ test_example "Upload",
47
+ "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",
48
+ "ilyl83RwaSoYIEdixDQcA4OnAnc="
49
+
50
+ test_example "List All My Buckets",
51
+ "GET\n\n\nWed, 28 Mar 2007 01:29:59 +0000\n/",
52
+ "qGdzdERIC03wnaRNKh6OqZehG9s="
53
+
54
+ test_example "Unicode Keys",
55
+ "GET\n\n\nWed, 28 Mar 2007 01:49:49 +0000\n/dictionary/fran%C3%A7ais/pr%c3%a9f%c3%a8re",
56
+ "DNEZGsoieTZ92F3bUfSPQcbGmlM="
57
+ end
58
+ end
59
+
60
+ context ".authorization_header" do
61
+ it "structures the header correctly" do
62
+ header = described_class.authorization_header("GET\n\n\nTue, 27 Mar 2007 19:36:42 +0000\n/johnsmith/photos/puppy.jpg", credentials)
63
+ expect(header).to eq("AWS #{credentials.access_key_id}:bWq2s1WEIj+Ydj0vQ697zp+IXMU=")
64
+ end
65
+ end
66
+
67
+ context "HTML form uploads" do
68
+ # Example data taken from:
69
+ # http://docs.aws.amazon.com/AmazonS3/latest/dev/HTTPPOSTExamples.html
70
+
71
+ let(:policy_json) do
72
+ <<EOF
73
+ { "expiration": "2007-12-01T12:00:00.000Z",
74
+ "conditions": [
75
+ {"bucket": "johnsmith"},
76
+ ["starts-with", "$key", "user/eric/"],
77
+ {"acl": "public-read"},
78
+ {"success_action_redirect": "http://johnsmith.s3.amazonaws.com/successful_upload.html"},
79
+ ["starts-with", "$Content-Type", "image/"],
80
+ {"x-amz-meta-uuid": "14365123651274"},
81
+ ["starts-with", "$x-amz-meta-tag", ""]
82
+ ]
83
+ }
84
+ EOF
85
+ end
86
+
87
+ let(:policy_base64) do
88
+ "eyAiZXhwaXJhdGlvbiI6ICIyMDA3LTEyLTAxVDEyOjAwOjAwLjAwMFoiLAogICJjb25kaXRpb25zIjogWwogICAgeyJidWNrZXQiOiAiam9obnNtaXRoIn0sCiAgICBbInN0YXJ0cy13aXRoIiwgIiRrZXkiLCAidXNlci9lcmljLyJdLAogICAgeyJhY2wiOiAicHVibGljLXJlYWQifSwKICAgIHsic3VjY2Vzc19hY3Rpb25fcmVkaXJlY3QiOiAiaHR0cDovL2pvaG5zbWl0aC5zMy5hbWF6b25hd3MuY29tL3N1Y2Nlc3NmdWxfdXBsb2FkLmh0bWwifSwKICAgIFsic3RhcnRzLXdpdGgiLCAiJENvbnRlbnQtVHlwZSIsICJpbWFnZS8iXSwKICAgIHsieC1hbXotbWV0YS11dWlkIjogIjE0MzY1MTIzNjUxMjc0In0sCiAgICBbInN0YXJ0cy13aXRoIiwgIiR4LWFtei1tZXRhLXRhZyIsICIiXQogIF0KfQo="
89
+ end
90
+
91
+ let(:signature) { "0RavWzkygo6QX9caELEqKi9kDbU=" }
92
+
93
+ it ".encode_form_policy correctly encodes a policy" do
94
+ expect(subject.encode_form_policy(policy_json)).to eq(policy_base64)
95
+ end
96
+
97
+ # Note: This test fails. I'm pretty sure the example in the AWS docs is
98
+ # wrong, but I'm leaving it failing until I can confirm that.
99
+ it ".form_signature correctly signs a policy" do
100
+ pending "Figure out which is wrong: the AWS examples or the code"
101
+ expect(subject.form_signature(policy_base64, credentials)).to eq(signature)
102
+ end
103
+
104
+ end
105
+
106
+ end
107
+
@@ -0,0 +1,94 @@
1
+ require 'awsraw/s3/string_to_sign'
2
+
3
+ describe AWSRaw::S3::StringToSign do
4
+
5
+ context ".string_to_sign" do
6
+ context "AWS example tests:" do
7
+ # Examples are pulled from the AWS docs:
8
+ # http://docs.aws.amazon.com/AmazonS3/latest/dev/RESTAuthentication.html
9
+
10
+ def self.test_example(title, request, string_to_sign)
11
+ it "#{title} works" do
12
+ expect(described_class.string_to_sign(request)).to eq(string_to_sign)
13
+ end
14
+ end
15
+
16
+ test_example "Object GET",
17
+ {
18
+ :method => "GET",
19
+ :uri => "http://johnsmith.s3.amazonaws.com/photos/puppy.jpg",
20
+ :date => "Tue, 27 Mar 2007 19:36:42 +0000"
21
+ },
22
+ "GET\n\n\nTue, 27 Mar 2007 19:36:42 +0000\n/johnsmith/photos/puppy.jpg"
23
+
24
+ test_example "Object PUT",
25
+ {
26
+ :method => "PUT",
27
+ :uri => "http://johnsmith.s3.amazonaws.com/photos/puppy.jpg",
28
+ :content_type => "image/jpeg",
29
+ :date => "Tue, 27 Mar 2007 21:15:45 +0000"
30
+ },
31
+ "PUT\n\nimage/jpeg\nTue, 27 Mar 2007 21:15:45 +0000\n/johnsmith/photos/puppy.jpg"
32
+
33
+ test_example "List",
34
+ {
35
+ :method => "GET",
36
+ :uri => "http://johnsmith.s3.amazonaws.com/?prefix=photos&max-keys=50&marker=puppy",
37
+ :bucket => "johnsmith",
38
+ :date => "Tue, 27 Mar 2007 19:42:41 +0000"
39
+ },
40
+ "GET\n\n\nTue, 27 Mar 2007 19:42:41 +0000\n/johnsmith/"
41
+
42
+ test_example "Fetch",
43
+ {
44
+ :method => "GET",
45
+ :uri => "http://johnsmith.s3.amazonaws.com/?acl",
46
+ :date => "Tue, 27 Mar 2007 19:44:46 +0000"
47
+ },
48
+ "GET\n\n\nTue, 27 Mar 2007 19:44:46 +0000\n/johnsmith/?acl"
49
+
50
+ test_example "Delete",
51
+ {
52
+ :method => "DELETE",
53
+ :uri => "http://s3.amazonaws.com/johnsmith/photos/puppy.jpg",
54
+ :date => "Tue, 27 Mar 2007 21:20:26 +0000"
55
+ },
56
+ "DELETE\n\n\nTue, 27 Mar 2007 21:20:26 +0000\n/johnsmith/photos/puppy.jpg"
57
+
58
+ test_example "Upload",
59
+ {
60
+ :method => "PUT",
61
+ :uri => "http://static.johnsmith.net:8080/db-backup.dat.gz",
62
+ :date => "Tue, 27 Mar 2007 21:06:08 +0000",
63
+ :content_md5 => "4gJE4saaMU4BqNR0kLY+lw==",
64
+ :content_type => "application/x-download",
65
+ :amz_headers => {
66
+ "x-amz-acl" => "public-read",
67
+ "X-Amz-Meta-ReviewedBy" => "joe@johnsmith.net,jane@johnsmith.net",
68
+ "X-Amz-Meta-FileChecksum" => "0x02661779",
69
+ "X-Amz-Meta-ChecksumAlgorithm" => "crc32"
70
+ }
71
+ },
72
+ "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"
73
+
74
+ test_example "List All My Buckets",
75
+ {
76
+ :method => "GET",
77
+ :uri => "http://s3.amazonaws.com/",
78
+ :date => "Wed, 28 Mar 2007 01:29:59 +0000",
79
+ },
80
+ "GET\n\n\nWed, 28 Mar 2007 01:29:59 +0000\n/"
81
+
82
+ test_example "Unicode Keys",
83
+ {
84
+ :method => "GET",
85
+ :uri => "http://s3.amazonaws.com/dictionary/fran%C3%A7ais/pr%c3%a9f%c3%a8re",
86
+ :date => "Wed, 28 Mar 2007 01:49:49 +0000"
87
+ },
88
+ "GET\n\n\nWed, 28 Mar 2007 01:49:49 +0000\n/dictionary/fran%C3%A7ais/pr%c3%a9f%c3%a8re"
89
+ end
90
+ end
91
+
92
+ end
93
+
94
+
metadata CHANGED
@@ -1,101 +1,105 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awsraw
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 1.0.0.alpha.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pete Yandell
8
8
  - David Goodlad
9
9
  - Jack 'chendo' Chen
10
- - Warren Seen
11
10
  autorequire:
12
11
  bindir: bin
13
- cert_chain:
14
- - |
15
- -----BEGIN CERTIFICATE-----
16
- MIIDKDCCAhCgAwIBAgIBAzANBgkqhkiG9w0BAQUFADA6MQ0wCwYDVQQDDARzajI2
17
- MRQwEgYKCZ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JJ5ETERp9alo88E=
33
- -----END CERTIFICATE-----
34
- date: 2016-01-29 00:00:00.000000000 Z
12
+ cert_chain: []
13
+ date: 2013-10-10 00:00:00.000000000 Z
35
14
  dependencies:
36
15
  - !ruby/object:Gem::Dependency
37
16
  name: rake
38
17
  requirement: !ruby/object:Gem::Requirement
39
18
  requirements:
40
- - - ">="
19
+ - - '>='
41
20
  - !ruby/object:Gem::Version
42
21
  version: '0'
43
22
  type: :development
44
23
  prerelease: false
45
24
  version_requirements: !ruby/object:Gem::Requirement
46
25
  requirements:
47
- - - ">="
26
+ - - '>='
48
27
  - !ruby/object:Gem::Version
49
28
  version: '0'
50
29
  - !ruby/object:Gem::Dependency
51
30
  name: rspec
52
31
  requirement: !ruby/object:Gem::Requirement
53
32
  requirements:
54
- - - ">="
33
+ - - ~>
55
34
  - !ruby/object:Gem::Version
56
- version: '0'
35
+ version: '2.14'
57
36
  type: :development
58
37
  prerelease: false
59
38
  version_requirements: !ruby/object:Gem::Requirement
60
39
  requirements:
61
- - - ">="
40
+ - - ~>
62
41
  - !ruby/object:Gem::Version
63
- version: '0'
42
+ version: '2.14'
43
+ - !ruby/object:Gem::Dependency
44
+ name: finer_struct
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ~>
48
+ - !ruby/object:Gem::Version
49
+ version: 0.0.5
50
+ type: :runtime
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ~>
55
+ - !ruby/object:Gem::Version
56
+ version: 0.0.5
57
+ - !ruby/object:Gem::Dependency
58
+ name: faraday
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ~>
62
+ - !ruby/object:Gem::Version
63
+ version: 0.8.8
64
+ type: :runtime
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ~>
69
+ - !ruby/object:Gem::Version
70
+ version: 0.8.8
64
71
  description: A client for Amazon Web Services in the style of FlickRaw
65
72
  email:
66
73
  - pete@notahat.com
67
74
  - david@goodlad.net
68
75
  - gems.awsraw@chen.do
69
- - warren@warrenseen.com
70
76
  executables: []
71
77
  extensions: []
72
78
  extra_rdoc_files: []
73
79
  files:
74
- - ".gitignore"
75
- - ".travis.yml"
80
+ - .gitignore
76
81
  - Gemfile
77
82
  - LICENSE
78
83
  - README.md
79
84
  - Rakefile
80
85
  - awsraw.gemspec
81
86
  - lib/awsraw.rb
82
- - lib/awsraw/s3.rb
87
+ - lib/awsraw/credentials.rb
88
+ - lib/awsraw/error.rb
89
+ - lib/awsraw/s3/canonicalized_resource.rb
83
90
  - lib/awsraw/s3/client.rb
84
- - lib/awsraw/s3/configuration.rb
85
- - lib/awsraw/s3/http_request_builder.rb
86
- - lib/awsraw/s3/md5_digester.rb
91
+ - lib/awsraw/s3/content_md5_header.rb
92
+ - lib/awsraw/s3/faraday_middleware.rb
87
93
  - lib/awsraw/s3/query_string_signer.rb
88
- - lib/awsraw/s3/request.rb
89
- - lib/awsraw/s3/response.rb
90
- - lib/awsraw/s3/signer.rb
94
+ - lib/awsraw/s3/signature.rb
95
+ - lib/awsraw/s3/string_to_sign.rb
91
96
  - lib/awsraw/version.rb
92
- - spec/s3/client_spec.rb
93
- - spec/s3/configuration_spec.rb
94
- - spec/s3/http_request_builder_spec.rb
95
- - spec/s3/md5_digester_spec.rb
97
+ - spec/s3/canonicalized_resource_spec.rb
98
+ - spec/s3/content_md5_header_spec.rb
99
+ - spec/s3/faraday_middleware_spec.rb
96
100
  - spec/s3/query_string_signer_spec.rb
97
- - spec/s3/request_spec.rb
98
- - spec/s3/signer_spec.rb
101
+ - spec/s3/signature_spec.rb
102
+ - spec/s3/string_to_sign_spec.rb
99
103
  homepage: http://github.com/envato/awsraw
100
104
  licenses:
101
105
  - MIT
@@ -106,25 +110,24 @@ require_paths:
106
110
  - lib
107
111
  required_ruby_version: !ruby/object:Gem::Requirement
108
112
  requirements:
109
- - - ">="
113
+ - - '>='
110
114
  - !ruby/object:Gem::Version
111
115
  version: '0'
112
116
  required_rubygems_version: !ruby/object:Gem::Requirement
113
117
  requirements:
114
- - - ">="
118
+ - - '>'
115
119
  - !ruby/object:Gem::Version
116
- version: '0'
120
+ version: 1.3.1
117
121
  requirements: []
118
122
  rubyforge_project: awsraw
119
- rubygems_version: 2.5.1
123
+ rubygems_version: 2.0.3
120
124
  signing_key:
121
125
  specification_version: 4
122
126
  summary: Minimal AWS client
123
127
  test_files:
124
- - spec/s3/client_spec.rb
125
- - spec/s3/configuration_spec.rb
126
- - spec/s3/http_request_builder_spec.rb
127
- - spec/s3/md5_digester_spec.rb
128
+ - spec/s3/canonicalized_resource_spec.rb
129
+ - spec/s3/content_md5_header_spec.rb
130
+ - spec/s3/faraday_middleware_spec.rb
128
131
  - spec/s3/query_string_signer_spec.rb
129
- - spec/s3/request_spec.rb
130
- - spec/s3/signer_spec.rb
132
+ - spec/s3/signature_spec.rb
133
+ - spec/s3/string_to_sign_spec.rb
checksums.yaml.gz.sig DELETED
@@ -1,2 +0,0 @@
1
- I�\��D|wP���Mg�a���K��ȇ&�3�!�i�^�qfnlw���CDn��C>���R{��'�$�Q4�ܓRG���4���;fϩ� ������K.f�LD��ݽ�VI��(�y�E�}M�j�����W�T7%J��� �E�c��
2
- a��U���3M�j�YK w��<ګcoi%��0|��hOb�b>��|]�y9��6�z��,���FO�C�B\�oC��8 P0 �˄��m�nR1L�x?��:_�
data.tar.gz.sig DELETED
Binary file
data/.travis.yml DELETED
@@ -1,7 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 1.9
5
- - 2.0
6
- - 2.1
7
- - 2.2
data/lib/awsraw/s3.rb DELETED
@@ -1,15 +0,0 @@
1
- require 'awsraw/s3/configuration'
2
-
3
- module AWSRaw
4
- module S3
5
- def configuration
6
- @configuration ||= self::Configuration.new
7
- end
8
- module_function :configuration
9
-
10
- def configure
11
- yield(configuration)
12
- end
13
- module_function :configure
14
- end
15
- end
@@ -1,12 +0,0 @@
1
- module AWSRaw
2
- module S3
3
- class Configuration
4
- attr_accessor :host, :regional_hosts
5
-
6
- def initialize
7
- @host = "s3.amazonaws.com"
8
- @regional_hosts = Hash.new { |hash, region| hash[region] = "s3-#{region}.amazonaws.com" }
9
- end
10
- end
11
- end
12
- end
@@ -1,51 +0,0 @@
1
- require 'net/http'
2
- module AWSRaw
3
- module S3
4
- class HTTPRequestBuilder
5
- attr_reader :s3_request
6
-
7
- def initialize(s3_request)
8
- @s3_request = s3_request
9
- end
10
-
11
- def build
12
- klass = http_request_class(s3_request)
13
- path = s3_request.uri.request_uri
14
-
15
- klass.new(path).tap do |http_request|
16
- s3_request.headers.each do |name, value|
17
- http_request[name] = value
18
- end
19
- set_content_on_request(http_request, s3_request.content)
20
- end
21
- end
22
-
23
- private
24
-
25
- def http_request_class(s3_request)
26
- case s3_request.method
27
- when "GET"
28
- Net::HTTP::Get
29
- when "HEAD"
30
- Net::HTTP::Head
31
- when "PUT"
32
- Net::HTTP::Put
33
- when "POST"
34
- Net::HTTP::Post
35
- else
36
- raise "Invalid HTTP method!"
37
- end
38
- end
39
-
40
- def set_content_on_request(http_request, content)
41
- if content.is_a?(File)
42
- http_request.body_stream = content
43
- http_request['Content-Length'] = content.size.to_s
44
- else
45
- http_request.body = content
46
- end
47
- end
48
-
49
- end
50
- end
51
- end