summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--hscript/script.cc3
-rw-r--r--hscript/user.cc39
-rw-r--r--tests/fixtures/0104-usergroups-basic.installfile15
-rw-r--r--tests/fixtures/0105-usergroups-without-groups.installfile7
-rw-r--r--tests/fixtures/0106-usergroups-comma.installfile7
-rw-r--r--tests/fixtures/0107-usergroups-unknown-name.installfile8
-rw-r--r--tests/fixtures/0108-jumbo-usergroups.installfile7
-rw-r--r--tests/fixtures/0109-usergroups-unknown.installfile8
-rw-r--r--tests/fixtures/0110-usergroups-duplicate.installfile8
-rw-r--r--tests/spec/validator.rb44
10 files changed, 143 insertions, 3 deletions
diff --git a/hscript/script.cc b/hscript/script.cc
index 8dbf9e1..0d1c10a 100644
--- a/hscript/script.cc
+++ b/hscript/script.cc
@@ -597,9 +597,10 @@ bool Script::validate() const {
})
) {
output_error("installfile:" + std::to_string(group->lineno()),
- "usergroups: group specified twice");
+ "usergroups: duplicate group name specified");
failures++;
}
+ seen_groups.insert(these.begin(), these.end());
}
/* REQ: Runner.Validate.usergroups.Count */
diff --git a/hscript/user.cc b/hscript/user.cc
index 04258e4..ec59a67 100644
--- a/hscript/user.cc
+++ b/hscript/user.cc
@@ -298,11 +298,46 @@ bool UserIcon::execute(ScriptOptions) const {
Key *UserGroups::parseFromData(const std::string &data, int lineno,
int *errors, int *warnings) {
- return nullptr;
+ /* REQ: Runner.Validate.usergroups.Validity */
+ const std::string::size_type sep = data.find_first_of(' ');
+ if(sep == std::string::npos || data.length() == sep + 1) {
+ if(errors) *errors += 1;
+ output_error("installfile:" + std::to_string(lineno),
+ "usergroups: at least one group is required",
+ "expected format is: usergroups [user] [group(,...)]");
+ return nullptr;
+ }
+
+ std::set<std::string> group_set;
+ char next_group[17];
+ std::istringstream stream(data.substr(sep + 1));
+ while(stream.getline(next_group, 17, ',')) {
+ std::string group(next_group);
+ /* REQ: Runner.Validate.usergroups.Group */
+ if(system_groups.find(group) == system_groups.end()) {
+ if(errors) *errors += 1;
+ output_error("installfile:" + std::to_string(lineno),
+ "usergroups: group name '" + group + "' is invalid",
+ "group is not a recognised system group");
+ return nullptr;
+ }
+ group_set.insert(group);
+ }
+ /* REQ: Runner.Validate.usergroups.Group */
+ if(stream.fail() && !stream.eof()) {
+ if(errors) *errors += 1;
+ output_error("installfile:" + std::to_string(lineno),
+ "usergroups: group name exceeds maximum length",
+ "groups may only be 16 characters or less");
+ return nullptr;
+ }
+
+ return new UserGroups(lineno, data.substr(0, sep), group_set);
}
bool UserGroups::validate(ScriptOptions) const {
- return false;
+ /* All validation is done in parsing stage */
+ return true;
}
bool UserGroups::execute(ScriptOptions) const {
diff --git a/tests/fixtures/0104-usergroups-basic.installfile b/tests/fixtures/0104-usergroups-basic.installfile
new file mode 100644
index 0000000..fb4c31e
--- /dev/null
+++ b/tests/fixtures/0104-usergroups-basic.installfile
@@ -0,0 +1,15 @@
+network false
+hostname test.machine
+pkginstall adelie-base
+rootpw $6$gumtLGmHwOVIRpQR$2M9PUO24hy5mofzWWf9a.YLbzOgOlUby1g0hDj.wG67E2wrrvys59fq02PPdxBdbgkLZFtjfEx6MHZwMBamwu/
+mount /dev/sda1 /
+username chris
+usergroups chris disk,lp,wheel,floppy,audio,cdrom,video,games,cdrw,usb,users
+username kayla
+usergroups kayla lp,audio,cdrom,video,games,users
+username meg
+usergroups meg lp,audio,cdrom,video,games,users
+username steph
+usergroups steph lp,audio,cdrom,video,games,users
+username amanda
+usergroups amanda lp,audio,cdrom,video,games,users
diff --git a/tests/fixtures/0105-usergroups-without-groups.installfile b/tests/fixtures/0105-usergroups-without-groups.installfile
new file mode 100644
index 0000000..63cc3fd
--- /dev/null
+++ b/tests/fixtures/0105-usergroups-without-groups.installfile
@@ -0,0 +1,7 @@
+network false
+hostname test.machine
+pkginstall adelie-base
+rootpw $6$gumtLGmHwOVIRpQR$2M9PUO24hy5mofzWWf9a.YLbzOgOlUby1g0hDj.wG67E2wrrvys59fq02PPdxBdbgkLZFtjfEx6MHZwMBamwu/
+mount /dev/sda1 /
+username awilfox
+usergroups awilfox
diff --git a/tests/fixtures/0106-usergroups-comma.installfile b/tests/fixtures/0106-usergroups-comma.installfile
new file mode 100644
index 0000000..b337fb5
--- /dev/null
+++ b/tests/fixtures/0106-usergroups-comma.installfile
@@ -0,0 +1,7 @@
+network false
+hostname test.machine
+pkginstall adelie-base
+rootpw $6$gumtLGmHwOVIRpQR$2M9PUO24hy5mofzWWf9a.YLbzOgOlUby1g0hDj.wG67E2wrrvys59fq02PPdxBdbgkLZFtjfEx6MHZwMBamwu/
+mount /dev/sda1 /
+username awilfox
+usergroups awilfox ,,,
diff --git a/tests/fixtures/0107-usergroups-unknown-name.installfile b/tests/fixtures/0107-usergroups-unknown-name.installfile
new file mode 100644
index 0000000..6cbec3b
--- /dev/null
+++ b/tests/fixtures/0107-usergroups-unknown-name.installfile
@@ -0,0 +1,8 @@
+network false
+hostname test.machine
+pkginstall adelie-base
+rootpw $6$gumtLGmHwOVIRpQR$2M9PUO24hy5mofzWWf9a.YLbzOgOlUby1g0hDj.wG67E2wrrvys59fq02PPdxBdbgkLZFtjfEx6MHZwMBamwu/
+mount /dev/sda1 /
+username awilfox
+# Intentional misspelling
+usergroups awilcox users,wheel
diff --git a/tests/fixtures/0108-jumbo-usergroups.installfile b/tests/fixtures/0108-jumbo-usergroups.installfile
new file mode 100644
index 0000000..6b3cd03
--- /dev/null
+++ b/tests/fixtures/0108-jumbo-usergroups.installfile
@@ -0,0 +1,7 @@
+network false
+hostname test.machine
+pkginstall adelie-base
+rootpw $6$gumtLGmHwOVIRpQR$2M9PUO24hy5mofzWWf9a.YLbzOgOlUby1g0hDj.wG67E2wrrvys59fq02PPdxBdbgkLZFtjfEx6MHZwMBamwu/
+mount /dev/sda1 /
+username awilfox
+usergroups awilfox root,bin,daemon,sys,adm,tty,disk,lp,mem,kmem,wheel,floppy,mail,news,uucp,man,cron,console,audio,cdrom,dialout,ftp,sshd,input,at,tape,video
diff --git a/tests/fixtures/0109-usergroups-unknown.installfile b/tests/fixtures/0109-usergroups-unknown.installfile
new file mode 100644
index 0000000..4557950
--- /dev/null
+++ b/tests/fixtures/0109-usergroups-unknown.installfile
@@ -0,0 +1,8 @@
+network false
+hostname test.machine
+pkginstall adelie-base
+rootpw $6$gumtLGmHwOVIRpQR$2M9PUO24hy5mofzWWf9a.YLbzOgOlUby1g0hDj.wG67E2wrrvys59fq02PPdxBdbgkLZFtjfEx6MHZwMBamwu/
+mount /dev/sda1 /
+username awilfox
+# Groups that are not in the base set
+usergroups awilfox messagebus,www-data,pulse
diff --git a/tests/fixtures/0110-usergroups-duplicate.installfile b/tests/fixtures/0110-usergroups-duplicate.installfile
new file mode 100644
index 0000000..9d04ae7
--- /dev/null
+++ b/tests/fixtures/0110-usergroups-duplicate.installfile
@@ -0,0 +1,8 @@
+network false
+hostname test.machine
+pkginstall adelie-base
+rootpw $6$gumtLGmHwOVIRpQR$2M9PUO24hy5mofzWWf9a.YLbzOgOlUby1g0hDj.wG67E2wrrvys59fq02PPdxBdbgkLZFtjfEx6MHZwMBamwu/
+mount /dev/sda1 /
+username awilfox
+usergroups awilfox disk,lp,wheel,floppy,audio,cdrom
+usergroups awilfox wheel,video,games,cdrw,usb,users
diff --git a/tests/spec/validator.rb b/tests/spec/validator.rb
index e43e5ed..023d49e 100644
--- a/tests/spec/validator.rb
+++ b/tests/spec/validator.rb
@@ -651,6 +651,50 @@ RSpec.describe 'HorizonScript validation', :type => :aruba do
expect(last_command_started).to have_output(/error: .*usericon.*URL/)
end
end
+ context "'usergroups'" do
+ # Runner.Validate.usergroups.
+ it "succeeds with a valid account/group set" do
+ use_fixture '0104-usergroups-basic.installfile'
+ run_validate
+ expect(last_command_started).to have_output(PARSER_SUCCESS)
+ expect(last_command_started).to have_output(VALIDATOR_SUCCESS)
+ end
+ # Runner.Validate.usergroups.Validity.
+ it "requires at least one group to be provided" do
+ use_fixture '0105-usergroups-without-groups.installfile'
+ run_validate
+ expect(last_command_started).to have_output(/error: .*usergroups.*required/)
+ end
+ it "correctly errors when only a , is given" do
+ use_fixture '0106-usergroups-comma.installfile'
+ run_validate
+ expect(last_command_started).to have_output(/error: .*usergroups.*invalid/)
+ end
+ # Runner.Validate.usergroups.Name.
+ it "fails with a username that wasn't given" do
+ use_fixture '0107-usergroups-unknown-name.installfile'
+ run_validate
+ expect(last_command_started).to have_output(/error: .*usergroups.*name/)
+ end
+ # Runner.Validate.usergroups.Count.
+ it "fails with more than 16 groups for a single name" do
+ use_fixture '0108-jumbo-usergroups.installfile'
+ run_validate
+ expect(last_command_started).to have_output(/error: .*usergroups.*16/)
+ end
+ # Runner.Validate.usergroups.Group.
+ it "fails with an unknown group name" do
+ use_fixture '0109-usergroups-unknown.installfile'
+ run_validate
+ expect(last_command_started).to have_output(/error: .*usergroups.*group/)
+ end
+ # Runner.Validate.usergroups.Unique.
+ it "fails with the same group specified twice" do
+ use_fixture '0110-usergroups-duplicate.installfile'
+ run_validate
+ expect(last_command_started).to have_output(/error: .*usergroups.*duplicate/)
+ end
+ end
end
context "package specifications" do
# no requirements for these, but I think obvious.