Sha256: f43f86ddca4ec8eee15f25d7ec54854ebbbb25b7b180e9529795cdfdea972d4b

Contents?: true

Size: 1.28 KB

Versions: 7

Compression:

Stored size: 1.28 KB

Contents

require File.expand_path("../spec_helper", __dir__)
require "search_flip/aws_sigv4_plugin"

RSpec.describe SearchFlip::AwsSigv4Plugin do
  describe "#call" do
    subject(:plugin) do
      SearchFlip::AwsSigv4Plugin.new(
        region: "us-east-1",
        access_key_id: "access key",
        secret_access_key: "secret access key"
      )
    end

    let(:client) { SearchFlip::HTTPClient.new }

    it "adds the signed headers to the request" do
      Timecop.freeze Time.parse("2020-01-01 12:00:00 UTC") do
        expect(client).to receive(:headers).with(
          an_object_matching(
            "host" => "localhost",
            "authorization" => /.*/,
            "x-amz-content-sha256" => /.*/,
            "x-amz-date" => /20200101T120000Z/
          )
        )

        plugin.call(client, :get, "http://localhost/index")
      end
    end

    it "feeds the http method, full url and body to the signer" do
      body = JSON.generate(key: "value")

      signing_request = {
        http_method: "GET",
        url: "http://localhost/index?param=value",
        body: body
      }

      expect(plugin.signer).to receive(:sign_request).with(signing_request).and_call_original

      plugin.call(client, :get, "http://localhost/index", params: { param: "value" }, body: body)
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
search_flip-3.9.0 spec/search_flip/aws_sigv4_plugin_spec.rb
search_flip-4.0.0.beta16 spec/search_flip/aws_sigv4_plugin_spec.rb
search_flip-4.0.0.beta15 spec/search_flip/aws_sigv4_plugin_spec.rb
search_flip-4.0.0.beta14 spec/search_flip/aws_sigv4_plugin_spec.rb
search_flip-3.8.0 spec/search_flip/aws_sigv4_plugin_spec.rb
search_flip-4.0.0.beta13 spec/search_flip/aws_sigv4_plugin_spec.rb
search_flip-3.7.2 spec/search_flip/aws_sigv4_plugin_spec.rb