[users] Add unit-test for new parsing and configuration options

This commit is contained in:
Adriaan de Groot 2024-09-23 21:52:55 +02:00
parent e80437c9b9
commit 09a3f58800
4 changed files with 85 additions and 0 deletions

View File

@ -56,6 +56,8 @@ private Q_SLOTS:
void testUserYAML_data();
void testUserYAML();
void testUserUmask_data();
void testUserUmask();
};
UserTests::UserTests() {}
@ -511,6 +513,56 @@ UserTests::testUserYAML()
QCOMPARE( c.userShell(), shell );
}
void
UserTests::testUserUmask_data()
{
QTest::addColumn< QString >( "filename" );
QTest::addColumn< int >( "permission" );
QTest::addColumn< int >( "umask" );
QTest::newRow( "good " ) << "tests/8a-issue-2362.conf" << 0700 << 0077;
QTest::newRow( "open " ) << "tests/8b-issue-2362.conf" << 0755 << 0022;
QTest::newRow( "weird" ) << "tests/8c-issue-2362.conf" << 0126 << 0651;
}
void
UserTests::testUserUmask()
{
static constexpr int no_permissions = -1;
const QString old_shell = QStringLiteral( "/bin/ls" );
const QString new_shell = QStringLiteral( "/usr/bin/new" );
const QStringList forbidden { QStringLiteral( "me" ), QStringLiteral( "myself" ), QStringLiteral( "moi" ) };
Config c;
c.setUserShell( old_shell );
QCOMPARE( c.homePermissions(), no_permissions );
QCOMPARE( c.homeUMask(), no_permissions );
QFETCH( QString, filename );
QFETCH( int, permission );
QFETCH( int, umask );
QCOMPARE( permission & umask, 0 );
QCOMPARE( permission | umask, 0777 );
QFileInfo fi( QString( "%1/%2" ).arg( BUILD_AS_TEST, filename ) );
QVERIFY( fi.exists() );
bool ok = false;
const auto map = Calamares::YAML::load( fi, &ok );
QVERIFY( ok );
QVERIFY( map.count() > 0 );
QCOMPARE( c.userShell(), old_shell );
c.setConfigurationMap( map );
QCOMPARE( c.userShell(), new_shell );
QCOMPARE( c.homePermissions(), permission );
QCOMPARE( c.homeUMask(), umask );
QCOMPARE( c.forbiddenLoginNames(), forbidden );
}
QTEST_GUILESS_MAIN( UserTests )
#include "utils/moc-warnings.h"

View File

@ -0,0 +1,11 @@
# SPDX-FileCopyrightText: no
# SPDX-License-Identifier: CC0-1.0
#
---
user:
shell: /usr/bin/new
forbidden_names:
- me
- myself
- moi
home_permissions: "700"

View File

@ -0,0 +1,11 @@
# SPDX-FileCopyrightText: no
# SPDX-License-Identifier: CC0-1.0
#
---
user:
shell: /usr/bin/new
forbidden_names:
- me
- myself
- moi
home_permissions: "755"

View File

@ -0,0 +1,11 @@
# SPDX-FileCopyrightText: no
# SPDX-License-Identifier: CC0-1.0
#
---
user:
shell: /usr/bin/new
forbidden_names:
- me
- myself
- moi
home_permissions: "126"