summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2007-10-22 10:22:36 -0500
committerLuke Kanies <luke@madstop.com>2007-10-22 10:22:36 -0500
commitaab157e77bf471269ef0403576eca0e77e6f51ec (patch)
tree82247db10a346895220aaa8c88b5ec3e90e719ee /spec
parentb2b8f756c813f7c9a59ac91b4099304b4be2db4c (diff)
parent264331b3287067251c202c96ceb3a6d1f5039976 (diff)
downloadpuppet-aab157e77bf471269ef0403576eca0e77e6f51ec.tar.gz
puppet-aab157e77bf471269ef0403576eca0e77e6f51ec.tar.xz
puppet-aab157e77bf471269ef0403576eca0e77e6f51ec.zip
Merge branch 'master' of git://michaelobrien.info/puppet into michael
Diffstat (limited to 'spec')
-rwxr-xr-xspec/unit/indirector/ssl_rsa/file.rb116
1 files changed, 116 insertions, 0 deletions
diff --git a/spec/unit/indirector/ssl_rsa/file.rb b/spec/unit/indirector/ssl_rsa/file.rb
new file mode 100755
index 000000000..76e5e3a94
--- /dev/null
+++ b/spec/unit/indirector/ssl_rsa/file.rb
@@ -0,0 +1,116 @@
+#!/usr/bin/env ruby
+#
+# Created by Luke Kanies on 2007-9-22.
+# Copyright (c) 2007. All rights reserved.
+
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+require 'puppet/sslcertificates/monkey_patch'
+require 'puppet/indirector/ssl_rsa/file'
+
+
+describe Puppet::Indirector::SslRsa::File do
+
+ it "should be a subclass of the File terminus class" do
+ Puppet::Indirector::SslRsa::File.superclass.should equal(Puppet::Indirector::File)
+ end
+
+ it "should have documentation" do
+ Puppet::Indirector::SslRsa::File.doc.should be_instance_of(String)
+ end
+end
+
+describe Puppet::Indirector::SslRsa::File, " when choosing a path for a ca key" do
+ before do
+ @file = Puppet::Indirector::SslRsa::File.new
+ @name = :ca
+ end
+
+ it "should use the cadir" do
+ Puppet.settings.stubs(:value).with(:cadir).returns("/dir")
+ @file.path(@name).should =~ /^\/dir/
+ end
+
+ it "should use 'ca_key.pem' as the file name" do
+ @file.path(@name).should =~ /ca_key\.pem$/
+ end
+end
+
+describe Puppet::Indirector::SslRsa::File, " when choosing a path for a non-ca key" do
+ before do
+ @file = Puppet::Indirector::SslRsa::File.new
+ @name = :publickey
+ end
+
+ it "should use the publickeydir" do
+ Puppet.settings.stubs(:value).with(:publickeydir).returns("/dir")
+ @file.path(@name).should =~ /^\/dir/
+ end
+
+ it "should use the key name with the pem file extension" do
+ @file.path(@name).should =~ /#{@name}\.pem$/
+ end
+end
+
+describe Puppet::Indirector::SslRsa::File, " when saving" do
+ before do
+ @file = Puppet::Indirector::SslRsa::File.new
+
+ Puppet.settings.stubs(:value).with(:publickeydir).returns("/dir")
+ @key = stub "key", :name => "foo"
+ end
+
+ it "should store the rsa key to disk in pem format" do
+ @key.expects(:to_pem).returns(:data)
+ @path = "/dir/foo.pem"
+ filehandle = mock "filehandle"
+ File.expects(:open).with(@path, "w").yields(filehandle)
+ filehandle.expects(:print).with(:data)
+ @file.save(@key)
+ end
+end
+
+describe Puppet::Indirector::SslRsa::File, " when finding a key by name" do
+ before do
+ @file = Puppet::Indirector::SslRsa::File.new
+
+ Puppet.settings.stubs(:value).with(:publickeydir).returns("/dir")
+ @name = "foo"
+ end
+
+ it "should return the key as a key object on success" do
+ @path = "/dir/foo.pem"
+ FileTest.stubs(:exists?).with(@path).returns(true)
+ File.stubs(:read).with(@path).returns(:data)
+ OpenSSL::PKey::RSA.expects(:new).with(:data).returns(:mykey)
+ @file.find(@name).should == :mykey
+ end
+
+ it "should return 'nil' on failure" do
+ @path = "/dir/foo.pem"
+ FileTest.stubs(:exists?).with(@path).returns(false)
+ @file.find(@name).should == nil
+ end
+end
+
+describe Puppet::Indirector::SslRsa::File, " when removing a key" do
+ before do
+ @file = Puppet::Indirector::SslRsa::File.new
+
+ Puppet.settings.stubs(:value).with(:publickeydir).returns("/dir")
+ @name = "foo"
+ end
+
+ it "should remove the key from disk and return true" do
+ @path = "/dir/foo.pem"
+ FileTest.stubs(:exists?).with(@path).returns(true)
+ File.stubs(:unlink).with(@path).returns(true)
+ @file.destroy(@name).should == true
+ end
+
+ it "should return an exception on failure" do
+ @path = "/dir/foo.pem"
+ FileTest.stubs(:exists?).with(@path).returns(false)
+ @file.destroy(@name).should == nil
+ end
+end