File tree Expand file tree Collapse file tree 4 files changed +49
-5
lines changed
Expand file tree Collapse file tree 4 files changed +49
-5
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 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
7993end
Original file line number Diff line number Diff line change 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
81100end
You can’t perform that action at this time.
0 commit comments