Sha256: 819500e11947f88c550f6353033b5bf7fd39f06ebc68633df03a920c8ef79a24
Contents?: true
Size: 1 KB
Versions: 2
Compression:
Stored size: 1 KB
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' expect(last_response).to be_challenge end it 'throws a 401 if no auth is given' do get '/test' expect(last_response.status).to eq(401) end it 'authenticates if given valid creds' do digest_authorize "foo", "bar" get '/test' expect(last_response.status).to eq(200) end it 'throws a 401 if given invalid creds' do digest_authorize "bar", "foo" get '/test' expect(last_response.status).to eq(401) end end
Version data entries
2 entries across 2 versions & 2 rubygems
Version | Path |
---|---|
grape-security-0.8.0 | spec/grape/middleware/auth/digest_spec.rb |
grape-0.8.0 | spec/grape/middleware/auth/digest_spec.rb |