2
* Copyright (C) 2008 Remko Troncon
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Lesser General Public
6
* License as published by the Free Software Foundation; either
7
* version 2.1 of the License, or (at your option) any later version.
9
* This library is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* Lesser General Public License for more details.
14
* You should have received a copy of the GNU Lesser General Public
15
* License along with this library; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
#include <QtTest/QtTest>
24
#include "qttestutil/qttestutil.h"
25
#include "xmpp/sasl/digestmd5response.h"
26
#include "xmpp/base/unittest/incrementingrandomnumbergenerator.h"
30
class DIGESTMD5ResponseTest : public QObject
35
void testConstructor_WithAuthzid() {
36
DIGESTMD5Response response(
37
"realm=\"example.com\","
38
"nonce=\"O6skKPuaCZEny3hteI19qXMBXSadoWs840MchORo\","
39
"qop=\"auth\",charset=\"utf-8\",algorithm=\"md5-sess\"",
40
"xmpp", "jabber.example.com", "example.com", "myuser", "myuser_authz",
42
IncrementingRandomNumberGenerator(255));
43
QByteArray expectedValue(
44
"username=\"myuser\",realm=\"example.com\","
45
"nonce=\"O6skKPuaCZEny3hteI19qXMBXSadoWs840MchORo\","
46
"cnonce=\"AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8=\","
48
"digest-uri=\"xmpp/jabber.example.com\","
49
"qop=auth,response=8fe15bc2aa31956b62d9de831b21a5d4,"
50
"charset=utf-8,authzid=\"myuser_authz\"");
52
QVERIFY(response.isValid());
53
QCOMPARE(response.getValue(), expectedValue);
56
void testConstructor_WithoutAuthzid() {
57
DIGESTMD5Response response(
58
"realm=\"example.com\","
59
"nonce=\"O6skKPuaCZEny3hteI19qXMBXSadoWs840MchORo\","
60
"qop=\"auth\",charset=\"utf-8\",algorithm=\"md5-sess\"",
61
"xmpp", "jabber.example.com", "example.com", "myuser", "",
63
IncrementingRandomNumberGenerator(255));
64
QByteArray expectedValue(
65
"username=\"myuser\",realm=\"example.com\","
66
"nonce=\"O6skKPuaCZEny3hteI19qXMBXSadoWs840MchORo\","
67
"cnonce=\"AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8=\","
69
"digest-uri=\"xmpp/jabber.example.com\","
70
"qop=auth,response=564b1c1cc16d97b019f18b14c979964b,charset=utf-8");
72
QVERIFY(response.isValid());
73
QCOMPARE(response.getValue(), expectedValue);
77
QCA::Initializer initializer;
80
QTTESTUTIL_REGISTER_TEST(DIGESTMD5ResponseTest);
81
#include "digestmd5responsetest.moc"