Sha256: 2fc0a11c70c547dc48ad577e78d2c4769b7a3037a528d184d7d515ac6057a27e

Contents?: true

Size: 833 Bytes

Versions: 6

Compression:

Stored size: 833 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_auth('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_auth('admin','wrong')
    last_response.status.should == 401
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
grape-0.2.1.1 spec/grape/middleware/auth/basic_spec.rb
grape-0.2.3 spec/grape/middleware/auth/basic_spec.rb
fragrant-0.0.5 vendor/bundle/ruby/1.9.1/gems/grape-0.2.2/spec/grape/middleware/auth/basic_spec.rb
grape-0.2.2 spec/grape/middleware/auth/basic_spec.rb
grape-0.2.1 spec/grape/middleware/auth/basic_spec.rb
grape-0.2.0 spec/grape/middleware/auth/basic_spec.rb