escher 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bf5ca3954d669d4c1305dd98027a8b5d4fe37c49
4
- data.tar.gz: 4a16a2338e1a81efade3a7bd9e01ac5bc888c453
3
+ metadata.gz: 4b2aaa51a97cbcacb8f91e5ee93053a4bbe4e5a1
4
+ data.tar.gz: d7b41ccf26d7f5a94562b092f88072bdb5691f75
5
5
  SHA512:
6
- metadata.gz: 7f121d4fc3afed7141855fc060e8a6f04af57f783d823b15a43f61bbad4dbcefc671514938b103d01e2fbbd605853aeb0cdb47a7d78762c2c86b5edf2820f133
7
- data.tar.gz: 102ca5ed92167b8cfa9ddb9fca6d1cd54e5a6d32006a46e2965185cf575e91ff449012fa7e86be7578600687734adcfc9e6bc210d5ce81b25a409133d0b72c07
6
+ metadata.gz: 2e2d44cc276b8bf74e66148e298f02286241233ed020139c426cb5fc6fd6e0b1b4e3c7f089996903a223df929528c67cba68cb48152a9575ee5eeeca460997e8
7
+ data.tar.gz: a565aa6cc4ce556d81cf566c0d14fac90087789495e3ffb383582f84a3afacecf8976938ab8c5c5273f27bb4820b605d72a657329453a97daf14300c9e01b6de
data/README.md CHANGED
@@ -6,3 +6,5 @@ Escher helps you creating secure HTTP requests (for APIs) by signing HTTP(s) req
6
6
  The algorithm is based on [Amazon's _AWS Signature Version 4_](http://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-authenticating-requests.html), but we have generalized and extended it.
7
7
 
8
8
  More details will be available at our [documentation site](http://escherauth.io/).
9
+
10
+ Check out a [working example] (https://github.com/emartech/escher-ruby-example).
data/lib/escher/auth.rb CHANGED
@@ -106,7 +106,13 @@ module Escher
106
106
 
107
107
  def generate_signed_url(url_to_sign, client, expires = 86400)
108
108
  uri = Addressable::URI.parse(url_to_sign)
109
- host = uri.host
109
+
110
+ if (uri.port.present?) && (uri.port != uri.default_port)
111
+ host = "#{uri.host}:#{uri.port}"
112
+ else
113
+ host = uri.host
114
+ end
115
+
110
116
  path = uri.path
111
117
  query_parts = (uri.query || '')
112
118
  .split('&', -1)
@@ -128,7 +134,7 @@ module Escher
128
134
  signature = generate_signature(client[:api_secret], body, headers, 'GET', headers_to_sign, path, query_parts)
129
135
  query_parts_with_signature = (query_parts.map { |k, v| [uri_encode(k), uri_encode(v)] } << query_pair('Signature', signature))
130
136
 
131
- uri.scheme + '://' + host + path + '?' + query_parts_with_signature.map { |k, v| k + '=' + v }.join('&') + (fragment === nil ? '' : '#' + fragment)
137
+ "#{uri.scheme}://#{host}#{path}?#{query_parts_with_signature.map { |k, v| k + '=' + v }.join('&')}#{(fragment === nil ? '' : '#' + fragment)}"
132
138
  end
133
139
 
134
140
 
@@ -17,13 +17,18 @@ module Escher
17
17
 
18
18
 
19
19
  def body
20
- request.body or ''
20
+ case request.body
21
+ when StringIO
22
+ request.body.string
23
+ else
24
+ request.body.to_s
25
+ end
21
26
  end
22
27
 
23
28
 
24
29
 
25
30
  def path
26
- request.env['REQUEST_PATH']
31
+ request.env['REQUEST_PATH'] || request.path
27
32
  end
28
33
 
29
34
 
@@ -1,3 +1,3 @@
1
1
  module Escher
2
- VERSION = '0.3.3'
2
+ VERSION = '0.3.4'
3
3
  end
@@ -189,6 +189,22 @@ module Escher
189
189
  end
190
190
 
191
191
 
192
+ [
193
+ ['http://iam.amazonaws.com:5000/', 'iam.amazonaws.com:5000'],
194
+ ['https://iam.amazonaws.com:5000/', 'iam.amazonaws.com:5000'],
195
+ ['http://iam.amazonaws.com:80/', 'iam.amazonaws.com'],
196
+ ['https://iam.amazonaws.com:443/', 'iam.amazonaws.com'],
197
+ ['http://iam.amazonaws.com:443/', 'iam.amazonaws.com:443'],
198
+ ['https://iam.amazonaws.com:80/', 'iam.amazonaws.com:80']
199
+ ].each do |input, expected_output|
200
+ it 'should automagically handle ports' do
201
+ escher = described_class.new('us-east-1/host/aws4_request', ESCHER_MIXED_OPTIONS.merge(current_time: Time.parse('2011/05/11 12:00:00 UTC')))
202
+ client = {:api_key_id => 'th3K3y', :api_secret => 'very_secure'}
203
+ expect(escher.generate_signed_url("#{input}something?foo=bar&baz=barbaz#hash", client, 123456)).to include expected_output
204
+ end
205
+ end
206
+
207
+
192
208
  it 'should validate presigned url' do
193
209
  escher = described_class.new('us-east-1/host/aws4_request', ESCHER_MIXED_OPTIONS.merge(current_time: Time.parse('2011/05/12 21:59:00 UTC')))
194
210
  presigned_uri =
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: escher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andras Barthazi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-03 00:00:00.000000000 Z
11
+ date: 2015-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler