Skip to content

Commit 59b3fb4

Browse files
committed
Merge pull request #434 from bmjen/modules-2474
Modules-2474: Only runs enhanced salts functions test on systems that ...
2 parents cf7dbef + 601e2e2 commit 59b3fb4

1 file changed

Lines changed: 29 additions & 20 deletions

File tree

spec/functions/pw_hash_spec.rb

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
require 'spec_helper'
33

44
describe "the pw_hash function" do
5+
6+
before :all do
7+
@enhanced_salts_supported = RUBY_PLATFORM == 'java'
8+
end
9+
510
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
611

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

60-
it "should return a hashed password" do
61-
result = scope.function_pw_hash(['password', 'sha-512', 'salt'])
62-
expect(result).to eql('$6$salt$IxDD3jeSOb5eB1CX5LBsqZFVkJdido3OUILO5Ifz5iwMuTS4XMS130MTSuDDl3aCI6WouIL9AjRbLCelDCy.g.')
63-
end
65+
if @enhanced_salts_supported
66+
describe "on systems with enhanced salts support" do
67+
it "should return a hashed password" do
68+
result = scope.function_pw_hash(['password', 'sha-512', 'salt'])
69+
expect(result).to eql('$6$salt$IxDD3jeSOb5eB1CX5LBsqZFVkJdido3OUILO5Ifz5iwMuTS4XMS130MTSuDDl3aCI6WouIL9AjRbLCelDCy.g.')
70+
end
6471

65-
it "should use the specified salt" do
66-
result = scope.function_pw_hash(['password', 'sha-512', 'salt'])
67-
expect(result).to match('salt')
68-
end
72+
it "should use the specified salt" do
73+
result = scope.function_pw_hash(['password', 'sha-512', 'salt'])
74+
expect(result).to match('salt')
75+
end
6976

70-
it "should use the specified hash type" do
71-
resultmd5 = scope.function_pw_hash(['password', 'md5', 'salt'])
72-
resultsha256 = scope.function_pw_hash(['password', 'sha-256', 'salt'])
73-
resultsha512 = scope.function_pw_hash(['password', 'sha-512', 'salt'])
77+
it "should use the specified hash type" do
78+
resultmd5 = scope.function_pw_hash(['password', 'md5', 'salt'])
79+
resultsha256 = scope.function_pw_hash(['password', 'sha-256', 'salt'])
80+
resultsha512 = scope.function_pw_hash(['password', 'sha-512', 'salt'])
7481

75-
expect(resultmd5).to eql('$1$salt$qJH7.N4xYta3aEG/dfqo/0')
76-
expect(resultsha256).to eql('$5$salt$Gcm6FsVtF/Qa77ZKD.iwsJlCVPY0XSMgLJL0Hnww/c1')
77-
expect(resultsha512).to eql('$6$salt$IxDD3jeSOb5eB1CX5LBsqZFVkJdido3OUILO5Ifz5iwMuTS4XMS130MTSuDDl3aCI6WouIL9AjRbLCelDCy.g.')
78-
end
82+
expect(resultmd5).to eql('$1$salt$qJH7.N4xYta3aEG/dfqo/0')
83+
expect(resultsha256).to eql('$5$salt$Gcm6FsVtF/Qa77ZKD.iwsJlCVPY0XSMgLJL0Hnww/c1')
84+
expect(resultsha512).to eql('$6$salt$IxDD3jeSOb5eB1CX5LBsqZFVkJdido3OUILO5Ifz5iwMuTS4XMS130MTSuDDl3aCI6WouIL9AjRbLCelDCy.g.')
85+
end
7986

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

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

85-
expect(hash_parts).not_to eql(nil)
92+
expect(hash_parts).not_to eql(nil)
93+
end
94+
end
8695
end
8796
end

0 commit comments

Comments
 (0)