Sha256: 73794314333c5e703952b64c3573268ff7b95f886fa855b6255f0c27b1028da1

Contents?: true

Size: 754 Bytes

Versions: 3

Compression:

Stored size: 754 Bytes

Contents

# frozen_string_literal: true

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

3 entries across 3 versions & 1 rubygems

Version Path
grape-1.8.0 spec/grape/middleware/auth/base_spec.rb
grape-1.7.1 spec/grape/middleware/auth/base_spec.rb
grape-1.7.0 spec/grape/middleware/auth/base_spec.rb