summaryrefslogtreecommitdiff
path: root/spec/unit/parser/functions/mkpasswd.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/unit/parser/functions/mkpasswd.rb')
-rw-r--r--spec/unit/parser/functions/mkpasswd.rb41
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