Sha256: 8286b8dc9d7b120070ab5e3fe70e148bcf677210209368fb4e3924a2e44a250a

Contents?: true

Size: 1.17 KB

Versions: 21

Compression:

Stored size: 1.17 KB

Contents

# frozen_string_literal: true

require 'rails_helper'

describe LHC::Auth do
  let(:initial_token) { '123456' }
  let(:refresh_token) { 'abcdef' }
  let(:options) { { bearer: initial_token, refresh_client_token: -> { refresh_token } } }
  let!(:auth_failing) do
    stub_request(:get, 'http://local.ch')
      .with(headers: { 'Authorization' => "Bearer #{initial_token}" })
      .to_return(status: 401, body: "{}") # LHC::Unauthorized
  end
  let!(:auth_suceeding_after_recovery) do
    stub_request(:get, 'http://local.ch')
      .with(headers: { 'Authorization' => "Bearer #{refresh_token}" })
  end

  before(:each) do
    LHC.config.interceptors = [LHC::Auth, LHC::Retry]
  end

  it "recovery is attempted" do
    LHC.config.endpoint(:local, 'http://local.ch', auth: options)
    # the retried request (with updated Bearer), that should work
    LHC.get(:local)
    expect(auth_suceeding_after_recovery).to have_been_made.once
  end

  it "recovery is not attempted again when the request has reauthenticated: true " do
    LHC.config.endpoint(:local, 'http://local.ch', auth: options.merge(reauthenticated: true))
    expect { LHC.get(:local) }.to raise_error(LHC::Unauthorized)
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
lhc-11.1.0 spec/interceptors/auth/reauthentication_spec.rb
lhc-11.0.2 spec/interceptors/auth/reauthentication_spec.rb
lhc-11.0.1 spec/interceptors/auth/reauthentication_spec.rb
lhc-11.0.0 spec/interceptors/auth/reauthentication_spec.rb
lhc-10.5.4 spec/interceptors/auth/reauthentication_spec.rb
lhc-10.5.3 spec/interceptors/auth/reauthentication_spec.rb
lhc-10.5.2 spec/interceptors/auth/reauthentication_spec.rb
lhc-10.5.1 spec/interceptors/auth/reauthentication_spec.rb
lhc-10.5.0 spec/interceptors/auth/reauthentication_spec.rb
lhc-10.4.3 spec/interceptors/auth/reauthentication_spec.rb
lhc-10.4.2 spec/interceptors/auth/reauthentication_spec.rb
lhc-10.4.1 spec/interceptors/auth/reauthentication_spec.rb
lhc-10.4.0 spec/interceptors/auth/reauthentication_spec.rb
lhc-10.3.0 spec/interceptors/auth/reauthentication_spec.rb
lhc-10.2.1 spec/interceptors/auth/reauthentication_spec.rb
lhc-10.2.0 spec/interceptors/auth/reauthentication_spec.rb
lhc-10.1.8 spec/interceptors/auth/reauthentication_spec.rb
lhc-10.1.7 spec/interceptors/auth/reauthentication_spec.rb
lhc-10.1.6 spec/interceptors/auth/reauthentication_spec.rb
lhc-10.1.5 spec/interceptors/auth/reauthentication_spec.rb