Sha256: 303cc52481e0135c18312c8ce086b601c8b6ee4ad5e2cf4fcabc0252bf005427

Contents?: true

Size: 1.51 KB

Versions: 24

Compression:

Stored size: 1.51 KB

Contents

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

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

    context 'when company credentials were provided' do
      let(:middleware) do
        FinApps::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) { {FinApps::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

24 entries across 24 versions & 1 rubygems

Version Path
finapps-2.0.13 spec/middleware/tenant_authentication_spec.rb
finapps-2.0.12 spec/middleware/tenant_authentication_spec.rb
finapps-2.0.11 spec/middleware/tenant_authentication_spec.rb
finapps-2.0.10 spec/middleware/tenant_authentication_spec.rb