Sha256: aecab73a8ab2661f0bdabd90732557b37368e06b4064f12e7984632ba0850abc
Contents?: true
Size: 1.36 KB
Versions: 4
Compression:
Stored size: 1.36 KB
Contents
require 'spec_helper' describe Restfulness::Resources::Authentication do let :app do Class.new(Restfulness::Application) do routes do # empty end end end let :request do Restfulness::Request.new(app).tap do |req| req.headers[:authorization] = "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==" end end let :response do Restfulness::Response.new(request) end describe "#authenticate_with_http_basic" do class AuthResource < Restfulness::Resource end it "should run block and provide user and password" do obj = AuthResource.new(request, response) expect { |b| obj.authenticate_with_http_basic(&b) }.to yield_control obj.authenticate_with_http_basic do |username, password| expect(username).to eql('Aladdin') expect(password).to eql('open sesame') end end it "should not run block if no authorization header" do request.headers[:authorization] = nil obj = AuthResource.new(request, response) expect { |b| obj.authenticate_with_http_basic(&b) }.not_to yield_control end it "should not run block if non-basic authorization header" do request.headers[:authorization] = "Digest QWxhZGRpbjpvcGVuIHNlc2FtZQ==" obj = AuthResource.new(request, response) expect { |b| obj.authenticate_with_http_basic(&b) }.not_to yield_control end end end
Version data entries
4 entries across 4 versions & 1 rubygems