Sha256: ee7e7ad8ba2577919b2f7ddd82bbcd8931c6ae7cb191f976417d881c71bed888

Contents?: true

Size: 1.77 KB

Versions: 8

Compression:

Stored size: 1.77 KB

Contents

shared_examples_for "authentication" do
  describe "#authenticated?" do
    it "should not authenticate invalid secret" do
      Ey::Hmac.sign!(request, key_id, "#{key_secret}bad", adapter: adapter)

      Ey::Hmac.authenticated?(request, adapter: adapter) do |auth_id|
        (auth_id == key_id) && key_secret
      end.should be_false
    end

    it "should not authenticate invalid id" do
      Ey::Hmac.sign!(request, "what#{key_id}", key_secret, adapter: adapter)

      Ey::Hmac.authenticated?(request, adapter: adapter) do |auth_id|
        (auth_id == key_id) && key_secret
      end.should be_false
    end

    it "should not authenticate missing header" do
      Ey::Hmac.authenticated?(request, adapter: adapter) do |auth_id|
        (auth_id == key_id) && key_secret
      end.should be_false
    end
  end

  describe "#authenticate!" do
    it "should not authenticate invalid secret" do
      Ey::Hmac.sign!(request, key_id, "#{key_secret}bad", adapter: adapter)

      lambda {
        Ey::Hmac.authenticate!(request, adapter: adapter) do |auth_id|
          (auth_id == key_id) && key_secret
        end
      }.should raise_exception(Ey::Hmac::SignatureMismatch)
    end

    it "should not authenticate invalid id" do
      Ey::Hmac.sign!(request, "what#{key_id}", key_secret, adapter: adapter)

      lambda {
        Ey::Hmac.authenticate!(request, adapter: adapter) do |auth_id|
          (auth_id == key_id) && key_secret
        end
      }.should raise_exception(Ey::Hmac::MissingSecret)
    end

    it "should not authenticate missing header" do
      lambda {
        Ey::Hmac.authenticate!(request, adapter: adapter) do |auth_id|
          (auth_id == key_id) && key_secret
        end.should be_false
      }.should raise_exception(Ey::Hmac::MissingAuthorization)
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
ey-hmac-1.0.0 spec/shared/authenticated.rb
ey-hmac-0.1.3 spec/shared/authenticated.rb
ey-hmac-0.1.2 spec/shared/authenticated.rb
ey-hmac-0.1.1 spec/shared/authenticated.rb
ey-hmac-0.0.5 spec/shared/authenticated.rb
ey-hmac-0.0.4 spec/shared/authenticated.rb
ey-hmac-0.0.3 spec/shared/authenticated.rb
ey-hmac-0.0.2 spec/shared/authenticated.rb