Sha256: a391d94b1b84bee459e5b495ff4eac6da9dc2fc375dbc6d97144ae425f33a3bb

Contents?: true

Size: 1.92 KB

Versions: 12

Compression:

Stored size: 1.92 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 policies" do
    expected_error = "enumerable collection of policies 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 policies 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 policies 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])
    policies = [refuse_last, refuse_first]

    policies.each do |policy|
      response = policy.authenticate({anything: 'something'})
      expect(response).to_not be_authenticated
    end
  end

  it "uses the error message of the first encountered refusal in the chain" do
    policy = Certmeister::Policy::ChainAll.new([
      Certmeister::Policy::Domain.new(['unmatched.com']),
      Certmeister::Policy::Blackhole.new,
    ])
    response = policy.authenticate({cn: 'wrongdomain.com'})
    expect(response.error).to eql 'cn in unknown domain'
  end

end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
certmeister-2.3.2 spec/certmeister/policy/chain_all_spec.rb
certmeister-2.3.1 spec/certmeister/policy/chain_all_spec.rb
certmeister-2.3.0 spec/certmeister/policy/chain_all_spec.rb
certmeister-2.2.0 spec/certmeister/policy/chain_all_spec.rb
certmeister-2.1.0 spec/certmeister/policy/chain_all_spec.rb
certmeister-2.0.0 spec/certmeister/policy/chain_all_spec.rb
certmeister-1.2.1 spec/certmeister/policy/chain_all_spec.rb
certmeister-1.2.0 spec/certmeister/policy/chain_all_spec.rb
certmeister-1.1.0 spec/certmeister/policy/chain_all_spec.rb
certmeister-1.0.1 spec/certmeister/policy/chain_all_spec.rb
certmeister-1.0.0 spec/certmeister/policy/chain_all_spec.rb
certmeister-0.4.1 spec/certmeister/policy/chain_all_spec.rb