From 3d913534ce2d60d8f245f65304907b8e1eb24665 Mon Sep 17 00:00:00 2001 From: Marcel Haerry Date: Thu, 23 Dec 2010 10:39:33 +0100 Subject: adjust mkpasswd function to use plain ruby method, add tests for that function --- spec/unit/parser/functions/mkpasswd.rb | 41 ++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 spec/unit/parser/functions/mkpasswd.rb (limited to 'spec/unit/parser') diff --git a/spec/unit/parser/functions/mkpasswd.rb b/spec/unit/parser/functions/mkpasswd.rb new file mode 100644 index 0000000..1664701 --- /dev/null +++ b/spec/unit/parser/functions/mkpasswd.rb @@ -0,0 +1,41 @@ +#! /usr/bin/env ruby + + +require File.dirname(__FILE__) + '/../../../spec_helper' + +require 'mocha' +require 'fileutils' + +describe "the mkpasswd function" do + + before :each do + @scope = Puppet::Parser::Scope.new + end + + it "should exist" do + Puppet::Parser::Functions.function("mkpasswd").should == "function_mkpasswd" + end + + it "should raise a ParseError if less than 2 arguments is passed" do + lambda { @scope.function_mkpasswd(['aaa']) }.should( raise_error(Puppet::ParseError)) + end + + it "should raise a ParseError if there is more than 2 arguments" do + lambda { @scope.function_mkpasswd(['foo', 'bar','foo']) }.should( raise_error(Puppet::ParseError)) + end + + it "should raise a ParseError if the sencond argument is not 8 characters" do + lambda { @scope.function_mkpasswd(['foo','aaa']) }.should( raise_error(Puppet::ParseError)) + end + + describe "when executing properly" do + it "should return a salted md5 hash" do + res = @scope.function_mkpasswd(['foobar','12345678']).should == "$1$12345678$z10EIqhVCcU9.xpb4navW0" + end + + it "should use the crypt string method" do + String.any_instance.expects(:crypt).with('$1$' << '12345678' << '$') + @scope.function_mkpasswd(['foobar','12345678']) + end + end +end -- cgit v1.2.3