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
|
/*
* Copyright (c) 2010 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include "Swiften/SASL/DIGESTMD5ClientAuthenticator.h"
#include "Swiften/Base/ByteArray.h"
using namespace Swift;
class DIGESTMD5ClientAuthenticatorTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(DIGESTMD5ClientAuthenticatorTest);
CPPUNIT_TEST(testGetInitialResponse);
CPPUNIT_TEST(testGetResponse);
CPPUNIT_TEST(testGetResponse_WithAuthorizationID);
/*CPPUNIT_TEST(testSetChallenge);
CPPUNIT_TEST(testSetChallenge_InvalidBlabBla);*/
CPPUNIT_TEST_SUITE_END();
public:
void testGetInitialResponse() {
DIGESTMD5ClientAuthenticator testling("xmpp.example.com", "abcdefgh");
CPPUNIT_ASSERT(!testling.getResponse());
}
void testGetResponse() {
DIGESTMD5ClientAuthenticator testling("xmpp.example.com", "abcdefgh");
testling.setCredentials("user", "pass", "");
testling.setChallenge(ByteArray(
"realm=\"example.com\","
"nonce=\"O6skKPuaCZEny3hteI19qXMBXSadoWs840MchORo\","
"qop=auth,charset=utf-8,algorithm=md5-sess"));
ByteArray response = *testling.getResponse();
CPPUNIT_ASSERT_EQUAL(String("charset=utf-8,cnonce=\"abcdefgh\",digest-uri=\"xmpp/xmpp.example.com\",nc=00000001,nonce=\"O6skKPuaCZEny3hteI19qXMBXSadoWs840MchORo\",qop=auth,realm=\"example.com\",response=088891c800ecff1b842159ad6459104a,username=\"user\""), response.toString());
}
void testGetResponse_WithAuthorizationID() {
DIGESTMD5ClientAuthenticator testling("xmpp.example.com", "abcdefgh");
testling.setCredentials("user", "pass", "myauthzid");
testling.setChallenge(ByteArray(
"realm=\"example.com\","
"nonce=\"O6skKPuaCZEny3hteI19qXMBXSadoWs840MchORo\","
"qop=auth,charset=utf-8,algorithm=md5-sess"));
ByteArray response = *testling.getResponse();
CPPUNIT_ASSERT_EQUAL(String("authzid=\"myauthzid\",charset=utf-8,cnonce=\"abcdefgh\",digest-uri=\"xmpp/xmpp.example.com\",nc=00000001,nonce=\"O6skKPuaCZEny3hteI19qXMBXSadoWs840MchORo\",qop=auth,realm=\"example.com\",response=4293834432b6e7889a2dee7e8fe7dd06,username=\"user\""), response.toString());
}
};
CPPUNIT_TEST_SUITE_REGISTRATION(DIGESTMD5ClientAuthenticatorTest);
|