Skip to content

Commit

Permalink
WIP: fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
joseivanlopez committed Sep 24, 2021
1 parent b1b6c10 commit 0238f61
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/lib/y2users/home.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ class Home
# Sets whether home is a btrfs subvolume
#
# @return [Boolean]
attr_writer :btrfs_subvol
attr_accessor :btrfs_subvol

eql_attr :path, :permissions, :btrfs_subvol?
eql_attr :path, :permissions, :btrfs_subvol

# Constructor
#
Expand Down
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 @@ -116,7 +116,7 @@ def read_authorized_keys(config)
config.users.each do |user|
next unless user.home

user.authorized_keys = Yast::Users::SSHAuthorizedKeyring.new(user.home).read_keys
user.authorized_keys = Yast::Users::SSHAuthorizedKeyring.new(user.home.path).read_keys
end
end

Expand Down
1 change: 1 addition & 0 deletions src/lib/y2users/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ def receive_system_mail?
# @return [User]
def copy
user = super
user.home = home.dup if home
user.password = password.copy if password
user.authorized_keys = authorized_keys.map(&:dup)

Expand Down
12 changes: 6 additions & 6 deletions test/lib/y2users/autoinst/reader_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,10 @@
{ "users" => [{ "username" => "test" }] }
end

it "sets User#btrfs_subvolume_home to nil" do
it "sets Home#btrfs_subvol to nil" do
user = subject.read.config.users.by_name("test")

expect(user.btrfs_subvolume_home).to be_nil
expect(user.home.btrfs_subvol).to be_nil
end
end

Expand All @@ -296,20 +296,20 @@
context "and set to true" do
let(:subvol) { true }

it "sets User#btrfs_subvolume_home to true" do
it "sets Home#btrfs_subvol to true" do
user = subject.read.config.users.by_name("test")

expect(user.btrfs_subvolume_home).to eq true
expect(user.home.btrfs_subvol).to eq true
end
end

context "and set to false" do
let(:subvol) { false }

it "sets User#btrfs_subvolume_home to false" do
it "sets Home#btrfs_subvol to false" do
user = subject.read.config.users.by_name("test")

expect(user.btrfs_subvolume_home).to eq false
expect(user.home.btrfs_subvol?).to eq false
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/lib/y2users/linux/reader_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@

root_user = config.users.root
expect(root_user.uid).to eq "0"
expect(root_user.home).to eq "/root"
expect(root_user.home.path).to eq "/root"
expect(root_user.shell).to eq "/bin/bash"
expect(root_user.primary_group.name).to eq "root"
expect(root_user.password.value.encrypted?).to eq true
Expand Down
72 changes: 68 additions & 4 deletions test/lib/y2users/user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
expect(user.root?).to eq(true)
expect(user.uid).to eq("0")
expect(user.gecos).to contain_exactly("root")
expect(user.home).to eq("/root")
expect(user.home.path).to eq("/root")
expect(user.attached?).to eq(false)
end
end
Expand All @@ -48,10 +48,33 @@

describe "#copy" do
before do
subject.home = Y2Users::Home.new("/home/test")
subject.password = Y2Users::Password.create_plain("test")
subject.assign_config(Y2Users::Config.new)
end

it "uses a dup of authorized keys" do
it "generates a copy of the user" do
other = subject.copy

expect(other).to be_a(described_class)
expect(other).to eq(subject)
end

it "generates a copy with a duplicated home" do
other = subject.copy
other.home.path = "/home/other"

expect(subject.home.path).to eq("/home/test")
end

it "generates a copy with a duplicated password" do
other = subject.copy
other.password.value = Y2Users::PasswordPlainValue.new("other")

expect(subject.password_content).to eq("test")
end

it "generates a copy with duplicated authorized keys" do
other = subject.copy

expect(other.authorized_keys).to eq(subject.authorized_keys)
Expand Down Expand Up @@ -314,9 +337,10 @@
subject.uid = 1000
subject.gid = 100
subject.shell = "/dev/bash"
subject.home = "/home/test1"
subject.home = Y2Users::Home.new("/home/test1")
subject.gecos = ["User Test1", "Other"]
subject.source = [:ldap]
subject.receive_system_mail = true
subject.password = Y2Users::Password.create_plain("S3cr3T")
end

Expand Down Expand Up @@ -370,7 +394,7 @@

context "when the #home does not match" do
before do
other.home = "/home/test2"
other.home.path = "/home/test2"
end

it "returns false" do
Expand Down Expand Up @@ -398,6 +422,16 @@
end
end

context "when #receive_system_mail does not match" do
before do
other.receive_system_mail = false
end

it "returns false" do
expect(subject == other).to eq(false)
end
end

context "when the #password does not match" do
before do
other.password.value.content = "M0r3-S3cr3T"
Expand Down Expand Up @@ -562,6 +596,36 @@
end
end

describe "#receive_system_mail?" do
before do
subject.receive_system_mail = value
end

context "when the value is set to nil" do
let(:value) { nil }

it "returns false" do
expect(subject.receive_system_mail?).to eq(false)
end
end

context "when the value is set to false" do
let(:value) { false }

it "returns false" do
expect(subject.receive_system_mail?).to eq(false)
end
end

context "when the value is set to true" do
let(:value) { true }

it "returns true" do
expect(subject.receive_system_mail?).to eq(true)
end
end
end

describe "#issues" do
let(:user_validator) { instance_double(Y2Users::UserValidator, issues: Y2Issues::List.new) }

Expand Down
9 changes: 7 additions & 2 deletions test/lib/y2users/users_module/reader_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
# real data with data dumper from perl after modifications in UI
{
"addit_data" => "",
"btrfs_subvolume" => false,
"btrfs_subvolume" => true,
"chown_home" => true,
"cn" => "test5",
"create_home" => true,
Expand Down Expand Up @@ -124,6 +124,7 @@
mapped_sys_groups = Hash[sys_groups.map { |g| [g["cn"], g] }]
mapped_local_groups = Hash[local_groups.map { |g| [g["cn"], g] }]
allow(Yast::Users).to receive(:GetGroups).and_return(mapped_sys_groups, mapped_local_groups)
allow(Yast::Users).to receive(:GetRootAliases).and_return({"test5" => 1})
end

describe "#read" do
Expand All @@ -137,9 +138,13 @@

test_user = config.users.by_name("test5")
expect(test_user.uid).to eq "1002"
expect(test_user.home).to eq "/home/test5"
expect(test_user.home).to be_a(Y2Users::Home)
expect(test_user.home.path).to eq "/home/test5"
expect(test_user.home.btrfs_subvol?).to eq true
expect(test_user.home.permissions).to eq "0755"
expect(test_user.shell).to eq "/bin/bash"
expect(test_user.primary_group.name).to eq "users"
expect(test_user.receive_system_mail?).to eq true
expect(test_user.password.value.encrypted?).to eq true
expect(test_user.password.value.content).to match(/^\$6\$CI/)
expect(test_user.password.aging.content).to eq("18887")
Expand Down

0 comments on commit 0238f61

Please sign in to comment.