From e786aaf6f985791307ef6f1047cf58777ea452eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Iv=C3=A1n=20L=C3=B3pez=20Gonz=C3=A1lez?= Date: Fri, 24 Sep 2021 16:37:11 +0100 Subject: [PATCH] Add User#receive_system_mail --- src/lib/y2users/user.rb | 14 +++++++++++- test/lib/y2users/user_test.rb | 41 +++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/src/lib/y2users/user.rb b/src/lib/y2users/user.rb index 5257bc340..8028a448a 100644 --- a/src/lib/y2users/user.rb +++ b/src/lib/y2users/user.rb @@ -95,10 +95,15 @@ class User < ConfigElement # @return [Array] attr_accessor :authorized_keys + # Whether the user should receive system mails (i.e., be a root alias) + # + # @return [Boolean] + attr_accessor :receive_system_mail + # Only relevant attributes are compared. For example, the config in which the user is attached # and the internal user id are not considered. eql_attr :name, :uid, :gid, :shell, :home, :gecos, :source, :password, :authorized_keys, - :secondary_groups_name + :receive_system_mail, :secondary_groups_name # Creates a prototype root user # @@ -236,6 +241,13 @@ def system=(value) @system = value end + # @see receive_system_mail + # + # @return [Boolean] + def receive_system_mail? + !!@receive_system_mail + end + # Generates a deep copy of the user # # @see ConfigElement#copy diff --git a/test/lib/y2users/user_test.rb b/test/lib/y2users/user_test.rb index ac3d8780f..e4a211987 100755 --- a/test/lib/y2users/user_test.rb +++ b/test/lib/y2users/user_test.rb @@ -340,6 +340,7 @@ 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 @@ -421,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" @@ -585,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) }