summaryrefslogtreecommitdiffstats
blob: 6659ee449391bd59b8eb996613a4bca7dd353ff3 (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
56
57
58
59
60
61
62
63
64
65
66
67
/*
 * 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/PLAINMessage.h"

using namespace Swift;

class PLAINMessageTest : public CppUnit::TestFixture
{
		CPPUNIT_TEST_SUITE(PLAINMessageTest);
		CPPUNIT_TEST(testGetValue_WithoutAuthzID);
		CPPUNIT_TEST(testGetValue_WithAuthzID);
		CPPUNIT_TEST(testConstructor_WithoutAuthzID);
		CPPUNIT_TEST(testConstructor_WithAuthzID);
		CPPUNIT_TEST(testConstructor_NoAuthcid);
		CPPUNIT_TEST(testConstructor_NoPassword);
		CPPUNIT_TEST_SUITE_END();

	public:
		PLAINMessageTest() {}

		void testGetValue_WithoutAuthzID() {
			PLAINMessage message("user", "pass");
			CPPUNIT_ASSERT_EQUAL(message.getValue(), ByteArray("\0user\0pass", 10));
		}

		void testGetValue_WithAuthzID() {
			PLAINMessage message("user", "pass", "authz");
			CPPUNIT_ASSERT_EQUAL(message.getValue(), ByteArray("authz\0user\0pass", 15));
		}

		void testConstructor_WithoutAuthzID() {
			PLAINMessage message(ByteArray("\0user\0pass", 10));

			CPPUNIT_ASSERT_EQUAL(String(""), message.getAuthorizationID());
			CPPUNIT_ASSERT_EQUAL(String("user"), message.getAuthenticationID());
			CPPUNIT_ASSERT_EQUAL(String("pass"), message.getPassword());
		}

		void testConstructor_WithAuthzID() {
			PLAINMessage message(ByteArray("authz\0user\0pass", 15));

			CPPUNIT_ASSERT_EQUAL(String("authz"), message.getAuthorizationID());
			CPPUNIT_ASSERT_EQUAL(String("user"), message.getAuthenticationID());
			CPPUNIT_ASSERT_EQUAL(String("pass"), message.getPassword());
		}

		void testConstructor_NoAuthcid() {
			PLAINMessage message(ByteArray("authzid", 7));

			CPPUNIT_ASSERT_EQUAL(String(""), message.getAuthenticationID());
		}

		void testConstructor_NoPassword() {
			PLAINMessage message(ByteArray("authzid\0authcid", 15));

			CPPUNIT_ASSERT_EQUAL(String(""), message.getAuthenticationID());
		}
};

CPPUNIT_TEST_SUITE_REGISTRATION(PLAINMessageTest);