From 09a3f5880015fbbc11887bef44835cbe92bae04d Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 23 Sep 2024 21:52:55 +0200 Subject: [PATCH] [users] Add unit-test for new parsing and configuration options --- src/modules/users/Tests.cpp | 52 ++++++++++++++++++++++ src/modules/users/tests/8a-issue-2362.conf | 11 +++++ src/modules/users/tests/8b-issue-2362.conf | 11 +++++ src/modules/users/tests/8c-issue-2362.conf | 11 +++++ 4 files changed, 85 insertions(+) create mode 100644 src/modules/users/tests/8a-issue-2362.conf create mode 100644 src/modules/users/tests/8b-issue-2362.conf create mode 100644 src/modules/users/tests/8c-issue-2362.conf diff --git a/src/modules/users/Tests.cpp b/src/modules/users/Tests.cpp index ba2fd2dab..7df04dcd6 100644 --- a/src/modules/users/Tests.cpp +++ b/src/modules/users/Tests.cpp @@ -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" diff --git a/src/modules/users/tests/8a-issue-2362.conf b/src/modules/users/tests/8a-issue-2362.conf new file mode 100644 index 000000000..03859f19c --- /dev/null +++ b/src/modules/users/tests/8a-issue-2362.conf @@ -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" diff --git a/src/modules/users/tests/8b-issue-2362.conf b/src/modules/users/tests/8b-issue-2362.conf new file mode 100644 index 000000000..996142b30 --- /dev/null +++ b/src/modules/users/tests/8b-issue-2362.conf @@ -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" diff --git a/src/modules/users/tests/8c-issue-2362.conf b/src/modules/users/tests/8c-issue-2362.conf new file mode 100644 index 000000000..6cb48de06 --- /dev/null +++ b/src/modules/users/tests/8c-issue-2362.conf @@ -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"