[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
This commit is contained in:
parent
8a6e4af511
commit
8ce7457023
@ -49,6 +49,13 @@ calamares_add_test(
|
|||||||
${CRYPT_LIBRARIES}
|
${CRYPT_LIBRARIES}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
calamares_add_test(
|
||||||
|
userscreatetest
|
||||||
|
SOURCES
|
||||||
|
CreateUserTests.cpp
|
||||||
|
CreateUserJob.cpp
|
||||||
|
)
|
||||||
|
|
||||||
calamares_add_test(
|
calamares_add_test(
|
||||||
userstest
|
userstest
|
||||||
SOURCES
|
SOURCES
|
||||||
|
@ -55,7 +55,7 @@ CreateUserJob::prettyStatusMessage() const
|
|||||||
return tr( "Creating user %1." ).arg( m_userName );
|
return tr( "Creating user %1." ).arg( m_userName );
|
||||||
}
|
}
|
||||||
|
|
||||||
static QStringList
|
STATICTEST QStringList
|
||||||
groupsInTargetSystem( const QDir& targetRoot )
|
groupsInTargetSystem( const QDir& targetRoot )
|
||||||
{
|
{
|
||||||
QFileInfo groupsFi( targetRoot.absoluteFilePath( "etc/group" ) );
|
QFileInfo groupsFi( targetRoot.absoluteFilePath( "etc/group" ) );
|
||||||
@ -66,10 +66,22 @@ groupsInTargetSystem( const QDir& targetRoot )
|
|||||||
}
|
}
|
||||||
QString groupsData = QString::fromLocal8Bit( groupsFile.readAll() );
|
QString groupsData = QString::fromLocal8Bit( groupsFile.readAll() );
|
||||||
QStringList groupsLines = groupsData.split( '\n' );
|
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( ':' );
|
int indexOfFirstToDrop = it->indexOf( ':' );
|
||||||
|
if ( indexOfFirstToDrop < 1 )
|
||||||
|
{
|
||||||
|
it = groupsLines.erase( it );
|
||||||
|
continue;
|
||||||
|
}
|
||||||
it->truncate( indexOfFirstToDrop );
|
it->truncate( indexOfFirstToDrop );
|
||||||
|
++it;
|
||||||
}
|
}
|
||||||
return groupsLines;
|
return groupsLines;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user