~ubuntu-branches/ubuntu/saucy/kopete/saucy-proposed

« back to all changes in this revision

Viewing changes to protocols/jabber/libiris/src/xmpp/sasl/unittest/digestmd5responsetest.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-06-21 02:22:39 UTC
  • Revision ID: package-import@ubuntu.com-20130621022239-63l3zc8p0nf26pt6
Tags: upstream-4.10.80
ImportĀ upstreamĀ versionĀ 4.10.80

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2008  Remko Troncon
 
3
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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
 
17
 *
 
18
 */
 
19
 
 
20
#include <QObject>
 
21
#include <QtTest/QtTest>
 
22
#include <QtCrypto>
 
23
 
 
24
#include "qttestutil/qttestutil.h"
 
25
#include "xmpp/sasl/digestmd5response.h"
 
26
#include "xmpp/base/unittest/incrementingrandomnumbergenerator.h"
 
27
 
 
28
using namespace XMPP;
 
29
 
 
30
class DIGESTMD5ResponseTest : public QObject
 
31
{
 
32
                Q_OBJECT
 
33
 
 
34
        private slots:
 
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",
 
41
                                "mypass",
 
42
                                IncrementingRandomNumberGenerator(255));
 
43
                        QByteArray expectedValue(
 
44
                                "username=\"myuser\",realm=\"example.com\","
 
45
                                "nonce=\"O6skKPuaCZEny3hteI19qXMBXSadoWs840MchORo\","
 
46
                                "cnonce=\"AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8=\","
 
47
                                "nc=00000001,"
 
48
                                "digest-uri=\"xmpp/jabber.example.com\","
 
49
                                "qop=auth,response=8fe15bc2aa31956b62d9de831b21a5d4,"
 
50
                                "charset=utf-8,authzid=\"myuser_authz\"");
 
51
 
 
52
                        QVERIFY(response.isValid());
 
53
                        QCOMPARE(response.getValue(), expectedValue);
 
54
                }
 
55
 
 
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", "",
 
62
                                "mypass",
 
63
                                IncrementingRandomNumberGenerator(255));
 
64
                        QByteArray expectedValue(
 
65
                                "username=\"myuser\",realm=\"example.com\","
 
66
                                "nonce=\"O6skKPuaCZEny3hteI19qXMBXSadoWs840MchORo\","
 
67
                                "cnonce=\"AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8=\","
 
68
                                "nc=00000001,"
 
69
                                "digest-uri=\"xmpp/jabber.example.com\","
 
70
                                "qop=auth,response=564b1c1cc16d97b019f18b14c979964b,charset=utf-8");
 
71
                        
 
72
                        QVERIFY(response.isValid());
 
73
                        QCOMPARE(response.getValue(), expectedValue);
 
74
                }
 
75
        
 
76
        private:
 
77
                QCA::Initializer initializer;
 
78
};
 
79
 
 
80
QTTESTUTIL_REGISTER_TEST(DIGESTMD5ResponseTest);
 
81
#include "digestmd5responsetest.moc"