Sha256: 798970c1e549a4eed1e4039b8880b0f67af23ea3ff94b8142adef8b66e14adb4

Contents?: true

Size: 815 Bytes

Versions: 10

Compression:

Stored size: 815 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 'throws a 401 if no auth is given' do
    @proc = lambda{ false }
    get '/whatever'
    last_response.status.should == 401
  end
  
  it 'authenticates if given valid creds' do
    get '/whatever', {}, 'HTTP_AUTHORIZATION' => encode_basic_auth('admin','admin')
    last_response.status.should == 200
  end
  
  it 'throws a 401 is wrong auth is given' do
    get '/whatever', {}, 'HTTP_AUTHORIZATION' => encode_basic_auth('admin','wrong')
    last_response.status.should == 401
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
grape-0.6.0 spec/grape/middleware/auth/basic_spec.rb
grape-0.5.0 spec/grape/middleware/auth/basic_spec.rb
grape-0.4.1 spec/grape/middleware/auth/basic_spec.rb
grape-0.4.0 spec/grape/middleware/auth/basic_spec.rb
grape-0.3.2 spec/grape/middleware/auth/basic_spec.rb
grape-0.3.1 spec/grape/middleware/auth/basic_spec.rb
grape-0.3.0 spec/grape/middleware/auth/basic_spec.rb
grape-0.2.6 spec/grape/middleware/auth/basic_spec.rb
grape-0.2.5 spec/grape/middleware/auth/basic_spec.rb
grape-0.2.4 spec/grape/middleware/auth/basic_spec.rb