1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-09 23:57:34 +02:00

Check for sane host addresses returned by Servent

This commit is contained in:
Uwe L. Korn
2014-08-25 23:20:31 +01:00
parent 0d08826ac3
commit bd33726c86

View File

@@ -29,16 +29,28 @@ class TestServent : public QObject
Q_OBJECT Q_OBJECT
private: private:
bool plainIPAddress( const QString& address ) void saneHostAddress( const QString& address )
{ {
// TODO: Add real checks // We do not use QHostAddress here as we use it inside our code.
return true; // (Do not use the same code to test and generate)
// No loopback IPv4 addresses
QVERIFY2( !address.startsWith( QLatin1String( "127.0.0." ) ),
"Loopback IPv4 address detected" );
// No IPv6 localhost address
QVERIFY2( address != "::1", "IPv6 localhost address detected" );
// No IPv4 localhost as IPv6 address
QVERIFY2( address != "::7F00:1",
"IPv4 localhost as IPv6 address detected" );
// No link-local IPv6 addresses
QVERIFY2( !address.startsWith( QLatin1String( "fe80::" ) ),
"Link-local IPv6 address detected" );
} }
private slots: private slots:
void testListenAll() void testListenAll()
{ {
// Instatiante a new instance for each test so we have a sane state. // Instantiate a new instance for each test so we have a sane state.
Servent* servent = new Servent(); Servent* servent = new Servent();
QVERIFY( servent != NULL ); QVERIFY( servent != NULL );
@@ -60,14 +72,14 @@ private slots:
QList<QHostAddress> externalAddresses = servent->addresses(); QList<QHostAddress> externalAddresses = servent->addresses();
foreach ( QHostAddress addr, externalAddresses ) foreach ( QHostAddress addr, externalAddresses )
{ {
QVERIFY( plainIPAddress( addr.toString() ) ); saneHostAddress( addr.toString() );
} }
// Verify that the local SipInfos contain valid addresses // Verify that the local SipInfos contain valid addresses
QList<SipInfo> sipInfos = servent->getLocalSipInfos( uuid(), uuid() ); QList<SipInfo> sipInfos = servent->getLocalSipInfos( uuid(), uuid() );
foreach ( SipInfo sipInfo, sipInfos ) foreach ( SipInfo sipInfo, sipInfos )
{ {
QVERIFY( plainIPAddress( sipInfo.host() ) ); saneHostAddress( sipInfo.host() );
} }
delete servent; delete servent;