Sha256: 1933549a95936d240a20f254e9012167ff069f331cce0a43f110ba2dd625ebbc

Contents?: true

Size: 1.36 KB

Versions: 10

Compression:

Stored size: 1.36 KB

Contents

require 'spec_helper'

describe Gris::AuthenticationHelpers do
  context 'without permitted token' do
    before(:each) do
      stub_const 'ENV', 'PERMITTED_TOKENS' => %w(my-token another-token)
      @helper = SpecApiAuthHelper.new
    end

    context '#token_authentication!' do
      context 'without matching tokens' do
        it 'returns a 401 Forbidden error' do
          allow(@helper).to receive(:params).and_return(token: nil)
          allow(@helper).to receive_message_chain(:request, :headers).and_return('Http-Authorization' => nil)
          @helper.token_authentication!
          expect(@helper.message).to eq(message: 'Forbidden', status: 401)
        end
      end
      context 'with included params token' do
        it 'returns nil' do
          allow(@helper).to receive(:params).and_return(token: 'my-token')
          allow(@helper).to receive_message_chain(:request, :headers).and_return('Http-Authorization' => nil)
          expect(@helper.token_authentication!).to be_nil
        end
      end
      context 'with included request header token' do
        it 'returns nil' do
          allow(@helper).to receive(:params).and_return(token: nil)
          allow(@helper).to receive_message_chain(:request, :headers).and_return('Http-Authorization' => 'my-token')
          expect(@helper.token_authentication!).to be_nil
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
gris-0.1.3 spec/grape_extensions/authentication_helpers_spec.rb
gris-0.1.2 spec/grape_extensions/authentication_helpers_spec.rb
gris-0.1.1 spec/grape_extensions/authentication_helpers_spec.rb
gris-0.1.0 spec/grape_extensions/authentication_helpers_spec.rb
gris-0.0.9 spec/grape_extensions/authentication_helpers_spec.rb
gris-0.0.8 spec/grape_extensions/authentication_helpers_spec.rb
gris-0.0.7 spec/grape_extensions/authentication_helpers_spec.rb
gris-0.0.6 spec/grape_extensions/authentication_helpers_spec.rb
gris-0.0.5 spec/grape_extensions/authentication_helpers_spec.rb
gris-0.0.4 spec/grape_extensions/authentication_helpers_spec.rb