Skip to content

Commit

Permalink
Fix check for user home existence
Browse files Browse the repository at this point in the history
Using Yast::Execute.on_target! to ensure the check is done against right
path in both, installation and running system.
  • Loading branch information
dgdavid committed Nov 3, 2021
1 parent f6d4a58 commit 16da455
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
5 changes: 4 additions & 1 deletion src/lib/y2users/linux/users_writer.rb
Expand Up @@ -328,7 +328,10 @@ def commit_config(user)
def exist_user_home?(user)
return false unless user.home&.path

File.exist?(user.home.path)
Yast::Execute.on_target!("/usr/bin/stat", user.home.path)
true
rescue Cheetah::ExecutionFailed
false
end
end
end
Expand Down
25 changes: 13 additions & 12 deletions test/lib/y2users/linux/users_writer_test.rb
Expand Up @@ -93,6 +93,7 @@ def issues(messages)
end

before do
allow(Yast::Execute).to receive(:on_target!)
# Prevent to perform real actions into the system
allow_any_instance_of(Y2Users::Linux::Action).to receive(:perform).and_return(success)
allow(Yast::MailAliases).to receive(:SetRootAlias)
Expand Down Expand Up @@ -172,8 +173,7 @@ def issues(messages)
before do
target_user.home.path = "/home/new_home"

allow(File).to receive(:exist?)
allow(File).to receive(:exist?).with("/home/new_home").and_return(true)
allow(subject).to receive(:exist_user_home?).with(target_user).and_return(true)
end

let(:commit_config) do
Expand Down Expand Up @@ -202,7 +202,7 @@ def issues(messages)
before do
mock_action(edit_user_action, success, initial_user, target_user)

allow(File).to receive(:exist?).and_call_original
allow(subject).to receive(:exist_user_home?).and_call_original
end

let(:commit_config) do
Expand All @@ -218,7 +218,7 @@ def issues(messages)
let(:adapt_home_ownership) { true }

before do
allow(File).to receive(:exist?).with(target_user.home.path).and_return(exist_home)
allow(subject).to receive(:exist_user_home?).with(target_user).and_return(exist_home)
end

context "and the user home exists" do
Expand Down Expand Up @@ -335,7 +335,7 @@ def issues(messages)

context "and the user home exists" do
before do
allow(File).to receive(:exist?).with(target_user.home.path).and_return(true)
allow(subject).to receive(:exist_user_home?).with(target_user).and_return(true)
end

it "performs the action for setting the authorized keys" do
Expand Down Expand Up @@ -369,7 +369,7 @@ def issues(messages)

context "and the user home does not exist" do
before do
allow(File).to receive(:exist?).with(target_user.home.path).and_return(false)
allow(subject).to receive(:exist_user_home?).with(target_user).and_return(false)
end

it "does not perform the action for setting the authorized keys" do
Expand Down Expand Up @@ -543,14 +543,14 @@ def issues(messages)
let(:adapt_home_ownership) { nil }

before do
allow(File).to receive(:exist?).and_call_original
allow(subject).to receive(:exist_user_home?).and_call_original
end

context "and the user home should be created without skel" do
let(:home_without_skel) { true }

before do
allow(File).to receive(:exist?).with(test3.home.path).and_return(exist_home)
allow(subject).to receive(:exist_user_home?).with(test3).and_return(exist_home)
end

context "and the home already existed on disk" do
Expand All @@ -568,7 +568,8 @@ def issues(messages)

context "and the home was created" do
before do
allow(File).to receive(:exist?).with(test3.home.path).and_return(exist_home, true)
allow(subject).to receive(:exist_user_home?).with(test3)
.and_return(exist_home, true)
end

it "performs the action for removing the home content" do
Expand Down Expand Up @@ -604,7 +605,7 @@ def issues(messages)
let(:adapt_home_ownership) { true }

before do
allow(File).to receive(:exist?).with(test3.home.path).and_return(exist_home)
allow(subject).to receive(:exist_user_home?).with(test3).and_return(exist_home)
end

context "and the home was created" do
Expand Down Expand Up @@ -684,7 +685,7 @@ def issues(messages)

context "and the user home exists" do
before do
allow(File).to receive(:exist?).with(test3.home.path).and_return(true)
allow(subject).to receive(:exist_user_home?).with(test3).and_return(true)
end

it "performs the action for setting the authorized keys" do
Expand All @@ -706,7 +707,7 @@ def issues(messages)

context "and the user home does not exist" do
before do
allow(File).to receive(:exist?).with(test3.home.path).and_return(false)
allow(subject).to receive(:exist_user_home?).with(test3).and_return(false)
end

it "does not perform the action for setting the authorized keys" do
Expand Down

0 comments on commit 16da455

Please sign in to comment.