Sha256: ecf3040287c944e0012f340f2d4d064ca0bd0106b90e774ae69c482af332157c

Contents?: true

Size: 1.11 KB

Versions: 6

Compression:

Stored size: 1.11 KB

Contents

# frozen_string_literal: true

RSpec.describe FinAppsCore::Middleware::NoEncodingBasicAuthentication do
  let(:key) { FinAppsCore::Middleware::NoEncodingBasicAuthentication::KEY }

  describe '#call' do
    app = proc {|env| env }

    context 'when credentials were provided' do
      let(:middleware) { FinAppsCore::Middleware::NoEncodingBasicAuthentication.new(app, :token) }
      let(:expected_header_value) { "Bearer #{:token}" }

      context 'when header was not previously set' do
        let(:request_env) { {request_headers: {}} }
        subject(:result) { middleware.call(request_env) }

        it('generates a header') { expect(result[:request_headers][key]).to eq(expected_header_value) }
      end

      context 'when header was previously set' do
        let(:request_env) { {request_headers: {key => 'foo'}} }
        subject(:result) { middleware.call(request_env) }

        it('does not override existing header') { expect(result[:request_headers][key]).to eq('foo') }
        it('does not generate a header') { expect(result[:request_headers][key]).to_not eq(expected_header_value) }
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
finapps_core-3.0.6 spec/middleware/request/no_encoding_basic_authentication_spec.rb
finapps_core-3.0.5 spec/middleware/request/no_encoding_basic_authentication_spec.rb
finapps_core-3.0.3 spec/middleware/request/no_encoding_basic_authentication_spec.rb
finapps_core-3.0.1 spec/middleware/request/no_encoding_basic_authentication_spec.rb
finapps_core-2.1.2 spec/middleware/request/no_encoding_basic_authentication_spec.rb
finapps_core-2.1.1 spec/middleware/request/no_encoding_basic_authentication_spec.rb