Sha256: 6125344be38c7bf1e8cefc5225c062e38d78f798f23385033c30f82af2676cfb

Contents?: true

Size: 1.61 KB

Versions: 9

Compression:

Stored size: 1.61 KB

Contents

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

require 'certmeister/policy/chain_all'

describe Certmeister::Policy::ChainAll do

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

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

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

  it "refuses a request that any one of its chained policys refuses" do
    refuse_last = Certmeister::Policy::ChainAll.new([ Certmeister::Policy::Noop.new, Certmeister::Policy::Blackhole.new])
    refuse_first = Certmeister::Policy::ChainAll.new([ Certmeister::Policy::Blackhole.new, Certmeister::Policy::Noop.new])
    policys = [refuse_last, refuse_first]

    policys.each do |policy|
      response = policy.authenticate({anything: 'something'})
      expect(response).to_not be_authenticated
      expect(response.error).to eql "blackholed"
    end
  end

end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
certmeister-0.3.2 spec/certmeister/policy/chain_all_spec.rb
certmeister-0.3.1 spec/certmeister/policy/chain_all_spec.rb
certmeister-0.3.0 spec/certmeister/policy/chain_all_spec.rb
certmeister-0.2.3 spec/certmeister/policy/chain_all_spec.rb
certmeister-0.2.1 spec/certmeister/policy/chain_all_spec.rb
certmeister-0.2.0 spec/certmeister/policy/chain_all_spec.rb
certmeister-0.1.0 spec/certmeister/policy/chain_all_spec.rb
certmeister-0.0.2 spec/certmeister/policy/chain_all_spec.rb
certmeister-0.0.1 spec/certmeister/policy/chain_all_spec.rb