-
Notifications
You must be signed in to change notification settings - Fork 43
/
login_defs_test.rb
111 lines (96 loc) · 3.26 KB
/
login_defs_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# Copyright (c) [2019] SUSE LLC
#
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of version 2 of the GNU General Public License as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, contact SUSE LLC.
#
# To contact SUSE LLC about this file by physical or electronic mail, you may
# find current contact information at www.suse.com.
require_relative "../test_helper"
require "cfa/login_defs"
require "tmpdir"
describe CFA::LoginDefs do
subject(:login_defs) { described_class.new(file_path: file_path, file_handler: file_handler) }
let(:file_path) { File.join(GENERAL_DATA_PATH, "login.defs-example") }
let(:file_handler) { File }
before { login_defs.load }
describe "#load" do
it "loads the file content" do
file = described_class.load(file_path: file_path, file_handler: file_handler)
expect(file.loaded?).to eq(true)
end
end
describe "#save" do
let(:file_path) { File.join(tmpdir, "login.defs.d", "70-yast.defs") }
let(:tmpdir) { Dir.mktmpdir }
after do
FileUtils.remove_entry(tmpdir)
end
context "when the directory does not exist" do
it "creates the directory" do
login_defs.save
expect(File).to be_directory(File.join(tmpdir, "login.defs.d"))
end
end
context "when the directory exists" do
before do
FileUtils.mkdir(File.join(tmpdir, "login.defs.d"))
end
it "does not create the directory" do
expect(Yast::Execute).to_not receive(:on_target).with("/usr/bin/mkdir", any_args)
login_defs.save
end
end
end
ATTRS_VALUES = {
character_class: "[A-Za-z_][A-Za-z0-9_.-]*",
encrypt_method: "SHA512",
fail_delay: "3",
gid_max: "60000",
gid_min: "1000",
groupadd_cmd: "/usr/sbin/groupadd.local",
pass_max_days: "99999",
pass_min_days: "0",
pass_warn_age: "7",
sys_gid_max: "499",
sys_gid_min: "100",
sys_uid_max: "499",
sys_uid_min: "100",
uid_max: "60000",
uid_min: "1000",
useradd_cmd: "/usr/sbin/useradd.local",
userdel_postcmd: "/usr/sbin/userdel-post.local",
userdel_precmd: "/usr/sbin/userdel-pre.local"
}.freeze
ATTRS_VALUES.each do |attr, value|
describe "##{attr}" do
it "returns the #{attr.upcase} value" do
expect(login_defs.public_send(attr)).to eq(value)
end
end
end
describe "#present_attributes" do
it "returns the list of present attributes" do
expect(login_defs.present_attributes).to include(*ATTRS_VALUES.keys)
end
end
describe "#conflicts" do
subject(:other) { described_class.new(file_path: file_path, file_handler: file_handler) }
before do
other.encrypt_method = "SHA256"
end
it "returns the list of attributes with different values" do
expect(login_defs.conflicts(other)).to eq([:encrypt_method])
end
end
end