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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 93fd0b3729fe8e56836fe64f413fe653ae220cee
|
4
|
+
data.tar.gz: 6d34da98cfa5b789cbeea5b921b1b257c14bcf91
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 286a1234f05dda3f6ade05dfd5fbdf35b43ca8a03c5821f94720c1150d941dd805b92e198de89a5cbd9871edd7230cbe0c171ea218da74855d69267789822f42
|
7
|
+
data.tar.gz: c471d4bf302effaff92515fbfe17e5f4373f5dc59c91f8038eee359597729fd6d6c34bf4b8a8b761b887f05b8f812a010c53a436f685fc16e3ee5cbb8d449d9b
|
data/lib/simple-api-auth.rb
CHANGED
@@ -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
|