simple-api-auth 0.1.0 → 0.1.1

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: 4b66b03e6dde55a63109efefcf8571850b7c471e
4
- data.tar.gz: 8409349483eea331a07698ccf8c25de59ad14fb4
3
+ metadata.gz: 93fd0b3729fe8e56836fe64f413fe653ae220cee
4
+ data.tar.gz: 6d34da98cfa5b789cbeea5b921b1b257c14bcf91
5
5
  SHA512:
6
- metadata.gz: 1696e31b7c4af412db8382b66ed70727422dfdb0c6a2225331f96c9d94eb4dc4e35cd04dde3e970963aee49545947b834765d2557c8663cce24f5ba80ed81119
7
- data.tar.gz: 2123dd8a3fe6c5eac4c430e1ac80594d18596d7fe0df9eaf8ecddd7bfcbc8c29d88c96b4698fffa4fca2a4e8dae975ce07519aae464cbf17f153ef17161b980d
6
+ metadata.gz: 286a1234f05dda3f6ade05dfd5fbdf35b43ca8a03c5821f94720c1150d941dd805b92e198de89a5cbd9871edd7230cbe0c171ea218da74855d69267789822f42
7
+ data.tar.gz: c471d4bf302effaff92515fbfe17e5f4373f5dc59c91f8038eee359597729fd6d6c34bf4b8a8b761b887f05b8f812a010c53a436f685fc16e3ee5cbb8d449d9b
@@ -15,7 +15,7 @@ module SimpleApiAuth
15
15
  def time
16
16
  header_key = SimpleApiAuth.config.header_keys[:time]
17
17
  Time.parse(headers[header_key])
18
- rescue ArgumentError
18
+ rescue ArgumentError, TypeError
19
19
  nil
20
20
  end
21
21
 
@@ -1,6 +1,6 @@
1
1
  module SimpleApiAuth
2
2
  MAJOR = 0
3
3
  MINOR = 1
4
- PATCH = 0
4
+ PATCH = 1
5
5
  VERSION = "#{MAJOR}.#{MINOR}.#{PATCH}"
6
6
  end
@@ -31,13 +31,15 @@ module SimpleApiAuth
31
31
  end
32
32
 
33
33
  def self.compute_signature(request, secret_key, options = {})
34
+ request = SimpleApiAuth::Request.create(request)
34
35
  signer = SimpleApiAuth.config.signer.new(options)
35
36
  signer.sign(request, secret_key)
36
37
  end
37
38
 
38
39
  def self.sign!(request, secret_key, options = {})
39
- signature = compute_signature(request, secret_key, options)
40
40
  header_name = SimpleApiAuth.config.request_fields[:headers]
41
+ request.send(header_name)[SimpleApiAuth.config.header_keys[:time]] = Time.now.utc.iso8601
42
+ signature = compute_signature(request, secret_key, options)
41
43
  authorization_key = SimpleApiAuth.config.header_keys[:authorization]
42
44
  request.send(header_name)[authorization_key] = "Signature: #{signature}"
43
45
  request
@@ -44,6 +44,11 @@ describe SimpleApiAuth do
44
44
  base_request.headers[:x_saa_auth_time] = 'foobar'
45
45
  expect(base_request.time).to be_nil
46
46
  end
47
+
48
+ it 'should return nil on empty time' do
49
+ base_request.headers.delete :x_saa_auth_time
50
+ expect(base_request.time).to be_nil
51
+ end
47
52
  end
48
53
  end
49
54
  end
@@ -101,10 +101,17 @@ describe SimpleApiAuth do
101
101
  end
102
102
 
103
103
  describe '#sign!' do
104
- before(:each) { SimpleApiAuth.sign!(request, secret_key) }
105
104
  it 'should sign the current request' do
105
+ SimpleApiAuth.sign!(request, secret_key)
106
106
  expect(subject).to be_truthy
107
107
  end
108
+
109
+ it 'should add time header' do
110
+ request.headers.delete :x_saa_auth_time
111
+ SimpleApiAuth.sign!(request, secret_key)
112
+ expect(subject).to be_truthy
113
+ expect(request.headers[:x_saa_auth_time]).not_to be_nil
114
+ end
108
115
  end
109
116
  end
110
117
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple-api-auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Perez