authmac 1.0.0 → 1.0.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: 79cdcf6928f30abe694de994eba88c6f2ec89e28
4
- data.tar.gz: 62c7ba521390202bb2d61b28d183be513060a1b4
3
+ metadata.gz: e4b7bd1e6888d9396a2b8625350f3626575facb4
4
+ data.tar.gz: c868726a7655dd6063eea99029a2b09296d1b405
5
5
  SHA512:
6
- metadata.gz: a7faef3549f1033ed067aa165c1fbe6c9c2e6572d0d4564f5fbd83ccadaed50bc9c2f0922ff55a23d546ada894ef0fb025cba7e0e9536b8adca8a3d68427e712
7
- data.tar.gz: 486d280fccd12f4127caef2fe1c65982cd7b9d721ef350aa2224ae82e6526ca951ed51caa4655350ce14e4a8eee88144f46c243d04a3482da31f320028ebda56
6
+ metadata.gz: 864d917472213fda96505a9b093a24954805023619b6725b259dc26b9a705605a95156f9914944ec6716e4f348f3f05e211c24bff74069e8bedcdb34eb1164cc
7
+ data.tar.gz: 9501f5e4860c67f36f2fb0c9c758207c89090c1d10cfc6dc55accbf8f9b5eb81123101ab7728960b60ab392dc1d7063781d700e71f44754b1c785747c91aa0d4
data/authmac.gemspec CHANGED
@@ -18,5 +18,5 @@ Gem::Specification.new do |gem|
18
18
  gem.require_paths = ["lib"]
19
19
 
20
20
  gem.add_development_dependency "rake", "~> 10.0.3"
21
- gem.add_development_dependency "rspec", "~> 2.11"
21
+ gem.add_development_dependency "rspec", "~> 3.0.0.beta1"
22
22
  end
@@ -19,7 +19,7 @@ module Authmac
19
19
  private
20
20
 
21
21
  def digester
22
- OpenSSL::Digest::Digest.new(@digest)
22
+ OpenSSL::Digest.new(@digest)
23
23
  end
24
24
 
25
25
  def message_string(hash)
@@ -1,3 +1,3 @@
1
1
  module Authmac
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -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('')).should be_true
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").should be_false
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")).should be_true
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').should be_false
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
- hmacify('parameter|another')).should be_true
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
- hmacify('parameter|another')).should be_true
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').should == hmacify('parameter|another')
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::Digest.new(method)
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).should be_true
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)).should be_false
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)).should be_false
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) { stub("HmacChecker", validate: true) }
6
- let(:timestamp_checker) { stub("TimestampChecker", validate: true) }
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.should_receive(:validate).with(hash, hmac)
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.stub(validate: false)
19
- auth.validate({}).hmac_failure?.should be_true
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.should_receive(:validate).with(timestamp)
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.stub(validate: false)
30
- auth.validate({}).timestamp_failure?.should be_true
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.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: '2.11'
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: '2.11'
40
+ version: 3.0.0.beta1
41
41
  description: Single Sign-On implementation based on HMAC.
42
42
  email:
43
43
  - marten@veldthuis.com