From c68c3632cc7465a2a1bba1f7ceaab7bf96e751b9 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 22 Oct 2024 15:07:24 +0200 Subject: [PATCH] [users] Expand tests and repair newly-acceptable cases --- src/modules/users/Tests.cpp | 19 ++++++++++++++++--- src/modules/users/tests/8a-issue-2362.conf | 2 +- src/modules/users/tests/8b-issue-2362.conf | 6 ++++-- src/modules/users/tests/8c-issue-2362.conf | 2 +- src/modules/users/tests/8d-issue-2362.conf | 11 +++++++++++ src/modules/users/tests/8e-issue-2362.conf | 11 +++++++++++ src/modules/users/tests/8f-issue-2362.conf | 11 +++++++++++ src/modules/users/tests/8g-issue-2362.conf | 12 ++++++++++++ 8 files changed, 67 insertions(+), 7 deletions(-) create mode 100644 src/modules/users/tests/8d-issue-2362.conf create mode 100644 src/modules/users/tests/8e-issue-2362.conf create mode 100644 src/modules/users/tests/8f-issue-2362.conf create mode 100644 src/modules/users/tests/8g-issue-2362.conf diff --git a/src/modules/users/Tests.cpp b/src/modules/users/Tests.cpp index 7df04dcd6..f44e73f6a 100644 --- a/src/modules/users/Tests.cpp +++ b/src/modules/users/Tests.cpp @@ -523,6 +523,10 @@ UserTests::testUserUmask_data() 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; + QTest::newRow( "rwxx " ) << "tests/8d-issue-2362.conf" << 0710 << 0067; + QTest::newRow( "-wrd " ) << "tests/8e-issue-2362.conf" << 0214 << 0563; + QTest::newRow( "bogus" ) << "tests/8f-issue-2362.conf" << -1 << -1; + QTest::newRow( "good2" ) << "tests/8g-issue-2362.conf" << 0750 << 0027; } void @@ -531,7 +535,12 @@ 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" ) }; + // nobody and root are always forbidden, even if not mentioned in the config, entries are alphabetical + const QStringList forbidden { QStringLiteral( "me" ), + QStringLiteral( "moi" ), + QStringLiteral( "myself" ), + QStringLiteral( "nobody" ), + QStringLiteral( "root" ) }; Config c; c.setUserShell( old_shell ); QCOMPARE( c.homePermissions(), no_permissions ); @@ -541,8 +550,12 @@ UserTests::testUserUmask() QFETCH( int, permission ); QFETCH( int, umask ); - QCOMPARE( permission & umask, 0 ); - QCOMPARE( permission | umask, 0777 ); + // Checks that the test-data is valid + if ( permission != -1 ) + { + QCOMPARE( permission & umask, 0 ); + QCOMPARE( permission | umask, 0777 ); + } QFileInfo fi( QString( "%1/%2" ).arg( BUILD_AS_TEST, filename ) ); QVERIFY( fi.exists() ); diff --git a/src/modules/users/tests/8a-issue-2362.conf b/src/modules/users/tests/8a-issue-2362.conf index 03859f19c..1b77b74d0 100644 --- a/src/modules/users/tests/8a-issue-2362.conf +++ b/src/modules/users/tests/8a-issue-2362.conf @@ -8,4 +8,4 @@ user: - me - myself - moi - home_permissions: "700" + home_permissions: "o700" diff --git a/src/modules/users/tests/8b-issue-2362.conf b/src/modules/users/tests/8b-issue-2362.conf index 996142b30..6ef934b42 100644 --- a/src/modules/users/tests/8b-issue-2362.conf +++ b/src/modules/users/tests/8b-issue-2362.conf @@ -4,8 +4,10 @@ --- user: shell: /usr/bin/new + # Order of names here doesn't matter (and "nobody" and "root" are always added) forbidden_names: - - me - myself - moi - home_permissions: "755" + - me + - root + home_permissions: "o755" diff --git a/src/modules/users/tests/8c-issue-2362.conf b/src/modules/users/tests/8c-issue-2362.conf index 6cb48de06..b229f5c2f 100644 --- a/src/modules/users/tests/8c-issue-2362.conf +++ b/src/modules/users/tests/8c-issue-2362.conf @@ -8,4 +8,4 @@ user: - me - myself - moi - home_permissions: "126" + home_permissions: "o126" diff --git a/src/modules/users/tests/8d-issue-2362.conf b/src/modules/users/tests/8d-issue-2362.conf new file mode 100644 index 000000000..e14683a46 --- /dev/null +++ b/src/modules/users/tests/8d-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: rwx--x--- diff --git a/src/modules/users/tests/8e-issue-2362.conf b/src/modules/users/tests/8e-issue-2362.conf new file mode 100644 index 000000000..a9c794eca --- /dev/null +++ b/src/modules/users/tests/8e-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: -w---xr-- diff --git a/src/modules/users/tests/8f-issue-2362.conf b/src/modules/users/tests/8f-issue-2362.conf new file mode 100644 index 000000000..7da938ba7 --- /dev/null +++ b/src/modules/users/tests/8f-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: Bogus diff --git a/src/modules/users/tests/8g-issue-2362.conf b/src/modules/users/tests/8g-issue-2362.conf new file mode 100644 index 000000000..3921642a9 --- /dev/null +++ b/src/modules/users/tests/8g-issue-2362.conf @@ -0,0 +1,12 @@ +# SPDX-FileCopyrightText: no +# SPDX-License-Identifier: CC0-1.0 +# +--- +user: + shell: /usr/bin/new + forbidden_names: + - me + - myself + - moi + # This is a number, not a string, due to vagaries of YAML + home_permissions: "0750"