authmac 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/authmac.gemspec +1 -1
- data/lib/authmac/hmac_checker.rb +1 -1
- data/lib/authmac/version.rb +1 -1
- data/spec/authmac/hmac_checker_spec.rb +10 -10
- data/spec/authmac/timestamp_checker_spec.rb +3 -3
- data/spec/authmac_spec.rb +8 -8
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e4b7bd1e6888d9396a2b8625350f3626575facb4
|
4
|
+
data.tar.gz: c868726a7655dd6063eea99029a2b09296d1b405
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 864d917472213fda96505a9b093a24954805023619b6725b259dc26b9a705605a95156f9914944ec6716e4f348f3f05e211c24bff74069e8bedcdb34eb1164cc
|
7
|
+
data.tar.gz: 9501f5e4860c67f36f2fb0c9c758207c89090c1d10cfc6dc55accbf8f9b5eb81123101ab7728960b60ab392dc1d7063781d700e71f44754b1c785747c91aa0d4
|
data/authmac.gemspec
CHANGED
data/lib/authmac/hmac_checker.rb
CHANGED
data/lib/authmac/version.rb
CHANGED
@@ -9,33 +9,33 @@ module Authmac
|
|
9
9
|
let(:hash) { Hash.new }
|
10
10
|
|
11
11
|
it 'succeeds with the correct hmac' do
|
12
|
-
checker.validate(hash, hmacify('')).
|
12
|
+
expect(checker.validate(hash, hmacify(''))).to be_truthy
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'fails with an incorrect hmac' do
|
16
|
-
checker.validate(hash, "wrong").
|
16
|
+
expect(checker.validate(hash, "wrong")).to be_falsey
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
context 'for a hash with a single parameter' do
|
21
21
|
it 'succeeds with the correct hmac' do
|
22
|
-
checker.validate({single: 'parameter'}, hmacify("parameter")).
|
22
|
+
expect(checker.validate({single: 'parameter'}, hmacify("parameter"))).to be_truthy
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'fails with incorrect hmac' do
|
26
|
-
checker.validate({single: 'parameter'}, 'wrong').
|
26
|
+
expect(checker.validate({single: 'parameter'}, 'wrong')).to be_falsey
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
30
|
context 'for a hash with multiple parameters' do
|
31
31
|
it 'succeeds with correct hmac' do
|
32
|
-
checker.validate({first: 'parameter', second: 'another'},
|
33
|
-
|
32
|
+
expect(checker.validate({first: 'parameter', second: 'another'},
|
33
|
+
hmacify('parameter|another'))).to be_truthy
|
34
34
|
end
|
35
35
|
|
36
36
|
it 'sorts hash values based on their keys' do
|
37
|
-
checker.validate({second: 'another', first: 'parameter'},
|
38
|
-
|
37
|
+
expect(checker.validate({second: 'another', first: 'parameter'},
|
38
|
+
hmacify('parameter|another'))).to be_truthy
|
39
39
|
|
40
40
|
end
|
41
41
|
end
|
@@ -43,12 +43,12 @@ module Authmac
|
|
43
43
|
|
44
44
|
describe '#calculate_hmac' do
|
45
45
|
it 'generates hmac' do
|
46
|
-
checker.sign(second: 'another', first: 'parameter').
|
46
|
+
expect(checker.sign(second: 'another', first: 'parameter')).to eq(hmacify('parameter|another'))
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
50
|
def hmacify(string, method='sha1')
|
51
|
-
digester = OpenSSL::Digest
|
51
|
+
digester = OpenSSL::Digest.new(method)
|
52
52
|
OpenSSL::HMAC.hexdigest(digester, "very secret key", string)
|
53
53
|
end
|
54
54
|
end
|
@@ -5,15 +5,15 @@ module Authmac
|
|
5
5
|
let(:checker) { TimestampChecker.new(15*60, 5*60) }
|
6
6
|
|
7
7
|
it 'returns true if timestamp is recent' do
|
8
|
-
checker.validate(Time.now.to_i).
|
8
|
+
expect(checker.validate(Time.now.to_i)).to be_truthy
|
9
9
|
end
|
10
10
|
|
11
11
|
it 'returns false if timestamp is too old' do
|
12
|
-
checker.validate(Time.now.to_i - (15*60 + 1)).
|
12
|
+
expect(checker.validate(Time.now.to_i - (15*60 + 1))).to be_falsey
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'returns false if timestamp is too far in the future' do
|
16
|
-
checker.validate(Time.now.to_i + (5*60 + 1)).
|
16
|
+
expect(checker.validate(Time.now.to_i + (5*60 + 1))).to be_falsey
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
data/spec/authmac_spec.rb
CHANGED
@@ -2,32 +2,32 @@ require 'authmac'
|
|
2
2
|
|
3
3
|
module Authmac
|
4
4
|
describe Authenticator do
|
5
|
-
let(:hmac_checker) {
|
6
|
-
let(:timestamp_checker) {
|
5
|
+
let(:hmac_checker) { double("HmacChecker", validate: true) }
|
6
|
+
let(:timestamp_checker) { double("TimestampChecker", validate: true) }
|
7
7
|
let(:auth) { Authenticator.new(hmac_checker, timestamp_checker) }
|
8
8
|
|
9
9
|
describe '#validate' do
|
10
10
|
it 'checks hmac' do
|
11
11
|
hash = {userid: 'someone', clientid: 'something'}
|
12
12
|
hmac = "a-calculated-hmac"
|
13
|
-
hmac_checker.
|
13
|
+
expect(hmac_checker).to receive(:validate).with(hash, hmac)
|
14
14
|
auth.validate(hash.merge(hmac: hmac))
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'raises HmacError if hmac is incorrect' do
|
18
|
-
hmac_checker.
|
19
|
-
auth.validate({}).hmac_failure
|
18
|
+
allow(hmac_checker).to receive(:validate).and_return(false)
|
19
|
+
expect(auth.validate({}).hmac_failure?).to be_truthy
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'checks timestamp' do
|
23
23
|
timestamp = Time.now.to_i
|
24
|
-
timestamp_checker.
|
24
|
+
expect(timestamp_checker).to receive(:validate).with(timestamp)
|
25
25
|
auth.validate({timestamp: timestamp.to_s})
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'raises TimestampError if timestamp is out of bounds' do
|
29
|
-
timestamp_checker.
|
30
|
-
auth.validate({}).timestamp_failure
|
29
|
+
allow(timestamp_checker).to receive(:validate).and_return(false)
|
30
|
+
expect(auth.validate({}).timestamp_failure?).to be_truthy
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: authmac
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marten Veldthuis
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 3.0.0.beta1
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 3.0.0.beta1
|
41
41
|
description: Single Sign-On implementation based on HMAC.
|
42
42
|
email:
|
43
43
|
- marten@veldthuis.com
|