Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modules-2474: Only runs enhanced salts functions test on systems that ... #434

Merged
merged 1 commit into from
Apr 10, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 29 additions & 20 deletions spec/functions/pw_hash_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
require 'spec_helper'

describe "the pw_hash function" do

before :all do
@enhanced_salts_supported = RUBY_PLATFORM == 'java'
end

let(:scope) { PuppetlabsSpec::PuppetInternals.scope }

it "should exist" do
Expand Down Expand Up @@ -57,31 +62,35 @@
expect { scope.function_pw_hash(['password', 'sha-512', 'salt']) }.to( raise_error(Puppet::ParseError, /system does not support enhanced salts/) )
end

it "should return a hashed password" do
result = scope.function_pw_hash(['password', 'sha-512', 'salt'])
expect(result).to eql('$6$salt$IxDD3jeSOb5eB1CX5LBsqZFVkJdido3OUILO5Ifz5iwMuTS4XMS130MTSuDDl3aCI6WouIL9AjRbLCelDCy.g.')
end
if @enhanced_salts_supported
describe "on systems with enhanced salts support" do
it "should return a hashed password" do
result = scope.function_pw_hash(['password', 'sha-512', 'salt'])
expect(result).to eql('$6$salt$IxDD3jeSOb5eB1CX5LBsqZFVkJdido3OUILO5Ifz5iwMuTS4XMS130MTSuDDl3aCI6WouIL9AjRbLCelDCy.g.')
end

it "should use the specified salt" do
result = scope.function_pw_hash(['password', 'sha-512', 'salt'])
expect(result).to match('salt')
end
it "should use the specified salt" do
result = scope.function_pw_hash(['password', 'sha-512', 'salt'])
expect(result).to match('salt')
end

it "should use the specified hash type" do
resultmd5 = scope.function_pw_hash(['password', 'md5', 'salt'])
resultsha256 = scope.function_pw_hash(['password', 'sha-256', 'salt'])
resultsha512 = scope.function_pw_hash(['password', 'sha-512', 'salt'])
it "should use the specified hash type" do
resultmd5 = scope.function_pw_hash(['password', 'md5', 'salt'])
resultsha256 = scope.function_pw_hash(['password', 'sha-256', 'salt'])
resultsha512 = scope.function_pw_hash(['password', 'sha-512', 'salt'])

expect(resultmd5).to eql('$1$salt$qJH7.N4xYta3aEG/dfqo/0')
expect(resultsha256).to eql('$5$salt$Gcm6FsVtF/Qa77ZKD.iwsJlCVPY0XSMgLJL0Hnww/c1')
expect(resultsha512).to eql('$6$salt$IxDD3jeSOb5eB1CX5LBsqZFVkJdido3OUILO5Ifz5iwMuTS4XMS130MTSuDDl3aCI6WouIL9AjRbLCelDCy.g.')
end
expect(resultmd5).to eql('$1$salt$qJH7.N4xYta3aEG/dfqo/0')
expect(resultsha256).to eql('$5$salt$Gcm6FsVtF/Qa77ZKD.iwsJlCVPY0XSMgLJL0Hnww/c1')
expect(resultsha512).to eql('$6$salt$IxDD3jeSOb5eB1CX5LBsqZFVkJdido3OUILO5Ifz5iwMuTS4XMS130MTSuDDl3aCI6WouIL9AjRbLCelDCy.g.')
end

it "should generate a valid hash" do
password_hash = scope.function_pw_hash(['password', 'sha-512', 'salt'])
it "should generate a valid hash" do
password_hash = scope.function_pw_hash(['password', 'sha-512', 'salt'])

hash_parts = password_hash.match(%r{\A\$(.*)\$([a-zA-Z0-9./]+)\$([a-zA-Z0-9./]+)\z})
hash_parts = password_hash.match(%r{\A\$(.*)\$([a-zA-Z0-9./]+)\$([a-zA-Z0-9./]+)\z})

expect(hash_parts).not_to eql(nil)
expect(hash_parts).not_to eql(nil)
end
end
end
end