613
describe Puppet::SSL::CertificateAuthority::Interface do
615
@class = Puppet::SSL::CertificateAuthority::Interface
617
describe "when initializing" do
618
it "should set its method using its settor" do
619
@class.any_instance.expects(:method=).with(:generate)
620
@class.new(:generate, :all)
623
it "should set its subjects using the settor" do
624
@class.any_instance.expects(:subjects=).with(:all)
625
@class.new(:generate, :all)
629
describe "when setting the method" do
630
it "should set the method" do
631
@class.new(:generate, :all).method.should == :generate
634
it "should fail if the method isn't a member of the INTERFACE_METHODS array" do
635
Puppet::SSL::CertificateAuthority::Interface::INTERFACE_METHODS.expects(:include?).with(:thing).returns false
637
lambda { @class.new(:thing, :all) }.should raise_error(ArgumentError)
641
describe "when setting the subjects" do
642
it "should set the subjects" do
643
@class.new(:generate, :all).subjects.should == :all
646
it "should fail if the subjects setting isn't :all or an array" do
647
lambda { @class.new(:generate, "other") }.should raise_error(ArgumentError)
651
it "should have a method for triggering the application" do
652
@class.new(:generate, :all).should respond_to(:apply)
655
describe "when applying" do
657
# We use a real object here, because :verify can't be stubbed, apparently.
661
it "should raise InterfaceErrors" do
662
@applier = @class.new(:revoke, :all)
664
@ca.expects(:list).raises Puppet::SSL::CertificateAuthority::Interface::InterfaceError
666
lambda { @applier.apply(@ca) }.should raise_error(Puppet::SSL::CertificateAuthority::Interface::InterfaceError)
669
it "should log non-Interface failures rather than failing" do
670
@applier = @class.new(:revoke, :all)
672
@ca.expects(:list).raises ArgumentError
676
lambda { @applier.apply(@ca) }.should_not raise_error
679
describe "with an empty array specified and the method is not list" do
681
@applier = @class.new(:sign, [])
682
lambda { @applier.apply(@ca) }.should raise_error(ArgumentError)
686
describe ":generate" do
687
it "should fail if :all was specified" do
688
@applier = @class.new(:generate, :all)
689
lambda { @applier.apply(@ca) }.should raise_error(ArgumentError)
692
it "should call :generate on the CA for each host specified" do
693
@applier = @class.new(:generate, %w{host1 host2})
695
@ca.expects(:generate).with("host1")
696
@ca.expects(:generate).with("host2")
702
describe ":verify" do
703
before { @method = :verify }
704
#it_should_behave_like "a normal interface method"
706
it "should call the method on the CA for each host specified if an array was provided" do
707
# LAK:NOTE Mocha apparently doesn't allow you to mock :verify, but I'm confident this works in real life.
710
it "should call the method on the CA for all existing certificates if :all was provided" do
711
# LAK:NOTE Mocha apparently doesn't allow you to mock :verify, but I'm confident this works in real life.
715
describe ":destroy" do
716
before { @method = :destroy }
717
it_should_behave_like "a normal interface method"
720
describe ":revoke" do
721
before { @method = :revoke }
722
it_should_behave_like "a normal interface method"
726
describe "and an array of names was provided" do
728
@applier = @class.new(:sign, %w{host1 host2})
731
it "should sign the specified waiting certificate requests" do
732
@ca.expects(:sign).with("host1")
733
@ca.expects(:sign).with("host2")
739
describe "and :all was provided" do
740
it "should sign all waiting certificate requests" do
741
@ca.stubs(:waiting?).returns(%w{cert1 cert2})
743
@ca.expects(:sign).with("cert1")
744
@ca.expects(:sign).with("cert2")
746
@applier = @class.new(:sign, :all)
750
it "should fail if there are no waiting certificate requests" do
751
@ca.stubs(:waiting?).returns([])
753
@applier = @class.new(:sign, :all)
754
lambda { @applier.apply(@ca) }.should raise_error(Puppet::SSL::CertificateAuthority::Interface::InterfaceError)
760
describe "and an empty array was provided" do
761
it "should print a string containing all certificate requests" do
762
@ca.expects(:waiting?).returns %w{host1 host2}
764
@applier = @class.new(:list, [])
766
@applier.expects(:puts).with "host1\nhost2"
772
describe "and :all was provided" do
773
it "should print a string containing all certificate requests and certificates" do
774
@ca.expects(:waiting?).returns %w{host1 host2}
775
@ca.expects(:list).returns %w{host3 host4}
777
@applier = @class.new(:list, :all)
779
@applier.expects(:puts).with "host1"
780
@applier.expects(:puts).with "host2"
781
@applier.expects(:puts).with "+ host3"
782
@applier.expects(:puts).with "+ host4"
788
describe "and an array of names was provided" do
789
it "should print a string of all named hosts that have a waiting request" do
790
@ca.expects(:waiting?).returns %w{host1 host2}
791
@ca.expects(:list).returns %w{host3 host4}
793
@applier = @class.new(:list, %w{host1 host2 host3 host4})
795
@applier.expects(:puts).with "host1"
796
@applier.expects(:puts).with "host2"
797
@applier.expects(:puts).with "+ host3"
798
@applier.expects(:puts).with "+ host4"
806
describe "and :all was provided" do
807
it "should print all certificates" do
808
@ca.expects(:list).returns %w{host1 host2}
810
@applier = @class.new(:print, :all)
812
@ca.expects(:print).with("host1").returns "h1"
813
@applier.expects(:puts).with "h1"
815
@ca.expects(:print).with("host2").returns "h2"
816
@applier.expects(:puts).with "h2"
822
describe "and an array of names was provided" do
823
it "should print each named certificate if found" do
824
@applier = @class.new(:print, %w{host1 host2})
826
@ca.expects(:print).with("host1").returns "h1"
827
@applier.expects(:puts).with "h1"
829
@ca.expects(:print).with("host2").returns "h2"
830
@applier.expects(:puts).with "h2"
835
it "should log any named but not found certificates" do
836
@applier = @class.new(:print, %w{host1 host2})
838
@ca.expects(:print).with("host1").returns "h1"
839
@applier.expects(:puts).with "h1"
841
@ca.expects(:print).with("host2").returns nil
842
Puppet.expects(:err).with { |msg| msg.include?("host2") }