diff options
| author | Jeremy Lainé <jeremy.laine@m4x.org> | 2012-10-01 14:10:35 +0200 |
|---|---|---|
| committer | Jeremy Lainé <jeremy.laine@m4x.org> | 2012-10-01 14:10:35 +0200 |
| commit | 44cc908b9cd4a469c30420dc329a3448fb4f20c4 (patch) | |
| tree | eca8a814d04da0191d641333161e0c132f02e94c | |
| parent | 10a6e8681fd32d67767f53f4e17166586d567494 (diff) | |
| download | qxmpp-44cc908b9cd4a469c30420dc329a3448fb4f20c4.tar.gz | |
split QXmppNonSASLAuthIq tests
| -rw-r--r-- | tests/all/tests.cpp | 50 | ||||
| -rw-r--r-- | tests/qxmppnonsaslauthiq/qxmppnonsaslauthiq.pro | 3 | ||||
| -rw-r--r-- | tests/qxmppnonsaslauthiq/tst_qxmppnonsaslauthiq.cpp | 92 | ||||
| -rw-r--r-- | tests/tests.pro | 1 |
4 files changed, 96 insertions, 50 deletions
diff --git a/tests/all/tests.cpp b/tests/all/tests.cpp index 7ac5c5e7..fdfbbd16 100644 --- a/tests/all/tests.cpp +++ b/tests/all/tests.cpp @@ -22,10 +22,8 @@ * */ -#include "QXmppNonSASLAuth.h" #include "QXmppSessionIq.h" #include "QXmppStreamFeatures.h" -#include "QXmppUtils.h" #include "util.h" class TestPackets : public QObject @@ -33,58 +31,10 @@ class TestPackets : public QObject Q_OBJECT private slots: - void testNonSaslAuth(); void testSession(); void testStreamFeatures(); }; -void TestPackets::testNonSaslAuth() -{ - // Client Requests Authentication Fields from Server - const QByteArray xml1( - "<iq id=\"auth1\" to=\"shakespeare.lit\" type=\"get\">" - "<query xmlns=\"jabber:iq:auth\"/>" - "</iq>"); - - QXmppNonSASLAuthIq iq1; - parsePacket(iq1, xml1); - serializePacket(iq1, xml1); - - // Client Provides Required Information (Plaintext) - const QByteArray xml3( - "<iq id=\"auth2\" type=\"set\">" - "<query xmlns=\"jabber:iq:auth\">" - "<username>bill</username>" - "<password>Calli0pe</password>" - "<resource>globe</resource>" - "</query>" - "</iq>"); - QXmppNonSASLAuthIq iq3; - parsePacket(iq3, xml3); - QCOMPARE(iq3.username(), QLatin1String("bill")); - QCOMPARE(iq3.digest(), QByteArray()); - QCOMPARE(iq3.password(), QLatin1String("Calli0pe")); - QCOMPARE(iq3.resource(), QLatin1String("globe")); - serializePacket(iq3, xml3); - - // Client Provides Required Information (Plaintext) - const QByteArray xml4( - "<iq id=\"auth2\" type=\"set\">" - "<query xmlns=\"jabber:iq:auth\">" - "<username>bill</username>" - "<digest>48fc78be9ec8f86d8ce1c39c320c97c21d62334d</digest>" - "<resource>globe</resource>" - "</query>" - "</iq>"); - QXmppNonSASLAuthIq iq4; - parsePacket(iq4, xml4); - QCOMPARE(iq4.username(), QLatin1String("bill")); - QCOMPARE(iq4.digest(), QByteArray("\x48\xfc\x78\xbe\x9e\xc8\xf8\x6d\x8c\xe1\xc3\x9c\x32\x0c\x97\xc2\x1d\x62\x33\x4d")); - QCOMPARE(iq4.password(), QString()); - QCOMPARE(iq4.resource(), QLatin1String("globe")); - serializePacket(iq4, xml4); -} - void TestPackets::testSession() { const QByteArray xml( diff --git a/tests/qxmppnonsaslauthiq/qxmppnonsaslauthiq.pro b/tests/qxmppnonsaslauthiq/qxmppnonsaslauthiq.pro new file mode 100644 index 00000000..29cf99e9 --- /dev/null +++ b/tests/qxmppnonsaslauthiq/qxmppnonsaslauthiq.pro @@ -0,0 +1,3 @@ +include(../tests.pri) +TARGET = tst_qxmppnonsaslauthiq +SOURCES += tst_qxmppnonsaslauthiq.cpp diff --git a/tests/qxmppnonsaslauthiq/tst_qxmppnonsaslauthiq.cpp b/tests/qxmppnonsaslauthiq/tst_qxmppnonsaslauthiq.cpp new file mode 100644 index 00000000..2574dcf1 --- /dev/null +++ b/tests/qxmppnonsaslauthiq/tst_qxmppnonsaslauthiq.cpp @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2008-2012 The QXmpp developers + * + * Authors: + * Jeremy Lainé + * Manjeet Dahiya + * + * Source: + * http://code.google.com/p/qxmpp + * + * This file is a part of QXmpp library. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + */ + +#include "QXmppNonSASLAuth.h" +#include "util.h" + +class tst_QXmppNonSASLAuthIq : public QObject +{ + Q_OBJECT + +private slots: + void testGet(); + void testSetPlain(); + void testSetDigest(); +}; + +void tst_QXmppNonSASLAuthIq::testGet() +{ + // Client requests authentication fields from server + const QByteArray xml( + "<iq id=\"auth1\" to=\"shakespeare.lit\" type=\"get\">" + "<query xmlns=\"jabber:iq:auth\"/>" + "</iq>"); + + QXmppNonSASLAuthIq iq; + parsePacket(iq, xml); + serializePacket(iq, xml); +} + +void tst_QXmppNonSASLAuthIq::testSetPlain() +{ + // Client provides required information (plain) + const QByteArray xml( + "<iq id=\"auth2\" type=\"set\">" + "<query xmlns=\"jabber:iq:auth\">" + "<username>bill</username>" + "<password>Calli0pe</password>" + "<resource>globe</resource>" + "</query>" + "</iq>"); + QXmppNonSASLAuthIq iq; + parsePacket(iq, xml); + QCOMPARE(iq.username(), QLatin1String("bill")); + QCOMPARE(iq.digest(), QByteArray()); + QCOMPARE(iq.password(), QLatin1String("Calli0pe")); + QCOMPARE(iq.resource(), QLatin1String("globe")); + serializePacket(iq, xml); +} + +void tst_QXmppNonSASLAuthIq::testSetDigest() +{ + // Client provides required information (digest) + const QByteArray xml( + "<iq id=\"auth2\" type=\"set\">" + "<query xmlns=\"jabber:iq:auth\">" + "<username>bill</username>" + "<digest>48fc78be9ec8f86d8ce1c39c320c97c21d62334d</digest>" + "<resource>globe</resource>" + "</query>" + "</iq>"); + QXmppNonSASLAuthIq iq; + parsePacket(iq, xml); + QCOMPARE(iq.username(), QLatin1String("bill")); + QCOMPARE(iq.digest(), QByteArray("\x48\xfc\x78\xbe\x9e\xc8\xf8\x6d\x8c\xe1\xc3\x9c\x32\x0c\x97\xc2\x1d\x62\x33\x4d")); + QCOMPARE(iq.password(), QString()); + QCOMPARE(iq.resource(), QLatin1String("globe")); + serializePacket(iq, xml); +} + +QTEST_MAIN(tst_QXmppNonSASLAuthIq) +#include "tst_qxmppnonsaslauthiq.moc" diff --git a/tests/tests.pro b/tests/tests.pro index 56b23419..ee3756ae 100644 --- a/tests/tests.pro +++ b/tests/tests.pro @@ -9,6 +9,7 @@ SUBDIRS = \ qxmppiq \ qxmppjingleiq \ qxmppmessage \ + qxmppnonsaslauthiq \ qxmpppresence \ qxmpppubsubiq \ qxmppregisteriq \ |
