1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
/*
* Copyright (C) 2008-2021 The QXmpp developers
*
* Authors:
* Manjeet Dahiya
*
* Source:
* https://github.com/qxmpp-project/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 "QXmppStreamFeatures.h"
#include "util.h"
template<class T>
static void parsePacketWithStream(T &packet, const QByteArray &xml)
{
QDomDocument doc;
const auto wrappedXml =
QByteArrayLiteral("<stream:stream xmlns:stream='http://etherx.jabber.org/streams'>") +
xml + QByteArrayLiteral("</stream:stream>");
QString err;
bool parsingSuccess = doc.setContent(wrappedXml, true, &err);
if (!err.isNull())
qDebug() << err;
QVERIFY(parsingSuccess);
packet.parse(doc.documentElement().firstChildElement());
}
class tst_QXmppStreamFeatures : public QObject
{
Q_OBJECT
private slots:
void testEmpty();
void testRequired();
void testFull();
void testSetters();
};
void tst_QXmppStreamFeatures::testEmpty()
{
const QByteArray xml("<stream:features/>");
QXmppStreamFeatures features;
parsePacketWithStream(features, xml);
QCOMPARE(features.bindMode(), QXmppStreamFeatures::Disabled);
QCOMPARE(features.sessionMode(), QXmppStreamFeatures::Disabled);
QCOMPARE(features.nonSaslAuthMode(), QXmppStreamFeatures::Disabled);
QCOMPARE(features.tlsMode(), QXmppStreamFeatures::Disabled);
QCOMPARE(features.clientStateIndicationMode(), QXmppStreamFeatures::Disabled);
QCOMPARE(features.registerMode(), QXmppStreamFeatures::Disabled);
QCOMPARE(features.preApprovedSubscriptionsSupported(), false);
QCOMPARE(features.rosterVersioningSupported(), false);
QCOMPARE(features.authMechanisms(), QStringList());
QCOMPARE(features.compressionMethods(), QStringList());
serializePacket(features, xml);
}
void tst_QXmppStreamFeatures::testRequired()
{
const QByteArray xml(
"<stream:features>"
"<starttls xmlns=\"urn:ietf:params:xml:ns:xmpp-tls\">"
"<required/>"
"</starttls>"
"</stream:features>");
QXmppStreamFeatures features;
parsePacketWithStream(features, xml);
QCOMPARE(features.tlsMode(), QXmppStreamFeatures::Required);
serializePacket(features, xml);
}
void tst_QXmppStreamFeatures::testFull()
{
const QByteArray xml("<stream:features>"
"<bind xmlns=\"urn:ietf:params:xml:ns:xmpp-bind\"/>"
"<session xmlns=\"urn:ietf:params:xml:ns:xmpp-session\"/>"
"<auth xmlns=\"http://jabber.org/features/iq-auth\"/>"
"<starttls xmlns=\"urn:ietf:params:xml:ns:xmpp-tls\"/>"
"<csi xmlns=\"urn:xmpp:csi:0\"/>"
"<register xmlns=\"http://jabber.org/features/iq-register\"/>"
"<sub xmlns=\"urn:xmpp:features:pre-approval\"/>"
"<ver xmlns=\"urn:xmpp:features:rosterver\"/>"
"<compression xmlns=\"http://jabber.org/features/compress\"><method>zlib</method></compression>"
"<mechanisms xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\"><mechanism>PLAIN</mechanism></mechanisms>"
"</stream:features>");
QXmppStreamFeatures features;
parsePacketWithStream(features, xml);
QCOMPARE(features.bindMode(), QXmppStreamFeatures::Enabled);
QCOMPARE(features.sessionMode(), QXmppStreamFeatures::Enabled);
QCOMPARE(features.nonSaslAuthMode(), QXmppStreamFeatures::Enabled);
QCOMPARE(features.tlsMode(), QXmppStreamFeatures::Enabled);
QCOMPARE(features.clientStateIndicationMode(), QXmppStreamFeatures::Enabled);
QCOMPARE(features.registerMode(), QXmppStreamFeatures::Enabled);
QCOMPARE(features.preApprovedSubscriptionsSupported(), true);
QCOMPARE(features.authMechanisms(), QStringList() << "PLAIN");
QCOMPARE(features.compressionMethods(), QStringList() << "zlib");
serializePacket(features, xml);
features = QXmppStreamFeatures();
features.setBindMode(QXmppStreamFeatures::Enabled);
features.setSessionMode(QXmppStreamFeatures::Enabled);
features.setNonSaslAuthMode(QXmppStreamFeatures::Enabled);
features.setTlsMode(QXmppStreamFeatures::Enabled);
features.setClientStateIndicationMode(QXmppStreamFeatures::Enabled);
features.setRegisterMode(QXmppStreamFeatures::Enabled);
features.setPreApprovedSubscriptionsSupported(true);
features.setRosterVersioningSupported(true);
features.setAuthMechanisms(QStringList { QStringLiteral("PLAIN") });
features.setCompressionMethods(QStringList { QStringLiteral("zlib") });
serializePacket(features, xml);
}
void tst_QXmppStreamFeatures::testSetters()
{
QXmppStreamFeatures features;
features.setBindMode(QXmppStreamFeatures::Enabled);
QCOMPARE(features.bindMode(), QXmppStreamFeatures::Enabled);
features.setSessionMode(QXmppStreamFeatures::Enabled);
QCOMPARE(features.sessionMode(), QXmppStreamFeatures::Enabled);
features.setNonSaslAuthMode(QXmppStreamFeatures::Enabled);
QCOMPARE(features.nonSaslAuthMode(), QXmppStreamFeatures::Enabled);
features.setTlsMode(QXmppStreamFeatures::Enabled);
QCOMPARE(features.tlsMode(), QXmppStreamFeatures::Enabled);
features.setClientStateIndicationMode(QXmppStreamFeatures::Enabled);
QCOMPARE(features.clientStateIndicationMode(), QXmppStreamFeatures::Enabled);
features.setClientStateIndicationMode(QXmppStreamFeatures::Enabled);
QCOMPARE(features.clientStateIndicationMode(), QXmppStreamFeatures::Enabled);
features.setRegisterMode(QXmppStreamFeatures::Enabled);
QCOMPARE(features.registerMode(), QXmppStreamFeatures::Enabled);
features.setAuthMechanisms(QStringList() << "custom-mechanism");
QCOMPARE(features.authMechanisms(), QStringList() << "custom-mechanism");
features.setCompressionMethods(QStringList() << "compression-methods");
QCOMPARE(features.compressionMethods(), QStringList() << "compression-methods");
}
QTEST_MAIN(tst_QXmppStreamFeatures)
#include "tst_qxmppstreamfeatures.moc"
|