diff options
author | Marcel Haerry <haerry@puzzle.ch> | 2010-12-23 10:39:33 +0100 |
---|---|---|
committer | Marcel Haerry <haerry@puzzle.ch> | 2010-12-23 10:39:33 +0100 |
commit | 3d913534ce2d60d8f245f65304907b8e1eb24665 (patch) | |
tree | 60efb5caed61b938c3e3ffe05f562660c35ce5d8 /spec/unit/parser/functions/mkpasswd.rb | |
parent | 17ea81d4d6eac289f5431b8817be9b38eb7a6966 (diff) |
adjust mkpasswd function to use plain ruby method, add tests for that function
Diffstat (limited to 'spec/unit/parser/functions/mkpasswd.rb')
-rw-r--r-- | spec/unit/parser/functions/mkpasswd.rb | 41 |
1 files changed, 41 insertions, 0 deletions
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 |