Sha256: 131f9dddf377fbce20837c048bc94d4c38efaf372a0d3ac9e31c310fadc94b15

Contents?: true

Size: 1.22 KB

Versions: 2

Compression:

Stored size: 1.22 KB

Contents

# frozen_string_literal: true

RSpec.shared_examples_for 'a warden authenticatable api' do
  context 'when user is authenticated' do
    let(:user) { create(:user) }
    let(:token_value) { user.g5_access_token }

    before { login_as(user, scope: :user) }
    after { logout }

    context 'when strict token validation is enabled' do
      before do
        G5AuthenticatableApi.strict_token_validation = true
      end

      include_examples 'token validation'
    end

    context 'when strict token validation is disabled' do
      before do
        G5AuthenticatableApi.strict_token_validation = false
        subject
      end

      it 'should be successful' do
        expect(response).to be_success
      end

      it 'should not validate the token against the auth server' do
        expect(a_request(:get, 'auth.g5search.com/oauth/token/info'))
          .to_not have_been_made
      end
    end
  end

  context 'when user is not authenticated' do
    before do
      logout
      subject
    end

    it 'should be unauthorized' do
      expect(response.status).to eq(401)
    end

    it 'should return an authenticate header without details' do
      expect(response.headers['WWW-Authenticate']).to eq('Bearer')
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
g5_authenticatable_api-1.0.0 spec/support/shared_examples/warden_authenticatable_api.rb
g5_authenticatable_api-1.0.0.pre.1 spec/support/shared_examples/warden_authenticatable_api.rb