summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMili Verma <mili.verma@isode.com>2015-06-25 12:13:14 (GMT)
committerKevin Smith <kevin.smith@isode.com>2015-06-29 17:02:01 (GMT)
commit394642c69bc232429621e209b787d3496967b37b (patch)
tree12fda8350b5694b4e6dc93899debc5a8c46e0adf /Swiften/SASL/UnitTest
parentac45f360be049242a89ae80258e4ea8350f909ba (diff)
downloadswift-394642c69bc232429621e209b787d3496967b37b.zip
swift-394642c69bc232429621e209b787d3496967b37b.tar.bz2
Add WindowsServicePrincipalName class
Test-information: Tested on Windows using WIP GSSAPI code. Unit tests pass. Change-Id: If872863d6a8b5a164f8ebec4f88e9939b4e73c62
Diffstat (limited to 'Swiften/SASL/UnitTest')
-rw-r--r--Swiften/SASL/UnitTest/WindowsServicePrincipalNameTest.cpp161
1 files changed, 161 insertions, 0 deletions
diff --git a/Swiften/SASL/UnitTest/WindowsServicePrincipalNameTest.cpp b/Swiften/SASL/UnitTest/WindowsServicePrincipalNameTest.cpp
new file mode 100644
index 0000000..1b0e6f6
--- /dev/null
+++ b/Swiften/SASL/UnitTest/WindowsServicePrincipalNameTest.cpp
@@ -0,0 +1,161 @@
+/*
+ * Copyright (c) 2015 Isode Limited.
+ * All rights reserved.
+ * See the COPYING file for more information.
+ */
+
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <Swiften/SASL/WindowsServicePrincipalName.h>
+
+using namespace Swift;
+
+class WindowsServicePrincipalNameTest : public CppUnit::TestFixture {
+ CPPUNIT_TEST_SUITE(WindowsServicePrincipalNameTest);
+ CPPUNIT_TEST(testServiceClass);
+ CPPUNIT_TEST(testServiceName);
+ CPPUNIT_TEST(testInstanceName);
+ CPPUNIT_TEST(testInstancePort);
+ CPPUNIT_TEST(testReferrer);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ void testServiceClass() {
+ WindowsServicePrincipalName spn("mlink.adlon.isode.net");
+
+ CPPUNIT_ASSERT_EQUAL(spn.toString(), std::string("xmpp/mlink.adlon.isode.net"));
+
+ spn.setServiceClass("ldap");
+ CPPUNIT_ASSERT_EQUAL(spn.toString(), std::string("ldap/mlink.adlon.isode.net"));
+
+ spn.setServiceClass("中文");
+ CPPUNIT_ASSERT_EQUAL(spn.toString(), std::string("中文/mlink.adlon.isode.net"));
+
+ try {
+ spn.setServiceClass("");
+ spn.toString();
+ CPPUNIT_ASSERT(false);
+ } catch (std::runtime_error) {
+ /* expected */
+ }
+
+ try {
+ spn.setServiceClass("xm/pp"); /* Foward slash not allowed */
+ spn.toString();
+ CPPUNIT_ASSERT(false);
+ } catch (std::runtime_error) {
+ /* expected */
+ }
+ }
+
+ void testServiceName() {
+ try {
+ WindowsServicePrincipalName spn("");
+ spn.toString();
+ CPPUNIT_ASSERT(false);
+ } catch (std::runtime_error) {
+ /* expected */
+ }
+
+ try {
+ WindowsServicePrincipalName spn2("mlink/adlon.isode.net"); /* Foward slash not allowed */
+ spn2.toString();
+ CPPUNIT_ASSERT(false);
+ } catch (std::runtime_error) {
+ /* expected */
+ }
+
+ WindowsServicePrincipalName spn3("mlinkÄ.adlon.isode.net");
+ CPPUNIT_ASSERT_EQUAL(spn3.toString(), std::string("xmpp/mlinkÄ.adlon.isode.net"));
+ }
+
+ void testInstanceName() {
+ WindowsServicePrincipalName spn("adlon.isode.net");
+
+ spn.setInstanceName("mlink.adlon.isode.net");
+ CPPUNIT_ASSERT_EQUAL(spn.toString(), std::string("xmpp/mlink.adlon.isode.net/adlon.isode.net"));
+
+ spn.setInstanceName("127.0.0.1");
+ CPPUNIT_ASSERT_EQUAL(spn.toString(), std::string("xmpp/127.0.0.1/adlon.isode.net"));
+
+ spn.setInstanceName("");
+ CPPUNIT_ASSERT_EQUAL(spn.toString(), std::string("xmpp/adlon.isode.net"));
+
+ spn.setInstanceName("cañón.adlon.isode.net");
+ CPPUNIT_ASSERT_EQUAL(spn.toString(), std::string("xmpp/cañón.adlon.isode.net/adlon.isode.net"));
+
+ try {
+ spn.setInstanceName("mlink/adlon.isode.net"); /* Foward slash not allowed */
+ spn.toString();
+ CPPUNIT_ASSERT(false);
+ } catch (std::runtime_error) {
+ /* expected */
+ }
+ }
+
+ void testInstancePort() {
+ WindowsServicePrincipalName spn("adlon.isode.net");
+
+ spn.setInstanceName("mlink.adlon.isode.net");
+ spn.setInstancePort(6222);
+ CPPUNIT_ASSERT_EQUAL(spn.toString(), std::string("xmpp/mlink.adlon.isode.net:6222/adlon.isode.net"));
+
+ spn.setInstancePort(0);
+ CPPUNIT_ASSERT_EQUAL(spn.toString(), std::string("xmpp/mlink.adlon.isode.net/adlon.isode.net"));
+
+ WindowsServicePrincipalName spn2("mlink.adlon.isode.net");
+
+ spn2.setInstancePort(6222);
+ CPPUNIT_ASSERT_EQUAL(spn2.toString(), std::string("xmpp/mlink.adlon.isode.net:6222"));
+
+ spn2.setInstancePort(0);
+ CPPUNIT_ASSERT_EQUAL(spn2.toString(), std::string("xmpp/mlink.adlon.isode.net"));
+ }
+
+ void testReferrer() {
+ WindowsServicePrincipalName spn("127.0.0.1");
+
+ spn.setReferrer("referrer.net");
+ CPPUNIT_ASSERT_EQUAL(spn.toString(), std::string("xmpp/127.0.0.1/referrer.net"));
+
+ spn.setInstancePort(6222);
+ CPPUNIT_ASSERT_EQUAL(spn.toString(), std::string("xmpp/127.0.0.1:6222/referrer.net"));
+
+ spn.setReferrer("हिन्दी.net");
+ CPPUNIT_ASSERT_EQUAL(spn.toString(), std::string("xmpp/127.0.0.1:6222/हिन्दी.net"));
+
+ try {
+ spn.setReferrer("referrer/net"); /* Foward slash not allowed */
+ spn.toString();
+ CPPUNIT_ASSERT(false);
+ } catch (std::runtime_error) {
+ /* expected */
+ }
+
+ try {
+ spn.setReferrer(""); /* seems like you must have referrer with an IP */
+ spn.toString();
+ CPPUNIT_ASSERT(false);
+ } catch (std::runtime_error) {
+ /* expected */
+ }
+
+ WindowsServicePrincipalName spn2("mlink.adlon.isode.net");
+
+ spn2.setReferrer("referrer.net"); /* Referrer ignored if service name is not IP */
+ CPPUNIT_ASSERT_EQUAL(spn2.toString(), std::string("xmpp/mlink.adlon.isode.net"));
+
+ spn2.setReferrer("referrer/net"); /* Referrer ignored if service name is not IP */
+ CPPUNIT_ASSERT_EQUAL(spn2.toString(), std::string("xmpp/mlink.adlon.isode.net"));
+
+ WindowsServicePrincipalName spn3("adlon.isode.net");
+
+ spn3.setInstanceName("mlink.adlon.isode.net");
+ spn3.setInstancePort(6222);
+ spn3.setReferrer("referrer.net"); /* Referrer ignored if service name is not IP */
+ CPPUNIT_ASSERT_EQUAL(spn3.toString(), std::string("xmpp/mlink.adlon.isode.net:6222/adlon.isode.net"));
+
+ }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(WindowsServicePrincipalNameTest);