Commit 2bc7588f authored by Kevin Ottens's avatar Kevin Ottens
Browse files

Handle properly inconsistent parser state by closing the session

BUG: 287424
parent 802926e0
......@@ -107,8 +107,11 @@ void SessionThread::readMessage()
}
*payload << Message::Part(literal);
} else {
// Oops! Something really bad happened
throw ImapParserException( "Inconsistent state, probably due to some packet loss" );
// Oops! Something really bad happened, we won't be able to recover
// so close the socket immediately
qWarning( "Inconsistent state, probably due to some packet loss" );
doCloseSocket();
return;
}
}
......
......@@ -309,6 +309,39 @@ class SessionTest : public QObject
QCOMPARE( s.jobQueueSize(), 0);
}
void shouldCloseOnInconsistency()
{
for (int count=0; count<10; count++) {
FakeServer fakeServer;
fakeServer.setScenario( QList<QByteArray>()
<< FakeServer::preauth()
<< "C: A000001 DUMMY"
<< "S: * DUMMY %"
<< "S: DUMMY)"
);
fakeServer.startAndWait();
KIMAP::Session s( "127.0.0.1", 5989 );
QSignalSpy spyFail(&s, SIGNAL(connectionFailed()));
QSignalSpy spyLost(&s, SIGNAL(connectionLost()));
QSignalSpy spyState(&s, SIGNAL(stateChanged(KIMAP::Session::State,KIMAP::Session::State)));
MockJob *mock = new MockJob(&s);
mock->setTimeout(5000);
mock->setCommand("DUMMY");
mock->start();
QTest::qWait(250); // Should be plenty
// We expect to get an error here due to the inconsistency
QVERIFY( mock->error()!=0 );
QCOMPARE( spyFail.count(), 0 );
QCOMPARE( spyLost.count(), 1 );
QCOMPARE( spyState.count(), 2 ); // Authenticated, Disconnected
}
}
public slots:
void jobDone(KJob *job)
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment