diff --git a/CHANGES b/CHANGES index 2619344a9..9856bb7d0 100644 --- a/CHANGES +++ b/CHANGES @@ -11,6 +11,7 @@ website will have to do for older versions. This release contains contributions from (alphabetically by first name): - Erik Dubois + - Joe Kamprad - Lisa Vitolo ## Core ## @@ -32,6 +33,15 @@ This release contains contributions from (alphabetically by first name): has been revived and merged. +# 3.2.39.3 (2021-04-14) # + +A minor bugfix tweak release. Since this contains yet **another** +autologin-related fix, and there is nothing large enough to justify +a 3.2.40 release yet, add it to the growing tail of 3.2.39. (Reported +by Joe Kamprad, #1672). Also fixes a regression from 3.2.28 in +localized packages (e.g. *package-LOCALE* did not work). + + # 3.2.39.2 (2021-04-02) # This is **another** hotfix release for issues around autologin .. diff --git a/src/modules/users/Config.cpp b/src/modules/users/Config.cpp index 2954b0381..6560d06ac 100644 --- a/src/modules/users/Config.cpp +++ b/src/modules/users/Config.cpp @@ -803,6 +803,29 @@ addPasswordCheck( const QString& key, const QVariant& value, PasswordCheckList& return true; } +/** @brief Returns a value of either key from the map + * + * Takes a function (e.g. getBool, or getString) and two keys, + * returning the value in the map of the one that is there (or @p defaultArg) + */ +template < typename T, typename U > +T +either( T ( *f )( const QVariantMap&, const QString&, U ), + const QVariantMap& configurationMap, + const QString& oldKey, + const QString& newKey, + U defaultArg ) +{ + if ( configurationMap.contains( oldKey ) ) + { + return f( configurationMap, oldKey, defaultArg ); + } + else + { + return f( configurationMap, newKey, defaultArg ); + } +} + void Config::setConfigurationMap( const QVariantMap& configurationMap ) { @@ -814,7 +837,8 @@ Config::setConfigurationMap( const QVariantMap& configurationMap ) // Now it might be explicitly set to empty, which is ok setUserShell( shell ); - setAutoLoginGroup( CalamaresUtils::getString( configurationMap, "autoLoginGroup" ) ); + setAutoLoginGroup( either< QString, const QString& >( + CalamaresUtils::getString, configurationMap, "autologinGroup", "autoLoginGroup", QString() ) ); setSudoersGroup( CalamaresUtils::getString( configurationMap, "sudoersGroup" ) ); m_hostNameActions = getHostNameActions( configurationMap ); @@ -823,16 +847,11 @@ Config::setConfigurationMap( const QVariantMap& configurationMap ) // Renaming of Autologin -> AutoLogin in 4ffa79d4cf also affected // configuration keys, which was not intended. Accept both. - const auto oldKey = QStringLiteral( "doAutologin" ); - const auto newKey = QStringLiteral( "doAutoLogin" ); - if ( configurationMap.contains( oldKey ) ) - { - m_doAutoLogin = CalamaresUtils::getBool( configurationMap, oldKey, false ); - } - else - { - m_doAutoLogin = CalamaresUtils::getBool( configurationMap, newKey, false ); - } + m_doAutoLogin = either( CalamaresUtils::getBool, + configurationMap, + QStringLiteral( "doAutologin" ), + QStringLiteral( "doAutoLogin" ), + false ); m_writeRootPassword = CalamaresUtils::getBool( configurationMap, "setRootPassword", true ); Calamares::JobQueue::instance()->globalStorage()->insert( "setRootPassword", m_writeRootPassword ); diff --git a/src/modules/users/Tests.cpp b/src/modules/users/Tests.cpp index 4106cd785..acb0c9d6d 100644 --- a/src/modules/users/Tests.cpp +++ b/src/modules/users/Tests.cpp @@ -44,6 +44,9 @@ private Q_SLOTS: void testHostActions(); void testPasswordChecks(); void testUserPassword(); + + void testAutoLogin_data(); + void testAutoLogin(); }; UserTests::UserTests() {} @@ -339,6 +342,43 @@ UserTests::testUserPassword() } } +void +UserTests::testAutoLogin_data() +{ + QTest::addColumn< QString >( "filename" ); + QTest::addColumn< bool >( "autoLoginIsSet" ); + QTest::addColumn< QString >( "autoLoginGroupName" ); + + QTest::newRow( "old, old" ) << "tests/6a-issue-1672.conf" << true << "derp"; + QTest::newRow( "old, new" ) << "tests/6b-issue-1672.conf" << true << "derp"; + QTest::newRow( "new, old" ) << "tests/6c-issue-1672.conf" << true << "derp"; + QTest::newRow( "new, new" ) << "tests/6d-issue-1672.conf" << true << "derp"; + QTest::newRow( "default" ) << "tests/6e-issue-1672.conf" << false << QString(); +} + +void +UserTests::testAutoLogin() +{ + QFETCH( QString, filename ); + QFETCH( bool, autoLoginIsSet ); + QFETCH( QString, autoLoginGroupName ); + + // 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 ); + + Config c; + c.setConfigurationMap( map ); + + QCOMPARE( c.doAutoLogin(), autoLoginIsSet ); + QCOMPARE( c.autoLoginGroup(), autoLoginGroupName ); +} + QTEST_GUILESS_MAIN( UserTests ) diff --git a/src/modules/users/tests/6a-issue-1672.conf b/src/modules/users/tests/6a-issue-1672.conf new file mode 100644 index 000000000..b8ba24266 --- /dev/null +++ b/src/modules/users/tests/6a-issue-1672.conf @@ -0,0 +1,7 @@ +# SPDX-FileCopyrightText: no +# SPDX-License-Identifier: CC0-1.0 +# +--- +autologinGroup: derp +doAutologin: true + diff --git a/src/modules/users/tests/6b-issue-1672.conf b/src/modules/users/tests/6b-issue-1672.conf new file mode 100644 index 000000000..a54e71e01 --- /dev/null +++ b/src/modules/users/tests/6b-issue-1672.conf @@ -0,0 +1,7 @@ +# SPDX-FileCopyrightText: no +# SPDX-License-Identifier: CC0-1.0 +# +--- +autologinGroup: derp +doAutoLogin: true + diff --git a/src/modules/users/tests/6c-issue-1672.conf b/src/modules/users/tests/6c-issue-1672.conf new file mode 100644 index 000000000..5d12bd71e --- /dev/null +++ b/src/modules/users/tests/6c-issue-1672.conf @@ -0,0 +1,7 @@ +# SPDX-FileCopyrightText: no +# SPDX-License-Identifier: CC0-1.0 +# +--- +autoLoginGroup: derp +doAutologin: true + diff --git a/src/modules/users/tests/6d-issue-1672.conf b/src/modules/users/tests/6d-issue-1672.conf new file mode 100644 index 000000000..80976bf64 --- /dev/null +++ b/src/modules/users/tests/6d-issue-1672.conf @@ -0,0 +1,7 @@ +# SPDX-FileCopyrightText: no +# SPDX-License-Identifier: CC0-1.0 +# +--- +autoLoginGroup: derp +doAutoLogin: true + diff --git a/src/modules/users/tests/6e-issue-1672.conf b/src/modules/users/tests/6e-issue-1672.conf new file mode 100644 index 000000000..df299b480 --- /dev/null +++ b/src/modules/users/tests/6e-issue-1672.conf @@ -0,0 +1,7 @@ +# SPDX-FileCopyrightText: no +# SPDX-License-Identifier: CC0-1.0 +# +--- +doautologin: true +autologingroup: wheel +