[users] Introduce new structure for users-settings
This commit is contained in:
parent
1bf5206bd7
commit
fe04ae3ac1
@ -884,13 +884,22 @@ copyLegacy( const QVariantMap& source, const QString& sourceKey, QVariantMap& ta
|
||||
void
|
||||
Config::setConfigurationMap( const QVariantMap& configurationMap )
|
||||
{
|
||||
QString shell( QLatin1String( "/bin/bash" ) ); // as if it's not set at all
|
||||
if ( configurationMap.contains( "userShell" ) )
|
||||
// Handle *user* key and subkeys and legacy settings
|
||||
{
|
||||
shell = CalamaresUtils::getString( configurationMap, "userShell" );
|
||||
bool ok = false; // Ignored
|
||||
QVariantMap userSettings = CalamaresUtils::getSubMap( configurationMap, "user", ok );
|
||||
|
||||
// TODO:3.3: Remove calls to copyLegacy
|
||||
copyLegacy( configurationMap, "userShell", userSettings, "shell" );
|
||||
|
||||
QString shell( QLatin1String( "/bin/bash" ) ); // as if it's not set at all
|
||||
if ( userSettings.contains( "shell" ) )
|
||||
{
|
||||
shell = CalamaresUtils::getString( userSettings, "shell" );
|
||||
}
|
||||
// Now it might be explicitly set to empty, which is ok
|
||||
setUserShell( shell );
|
||||
}
|
||||
// Now it might be explicitly set to empty, which is ok
|
||||
setUserShell( shell );
|
||||
|
||||
setAutoLoginGroup( either< QString, const QString& >(
|
||||
CalamaresUtils::getString, configurationMap, "autologinGroup", "autoLoginGroup", QString() ) );
|
||||
|
@ -53,6 +53,9 @@ private Q_SLOTS:
|
||||
|
||||
void testAutoLogin_data();
|
||||
void testAutoLogin();
|
||||
|
||||
void testUserYAML_data();
|
||||
void testUserYAML();
|
||||
};
|
||||
|
||||
UserTests::UserTests() {}
|
||||
@ -455,6 +458,58 @@ UserTests::testAutoLogin()
|
||||
QCOMPARE( c.autoLoginGroup(), autoLoginGroupName );
|
||||
}
|
||||
|
||||
void
|
||||
UserTests::testUserYAML_data()
|
||||
{
|
||||
QTest::addColumn< QString >( "filename" );
|
||||
QTest::addColumn< QString >( "shell" );
|
||||
|
||||
QTest::newRow( "old, unset " ) << "tests/7ao-shell.conf"
|
||||
<< "/bin/bash";
|
||||
QTest::newRow( "old, empty " ) << "tests/7bo-shell.conf"
|
||||
<< "";
|
||||
QTest::newRow( "old, relative" ) << "tests/7co-shell.conf"
|
||||
<< "/bin/ls"; // Setting is ignored
|
||||
QTest::newRow( "old, invalid " ) << "tests/7do-shell.conf"
|
||||
<< "";
|
||||
QTest::newRow( "old, absolute" ) << "tests/7eo-shell.conf"
|
||||
<< "/usr/bin/dash";
|
||||
|
||||
QTest::newRow( "new, unset " ) << "tests/7an-shell.conf"
|
||||
<< "/bin/bash";
|
||||
QTest::newRow( "new, empty " ) << "tests/7bn-shell.conf"
|
||||
<< "";
|
||||
QTest::newRow( "new, relative" ) << "tests/7cn-shell.conf"
|
||||
<< "/bin/ls"; // Setting is ignored
|
||||
QTest::newRow( "new, invalid " ) << "tests/7dn-shell.conf"
|
||||
<< "";
|
||||
QTest::newRow( "new, absolute" ) << "tests/7en-shell.conf"
|
||||
<< "/usr/bin/dash";
|
||||
}
|
||||
|
||||
void
|
||||
UserTests::testUserYAML()
|
||||
{
|
||||
Config c;
|
||||
c.setUserShell( QStringLiteral( "/bin/ls" ) );
|
||||
|
||||
QFETCH( QString, filename );
|
||||
QFETCH( QString, shell );
|
||||
|
||||
// BUILD_AS_TEST is the source-directory path
|
||||
QFile fi( QString( "%1/%2" ).arg( BUILD_AS_TEST, filename ) );
|
||||
QVERIFY( fi.exists() );
|
||||
|
||||
bool ok = false;
|
||||
const auto map = CalamaresUtils::loadYaml( fi, &ok );
|
||||
QVERIFY( ok );
|
||||
QVERIFY( map.count() > 0 );
|
||||
|
||||
QCOMPARE( c.userShell(), QStringLiteral( "/bin/ls" ) );
|
||||
c.setConfigurationMap( map );
|
||||
QCOMPARE( c.userShell(), shell );
|
||||
}
|
||||
|
||||
|
||||
QTEST_GUILESS_MAIN( UserTests )
|
||||
|
||||
|
8
src/modules/users/tests/7an-shell.conf
Normal file
8
src/modules/users/tests/7an-shell.conf
Normal file
@ -0,0 +1,8 @@
|
||||
# SPDX-FileCopyrightText: no
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
#
|
||||
---
|
||||
# Unset (bogus needed to keep it valid YAML)
|
||||
user:
|
||||
# shell: /usr/bin/dash
|
||||
bogus: true
|
7
src/modules/users/tests/7ao-shell.conf
Normal file
7
src/modules/users/tests/7ao-shell.conf
Normal file
@ -0,0 +1,7 @@
|
||||
# SPDX-FileCopyrightText: no
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
#
|
||||
---
|
||||
# Unset (bogus needed to keep it valid YAML)
|
||||
# userShell: /usr/bin/dash
|
||||
bogus: true
|
8
src/modules/users/tests/7bn-shell.conf
Normal file
8
src/modules/users/tests/7bn-shell.conf
Normal file
@ -0,0 +1,8 @@
|
||||
# SPDX-FileCopyrightText: no
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
#
|
||||
---
|
||||
# Explicitly empty
|
||||
user:
|
||||
shell: ""
|
||||
|
7
src/modules/users/tests/7bo-shell.conf
Normal file
7
src/modules/users/tests/7bo-shell.conf
Normal file
@ -0,0 +1,7 @@
|
||||
# SPDX-FileCopyrightText: no
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
#
|
||||
---
|
||||
# Explicitly empty
|
||||
userShell: ""
|
||||
|
8
src/modules/users/tests/7cn-shell.conf
Normal file
8
src/modules/users/tests/7cn-shell.conf
Normal file
@ -0,0 +1,8 @@
|
||||
# SPDX-FileCopyrightText: no
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
#
|
||||
---
|
||||
# Non-absolute path is ignored
|
||||
user:
|
||||
shell: dash
|
||||
|
7
src/modules/users/tests/7co-shell.conf
Normal file
7
src/modules/users/tests/7co-shell.conf
Normal file
@ -0,0 +1,7 @@
|
||||
# SPDX-FileCopyrightText: no
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
#
|
||||
---
|
||||
# Non-absolute path is ignored
|
||||
userShell: dash
|
||||
|
8
src/modules/users/tests/7dn-shell.conf
Normal file
8
src/modules/users/tests/7dn-shell.conf
Normal file
@ -0,0 +1,8 @@
|
||||
# SPDX-FileCopyrightText: no
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
#
|
||||
---
|
||||
# Invalid setting (should be string), won't pass validation
|
||||
user:
|
||||
shell: [1]
|
||||
|
7
src/modules/users/tests/7do-shell.conf
Normal file
7
src/modules/users/tests/7do-shell.conf
Normal file
@ -0,0 +1,7 @@
|
||||
# SPDX-FileCopyrightText: no
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
#
|
||||
---
|
||||
# Invalid setting (should be string), won't pass validation
|
||||
userShell: [1]
|
||||
|
8
src/modules/users/tests/7en-shell.conf
Normal file
8
src/modules/users/tests/7en-shell.conf
Normal file
@ -0,0 +1,8 @@
|
||||
# SPDX-FileCopyrightText: no
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
#
|
||||
---
|
||||
# Explicitly set with full path
|
||||
user:
|
||||
shell: /usr/bin/dash
|
||||
|
7
src/modules/users/tests/7eo-shell.conf
Normal file
7
src/modules/users/tests/7eo-shell.conf
Normal file
@ -0,0 +1,7 @@
|
||||
# SPDX-FileCopyrightText: no
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
#
|
||||
---
|
||||
# Explicitly set with full path
|
||||
userShell: /usr/bin/dash
|
||||
|
10
src/modules/users/tests/7fb-shell.conf
Normal file
10
src/modules/users/tests/7fb-shell.conf
Normal file
@ -0,0 +1,10 @@
|
||||
# SPDX-FileCopyrightText: no
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
#
|
||||
---
|
||||
# Explicitly set with full path
|
||||
user:
|
||||
shell: /usr/bin/new
|
||||
bogus: true
|
||||
|
||||
userShell: /usr/bin/old
|
10
src/modules/users/tests/7fn-shell.conf
Normal file
10
src/modules/users/tests/7fn-shell.conf
Normal file
@ -0,0 +1,10 @@
|
||||
# SPDX-FileCopyrightText: no
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
#
|
||||
---
|
||||
# Explicitly set with full path
|
||||
user:
|
||||
shell: /usr/bin/new
|
||||
bogus: true
|
||||
|
||||
# userShell: /usr/bin/old
|
10
src/modules/users/tests/7fo-shell.conf
Normal file
10
src/modules/users/tests/7fo-shell.conf
Normal file
@ -0,0 +1,10 @@
|
||||
# SPDX-FileCopyrightText: no
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
#
|
||||
---
|
||||
# Explicitly set with full path
|
||||
user:
|
||||
# shell: /usr/bin/new
|
||||
bogus: true
|
||||
|
||||
userShell: /usr/bin/old
|
@ -8,6 +8,11 @@ type: object
|
||||
properties:
|
||||
# User shell, should be path to /bin/sh or so
|
||||
userShell: { type: string }
|
||||
user:
|
||||
additionalProperties: false
|
||||
type: object
|
||||
properties:
|
||||
shell: { type: string } # Overrides userShell
|
||||
# Group settings
|
||||
defaultGroups:
|
||||
type: array
|
||||
|
Loading…
Reference in New Issue
Block a user