Sha256: 794388ae58e5693b4aecec21c5304f43af441367b45f15a70bf1ff008cb72c00

Contents?: true

Size: 1.14 KB

Versions: 13

Compression:

Stored size: 1.14 KB

Contents

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

13 entries across 13 versions & 1 rubygems

Version Path
lhc-10.1.2 spec/interceptors/auth/reauthentication_spec.rb
lhc-10.1.1 spec/interceptors/auth/reauthentication_spec.rb
lhc-10.1.0 spec/interceptors/auth/reauthentication_spec.rb
lhc-10.0.2 spec/interceptors/auth/reauthentication_spec.rb
lhc-9.4.4 spec/interceptors/auth/reauthentication_spec.rb
lhc-10.0.1 spec/interceptors/auth/reauthentication_spec.rb
lhc-10.0.0 spec/interceptors/auth/reauthentication_spec.rb
lhc-9.4.3 spec/interceptors/auth/reauthentication_spec.rb
lhc-9.4.2 spec/interceptors/auth/reauthentication_spec.rb
lhc-9.4.1 spec/interceptors/auth/reauthentication_spec.rb
lhc-9.4.0 spec/interceptors/auth/reauthentication_spec.rb
lhc-9.3.1 spec/interceptors/auth/reauthentication_spec.rb
lhc-9.3.0 spec/interceptors/auth/reauthentication_spec.rb