[users] Add unit-test for new parsing and configuration options
This commit is contained in:
parent
e80437c9b9
commit
09a3f58800
@ -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"
|
||||
|
11
src/modules/users/tests/8a-issue-2362.conf
Normal file
11
src/modules/users/tests/8a-issue-2362.conf
Normal 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"
|
11
src/modules/users/tests/8b-issue-2362.conf
Normal file
11
src/modules/users/tests/8b-issue-2362.conf
Normal 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"
|
11
src/modules/users/tests/8c-issue-2362.conf
Normal file
11
src/modules/users/tests/8c-issue-2362.conf
Normal 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"
|
Loading…
Reference in New Issue
Block a user