X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=3rdparty%2Fmodules%2Fstdlib%2Fspec%2Ffunctions%2Fstr2saltedsha512_spec.rb;fp=3rdparty%2Fmodules%2Fstdlib%2Fspec%2Ffunctions%2Fstr2saltedsha512_spec.rb;h=2e1e818b5f7919e4b223e409c58701925173c654;hb=6963202b4b62c2816655ac9532521b018fdf83bd;hp=ab7f57f113f2ba10900a9b6ea33e090a603af6f5;hpb=a69999e580f8b3abd12446c2d6ad59e517651813;p=mirror%2Fdsa-puppet.git diff --git a/3rdparty/modules/stdlib/spec/functions/str2saltedsha512_spec.rb b/3rdparty/modules/stdlib/spec/functions/str2saltedsha512_spec.rb index ab7f57f11..2e1e818b5 100755 --- a/3rdparty/modules/stdlib/spec/functions/str2saltedsha512_spec.rb +++ b/3rdparty/modules/stdlib/spec/functions/str2saltedsha512_spec.rb @@ -1,45 +1,17 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the str2saltedsha512 function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } +describe 'str2saltedsha512' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params('password', 2).and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, /Requires a String argument/) } - it "should exist" do - expect(Puppet::Parser::Functions.function("str2saltedsha512")).to eq("function_str2saltedsha512") - end - - it "should raise a ParseError if there is less than 1 argument" do - expect { scope.function_str2saltedsha512([]) }.to( raise_error(Puppet::ParseError) ) - end - - it "should raise a ParseError if there is more than 1 argument" do - expect { scope.function_str2saltedsha512(['foo', 'bar', 'baz']) }.to( raise_error(Puppet::ParseError) ) - end - - it "should return a salted-sha512 password hash 136 characters in length" do - result = scope.function_str2saltedsha512(["password"]) - expect(result.length).to(eq(136)) - end - - it "should raise an error if you pass a non-string password" do - expect { scope.function_str2saltedsha512([1234]) }.to( raise_error(Puppet::ParseError) ) - end - - it "should generate a valid password" do - # Allow the function to generate a password based on the string 'password' - password_hash = scope.function_str2saltedsha512(["password"]) - - # Separate the Salt and Password from the Password Hash - salt = password_hash[0..7] - password = password_hash[8..-1] - - # Convert the Salt and Password from Hex to Binary Data - str_salt = Array(salt.lines).pack('H*') - str_password = Array(password.lines).pack('H*') + context 'when running with a specific seed' do + # make tests deterministic + before(:each) { srand(2) } - # Combine the Binary Salt with 'password' and compare the end result - saltedpass = Digest::SHA512.digest(str_salt + 'password') - result = (str_salt + saltedpass).unpack('H*')[0] - expect(result).to eq(password_hash) + it { is_expected.to run.with_params('').and_return('0f8a612f4eeed08e47b3875d00f33c5688f7926298f2d9b5fe19d1323f910bc78b6f7b5892596d2fabaa65e7a8d99b3768c102610cf0432c4827eee01f09451e3fae4f7a') } + it { is_expected.to run.with_params('password').and_return('0f8a612f43134376566c5707718d600effcfb17581fc9d3fa64d7f447dfda317c174ffdb498d2c5bd5c2075dab41c9d7ada5afbdc6b55354980eb5ba61802371e6b64956') } + it { is_expected.to run.with_params('verylongpassword').and_return('0f8a612f7a448537540e062daa8621f9bae326ca8ccb899e1bdb10e7c218cebfceae2530b856662565fdc4d81e986fc50cfbbc46d50436610ed9429ff5e43f2c45b5d039') } end end