|
|
|
@ -31,6 +31,7 @@ public:
|
|
|
|
|
|
|
|
|
|
private Q_SLOTS:
|
|
|
|
|
void initTestCase();
|
|
|
|
|
void testConfigEntropyFiles();
|
|
|
|
|
|
|
|
|
|
void testCopyFile();
|
|
|
|
|
|
|
|
|
@ -45,6 +46,65 @@ MachineIdTests::initTestCase()
|
|
|
|
|
Logger::setupLogLevel( Logger::LOGDEBUG );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
MachineIdTests::testConfigEntropyFiles()
|
|
|
|
|
{
|
|
|
|
|
static QString urandom_entropy( "/var/lib/urandom/random-seed" );
|
|
|
|
|
// No config at all
|
|
|
|
|
{
|
|
|
|
|
QVariantMap m;
|
|
|
|
|
MachineIdJob j;
|
|
|
|
|
j.setConfigurationMap( m );
|
|
|
|
|
QCOMPARE( j.entropyFileNames(), QStringList() );
|
|
|
|
|
}
|
|
|
|
|
// No entropy, deprecated setting
|
|
|
|
|
{
|
|
|
|
|
QVariantMap m;
|
|
|
|
|
MachineIdJob j;
|
|
|
|
|
m.insert( "entropy", false );
|
|
|
|
|
j.setConfigurationMap( m );
|
|
|
|
|
QCOMPARE( j.entropyFileNames(), QStringList() );
|
|
|
|
|
}
|
|
|
|
|
// Entropy, deprecated setting
|
|
|
|
|
{
|
|
|
|
|
QVariantMap m;
|
|
|
|
|
MachineIdJob j;
|
|
|
|
|
m.insert( "entropy", true );
|
|
|
|
|
j.setConfigurationMap( m );
|
|
|
|
|
QCOMPARE( j.entropyFileNames(), QStringList { urandom_entropy } );
|
|
|
|
|
}
|
|
|
|
|
// Duplicate entry, with deprecated setting
|
|
|
|
|
{
|
|
|
|
|
QVariantMap m;
|
|
|
|
|
MachineIdJob j;
|
|
|
|
|
m.insert( "entropy", true );
|
|
|
|
|
m.insert( "entropy-files", QStringList { urandom_entropy } );
|
|
|
|
|
j.setConfigurationMap( m );
|
|
|
|
|
QCOMPARE( j.entropyFileNames(), QStringList { urandom_entropy } );
|
|
|
|
|
|
|
|
|
|
m.clear();
|
|
|
|
|
j.setConfigurationMap( m );
|
|
|
|
|
QCOMPARE( j.entropyFileNames(), QStringList() );
|
|
|
|
|
|
|
|
|
|
// This would be weird
|
|
|
|
|
m.insert( "entropy", false );
|
|
|
|
|
m.insert( "entropy-files", QStringList { urandom_entropy } );
|
|
|
|
|
j.setConfigurationMap( m );
|
|
|
|
|
QCOMPARE( j.entropyFileNames(), QStringList { urandom_entropy } );
|
|
|
|
|
}
|
|
|
|
|
// No deprecated setting
|
|
|
|
|
{
|
|
|
|
|
QString tmp_entropy( "/tmp/entropy" );
|
|
|
|
|
QVariantMap m;
|
|
|
|
|
MachineIdJob j;
|
|
|
|
|
m.insert( "entropy-files", QStringList { urandom_entropy, tmp_entropy } );
|
|
|
|
|
j.setConfigurationMap( m );
|
|
|
|
|
QVERIFY( !j.entropyFileNames().isEmpty() );
|
|
|
|
|
QCOMPARE( j.entropyFileNames(), QStringList() << urandom_entropy << tmp_entropy );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
MachineIdTests::testCopyFile()
|
|
|
|
|
{
|
|
|
|
@ -100,6 +160,7 @@ MachineIdTests::testJob()
|
|
|
|
|
Logger::setupLogLevel( Logger::LOGDEBUG );
|
|
|
|
|
|
|
|
|
|
QTemporaryDir tempRoot( QDir::tempPath() + QStringLiteral( "/test-job-XXXXXX" ) );
|
|
|
|
|
// Only clean up if the tests succeed
|
|
|
|
|
tempRoot.setAutoRemove( false );
|
|
|
|
|
cDebug() << "Temporary files as" << QDir::tempPath();
|
|
|
|
|
|
|
|
|
@ -158,6 +219,27 @@ MachineIdTests::testJob()
|
|
|
|
|
QCOMPARE( fi.size(), 5 );
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
QString tmp_entropy2( "/pineapple.random" );
|
|
|
|
|
QString tmp_entropy( "/tmp/entropy" );
|
|
|
|
|
QVariantMap m;
|
|
|
|
|
MachineIdJob j;
|
|
|
|
|
m.insert( "entropy-files", QStringList { tmp_entropy2, tmp_entropy } );
|
|
|
|
|
m.insert( "entropy", true );
|
|
|
|
|
j.setConfigurationMap( m );
|
|
|
|
|
QCOMPARE( j.entropyFileNames().count(), 3 ); // Because of the standard entropy entry
|
|
|
|
|
|
|
|
|
|
// Check all three are created
|
|
|
|
|
auto r = j.exec();
|
|
|
|
|
QVERIFY( r );
|
|
|
|
|
for ( const auto& fileName : j.entropyFileNames() )
|
|
|
|
|
{
|
|
|
|
|
cDebug() << "Verifying existence of" << fileName;
|
|
|
|
|
QVERIFY( QFile::exists( tempRoot.filePath( fileName.mid( 1 ) ) ) );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tempRoot.setAutoRemove( true ); // All tests succeeded
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|