Sha256: 782f366e3808049b42d83df1c8cf032da3734e6b7c7408089280b33e1be5757d

Contents?: true

Size: 1.52 KB

Versions: 1

Compression:

Stored size: 1.52 KB

Contents

require 'spec_helper'
require 'certmeister/policy/blackhole'
require 'certmeister/policy/noop'

require 'certmeister/policy/chain_any'

describe Certmeister::Policy::ChainAny do

  it "must be configured with a list of policies" do
    expected_error = "enumerable collection of policies required"
    expect { Certmeister::Policy::ChainAny.new }.to raise_error(ArgumentError)
    expect { Certmeister::Policy::ChainAny.new(Certmeister::Policy::Noop.new) }.to raise_error(ArgumentError, expected_error)
    expect { Certmeister::Policy::ChainAny.new([]) }.to raise_error(ArgumentError, expected_error)
  end

  it "demands a request" do
    policy = Certmeister::Policy::ChainAny.new([Certmeister::Policy::Noop.new])
    expect { policy.authenticate }.to raise_error(ArgumentError)
  end

  it "authenticates a request that any of its chained policies authenticate" do
    policy = Certmeister::Policy::ChainAny.new([Certmeister::Policy::Blackhole.new, Certmeister::Policy::Noop.new, Certmeister::Policy::Blackhole.new])
    response = policy.authenticate({anything: 'something'})
    expect(response).to be_authenticated
  end

  it "refuses a request that none of its chained policies refuses" do
    policy = Certmeister::Policy::ChainAll.new([ Certmeister::Policy::Blackhole.new, Certmeister::Policy::Blackhole.new])
    response = policy.authenticate({anything: 'something'})
    expect(response).to_not be_authenticated
    expect(response.error).to eql "blackholed"
  end

  it "uses the error message of the last encountered refusal in the chain"

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
certmeister-0.4.0 spec/certmeister/policy/chain_any_spec.rb