Sha256: 44f8ae4c6fc62ffc9daa29338d0daa8ea21933a48f86204a6c0ac26d330c3188

Contents?: true

Size: 1.17 KB

Versions: 5

Compression:

Stored size: 1.17 KB

Contents

require 'authmac'

module Authmac
  describe Authenticator do
    let(:hmac_checker)      { double("HmacChecker", validate: true) }
    let(:timestamp_checker) { double("TimestampChecker", validate: true) }
    let(:auth) { Authenticator.new(hmac_checker, timestamp_checker) }

    describe '#validate' do
      it 'checks hmac' do
        hash = {userid: 'someone', clientid: 'something'}
        hmac = "a-calculated-hmac"
        expect(hmac_checker).to receive(:validate).with(hash, hmac)
        auth.validate(hash.merge(hmac: hmac))
      end

      it 'sets the hmac_failure flag when hmac is incorrect' do
        allow(hmac_checker).to receive(:validate).and_return(false)
        expect(auth.validate({}).hmac_failure?).to be_truthy
      end

      it 'checks timestamp' do
        timestamp = Time.now.to_i
        expect(timestamp_checker).to receive(:validate).with(timestamp)
        auth.validate({timestamp: timestamp.to_s})
      end

      it 'sets the timestamp_failure flag when timestamp is out of bounds' do
        allow(timestamp_checker).to receive(:validate).and_return(false)
        expect(auth.validate({}).timestamp_failure?).to be_truthy
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
authmac-2.0.2 spec/authmac_spec.rb
authmac-2.0.1 spec/authmac_spec.rb
authmac-2.0.0 spec/authmac_spec.rb
authmac-1.0.4 spec/authmac_spec.rb
authmac-1.0.3 spec/authmac_spec.rb