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