Sha256: 65b4f1e5283bd70824d3e6e78b0c7a30869551ee1b9f689cd5b2e3797d839a2f

Contents?: true

Size: 1.48 KB

Versions: 11

Compression:

Stored size: 1.48 KB

Contents

require 'spec_helper'

describe Px::Service::Client::HmacSigning do
  let(:subject_class) {
    Class.new(Px::Service::Client::Base).tap do |c|
      # Anonymous classes don't have a name.  Stub out :name so that things work
      allow(c).to receive(:name).and_return("HmacSigning")
      c.include(Px::Service::Client::HmacSigning)
    end
  }

  let(:another_class) {
    Class.new(Px::Service::Client::Base).tap do |c|
      c.include(Px::Service::Client::HmacSigning)

      c.configure do |config|
        config.hmac_secret = "different secret"
      end
    end
  }

  subject { subject_class.new }
  let(:another_object) { another_class.new }

  describe '#make_request' do
    context "when the underlying request method succeeds" do
      let(:url) { 'http://localhost:3000/path' }
      let(:resp) { subject.send(:make_request, 'get', url) }
      let(:headers) { resp.request.options[:headers] }

      it "returns a Future" do
        expect(resp).to be_a_kind_of(Px::Service::Client::RetriableResponseFuture)
      end

      it "contains a header with auth signature" do
        expect(headers).to have_key("X-Service-Auth")
        expect(headers).to have_key("Timestamp")
      end

      let(:resp2) { another_object.send(:make_request, 'get', url) }
      let(:headers2) { resp2.request.options[:headers] }
      it "is different from the object of another class with a different key" do
        expect(headers["X-Service-Auth"]).not_to eq(headers2["X-Service-Auth"])
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
px-service-client-2.0.12 spec/px/service/client/hmac_signing_spec.rb
px-service-client-2.0.11 spec/px/service/client/hmac_signing_spec.rb
px-service-client-2.0.10 spec/px/service/client/hmac_signing_spec.rb
px-service-client-2.0.8 spec/px/service/client/hmac_signing_spec.rb
px-service-client-2.0.7 spec/px/service/client/hmac_signing_spec.rb
px-service-client-2.0.6 spec/px/service/client/hmac_signing_spec.rb
px-service-client-2.0.5 spec/px/service/client/hmac_signing_spec.rb
px-service-client-2.0.4 spec/px/service/client/hmac_signing_spec.rb
px-service-client-2.0.3 spec/px/service/client/hmac_signing_spec.rb
px-service-client-2.0.2 spec/px/service/client/hmac_signing_spec.rb
px-service-client-2.0.1 spec/px/service/client/hmac_signing_spec.rb