Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dgdavid committed Oct 27, 2021
1 parent c8ad7d8 commit be5dc8c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
20 changes: 12 additions & 8 deletions test/lib/y2users/linux/base_reader_test.rb
Expand Up @@ -31,9 +31,9 @@
end

describe "#read" do
let(:passwd_content) { File.read(File.join(FIXTURES_PATH, "/root/etc/passwd")) }
let(:group_content) { File.read(File.join(FIXTURES_PATH, "/root/etc/group")) }
let(:shadow_content) { File.read(File.join(FIXTURES_PATH, "/root/etc/shadow")) }
let(:passwd_content) { File.read(File.join(FIXTURES_PATH, "/root2/etc/passwd")) }
let(:group_content) { File.read(File.join(FIXTURES_PATH, "/root2/etc/group")) }
let(:shadow_content) { File.read(File.join(FIXTURES_PATH, "/root2/etc/shadow")) }
let(:root_home) { FIXTURES_PATH.join("home", "root").to_s }
let(:expected_root_auth_keys) { authorized_keys_from(root_home) }

Expand All @@ -45,9 +45,13 @@

allow(subject.log).to receive(:warn)
allow(Yast::MailAliases).to receive(:GetRootAlias).and_return("games, unknown, news")

# mocks to check reading of home permissions
allow(Dir).to receive(:exist?)
allow(Dir).to receive(:exist?).with("/home/a_user").and_return(true)
allow(Yast::Execute).to receive(:locally!)
allow(Yast::Execute).to receive(:locally!)
.with("/usr/bin/stat", any_args, "/root", stdout: :capture)
.with("/usr/bin/stat", any_args, "/home/a_user", stdout: :capture)
.and_return("700")
end

Expand All @@ -56,8 +60,8 @@

expect(config).to be_a(Y2Users::Config)

expect(config.users.size).to eq 18
expect(config.groups.size).to eq 37
expect(config.users.size).to eq 19
expect(config.groups.size).to eq 7

root_user = config.users.root
expect(root_user.uid).to eq "0"
Expand Down Expand Up @@ -89,8 +93,8 @@
it "sets home permissions" do
config = subject.read

root = config.users.root
expect(root.home.permissions).to eq("700")
user = config.users.by_name("a_user")
expect(user.home.permissions).to eq("700")
end
end
end
1 change: 1 addition & 0 deletions test/lib/y2users/linux/local_reader_test.rb
Expand Up @@ -37,6 +37,7 @@
allow(Yast::Execute).to receive(:on_target!).with(/useradd/, "-D", anything)
.and_return(useradd_default_values)

allow(Yast::ShadowConfig).to receive(:fetch)
allow(Yast::ShadowConfig).to receive(:fetch).with(:umask).and_return("044")
end

Expand Down
1 change: 1 addition & 0 deletions test/lib/y2users/linux/reader_test.rb
Expand Up @@ -47,6 +47,7 @@
allow(Yast::Execute).to receive(:on_target!).with(/useradd/, "-D", anything)
.and_return(useradd_default_values)

allow(Yast::ShadowConfig).to receive(:fetch)
allow(Yast::ShadowConfig).to receive(:fetch).with(:umask).and_return("024")
end

Expand Down

0 comments on commit be5dc8c

Please sign in to comment.