api-auth 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,2 +1,2 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
  gemspec
@@ -1,10 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- api-auth (1.0.2)
4
+ api-auth (1.0.3)
5
5
 
6
6
  GEM
7
- remote: http://rubygems.org/
7
+ remote: https://rubygems.org/
8
8
  specs:
9
9
  actionpack (2.3.14)
10
10
  activesupport (= 2.3.14)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.2
1
+ 1.0.3
@@ -42,7 +42,7 @@ module ApiAuth
42
42
  def canonical_string
43
43
  [ @request.content_type,
44
44
  @request.content_md5,
45
- @request.request_uri,
45
+ @request.request_uri.gsub(/http:\/\/[^(,|\?|\/)]*/,''), # remove host
46
46
  @request.timestamp
47
47
  ].join(",")
48
48
  end
@@ -95,7 +95,9 @@ module ApiAuth
95
95
  if use_hmac && hmac_access_id && hmac_secret_key
96
96
  h = arguments.last
97
97
  tmp = "Net::HTTP::#{method.to_s.capitalize}".constantize.new(path, h)
98
+ tmp.body = arguments[0] if arguments.length > 1
98
99
  ApiAuth.sign!(tmp, hmac_access_id, hmac_secret_key)
100
+ arguments.last['Content-MD5'] = tmp['Content-MD5'] if tmp['Content-MD5']
99
101
  arguments.last['DATE'] = tmp['DATE']
100
102
  arguments.last['Authorization'] = tmp['Authorization']
101
103
  end
@@ -20,7 +20,7 @@ module ApiAuth
20
20
 
21
21
  def calculated_md5
22
22
  if @request.body
23
- body = @request.body.read
23
+ body = @request.raw_post
24
24
  else
25
25
  body = ''
26
26
  end
@@ -1,3 +1,6 @@
1
+ # give access to RestClient @processed_headers
2
+ module RestClient;class Request;attr_accessor :processed_headers;end;end
3
+
1
4
  module ApiAuth
2
5
 
3
6
  module RequestDrivers # :nodoc:
@@ -15,6 +18,7 @@ module ApiAuth
15
18
  def set_auth_header(header)
16
19
  @request.headers.merge!({ "Authorization" => header })
17
20
  @headers = fetch_headers
21
+ save_headers # enforce update of processed_headers based on last updated headers
18
22
  @request
19
23
  end
20
24
 
@@ -77,7 +81,11 @@ module ApiAuth
77
81
  def find_header(keys)
78
82
  keys.map {|key| @headers[key] }.compact.first
79
83
  end
80
-
84
+
85
+ def save_headers
86
+ @request.processed_headers = @request.make_headers(@headers)
87
+ end
88
+
81
89
  end
82
90
 
83
91
  end
@@ -280,7 +280,7 @@ describe "ApiAuth" do
280
280
  'REQUEST_METHOD' => 'PUT',
281
281
  'CONTENT_TYPE' => 'text/plain',
282
282
  'HTTP_DATE' => 'Mon, 23 Jan 1984 03:29:56 GMT',
283
- 'rack.input' => StringIO.new("hello\nworld"))
283
+ 'RAW_POST_DATA' => "hello\nworld")
284
284
  signed_request = ApiAuth.sign!(request, @access_id, @secret_key)
285
285
  signed_request.env['Content-MD5'].should == Digest::MD5.base64digest("hello\nworld")
286
286
  end
@@ -194,7 +194,7 @@ describe "ApiAuth::Headers" do
194
194
  end
195
195
 
196
196
  it "should generate the proper canonical string" do
197
- @headers.canonical_string.should == "text/plain,e59ff97941044f85df5297e1c302d260,http://example.org/resource.xml?foo=bar&bar=foo,Mon, 23 Jan 1984 03:29:56 GMT"
197
+ @headers.canonical_string.should == CANONICAL_STRING
198
198
  end
199
199
 
200
200
  it "should set the authorization header" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api-auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-06 00:00:00.000000000 Z
12
+ date: 2013-04-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -189,7 +189,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
189
189
  version: '0'
190
190
  segments:
191
191
  - 0
192
- hash: 3429846398106267766
192
+ hash: 579957539921083557
193
193
  required_rubygems_version: !ruby/object:Gem::Requirement
194
194
  none: false
195
195
  requirements:
@@ -198,7 +198,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
198
198
  version: '0'
199
199
  segments:
200
200
  - 0
201
- hash: 3429846398106267766
201
+ hash: 579957539921083557
202
202
  requirements: []
203
203
  rubyforge_project:
204
204
  rubygems_version: 1.8.24