spec/headers_spec.rb in api-auth-2.4.1 vs spec/headers_spec.rb in api-auth-2.5.0

- old
+ new

@@ -1,6 +1,6 @@ -require File.expand_path(File.dirname(__FILE__) + '/spec_helper') +require 'spec_helper' describe ApiAuth::Headers do describe '#canonical_string' do context 'uri edge cases' do let(:request) { RestClient::Request.new(url: uri, method: :get) } @@ -51,11 +51,11 @@ let(:driver) { headers.instance_variable_get('@request') } before do allow(driver).to receive(:http_method).and_return 'GET' allow(driver).to receive(:content_type).and_return 'text/html' - allow(driver).to receive(:content_md5).and_return '12345' + allow(driver).to receive(:content_hash).and_return '12345' allow(driver).to receive(:request_uri).and_return '/foo' allow(driver).to receive(:timestamp).and_return 'Mon, 23 Jan 1984 03:29:56 GMT' end context 'when not passed an override' do @@ -81,11 +81,11 @@ let(:driver) { headers.instance_variable_get('@request') } before do allow(driver).to receive(:http_method).and_return nil allow(driver).to receive(:content_type).and_return 'text/html' - allow(driver).to receive(:content_md5).and_return '12345' + allow(driver).to receive(:content_hash).and_return '12345' allow(driver).to receive(:request_uri).and_return '/foo' allow(driver).to receive(:timestamp).and_return 'Mon, 23 Jan 1984 03:29:56 GMT' end context 'when not passed an override' do @@ -113,11 +113,11 @@ subject(:headers) { described_class.new(request) } let(:driver) { headers.instance_variable_get('@request') } before do allow(driver).to receive(:content_type).and_return 'text/html' - allow(driver).to receive(:content_md5).and_return '12345' + allow(driver).to receive(:content_hash).and_return '12345' allow(driver).to receive(:timestamp).and_return 'Mon, 23 Jan 1984 03:29:56 GMT' end context 'the driver uses the original_uri' do it 'constructs the canonical_string with the original_uri' do @@ -138,11 +138,11 @@ subject(:headers) { described_class.new(request) } let(:driver) { headers.instance_variable_get('@request') } before do allow(driver).to receive(:content_type).and_return 'text/html' - allow(driver).to receive(:content_md5).and_return '12345' + allow(driver).to receive(:content_hash).and_return '12345' allow(driver).to receive(:timestamp).and_return 'Mon, 23 Jan 1984 03:29:56 GMT' end context 'the driver uses the original_uri' do it 'constructs the canonical_string with the original_uri' do @@ -152,71 +152,71 @@ end end end end - describe '#calculate_md5' do + describe '#calculate_hash' do subject(:headers) { described_class.new(request) } let(:driver) { headers.instance_variable_get('@request') } - context 'no md5 already calculated' do + context 'no content hash already calculated' do let(:request) do RestClient::Request.new( url: 'http://google.com', method: :post, payload: "hello\nworld" ) end - it 'populates the md5 header' do - expect(driver).to receive(:populate_content_md5) - headers.calculate_md5 + it 'populates the content hash header' do + expect(driver).to receive(:populate_content_hash) + headers.calculate_hash end end - context 'md5 already calculated' do + context 'hash already calculated' do let(:request) do RestClient::Request.new( url: 'http://google.com', method: :post, payload: "hello\nworld", - headers: { content_md5: 'abcd' } + headers: { 'X-Authorization-Content-SHA256' => 'abcd' } ) end - it "doesn't populate the md5 header" do - expect(driver).not_to receive(:populate_content_md5) - headers.calculate_md5 + it "doesn't populate the X-Authorization-Content-SHA256 header" do + expect(driver).not_to receive(:populate_content_hash) + headers.calculate_hash end end end - describe '#md5_mismatch?' do + describe '#content_hash_mismatch?' do let(:request) { RestClient::Request.new(url: 'http://google.com', method: :get) } subject(:headers) { described_class.new(request) } let(:driver) { headers.instance_variable_get('@request') } - context 'when request has md5 header' do + context 'when request has X-Authorization-Content-SHA256 header' do it 'asks the driver' do - allow(driver).to receive(:content_md5).and_return '1234' + allow(driver).to receive(:content_hash).and_return '1234' - expect(driver).to receive(:md5_mismatch?).and_call_original - headers.md5_mismatch? + expect(driver).to receive(:content_hash_mismatch?).and_call_original + headers.content_hash_mismatch? end end - context 'when request has no md5' do + context 'when request has no content hash' do it "doesn't ask the driver" do - allow(driver).to receive(:content_md5).and_return nil + allow(driver).to receive(:content_hash).and_return nil - expect(driver).not_to receive(:md5_mismatch?).and_call_original - headers.md5_mismatch? + expect(driver).not_to receive(:content_hash_mismatch?).and_call_original + headers.content_hash_mismatch? end it 'returns false' do - allow(driver).to receive(:content_md5).and_return nil + allow(driver).to receive(:content_hash).and_return nil - expect(headers.md5_mismatch?).to be false + expect(headers.content_hash_mismatch?).to be false end end end end