Skip to content

Commit 417b240

Browse files
committed
Handle nil root/user passwords from AutoYaST
1 parent 0a8a45a commit 417b240

File tree

4 files changed

+49
-5
lines changed

4 files changed

+49
-5
lines changed

service/lib/agama/autoyast/root_reader.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,19 @@ def read
3838
root_user = config.users.find { |u| u.name == "root" }
3939
return {} unless root_user
4040

41-
hsh = { "password" => root_user.password.value.to_s }
42-
hsh["hashedPassword"] = true if root_user.password.value.encrypted?
41+
hsh = {}
42+
password = root_user.password
43+
44+
if password
45+
hsh["password"] = password.value.to_s
46+
hsh["hashedPassword"] = true if password.value.encrypted?
47+
end
4348

4449
public_key = root_user.authorized_keys.first
4550
hsh["sshPublicKey"] = public_key if public_key
51+
52+
return {} if hsh.empty?
53+
4654
{ "root" => hsh }
4755
end
4856

service/lib/agama/autoyast/user_reader.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,14 @@ def read
3939

4040
hsh = {
4141
"userName" => user.name,
42-
"fullName" => user.gecos.first.to_s,
43-
"password" => user.password.value.to_s
42+
"fullName" => user.gecos.first.to_s
4443
}
4544

46-
hsh["hashedPassword"] = true if user.password.value.encrypted?
45+
password = user.password
46+
if password
47+
hsh["password"] = password.value.to_s
48+
hsh["hashedPassword"] = true if password.value.encrypted?
49+
end
4750

4851
{ "user" => hsh }
4952
end

service/test/agama/autoyast/root_reader_test.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,20 @@
7474
"password" => "123456", "sshPublicKey" => "ssh-key 1"
7575
)
7676
end
77+
78+
context "but does not contain password or SSH public key" do
79+
let(:root) do
80+
{
81+
"username" => "root",
82+
"user_password" => nil,
83+
"encrypted" => nil
84+
}
85+
end
86+
87+
it "returns an empty hash" do
88+
expect(subject.read).to be_empty
89+
end
90+
end
7791
end
7892
end
7993
end

service/test/agama/autoyast/user_reader_test.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,24 @@
7777
)
7878
end
7979
end
80+
81+
context "when the password is nil" do
82+
let(:user) do
83+
{
84+
"username" => "suse",
85+
"fullname" => "SUSE",
86+
"user_password" => nil,
87+
"encrypted" => nil
88+
}
89+
end
90+
91+
it "does not include password information" do
92+
user = subject.read["user"]
93+
expect(user).to eq(
94+
"userName" => "suse",
95+
"fullName" => "SUSE"
96+
)
97+
end
98+
end
8099
end
81100
end

0 commit comments

Comments
 (0)