ralexa 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -20,13 +20,13 @@ module Ralexa
20
20
 
21
21
  def sign_uri(original_uri)
22
22
  original_uri.dup.tap do |uri|
23
- uri.query_values = uri.query_values.merge(
23
+ add_query_values(uri,
24
24
  "AWSAccessKeyId" => @access_key_id,
25
25
  "Timestamp" => timestamp,
26
26
  "SignatureVersion" => SIGNATURE_VERSION.to_s,
27
27
  "SignatureMethod" => signature_method,
28
28
  )
29
- uri.query_values = uri.query_values.merge(
29
+ add_query_values(uri,
30
30
  "Signature" => signature(uri)
31
31
  )
32
32
  end
@@ -34,6 +34,10 @@ module Ralexa
34
34
 
35
35
  private
36
36
 
37
+ def add_query_values(uri, parameters)
38
+ uri.query_values = (uri.query_values || {}).merge(parameters)
39
+ end
40
+
37
41
  def string_to_sign(uri)
38
42
  [
39
43
  "GET",
@@ -1,3 +1,3 @@
1
1
  module Ralexa
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/ralexa.gemspec CHANGED
@@ -15,7 +15,8 @@ Gem::Specification.new do |gem|
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = Ralexa::VERSION
17
17
 
18
- gem.add_runtime_dependency "addressable"
18
+ # addressable 2.2.7 introduces URI#hostname for Net::HTTP compatibility.
19
+ gem.add_runtime_dependency "addressable", ">= 2.2.7"
19
20
  gem.add_runtime_dependency "nokogiri"
20
21
 
21
22
  gem.add_development_dependency "minitest"
@@ -6,9 +6,17 @@ module Ralexa
6
6
  describe UriSigner do
7
7
 
8
8
  let(:time_utc) { Time.now.utc }
9
+ let(:timestamp) { time_utc.strftime("%Y-%m-%dT%H:%M:%S.000Z") }
9
10
  let(:digest) { MiniTest::Mock.new }
10
11
  let(:hmac_signer) { MiniTest::Mock.new }
11
12
  let(:base64_encoder) { MiniTest::Mock.new }
13
+ let(:signed_uri) { signer.sign_uri(uri) }
14
+
15
+ before do
16
+ digest.expect :name, "FAKE"
17
+ hmac_signer.expect :digest, "the_hmac", [ digest, "secret", combined ]
18
+ base64_encoder.expect :encode64, "base64_encoded\n", [ "the_hmac" ]
19
+ end
12
20
 
13
21
  def signer
14
22
  UriSigner.new("id", "secret").tap do |rs|
@@ -22,20 +30,12 @@ module Ralexa
22
30
  describe "for http://example.org/path?b=c&a=b" do
23
31
 
24
32
  let(:uri) { Addressable::URI.parse("http://example.org/path?b=c&a=b") }
25
- let(:signed_uri) { signer.sign_uri(uri) }
26
- let(:timestamp) { time_utc.strftime("%Y-%m-%dT%H:%M:%S.000Z") }
27
-
28
- before do
33
+ let(:combined) do
29
34
  ts = URI.escape(timestamp, /:/)
30
- combined = [
31
- "GET",
32
- "example.org",
33
- "/path",
35
+ [
36
+ "GET", "example.org", "/path",
34
37
  "AWSAccessKeyId=id&SignatureMethod=HmacFAKE&SignatureVersion=2&Timestamp=#{ts}&a=b&b=c"
35
38
  ].join("\n")
36
- hmac_signer.expect :digest, "the_hmac", [ digest, "secret", combined ]
37
- base64_encoder.expect :encode64, "base64_encoded\n", [ "the_hmac" ]
38
- digest.expect :name, "FAKE"
39
39
  end
40
40
 
41
41
  it "returns a signed URL" do
@@ -57,5 +57,26 @@ module Ralexa
57
57
  end
58
58
  end
59
59
 
60
+ describe "for URL without query string" do
61
+ let(:uri) { Addressable::URI.parse("http://example.org/") }
62
+ let(:combined) do
63
+ ts = URI.escape(timestamp, /:/)
64
+ [
65
+ "GET", "example.org", "/",
66
+ "AWSAccessKeyId=id&SignatureMethod=HmacFAKE&SignatureVersion=2&Timestamp=#{ts}"
67
+ ].join("\n")
68
+ end
69
+
70
+ it "returns a signed URL" do
71
+ signed_uri.query_values.must_equal(
72
+ "AWSAccessKeyId" => "id",
73
+ "Signature" => "base64_encoded",
74
+ "SignatureMethod" => "HmacFAKE",
75
+ "SignatureVersion" => "2",
76
+ "Timestamp" => timestamp,
77
+ )
78
+ end
79
+ end
80
+
60
81
  end
61
82
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ralexa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,18 +13,18 @@ date: 2012-03-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: addressable
16
- requirement: &70339587667200 !ruby/object:Gem::Requirement
16
+ requirement: &70150126400840 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: '0'
21
+ version: 2.2.7
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70339587667200
24
+ version_requirements: *70150126400840
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: nokogiri
27
- requirement: &70339587666780 !ruby/object:Gem::Requirement
27
+ requirement: &70150126400420 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70339587666780
35
+ version_requirements: *70150126400420
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: minitest
38
- requirement: &70339587666360 !ruby/object:Gem::Requirement
38
+ requirement: &70150126399960 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70339587666360
46
+ version_requirements: *70150126399960
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rake
49
- requirement: &70339587665940 !ruby/object:Gem::Requirement
49
+ requirement: &70150126399540 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70339587665940
57
+ version_requirements: *70150126399540
58
58
  description: Ruby client for Amazon Alexa APIs.
59
59
  email:
60
60
  - paul@annesley.cc