Sha256: 456435374844df49a8581a1f268445708436936358b8860820c9e932057f1781

Contents?: true

Size: 797 Bytes

Versions: 1

Compression:

Stored size: 797 Bytes

Contents

require 'spec_helper'

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

  describe 'create' do
    let(:hmac) { SignedForm::HMAC.new(secret_key: "superdupersecret") }

    it 'should create a hex signature' do
      hmac.create("my signed message").length.should == 40
      hmac.create("my signed message").should == "93c1ecd4c10122cbf873ca6cf9eff08888565054"
    end
  end

  describe 'verify' do
    let(:hmac) { SignedForm::HMAC.new(secret_key: "superdupersecret") }
    let(:signature) { hmac.create "My super secret" }

    specify { hmac.verify(signature, "My super secret").should be_true }
    specify { hmac.verify(signature, "My bad secret").should_not be_true }
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
signed_form-0.2.0 spec/hmac_spec.rb