[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
main
Adriaan de Groot 5 years ago
parent 8a6e4af511
commit 8ce7457023

@ -49,6 +49,13 @@ calamares_add_test(
${CRYPT_LIBRARIES}
)
calamares_add_test(
userscreatetest
SOURCES
CreateUserTests.cpp
CreateUserJob.cpp
)
calamares_add_test(
userstest
SOURCES

@ -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;
}

Loading…
Cancel
Save