|
2 | 2 | require 'spec_helper' |
3 | 3 |
|
4 | 4 | describe "the pw_hash function" do |
| 5 | + |
| 6 | + before :all do |
| 7 | + @enhanced_salts_supported = RUBY_PLATFORM == 'java' |
| 8 | + end |
| 9 | + |
5 | 10 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope } |
6 | 11 |
|
7 | 12 | it "should exist" do |
|
57 | 62 | expect { scope.function_pw_hash(['password', 'sha-512', 'salt']) }.to( raise_error(Puppet::ParseError, /system does not support enhanced salts/) ) |
58 | 63 | end |
59 | 64 |
|
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 |
64 | 71 |
|
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 |
69 | 76 |
|
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']) |
74 | 81 |
|
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 |
79 | 86 |
|
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']) |
82 | 89 |
|
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}) |
84 | 91 |
|
85 | | - expect(hash_parts).not_to eql(nil) |
| 92 | + expect(hash_parts).not_to eql(nil) |
| 93 | + end |
| 94 | + end |
86 | 95 | end |
87 | 96 | end |
0 commit comments