From 8ce7457023aa49bfce2d3291f70612cb2d86958e Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 27 Jul 2020 15:00:14 +0200 Subject: [PATCH] [users] Add test for create-users code - just one test for groups-file loading - while here fix bug that blank and comment lines were being kept as valid group names --- src/modules/users/CMakeLists.txt | 7 +++++++ src/modules/users/CreateUserJob.cpp | 16 ++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/modules/users/CMakeLists.txt b/src/modules/users/CMakeLists.txt index 1d969a93b..a449d39ac 100644 --- a/src/modules/users/CMakeLists.txt +++ b/src/modules/users/CMakeLists.txt @@ -49,6 +49,13 @@ calamares_add_test( ${CRYPT_LIBRARIES} ) +calamares_add_test( + userscreatetest + SOURCES + CreateUserTests.cpp + CreateUserJob.cpp +) + calamares_add_test( userstest SOURCES diff --git a/src/modules/users/CreateUserJob.cpp b/src/modules/users/CreateUserJob.cpp index 0fe931fa8..beb454ac0 100644 --- a/src/modules/users/CreateUserJob.cpp +++ b/src/modules/users/CreateUserJob.cpp @@ -55,7 +55,7 @@ CreateUserJob::prettyStatusMessage() const return tr( "Creating user %1." ).arg( m_userName ); } -static QStringList +STATICTEST QStringList groupsInTargetSystem( const QDir& targetRoot ) { QFileInfo groupsFi( targetRoot.absoluteFilePath( "etc/group" ) ); @@ -66,10 +66,22 @@ groupsInTargetSystem( const QDir& targetRoot ) } QString groupsData = QString::fromLocal8Bit( groupsFile.readAll() ); QStringList groupsLines = groupsData.split( '\n' ); - for ( QStringList::iterator it = groupsLines.begin(); it != groupsLines.end(); ++it ) + QStringList::iterator it = groupsLines.begin(); + while ( it != groupsLines.end() ) { + if ( it->startsWith( '#' ) ) + { + it = groupsLines.erase( it ); + continue; + } int indexOfFirstToDrop = it->indexOf( ':' ); + if ( indexOfFirstToDrop < 1 ) + { + it = groupsLines.erase( it ); + continue; + } it->truncate( indexOfFirstToDrop ); + ++it; } return groupsLines; }