Skip to content

Commit bf131cc

Browse files
committed
(PUP-11095) Align user password management method on all macOS versions
Before this commit, user password management was being special cased on `macOS 10.14`. The plist of the managed user was being saved directly to target on disk rather than being written in a temporary file which was later being imported using `dsimport`. This commit aligns the behaviour on all macOS versions by choosing the later variant due to some transient errors seen in CI where writing to said plist resulted in a `Operation not permitted @ rb_sysopen` error.
1 parent 2fde3e6 commit bf131cc

File tree

2 files changed

+2
-28
lines changed

2 files changed

+2
-28
lines changed

lib/puppet/provider/user/directoryservice.rb

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -591,11 +591,7 @@ def set_shadow_hash_data(users_plist, binary_plist)
591591
else
592592
users_plist['ShadowHashData'] = [binary_plist]
593593
end
594-
if Puppet::Util::Package.versioncmp(self.class.get_os_version, '10.15') < 0
595-
write_users_plist_to_disk(users_plist)
596-
else
597-
write_and_import_shadow_hash_data(users_plist['ShadowHashData'].first)
598-
end
594+
write_and_import_shadow_hash_data(users_plist['ShadowHashData'].first)
599595
end
600596

601597
# This method writes the ShadowHashData plist in a temporary file,
@@ -671,12 +667,6 @@ def set_salted_pbkdf2(users_plist, shadow_hash_data, field, value)
671667
set_shadow_hash_data(users_plist, binary_plist)
672668
end
673669

674-
# This method will accept a plist in XML format, save it to disk, convert
675-
# the plist to a binary format, and flush the dscl cache.
676-
def write_users_plist_to_disk(users_plist)
677-
Puppet::Util::Plist.write_plist_file(users_plist, "#{users_plist_dir}/#{@resource.name}.plist", :binary)
678-
end
679-
680670
# This is a simple wrapper method for writing values to a file.
681671
def write_to_file(filename, value)
682672
Puppet.deprecation_warning("Puppet::Type.type(:user).provider(:directoryservice).write_to_file is deprecated and will be removed in Puppet 5.")

spec/unit/provider/user/directoryservice_spec.rb

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,16 +1021,7 @@ module Puppet::Util::Plist
10211021
describe '#set_shadow_hash_data' do
10221022
let(:users_plist) { {'ShadowHashData' => ['string_data'] } }
10231023

1024-
it 'should flush the plist data to disk on OS X < 10.15' do
1025-
allow(provider.class).to receive(:get_os_version).and_return('10.12')
1026-
1027-
expect(provider).to receive(:write_users_plist_to_disk)
1028-
provider.set_shadow_hash_data(users_plist, pbkdf2_embedded_plist)
1029-
end
1030-
1031-
it 'should flush the plist data a temporary file on OS X >= 10.15' do
1032-
allow(provider.class).to receive(:get_os_version).and_return('10.15')
1033-
1024+
it 'should flush the plist data to a temporary file' do
10341025
expect(provider).to receive(:write_and_import_shadow_hash_data)
10351026
provider.set_shadow_hash_data(users_plist, pbkdf2_embedded_plist)
10361027
end
@@ -1080,13 +1071,6 @@ module Puppet::Util::Plist
10801071
end
10811072
end
10821073

1083-
describe '#write_users_plist_to_disk' do
1084-
it 'should save the passed plist to disk and convert it to a binary plist' do
1085-
expect(Puppet::Util::Plist).to receive(:write_plist_file).with(user_plist_xml, "#{users_plist_dir}/nonexistent_user.plist", :binary)
1086-
provider.write_users_plist_to_disk(user_plist_xml)
1087-
end
1088-
end
1089-
10901074
describe '#write_and_import_shadow_hash_data' do
10911075
it 'should save the passed plist to a temporary file and import it' do
10921076
tmpfile = double('tempfile', :path => "/tmp/dsimport_#{username}", :flush => nil)

0 commit comments

Comments
 (0)