Sha256: 8ab5e479c69287fd9fdf414635a21f1858a9e249ed2ed5214b71ab0b703242b0

Contents?: true

Size: 1.66 KB

Versions: 1

Compression:

Stored size: 1.66 KB

Contents

require 'spec_helper'

describe TimeSensitiveHmac do
  let(:secret) { 'abcd' * 8 }

  context "instantiating" do
    it "defaults to SHA256" do
      sig = TimeSensitiveHmac::Signature.new(secret)
      sig.digest.name.should == 'SHA256'
    end

    it "accepts any valid OpenSSL::Digest type" do
      sig = TimeSensitiveHmac::Signature.new(secret, :digest => 'sha1')
      sig.digest.name.should == 'SHA1'
    end

    it "assumes OpenSSL will reject default digest types" do
      -> {
        TimeSensitiveHmac::Signature.new(secret, :digest => 'sha666')
      }.should raise_error(RuntimeError)
    end
  end

  context "generating" do
    let!(:now)      { Time.utc(2013,1,1) }
    let(:signature) { TimeSensitiveHmac::Signature.new(secret) }

    it "generates with a time and data chunk" do
      digest = signature.generate(now, '{"sample"=>"data"}')
      digest.should == 'qDdAbSFV3/oDpmD10L0LySWZugYbzbCKxyZ7Z9Nd0RY='
    end

    it "generates with time, data, and a URL path context" do
      digest = signature.generate(
        now,
        '{"sample"=>"data"}',
        '/path/with?query=string'
      )
      digest.should == 'Wq+9pR/thhyUz0rTFHj4CxGQPGT271ZEJMdDSMPeucg='
    end
  end

  context "verification at exact moments" do
    pending "verifies signatures with valid data"
    pending "verifies signatures with a valid data and context pair"
    pending "fails invalid signatures"
  end

  context "verification with grace period" do
    pending "verifies signatures with valid data"
    pending "verifies signatures with a valid data and context pair"
    pending "fails invalid signatures"
    pending "fails valid signatures outside of the grace period"
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
time_sensitive_hmac-0.0.1 spec/time_sensitive_hmac_spec.rb