From 46af8229026a6122ca640f063c24d68876acdb11 Mon Sep 17 00:00:00 2001 From: "A. Wilcox" Date: Fri, 15 May 2020 02:29:01 -0500 Subject: hscript: Ensure user commands are correct in simulator --- hscript/user.cc | 13 +++++++++---- tests/spec/simulator_spec.rb | 22 +++++++++++----------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/hscript/user.cc b/hscript/user.cc index de92067..0dc4eba 100644 --- a/hscript/user.cc +++ b/hscript/user.cc @@ -219,7 +219,8 @@ bool Username::execute() const { "username: creating account " + _value); if(script->options().test(Simulate)) { - std::cout << "useradd -c \"Adélie User\" -m -U " << _value + std::cout << "useradd -c \"Adélie User\" -m -R " + << script->targetDirectory() << " -U " << _value << std::endl; return true; } @@ -263,7 +264,8 @@ bool UserAlias::execute() const { "useralias: setting GECOS name for " + _username); if(script->options().test(Simulate)) { - std::cout << "usermod -c \"" << _alias << "\" " << _username + std::cout << "usermod -c \"" << _alias << "\" " + << "-R " << script->targetDirectory() << " " << _username << std::endl; return true; } @@ -312,7 +314,8 @@ bool UserPassphrase::execute() const { "userpw: setting passphrase for " + _username); if(script->options().test(Simulate)) { - std::cout << "usermod -p '" << _passphrase << "' " << _username + std::cout << "usermod -p '" << _passphrase << "' " + << "-R " << script->targetDirectory() << " " << _username << std::endl; return true; } @@ -473,7 +476,9 @@ bool UserGroups::execute() const { groups.pop_back(); if(script->options().test(Simulate)) { - std::cout << "usermod -aG " << groups << " " << _username << std::endl; + std::cout << "usermod -aG " << groups + << "-R " << script->targetDirectory() + << " " << _username << std::endl; return true; } diff --git a/tests/spec/simulator_spec.rb b/tests/spec/simulator_spec.rb index 1206ab2..60e0186 100644 --- a/tests/spec/simulator_spec.rb +++ b/tests/spec/simulator_spec.rb @@ -335,29 +335,29 @@ printf '%s\\t%s\\t%s\\t%s\\t0\\t0\\n' /dev/gwyn/source /usr/src auto noatime >> it "creates the user account" do use_fixture '0082-username-basic.installfile' run_simulate - expect(last_command_started.stdout).to include('useradd -c "Adélie User" -m -U chris') - expect(last_command_started.stdout).to include('useradd -c "Adélie User" -m -U kayla') - expect(last_command_started.stdout).to include('useradd -c "Adélie User" -m -U meg') - expect(last_command_started.stdout).to include('useradd -c "Adélie User" -m -U steph') - expect(last_command_started.stdout).to include('useradd -c "Adélie User" -m -U amanda') + expect(last_command_started.stdout).to include('useradd -c "Adélie User" -m -R /target -U chris') + expect(last_command_started.stdout).to include('useradd -c "Adélie User" -m -R /target -U kayla') + expect(last_command_started.stdout).to include('useradd -c "Adélie User" -m -R /target -U meg') + expect(last_command_started.stdout).to include('useradd -c "Adélie User" -m -R /target -U steph') + expect(last_command_started.stdout).to include('useradd -c "Adélie User" -m -R /target -U amanda') end end context "simulating 'useralias' execution" do it "sets aliases on all named accounts" do use_fixture '0087-useralias-basic.installfile' run_simulate - expect(last_command_started.stdout).to include('usermod -c "Christopher" chris') - expect(last_command_started.stdout).to include('usermod -c "Kayla" kayla') - expect(last_command_started.stdout).to include('usermod -c "Meaghan" meg') - expect(last_command_started.stdout).to include('usermod -c "Stephanie" steph') - expect(last_command_started.stdout).to include('usermod -c "Amanda Jane" amanda') + expect(last_command_started.stdout).to include('usermod -c "Christopher" -R /target chris') + expect(last_command_started.stdout).to include('usermod -c "Kayla" -R /target kayla') + expect(last_command_started.stdout).to include('usermod -c "Meaghan" -R /target meg') + expect(last_command_started.stdout).to include('usermod -c "Stephanie" -R /target steph') + expect(last_command_started.stdout).to include('usermod -c "Amanda Jane" -R /target amanda') end end context "simulating 'userpw' execution" do it "sets the user's passphrase" do use_fixture '0091-userpw-basic.installfile' run_simulate - expect(last_command_started.stdout).to include("usermod -p '$6$UZJm/vBmVgyIdMZr$ppKEulz/HY0/e7RcXXujQbcqDXkUYgIqNEVPQJO6.le9kUpz8GvvRezY3ifqUUEwjhSo9tTOMG7lhqjn8gGpH0' awilfox") + expect(last_command_started.stdout).to include("usermod -p '$6$UZJm/vBmVgyIdMZr$ppKEulz/HY0/e7RcXXujQbcqDXkUYgIqNEVPQJO6.le9kUpz8GvvRezY3ifqUUEwjhSo9tTOMG7lhqjn8gGpH0' -R /target awilfox") end end context "simulating 'usergroups' execution" do -- cgit v1.2.3-60-g2f50