Sha256: 5aaa299e736bd46c9aa7c19170edac2e63163ca59793b0ac64861ec899a8f4ae

Contents?: true

Size: 745 Bytes

Versions: 27

Compression:

Stored size: 745 Bytes

Contents

require 'spec_helper'
require 'base64'

describe Grape::Middleware::Auth::Base do
  subject do
    Class.new(Grape::API) do
      http_basic realm: 'my_realm' do |user, password|
        user && password && user == password
      end
      get '/authorized' do
        'DONE'
      end
    end
  end

  def app
    subject
  end

  it 'authenticates if given valid creds' do
    get '/authorized', {}, 'HTTP_AUTHORIZATION' => encode_basic_auth('admin', 'admin')
    expect(last_response.status).to eq(200)
    expect(last_response.body).to eq('DONE')
  end

  it 'throws a 401 is wrong auth is given' do
    get '/authorized', {}, 'HTTP_AUTHORIZATION' => encode_basic_auth('admin', 'wrong')
    expect(last_response.status).to eq(401)
  end
end

Version data entries

27 entries across 27 versions & 2 rubygems

Version Path
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/grape-1.2.5/spec/grape/middleware/auth/base_spec.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/grape-1.2.5/spec/grape/middleware/auth/base_spec.rb
grape-1.2.5 spec/grape/middleware/auth/base_spec.rb
grape-1.2.4 spec/grape/middleware/auth/base_spec.rb
grape-1.2.3 spec/grape/middleware/auth/base_spec.rb
grape-1.2.2 spec/grape/middleware/auth/base_spec.rb
grape-1.2.1 spec/grape/middleware/auth/base_spec.rb
grape-1.2.0 spec/grape/middleware/auth/base_spec.rb
grape-1.1.0 spec/grape/middleware/auth/base_spec.rb
grape-1.0.3 spec/grape/middleware/auth/base_spec.rb
grape-1.0.2 spec/grape/middleware/auth/base_spec.rb
grape-1.0.1 spec/grape/middleware/auth/base_spec.rb
grape-1.0.0 spec/grape/middleware/auth/base_spec.rb
grape-0.19.2 spec/grape/middleware/auth/base_spec.rb
grape-0.19.1 spec/grape/middleware/auth/base_spec.rb
grape-0.19.0 spec/grape/middleware/auth/base_spec.rb
grape-0.18.0 spec/grape/middleware/auth/base_spec.rb
grape-0.17.0 spec/grape/middleware/auth/base_spec.rb
grape-0.16.2 spec/grape/middleware/auth/base_spec.rb
grape-0.16.1 spec/grape/middleware/auth/base_spec.rb