summaryrefslogtreecommitdiffstats
blob: 152a41e5eae0c73f13424a0d72d5645e904cf750 (plain)
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
/*
 * 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/DIGESTMD5Properties.h"

using namespace Swift;

class DIGESTMD5PropertiesTest : public CppUnit::TestFixture {
		CPPUNIT_TEST_SUITE(DIGESTMD5PropertiesTest);
		CPPUNIT_TEST(testParse);
		CPPUNIT_TEST(testSerialize);
		CPPUNIT_TEST_SUITE_END();

	public:
		void testParse() {
			DIGESTMD5Properties properties = DIGESTMD5Properties::parse(ByteArray(
					"realm=\"myrealm1\",realm=\"myrealm2\",nonce=\"mynonce\","
					"algorithm=md5-sess,charset=utf-8"));

			CPPUNIT_ASSERT(properties.getValue("realm"));
			CPPUNIT_ASSERT_EQUAL(std::string("myrealm1"), *properties.getValue("realm"));
			CPPUNIT_ASSERT(properties.getValue("nonce"));
			CPPUNIT_ASSERT_EQUAL(std::string("mynonce"), *properties.getValue("nonce"));
			CPPUNIT_ASSERT(properties.getValue("algorithm"));
			CPPUNIT_ASSERT_EQUAL(std::string("md5-sess"), *properties.getValue("algorithm"));
			CPPUNIT_ASSERT(properties.getValue("charset"));
			CPPUNIT_ASSERT_EQUAL(std::string("utf-8"), *properties.getValue("charset"));
		}

		void testSerialize() {
			DIGESTMD5Properties properties;
			properties.setValue("authzid", "myauthzid");
			properties.setValue("charset", "utf-8");
			properties.setValue("cnonce", "mycnonce");
			properties.setValue("digest-uri", "mydigesturi");
			properties.setValue("nc", "1");
			properties.setValue("nonce", "mynonce");
			properties.setValue("qop", "auth");
			properties.setValue("realm", "myrealm");
			properties.setValue("response", "myresponse");
			properties.setValue("username", "myuser");

			ByteArray result = properties.serialize();
			ByteArray expected("authzid=\"myauthzid\",charset=utf-8,cnonce=\"mycnonce\",digest-uri=\"mydigesturi\",nc=1,nonce=\"mynonce\",qop=auth,realm=\"myrealm\",response=myresponse,username=\"myuser\"");
			CPPUNIT_ASSERT_EQUAL(expected.toString(), result.toString());
		}
};

CPPUNIT_TEST_SUITE_REGISTRATION(DIGESTMD5PropertiesTest);