add test for incompatible authentication mechanisms
This commit is contained in:
parent
f11caabb14
commit
60167321a9
|
|
@ -10,6 +10,7 @@
|
|||
#include <QTimer>
|
||||
#include <QTcpSocket>
|
||||
#include <QTextStream>
|
||||
#include <QStringList>
|
||||
#include <QtEndian>
|
||||
|
||||
using namespace QAMQP;
|
||||
|
|
@ -243,6 +244,7 @@ bool ClientPrivate::_q_method(const Frame::Method &frame)
|
|||
|
||||
void ClientPrivate::start(const Frame::Method &frame)
|
||||
{
|
||||
Q_Q(Client);
|
||||
qAmqpDebug(">> Start");
|
||||
QByteArray data = frame.arguments();
|
||||
QDataStream stream(&data, QIODevice::ReadOnly);
|
||||
|
|
@ -254,7 +256,7 @@ void ClientPrivate::start(const Frame::Method &frame)
|
|||
Frame::TableField table;
|
||||
Frame::deserialize(stream, table);
|
||||
|
||||
QString mechanisms = Frame::readField('S', stream).toString();
|
||||
QStringList mechanisms = Frame::readField('S', stream).toString().split(' ');
|
||||
QString locales = Frame::readField('S', stream).toString();
|
||||
|
||||
qAmqpDebug(">> version_major: %d", version_major);
|
||||
|
|
@ -262,9 +264,15 @@ void ClientPrivate::start(const Frame::Method &frame)
|
|||
|
||||
Frame::print(table);
|
||||
|
||||
qAmqpDebug(">> mechanisms: %s", qPrintable(mechanisms));
|
||||
qAmqpDebug() << ">> mechanisms: " << mechanisms;
|
||||
qAmqpDebug(">> locales: %s", qPrintable(locales));
|
||||
|
||||
if (!mechanisms.contains(authenticator->type())) {
|
||||
socket->disconnectFromHost();
|
||||
Q_EMIT q->disconnected();
|
||||
return;
|
||||
}
|
||||
|
||||
startOk();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <QProcess>
|
||||
#include "amqp_client.h"
|
||||
#include "amqp_authenticator.h"
|
||||
|
||||
using namespace QAMQP;
|
||||
class tst_QAMQPClient : public TestCase
|
||||
|
|
@ -11,6 +12,7 @@ class tst_QAMQPClient : public TestCase
|
|||
private Q_SLOTS:
|
||||
void connect();
|
||||
void connectDisconnect();
|
||||
void invalidAuthenticationMechanism();
|
||||
|
||||
private:
|
||||
void autoReconnect();
|
||||
|
|
@ -33,6 +35,23 @@ void tst_QAMQPClient::connectDisconnect()
|
|||
QVERIFY(waitForSignal(&client, SIGNAL(disconnected())));
|
||||
}
|
||||
|
||||
class InvalidAuthenticator : public Authenticator
|
||||
{
|
||||
public:
|
||||
virtual QString type() const { return "CRAZYAUTH"; }
|
||||
virtual void write(QDataStream &out) {
|
||||
Q_UNUSED(out);
|
||||
}
|
||||
};
|
||||
|
||||
void tst_QAMQPClient::invalidAuthenticationMechanism()
|
||||
{
|
||||
Client client;
|
||||
client.setAuth(new InvalidAuthenticator);
|
||||
client.connectToHost();
|
||||
QVERIFY(waitForSignal(&client, SIGNAL(disconnected())));
|
||||
}
|
||||
|
||||
void tst_QAMQPClient::autoReconnect()
|
||||
{
|
||||
// TODO: this is a fairly crude way of testing this, research
|
||||
|
|
@ -46,7 +65,6 @@ void tst_QAMQPClient::autoReconnect()
|
|||
QVERIFY(waitForSignal(&client, SIGNAL(disconnected())));
|
||||
QProcess::execute("rabbitmqctl", QStringList() << "start_app");
|
||||
QVERIFY(waitForSignal(&client, SIGNAL(connected()), 2));
|
||||
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QAMQPClient)
|
||||
|
|
|
|||
Loading…
Reference in New Issue