Sha256: 476cd7d346c5e1ffbd0f07bca3b1d121b77c258e7c5973ecf8c396755f1bcf12
Contents?: true
Size: 1010 Bytes
Versions: 2
Compression:
Stored size: 1010 Bytes
Contents
require 'spec_helper' RSpec::Matchers.define :be_challenge do match do |actual_response| actual_response.status == 401 && actual_response['WWW-Authenticate'] =~ /^Digest / && actual_response.body.empty? end end class Test < Grape::API http_digest(realm: 'Test Api', opaque: 'secret') do |username| { 'foo' => 'bar' }[username] end get '/test' do [{ hey: 'you' }, { there: 'bar' }, { foo: 'baz' }] end end describe Grape::Middleware::Auth::Digest do def app Test end it 'is a digest authentication challenge' do get '/test' last_response.should be_challenge end it 'throws a 401 if no auth is given' do get '/test' last_response.status.should == 401 end it 'authenticates if given valid creds' do digest_authorize "foo", "bar" get '/test' last_response.status.should == 200 end it 'throws a 401 if given invalid creds' do digest_authorize "bar", "foo" get '/test' last_response.status.should == 401 end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
grape-0.7.0 | spec/grape/middleware/auth/digest_spec.rb |
grape-0.6.1 | spec/grape/middleware/auth/digest_spec.rb |