2020-08-25 16:05:56 +02:00
|
|
|
/* === This file is part of Calamares - <https://calamares.io> ===
|
2020-07-27 15:35:24 +02:00
|
|
|
*
|
|
|
|
* SPDX-FileCopyrightText: 2020 Adriaan de Groot <groot@kde.org>
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
*
|
2020-08-25 16:05:56 +02:00
|
|
|
* Calamares is Free Software: see the License-Identifier above.
|
2020-07-27 15:35:24 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-11-02 12:11:13 +01:00
|
|
|
#include "Config.h"
|
2020-07-27 15:35:24 +02:00
|
|
|
#include "CreateUserJob.h"
|
2020-11-02 12:11:13 +01:00
|
|
|
#include "MiscJobs.h"
|
2020-07-27 15:35:24 +02:00
|
|
|
|
2020-10-23 12:27:44 +02:00
|
|
|
#include "GlobalStorage.h"
|
2020-10-23 12:19:28 +02:00
|
|
|
#include "JobQueue.h"
|
2020-07-27 15:35:24 +02:00
|
|
|
#include "utils/Logger.h"
|
2020-11-02 12:11:13 +01:00
|
|
|
#include "utils/Yaml.h"
|
2020-07-27 15:35:24 +02:00
|
|
|
|
|
|
|
#include <QDir>
|
|
|
|
#include <QtTest/QtTest>
|
|
|
|
|
|
|
|
// Implementation details
|
2020-10-22 14:21:14 +02:00
|
|
|
extern QStringList groupsInTargetSystem(); // CreateUserJob
|
2020-07-27 15:35:24 +02:00
|
|
|
|
2020-10-22 14:21:14 +02:00
|
|
|
class GroupTests : public QObject
|
2020-07-27 15:35:24 +02:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2020-10-22 14:21:14 +02:00
|
|
|
GroupTests();
|
|
|
|
~GroupTests() override {}
|
2020-07-27 15:35:24 +02:00
|
|
|
|
|
|
|
private Q_SLOTS:
|
|
|
|
void initTestCase();
|
|
|
|
|
|
|
|
void testReadGroup();
|
2020-11-02 12:11:13 +01:00
|
|
|
void testCreateGroup();
|
2020-11-06 22:27:34 +01:00
|
|
|
|
|
|
|
void testSudoGroup();
|
2020-07-27 15:35:24 +02:00
|
|
|
};
|
|
|
|
|
2020-10-22 14:21:14 +02:00
|
|
|
GroupTests::GroupTests() {}
|
2020-07-27 15:35:24 +02:00
|
|
|
|
|
|
|
void
|
2020-10-22 14:21:14 +02:00
|
|
|
GroupTests::initTestCase()
|
2020-07-27 15:35:24 +02:00
|
|
|
{
|
|
|
|
Logger::setupLogLevel( Logger::LOGDEBUG );
|
|
|
|
cDebug() << "Users test started.";
|
2020-10-23 12:19:28 +02:00
|
|
|
if ( !Calamares::JobQueue::instance() )
|
|
|
|
{
|
|
|
|
(void)new Calamares::JobQueue();
|
|
|
|
}
|
2020-11-02 12:11:13 +01:00
|
|
|
Calamares::JobQueue::instance()->globalStorage()->insert( "rootMountPoint", "/" );
|
2020-07-27 15:35:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-10-22 14:21:14 +02:00
|
|
|
GroupTests::testReadGroup()
|
2020-07-27 15:35:24 +02:00
|
|
|
{
|
|
|
|
// Get the groups in the host system
|
2020-10-22 14:21:14 +02:00
|
|
|
QStringList groups = groupsInTargetSystem();
|
2020-07-27 15:35:24 +02:00
|
|
|
QVERIFY( groups.count() > 2 );
|
|
|
|
#ifdef __FreeBSD__
|
|
|
|
QVERIFY( groups.contains( QStringLiteral( "wheel" ) ) );
|
|
|
|
#else
|
|
|
|
QVERIFY( groups.contains( QStringLiteral( "root" ) ) );
|
|
|
|
#endif
|
2020-08-11 22:16:03 +02:00
|
|
|
// openSUSE doesn't have "sys"
|
|
|
|
// QVERIFY( groups.contains( QStringLiteral( "sys" ) ) );
|
|
|
|
QVERIFY( groups.contains( QStringLiteral( "nogroup" ) ) );
|
|
|
|
QVERIFY( groups.contains( QStringLiteral( "tty" ) ) );
|
2020-07-27 15:35:24 +02:00
|
|
|
|
|
|
|
for ( const QString& s : groups )
|
|
|
|
{
|
|
|
|
QVERIFY( !s.isEmpty() );
|
|
|
|
QVERIFY( !s.contains( '#' ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-05 00:00:29 +01:00
|
|
|
void
|
|
|
|
GroupTests::testCreateGroup()
|
2020-11-02 12:11:13 +01:00
|
|
|
{
|
|
|
|
// BUILD_AS_TEST is the source-directory path
|
|
|
|
QFile fi( QString( "%1/tests/5-issue-1523.conf" ).arg( BUILD_AS_TEST ) );
|
|
|
|
QVERIFY( fi.exists() );
|
|
|
|
|
|
|
|
bool ok = false;
|
|
|
|
const auto map = CalamaresUtils::loadYaml( fi, &ok );
|
|
|
|
QVERIFY( ok );
|
|
|
|
QVERIFY( map.count() > 0 ); // Just that it loaded, one key *defaultGroups*
|
|
|
|
|
|
|
|
Config c;
|
|
|
|
c.setConfigurationMap( map );
|
|
|
|
|
|
|
|
QCOMPARE( c.defaultGroups().count(), 4 );
|
|
|
|
QVERIFY( c.defaultGroups().contains( QStringLiteral( "adm" ) ) );
|
2020-11-02 12:27:50 +01:00
|
|
|
QVERIFY( c.defaultGroups().contains( QStringLiteral( "bar" ) ) );
|
|
|
|
|
|
|
|
Calamares::JobQueue::instance()->globalStorage()->insert( "rootMountPoint", "/" );
|
|
|
|
|
2020-11-05 00:00:29 +01:00
|
|
|
SetupGroupsJob j( &c );
|
2020-11-02 12:27:50 +01:00
|
|
|
QVERIFY( !j.exec() ); // running as regular user this should fail
|
2020-11-02 12:11:13 +01:00
|
|
|
}
|
|
|
|
|
2020-11-06 22:27:34 +01:00
|
|
|
void GroupTests::testSudoGroup()
|
|
|
|
{
|
|
|
|
// Test programmatic changes
|
|
|
|
{
|
|
|
|
Config c;
|
|
|
|
QSignalSpy spy(&c, &Config::sudoersGroupChanged);
|
|
|
|
QCOMPARE( c.sudoersGroup(), QString() );
|
|
|
|
c.setSudoersGroup( QStringLiteral( "wheel" ) );
|
|
|
|
QCOMPARE( c.sudoersGroup(), QStringLiteral( "wheel" ) );
|
|
|
|
QCOMPARE( spy.count(), 1); // Changed to wheel
|
|
|
|
// Do it again, no change
|
|
|
|
c.setSudoersGroup( QStringLiteral( "wheel" ) );
|
|
|
|
QCOMPARE( c.sudoersGroup(), QStringLiteral( "wheel" ) );
|
|
|
|
QCOMPARE( spy.count(), 1);
|
|
|
|
c.setSudoersGroup( QStringLiteral( "roue" ) );
|
|
|
|
QCOMPARE( c.sudoersGroup(), QStringLiteral( "roue" ) );
|
|
|
|
QCOMPARE( spy.count(), 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Test config loading
|
|
|
|
{
|
|
|
|
Config c;
|
|
|
|
QSignalSpy spy(&c, &Config::sudoersGroupChanged);
|
|
|
|
QCOMPARE( c.sudoersGroup(), QString() );
|
|
|
|
|
|
|
|
QVariantMap m;
|
|
|
|
c.setConfigurationMap( m );
|
|
|
|
QCOMPARE( c.sudoersGroup(), QString() );
|
|
|
|
QCOMPARE( spy.count(), 0); // Unchanged
|
|
|
|
|
|
|
|
const auto key = QStringLiteral( "sudoersGroup" );
|
|
|
|
const auto v0 = QStringLiteral( "wheel" );
|
|
|
|
const auto v1 = QStringLiteral( "roue" );
|
|
|
|
m.insert( key, v0 );
|
|
|
|
c.setConfigurationMap( m );
|
|
|
|
QCOMPARE( c.sudoersGroup(), v0 );
|
|
|
|
QCOMPARE( spy.count(), 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-02 12:11:13 +01:00
|
|
|
|
2020-10-22 14:21:14 +02:00
|
|
|
QTEST_GUILESS_MAIN( GroupTests )
|
2020-07-27 15:35:24 +02:00
|
|
|
|
|
|
|
#include "utils/moc-warnings.h"
|
|
|
|
|
2020-10-23 11:14:59 +02:00
|
|
|
#include "TestGroupInformation.moc"
|