Sha256: 88c94130251c7f625f1b6904c5a3bafdb56ad32e399d612468136ccc3fa9767e

Contents?: true

Size: 1.13 KB

Versions: 2

Compression:

Stored size: 1.13 KB

Contents

require 'spec_helper'

describe SignedForm::HMAC do
  describe 'create_hmac' do
    it 'should raise if no key is given' do
      expect { SignedForm::HMAC.create_hmac "foo" }.to raise_error(SignedForm::Errors::NoSecretKey)
    end

    context 'when a key is present' do
      before { SignedForm::HMAC.secret_key = "superdupersecret" }
      after  { SignedForm::HMAC.secret_key = nil }

      it 'should create a hex signature' do
        SignedForm::HMAC.create_hmac("my signed message").length.should == 40
      end
    end
  end

  describe 'verify_hmac' do
    it 'should raise if no key is given' do
      expect { SignedForm::HMAC.verify_hmac 'foo', 'bar' }.to raise_error(SignedForm::Errors::NoSecretKey)
    end

    context 'when a key is present' do
      before { SignedForm::HMAC.secret_key = "superdupersecret" }
      after  { SignedForm::HMAC.secret_key = nil }

      let(:signature) { SignedForm::HMAC.create_hmac "My super secret" }

      specify { SignedForm::HMAC.verify_hmac(signature, "My super secret").should be_true }
      specify { SignedForm::HMAC.verify_hmac(signature, "My bad secret").should_not be_true }
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
signed_form-0.0.1 spec/hmac_spec.rb
signed_form-0.0.1.pre1 spec/signed_form/hmac_spec.rb