summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdwin Mons <edwin.mons@isode.com>2018-11-13 10:54:58 (GMT)
committerEdwin Mons <edwin.mons@isode.com>2018-11-14 13:40:05 (GMT)
commit5d7fc97148125584a44a39a4beee1e71d9518385 (patch)
tree9f630e8a9f69bdbd701c1b3c082bacf2b769938d /Swiften/LinkLocal/UnitTest
parentc0615a472f8d23ce449fd59bbb1cdf7071082a43 (diff)
downloadswift-5d7fc97148125584a44a39a4beee1e71d9518385.zip
swift-5d7fc97148125584a44a39a4beee1e71d9518385.tar.bz2
Address LinkLocal issues
Generation of TXT records might fail if any of the fields is too long, so the result is now an optional (pending Expected). Callsites have been updated to deal with this. Three potentially uncaught exceptions in the Bonjour implementation have been addressed. Test-Information: Unit tests pass on macOS 10.14 and Debian 9 Change-Id: Iec02c4606a18eee855362fd3c3d15614a9e72547
Diffstat (limited to 'Swiften/LinkLocal/UnitTest')
-rw-r--r--Swiften/LinkLocal/UnitTest/LinkLocalConnectorTest.cpp4
-rw-r--r--Swiften/LinkLocal/UnitTest/LinkLocalServiceBrowserTest.cpp26
-rw-r--r--Swiften/LinkLocal/UnitTest/LinkLocalServiceInfoTest.cpp17
-rw-r--r--Swiften/LinkLocal/UnitTest/LinkLocalServiceTest.cpp6
4 files changed, 39 insertions, 14 deletions
diff --git a/Swiften/LinkLocal/UnitTest/LinkLocalConnectorTest.cpp b/Swiften/LinkLocal/UnitTest/LinkLocalConnectorTest.cpp
index ab1ee0c..59cf996 100644
--- a/Swiften/LinkLocal/UnitTest/LinkLocalConnectorTest.cpp
+++ b/Swiften/LinkLocal/UnitTest/LinkLocalConnectorTest.cpp
@@ -115,11 +115,13 @@ class LinkLocalConnectorTest : public CppUnit::TestFixture {
115 115
116 private: 116 private:
117 std::shared_ptr<LinkLocalConnector> createConnector(const std::string& hostname, unsigned short port) { 117 std::shared_ptr<LinkLocalConnector> createConnector(const std::string& hostname, unsigned short port) {
118 auto txtRecord = LinkLocalServiceInfo().toTXTRecord();
119 CPPUNIT_ASSERT(txtRecord);
118 LinkLocalService service( 120 LinkLocalService service(
119 DNSSDServiceID("myname", "local."), 121 DNSSDServiceID("myname", "local."),
120 DNSSDResolveServiceQuery::Result( 122 DNSSDResolveServiceQuery::Result(
121 "myname._presence._tcp.local", hostname, port, 123 "myname._presence._tcp.local", hostname, port,
122 LinkLocalServiceInfo().toTXTRecord())); 124 *txtRecord));
123 std::shared_ptr<LinkLocalConnector> result( 125 std::shared_ptr<LinkLocalConnector> result(
124 new LinkLocalConnector(service, querier, connection)); 126 new LinkLocalConnector(service, querier, connection));
125 result->onConnectFinished.connect( 127 result->onConnectFinished.connect(
diff --git a/Swiften/LinkLocal/UnitTest/LinkLocalServiceBrowserTest.cpp b/Swiften/LinkLocal/UnitTest/LinkLocalServiceBrowserTest.cpp
index a80d748..3491634 100644
--- a/Swiften/LinkLocal/UnitTest/LinkLocalServiceBrowserTest.cpp
+++ b/Swiften/LinkLocal/UnitTest/LinkLocalServiceBrowserTest.cpp
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2010-2016 Isode Limited. 2 * Copyright (c) 2010-2018 Isode Limited.
3 * All rights reserved. 3 * All rights reserved.
4 * See the COPYING file for more information. 4 * See the COPYING file for more information.
5 */ 5 */
@@ -47,10 +47,12 @@ class LinkLocalServiceBrowserTest : public CppUnit::TestFixture {
47 eventLoop = new DummyEventLoop(); 47 eventLoop = new DummyEventLoop();
48 querier = std::make_shared<FakeDNSSDQuerier>("wonderland.lit", eventLoop); 48 querier = std::make_shared<FakeDNSSDQuerier>("wonderland.lit", eventLoop);
49 aliceServiceID = new DNSSDServiceID("alice", "wonderland.lit"); 49 aliceServiceID = new DNSSDServiceID("alice", "wonderland.lit");
50 aliceServiceInfo = new DNSSDResolveServiceQuery::Result("_presence._tcp.wonderland.lit", "xmpp.wonderland.lit", 1234, LinkLocalServiceInfo().toTXTRecord()); 50 auto txtRecord = LinkLocalServiceInfo().toTXTRecord();
51 CPPUNIT_ASSERT(txtRecord);
52 aliceServiceInfo = new DNSSDResolveServiceQuery::Result("_presence._tcp.wonderland.lit", "xmpp.wonderland.lit", 1234, *txtRecord);
51 testServiceID = new DNSSDServiceID("foo", "bar.local"); 53 testServiceID = new DNSSDServiceID("foo", "bar.local");
52 testServiceInfo = new DNSSDResolveServiceQuery::Result("_presence._tcp.bar.local", "xmpp.bar.local", 1234, LinkLocalServiceInfo().toTXTRecord()); 54 testServiceInfo = new DNSSDResolveServiceQuery::Result("_presence._tcp.bar.local", "xmpp.bar.local", 1234, *txtRecord);
53 testServiceInfo2 = new DNSSDResolveServiceQuery::Result("_presence.tcp.bar.local", "xmpp.foo.local", 2345, LinkLocalServiceInfo().toTXTRecord()); 55 testServiceInfo2 = new DNSSDResolveServiceQuery::Result("_presence.tcp.bar.local", "xmpp.foo.local", 2345, *txtRecord);
54 errorStopReceived = false; 56 errorStopReceived = false;
55 normalStopReceived = false; 57 normalStopReceived = false;
56 } 58 }
@@ -292,7 +294,9 @@ class LinkLocalServiceBrowserTest : public CppUnit::TestFixture {
292 testling->registerService("foo@bar", 1234, info); 294 testling->registerService("foo@bar", 1234, info);
293 eventLoop->processEvents(); 295 eventLoop->processEvents();
294 296
295 CPPUNIT_ASSERT(querier->isServiceRegistered("foo@bar", 1234, info.toTXTRecord())); 297 auto txtRecord = info.toTXTRecord();
298 CPPUNIT_ASSERT(txtRecord);
299 CPPUNIT_ASSERT(querier->isServiceRegistered("foo@bar", 1234, *txtRecord));
296 CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(registeredServices.size())); 300 CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(registeredServices.size()));
297 CPPUNIT_ASSERT(registeredServices[0] == DNSSDServiceID("foo@bar", "wonderland.lit")); 301 CPPUNIT_ASSERT(registeredServices[0] == DNSSDServiceID("foo@bar", "wonderland.lit"));
298 testling->stop(); 302 testling->stop();
@@ -311,7 +315,9 @@ class LinkLocalServiceBrowserTest : public CppUnit::TestFixture {
311 CPPUNIT_ASSERT(!testling->isRunning()); 315 CPPUNIT_ASSERT(!testling->isRunning());
312 CPPUNIT_ASSERT(testling->hasError()); 316 CPPUNIT_ASSERT(testling->hasError());
313 CPPUNIT_ASSERT(errorStopReceived); 317 CPPUNIT_ASSERT(errorStopReceived);
314 CPPUNIT_ASSERT(!querier->isServiceRegistered("foo@bar", 1234, info.toTXTRecord())); 318 auto txtRecord = info.toTXTRecord();
319 CPPUNIT_ASSERT(txtRecord);
320 CPPUNIT_ASSERT(!querier->isServiceRegistered("foo@bar", 1234, *txtRecord));
315 } 321 }
316 322
317 void testRegisterService_Reregister() { 323 void testRegisterService_Reregister() {
@@ -329,7 +335,9 @@ class LinkLocalServiceBrowserTest : public CppUnit::TestFixture {
329 testling->registerService("bar@baz", 3456, info); 335 testling->registerService("bar@baz", 3456, info);
330 eventLoop->processEvents(); 336 eventLoop->processEvents();
331 337
332 CPPUNIT_ASSERT(querier->isServiceRegistered("bar@baz", 3456, info.toTXTRecord())); 338 auto txtRecord = info.toTXTRecord();
339 CPPUNIT_ASSERT(txtRecord);
340 CPPUNIT_ASSERT(querier->isServiceRegistered("bar@baz", 3456, *txtRecord));
333 341
334 testling->stop(); 342 testling->stop();
335 } 343 }
@@ -346,7 +354,9 @@ class LinkLocalServiceBrowserTest : public CppUnit::TestFixture {
346 info.setFirstName("Bar"); 354 info.setFirstName("Bar");
347 testling->updateService(info); 355 testling->updateService(info);
348 356
349 CPPUNIT_ASSERT(querier->isServiceRegistered("foo@bar", 1234, info.toTXTRecord())); 357 auto txtRecord = info.toTXTRecord();
358 CPPUNIT_ASSERT(txtRecord);
359 CPPUNIT_ASSERT(querier->isServiceRegistered("foo@bar", 1234, *txtRecord));
350 360
351 testling->stop(); 361 testling->stop();
352 } 362 }
diff --git a/Swiften/LinkLocal/UnitTest/LinkLocalServiceInfoTest.cpp b/Swiften/LinkLocal/UnitTest/LinkLocalServiceInfoTest.cpp
index 0a94a98..35cb1b4 100644
--- a/Swiften/LinkLocal/UnitTest/LinkLocalServiceInfoTest.cpp
+++ b/Swiften/LinkLocal/UnitTest/LinkLocalServiceInfoTest.cpp
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2010-2016 Isode Limited. 2 * Copyright (c) 2010-2018 Isode Limited.
3 * All rights reserved. 3 * All rights reserved.
4 * See the COPYING file for more information. 4 * See the COPYING file for more information.
5 */ 5 */
@@ -29,7 +29,9 @@ class LinkLocalServiceInfoTest : public CppUnit::TestFixture {
29 info.setLastName("Tron\xc3\xe7on"); 29 info.setLastName("Tron\xc3\xe7on");
30 info.setStatus(LinkLocalServiceInfo::Away); 30 info.setStatus(LinkLocalServiceInfo::Away);
31 31
32 CPPUNIT_ASSERT_EQUAL(createByteArray("\x09txtvers=1\x09" + std::string("1st=Remko\x0dlast=Tron\xc3\xe7on\x0bstatus=away")), info.toTXTRecord()); 32 auto txtRecord = info.toTXTRecord();
33 CPPUNIT_ASSERT(txtRecord);
34 CPPUNIT_ASSERT_EQUAL(createByteArray("\x09txtvers=1\x09" + std::string("1st=Remko\x0dlast=Tron\xc3\xe7on\x0bstatus=away")), *txtRecord);
33 } 35 }
34 36
35 void testCreateFromTXTRecord() { 37 void testCreateFromTXTRecord() {
@@ -57,7 +59,9 @@ class LinkLocalServiceInfoTest : public CppUnit::TestFixture {
57 info.setStatus(LinkLocalServiceInfo::DND); 59 info.setStatus(LinkLocalServiceInfo::DND);
58 info.setPort(1234); 60 info.setPort(1234);
59 61
60 LinkLocalServiceInfo info2 = LinkLocalServiceInfo::createFromTXTRecord(info.toTXTRecord()); 62 auto txtRecord = info.toTXTRecord();
63 CPPUNIT_ASSERT(txtRecord);
64 LinkLocalServiceInfo info2 = LinkLocalServiceInfo::createFromTXTRecord(*txtRecord);
61 CPPUNIT_ASSERT_EQUAL(info.getFirstName(), info2.getFirstName()); 65 CPPUNIT_ASSERT_EQUAL(info.getFirstName(), info2.getFirstName());
62 CPPUNIT_ASSERT_EQUAL(info.getLastName(), info2.getLastName()); 66 CPPUNIT_ASSERT_EQUAL(info.getLastName(), info2.getLastName());
63 CPPUNIT_ASSERT_EQUAL(info.getEMail(), info2.getEMail()); 67 CPPUNIT_ASSERT_EQUAL(info.getEMail(), info2.getEMail());
@@ -67,6 +71,13 @@ class LinkLocalServiceInfoTest : public CppUnit::TestFixture {
67 CPPUNIT_ASSERT(info.getStatus() == info2.getStatus()); 71 CPPUNIT_ASSERT(info.getStatus() == info2.getStatus());
68 CPPUNIT_ASSERT(info.getPort() == info2.getPort()); 72 CPPUNIT_ASSERT(info.getPort() == info2.getPort());
69 } 73 }
74
75 void testToTXTRecordWithInvalidParameter() {
76 LinkLocalServiceInfo info;
77 info.setFirstName(std::string(256, 'x'));
78 auto txtRecord = info.toTXTRecord();
79 CPPUNIT_ASSERT(!txtRecord);
80 }
70}; 81};
71 82
72CPPUNIT_TEST_SUITE_REGISTRATION(LinkLocalServiceInfoTest); 83CPPUNIT_TEST_SUITE_REGISTRATION(LinkLocalServiceInfoTest);
diff --git a/Swiften/LinkLocal/UnitTest/LinkLocalServiceTest.cpp b/Swiften/LinkLocal/UnitTest/LinkLocalServiceTest.cpp
index 206d824..cb5f40a 100644
--- a/Swiften/LinkLocal/UnitTest/LinkLocalServiceTest.cpp
+++ b/Swiften/LinkLocal/UnitTest/LinkLocalServiceTest.cpp
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2010 Isode Limited. 2 * Copyright (c) 2010-2018 Isode Limited.
3 * All rights reserved. 3 * All rights reserved.
4 * See the COPYING file for more information. 4 * See the COPYING file for more information.
5 */ 5 */
@@ -58,10 +58,12 @@ class LinkLocalServiceTest : public CppUnit::TestFixture {
58 info.setFirstName(firstName); 58 info.setFirstName(firstName);
59 info.setLastName(lastName); 59 info.setLastName(lastName);
60 info.setNick(nickName); 60 info.setNick(nickName);
61 auto txtRecord = info.toTXTRecord();
62 CPPUNIT_ASSERT(txtRecord);
61 return LinkLocalService(service, 63 return LinkLocalService(service,
62 DNSSDResolveServiceQuery::Result( 64 DNSSDResolveServiceQuery::Result(
63 name + "._presence._tcp.local", "rabbithole.local", 1234, 65 name + "._presence._tcp.local", "rabbithole.local", 1234,
64 info.toTXTRecord())); 66 *txtRecord));
65 } 67 }
66}; 68};
67 69