mkpasswd.rb 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #! /usr/bin/env ruby
  2. require File.dirname(__FILE__) + '/../../../spec_helper'
  3. require 'mocha'
  4. require 'fileutils'
  5. describe "the mkpasswd function" do
  6. before :each do
  7. @scope = Puppet::Parser::Scope.new
  8. end
  9. it "should exist" do
  10. Puppet::Parser::Functions.function("mkpasswd").should == "function_mkpasswd"
  11. end
  12. it "should raise a ParseError if less than 2 arguments is passed" do
  13. lambda { @scope.function_mkpasswd(['aaa']) }.should( raise_error(Puppet::ParseError))
  14. end
  15. it "should raise a ParseError if there is more than 2 arguments" do
  16. lambda { @scope.function_mkpasswd(['foo', 'bar','foo']) }.should( raise_error(Puppet::ParseError))
  17. end
  18. it "should raise a ParseError if the sencond argument is not 8 characters" do
  19. lambda { @scope.function_mkpasswd(['foo','aaa']) }.should( raise_error(Puppet::ParseError))
  20. end
  21. describe "when executing properly" do
  22. it "should return a salted md5 hash" do
  23. res = @scope.function_mkpasswd(['foobar','12345678']).should == "$1$12345678$z10EIqhVCcU9.xpb4navW0"
  24. end
  25. it "should use the crypt string method" do
  26. String.any_instance.expects(:crypt).with('$1$' << '12345678' << '$')
  27. @scope.function_mkpasswd(['foobar','12345678'])
  28. end
  29. end
  30. end