Sha256: d984a8188bcbf6a9621b122aa81ea0e40d0cba9d5650af575c5010178b30b807

Contents?: true

Size: 1.35 KB

Versions: 2

Compression:

Stored size: 1.35 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|
        username.should eql('Aladdin')
        password.should 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

2 entries across 2 versions & 1 rubygems

Version Path
restfulness-0.3.2 spec/unit/resources/authentication_spec.rb
restfulness-0.3.1 spec/unit/resources/authentication_spec.rb