Sha256: da7054176714e3a0c029e6f2a4a5a936bf6505ba849ce5aabfc426b8ed3a83a7

Contents?: true

Size: 823 Bytes

Versions: 3

Compression:

Stored size: 823 Bytes

Contents

require 'spec_helper'

require 'base64'

describe Grape::Middleware::Auth::Basic do
  def app
    Rack::Builder.new do |b|
      b.use Grape::Middleware::Error
      b.use(Grape::Middleware::Auth::Basic) do |u,p| 
        u && p && u == p
      end
      b.run lambda{|env| [200, {}, ["Hello there."]]}
    end
  end
  
  it 'should throw a 401 if no auth is given' do
    @proc = lambda{ false }
    get '/whatever'
    last_response.status.should == 401
  end
  
  it 'should authenticate if given valid creds' do
    get '/whatever', {}, 'HTTP_AUTHORIZATION' => encode_basic('admin','admin')
    last_response.status.should == 200
  end
  
  it 'should throw a 401 is wrong auth is given' do
    get '/whatever', {}, 'HTTP_AUTHORIZATION' => encode_basic('admin','wrong')
    last_response.status.should == 401
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
grape-0.1.5 spec/grape/middleware/auth/basic_spec.rb
grape-0.1.4 spec/grape/middleware/auth/basic_spec.rb
grape-0.1.3 spec/grape/middleware/auth/basic_spec.rb