From 9b912d028fe1a2622ec61a56b1f0774ef3c9f43b Mon Sep 17 00:00:00 2001 From: Ken Barber Date: Sun, 14 Aug 2011 03:47:32 +0200 Subject: (#8925) Added new function called 'get_certificate' for retrieving certificates from a CA (or locally). This function works by either obtaining the file locally or remotely based on Puppets configuration. Also added get_pubkey which wraps get_certificate and extracts the public key. --- .../puppet/parser/functions/get_pubkey_spec.rb | 54 ++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100755 spec/unit/puppet/parser/functions/get_pubkey_spec.rb (limited to 'spec/unit/puppet/parser/functions/get_pubkey_spec.rb') diff --git a/spec/unit/puppet/parser/functions/get_pubkey_spec.rb b/spec/unit/puppet/parser/functions/get_pubkey_spec.rb new file mode 100755 index 0000000..e4cdd9f --- /dev/null +++ b/spec/unit/puppet/parser/functions/get_pubkey_spec.rb @@ -0,0 +1,54 @@ +#!/usr/bin/env rspec + +require 'spec_helper' +require 'net/http' +require 'thread' +require 'fileutils' + +describe "the get_pubkey function" do + include PuppetSpec::Files + + before :all do + Puppet::Parser::Functions.autoloader.loadall + end + + before :each do + @scope = Puppet::Parser::Scope.new + end + + it "should exist" do + Puppet::Parser::Functions.function("get_pubkey").should == "function_get_pubkey" + end + + it "should raise a ParseError if there is less than 1 argument" do + lambda { @scope.function_get_pubkey([]) }.should(raise_error(Puppet::ParseError)) + end + + it "should raise a ParseError if the argument is empty" do + lambda { @scope.function_get_pubkey([""]) }.should(raise_error(Puppet::ParseError)) + end + + it "should raise a ParseError if the argument contains strange characters" do + lambda { @scope.function_get_pubkey(["%^&"]) }.should(raise_error(Puppet::ParseError)) + end + + it "should return a valid certificate if CA is local" do + Puppet[:ca] = true + Puppet[:signeddir] = "spec/master_config/ssl/ca/signed/" + result = @scope.function_get_pubkey(["bob@mydomain.com"]) + result.should(eq(<<-EOS)) +-----BEGIN RSA PUBLIC KEY----- +MIGJAoGBAL7+Idbd+eohxCXVXcICvo1IaqAzyjezWxfxMxoBF4mjdvwY9RalRM5j +Itm9ThVwLMezcISYSNPI42Y70+9XIK/3f6OxnSMoB7kDKX9MvcbZkRAtOfxDeWmA +un+PXuH87VN1r7sViRSSB2dIxB3qjF1HNhAm0ocmSW+sZ3eul2lpAgMBAAE= +-----END RSA PUBLIC KEY----- +EOS + end + + it "should throw an error if CN is missing and CA is local" do + Puppet[:ca] = true + Puppet[:signeddir] = "spec/master_config/ssl/ca/signed/" + result = @scope.function_get_pubkey(["missing@mydomain.com"]) + result.should(eq(:undef)) + end +end -- cgit v1.2.3