Sha256: fd920b5ac1fb34fd785c7055a06667440d02abfa54b0c22ea91e62b8381682a7

Contents?: true

Size: 1.57 KB

Versions: 5

Compression:

Stored size: 1.57 KB

Contents

shared_examples_for 'token validation' do
  context 'when token is valid' do
    include_context 'valid access token'

    before { subject }

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

    it 'should validate the access token against the auth server' do
      expect(a_request(:get, 'auth.g5search.com/oauth/token/info').
             with(headers: {'Authorization' => "Bearer #{token_value}"})).to have_been_made
    end
  end

  context 'when token is invalid' do
    include_context 'invalid access token'

    before { subject }

    it 'should be unauthorized' do
      expect(response).to be_http_unauthorized
    end

    it 'should return an authenticate header' do
      expect(response.headers).to have_key('WWW-Authenticate')
    end

    it 'should return the authentication error' do
      expect(response.headers['WWW-Authenticate']).to match("error=\"#{error_code}\"")
    end

    it 'should return the authentication error description' do
      expect(response.headers['WWW-Authenticate']).to match("error_description=\"#{error_description}\"")
    end
  end

  context 'when some other oauth error occurs' do
    include_context 'OAuth2 error'

    before { subject }

    it 'should be unauthorized' do
      expect(response).to be_http_unauthorized
    end

    it 'should return an authenticate header' do
      expect(response.headers).to have_key('WWW-Authenticate')
    end

    it 'should return the default authentication error code' do
      expect(response.headers['WWW-Authenticate']).to match('error="invalid_request"')
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
g5_authenticatable_api-0.4.1 spec/support/shared_examples/token_validation.rb
g5_authenticatable_api-0.4.0 spec/support/shared_examples/token_validation.rb
g5_authenticatable_api-0.3.2 spec/support/shared_examples/token_validation.rb
g5_authenticatable_api-0.3.1 spec/support/shared_examples/token_validation.rb
g5_authenticatable_api-0.3.0 spec/support/shared_examples/token_validation.rb