Skip to content

Commit

Permalink
Fix logging when found a password for a not existing user
Browse files Browse the repository at this point in the history
  • Loading branch information
dgdavid committed May 28, 2021
1 parent f219cfc commit 0e07251
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib/y2users/linux/base_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def read_passwords(config)
passwords.each_pair do |name, password|
user = config.users.by_name(name)
if !user
log.warn "Found password for non existing user #{password.name}."
log.warn "Found password for non existing user #{name}."
next
end

Expand Down
10 changes: 10 additions & 0 deletions test/lib/y2users/linux/base_reader_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
allow(subject).to receive(:load_users).and_return(passwd_content)
allow(subject).to receive(:load_groups).and_return(group_content)
allow(subject).to receive(:load_passwords).and_return(shadow_content)

allow(subject.log).to receive(:warn)
end

it "generates a config with read data" do
Expand All @@ -61,5 +63,13 @@
expect(root_user.password.value.content).to match(/^\$6\$pL/)
expect(root_user.authorized_keys).to eq(expected_root_auth_keys)
end

it "logs warning if password found for not existing user" do
shadow_content << "fakeuser:$6$fakepassword.:16899::::::\n"

expect(subject.log).to receive(:warn).with(/Found password for.*fakeuser./)

subject.read
end
end
end

0 comments on commit 0e07251

Please sign in to comment.