Sha256: c5c98214e0e3450b0e689f0976bd11b4095bc72c9a9000218fe03745ae063e6f

Contents?: true

Size: 1.53 KB

Versions: 4

Compression:

Stored size: 1.53 KB

Contents

# frozen_string_literal: true
RSpec.describe FinAppsCore::Middleware::TenantAuthentication do
  let(:valid_tenant_options) { VALID_CREDENTIALS }
  let(:key) { FinAppsCore::Middleware::TenantAuthentication::KEY }

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

    context 'when company credentials were provided' do
      let(:middleware) do
        FinAppsCore::Middleware::TenantAuthentication.new(fake_app,
                                                          VALID_CREDENTIALS[:identifier],
                                                          VALID_CREDENTIALS[:token])
      end
      let(:expected_header) { "#{valid_tenant_options[:identifier]}=#{valid_tenant_options[:token]}" }

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

        it('generates a Tenant Authentication header') { expect(actual_header).to eq(expected_header) }
      end

      context 'when header was previously set' do
        let(:existing_header) { {FinAppsCore::Middleware::TenantAuthentication::KEY => 'foo'} }
        let(:request_env) { {request_headers: existing_header} }
        subject(:actual_header) { middleware.call(request_env)[:request_headers][key] }

        it('does not override existing Tenant Authentication header') { expect(actual_header).to eq('foo') }
        it('does not generate a Tenant Authentication header') { expect(actual_header).to_not eq(expected_header) }
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
finapps_core-2.0.5 spec/middleware/request/tenant_authentication_spec.rb
finapps_core-2.0.4 spec/middleware/request/tenant_authentication_spec.rb
finapps_core-2.0.3 spec/middleware/request/tenant_authentication_spec.rb
finapps_core-2.0.2 spec/middleware/request/tenant_authentication_spec.rb