summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdwin Mons <edwin.mons@isode.com>2018-10-24 20:40:51 (GMT)
committerEdwin Mons <edwin.mons@isode.com>2018-10-25 09:18:39 (GMT)
commit5ce9e19ef0744f530a797c30a82e9723eb7ea306 (patch)
treef3f59b3e9a7dddff75fd222d15b3492c26bb86be /Swiften
parentf0b7ffcea9b9983555b0555ea5815a193d1e129c (diff)
downloadswift-5ce9e19ef0744f530a797c30a82e9723eb7ea306.zip
swift-5ce9e19ef0744f530a797c30a82e9723eb7ea306.tar.bz2
Strip off trailing dot from domainpart of jid
RFC 6122 specifies that if a domainpart ends in a dot, it must be stripped off before any other canonicalisation steps are taken. Unit tests have been added to check that various JID scenarios with a domain ending in a dot pass or are rejected as expected. Test-Information: Unit tests pass on macOS 10.13. Manual tests in sluift show expected behaviour. Change-Id: Id6813aaa4422a81bff0a4559eacd6855ef104dc3
Diffstat (limited to 'Swiften')
-rw-r--r--Swiften/JID/JID.cpp7
-rw-r--r--Swiften/JID/UnitTest/JIDTest.cpp48
2 files changed, 53 insertions, 2 deletions
diff --git a/Swiften/JID/JID.cpp b/Swiften/JID/JID.cpp
index a31c19f..fff88e9 100644
--- a/Swiften/JID/JID.cpp
+++ b/Swiften/JID/JID.cpp
@@ -111,7 +111,12 @@ void JID::nameprepAndSetComponents(const std::string& node, const std::string& d
111 111
112 try { 112 try {
113 node_ = idnConverter->getStringPrepared(node, IDNConverter::XMPPNodePrep); 113 node_ = idnConverter->getStringPrepared(node, IDNConverter::XMPPNodePrep);
114 domain_ = idnConverter->getStringPrepared(domain, IDNConverter::NamePrep); 114 if (domain.back() == '.') {
115 domain_ = idnConverter->getStringPrepared(domain.substr(0, domain.size() - 1), IDNConverter::NamePrep);
116 }
117 else {
118 domain_ = idnConverter->getStringPrepared(domain, IDNConverter::NamePrep);
119 }
115 resource_ = idnConverter->getStringPrepared(resource, IDNConverter::XMPPResourcePrep); 120 resource_ = idnConverter->getStringPrepared(resource, IDNConverter::XMPPResourcePrep);
116 } catch (...) { 121 } catch (...) {
117 valid_ = false; 122 valid_ = false;
diff --git a/Swiften/JID/UnitTest/JIDTest.cpp b/Swiften/JID/UnitTest/JIDTest.cpp
index aefda33..0753fb5 100644
--- a/Swiften/JID/UnitTest/JIDTest.cpp
+++ b/Swiften/JID/UnitTest/JIDTest.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 */
@@ -20,13 +20,19 @@ class JIDTest : public CppUnit::TestFixture
20 CPPUNIT_TEST(testConstructorWithString_NoNode); 20 CPPUNIT_TEST(testConstructorWithString_NoNode);
21 CPPUNIT_TEST(testConstructorWithString_EmptyResource); 21 CPPUNIT_TEST(testConstructorWithString_EmptyResource);
22 CPPUNIT_TEST(testConstructorWithString_OnlyDomain); 22 CPPUNIT_TEST(testConstructorWithString_OnlyDomain);
23 CPPUNIT_TEST(testConstructorWithString_OnlyDomainWithDot);
24 CPPUNIT_TEST(testConstructorWithString_OnlyDomainDotStrippedOff);
25 CPPUNIT_TEST(testConstructorWithString_InvalidOnlyDomainSingleDot);
23 CPPUNIT_TEST(testConstructorWithString_InvalidDomain); 26 CPPUNIT_TEST(testConstructorWithString_InvalidDomain);
27 CPPUNIT_TEST(testConstructorWithString_InvalidDomainEmptyLabel);
24 CPPUNIT_TEST(testConstructorWithString_UpperCaseNode); 28 CPPUNIT_TEST(testConstructorWithString_UpperCaseNode);
25 CPPUNIT_TEST(testConstructorWithString_UpperCaseDomain); 29 CPPUNIT_TEST(testConstructorWithString_UpperCaseDomain);
26 CPPUNIT_TEST(testConstructorWithString_UpperCaseResource); 30 CPPUNIT_TEST(testConstructorWithString_UpperCaseResource);
27 CPPUNIT_TEST(testConstructorWithString_EmptyNode); 31 CPPUNIT_TEST(testConstructorWithString_EmptyNode);
28 CPPUNIT_TEST(testConstructorWithString_EmptyDomain); 32 CPPUNIT_TEST(testConstructorWithString_EmptyDomain);
29 CPPUNIT_TEST(testConstructorWithString_EmptyDomainWithResource); 33 CPPUNIT_TEST(testConstructorWithString_EmptyDomainWithResource);
34 CPPUNIT_TEST(testConstructorWithString_DotDomain);
35 CPPUNIT_TEST(testConstructorWithString_DotDomainWithResource);
30 CPPUNIT_TEST(testConstructorWithString_IllegalResource); 36 CPPUNIT_TEST(testConstructorWithString_IllegalResource);
31 CPPUNIT_TEST(testConstructorWithString_SpacesInNode); 37 CPPUNIT_TEST(testConstructorWithString_SpacesInNode);
32 CPPUNIT_TEST(testConstructorWithStrings); 38 CPPUNIT_TEST(testConstructorWithStrings);
@@ -122,10 +128,38 @@ class JIDTest : public CppUnit::TestFixture
122 CPPUNIT_ASSERT(testling.isValid()); 128 CPPUNIT_ASSERT(testling.isValid());
123 } 129 }
124 130
131 void testConstructorWithString_OnlyDomainWithDot() {
132 JID testling("bar.");
133
134 CPPUNIT_ASSERT_EQUAL(std::string(""), testling.getNode());
135 CPPUNIT_ASSERT_EQUAL(std::string("bar"), testling.getDomain());
136 CPPUNIT_ASSERT_EQUAL(std::string(""), testling.getResource());
137 CPPUNIT_ASSERT(testling.isBare());
138 CPPUNIT_ASSERT(testling.isValid());
139 }
140
141 void testConstructorWithString_OnlyDomainDotStrippedOff() {
142 JID testling("foo.@bar./resource.");
143
144 CPPUNIT_ASSERT_EQUAL(std::string("foo."), testling.getNode());
145 CPPUNIT_ASSERT_EQUAL(std::string("bar"), testling.getDomain());
146 CPPUNIT_ASSERT_EQUAL(std::string("resource."), testling.getResource());
147 CPPUNIT_ASSERT(!testling.isBare());
148 CPPUNIT_ASSERT(testling.isValid());
149 }
150
151 void testConstructorWithString_InvalidOnlyDomainSingleDot() {
152 CPPUNIT_ASSERT(!JID(".").isValid());
153 }
154
125 void testConstructorWithString_InvalidDomain() { 155 void testConstructorWithString_InvalidDomain() {
126 CPPUNIT_ASSERT(!JID("foo@bar,baz").isValid()); 156 CPPUNIT_ASSERT(!JID("foo@bar,baz").isValid());
127 } 157 }
128 158
159 void testConstructorWithString_InvalidDomainEmptyLabel() {
160 CPPUNIT_ASSERT(!JID("foo@bar..").isValid());
161 }
162
129 void testConstructorWithString_UpperCaseNode() { 163 void testConstructorWithString_UpperCaseNode() {
130 JID testling("Fo\xCE\xA9@bar"); 164 JID testling("Fo\xCE\xA9@bar");
131 165
@@ -172,6 +206,18 @@ class JIDTest : public CppUnit::TestFixture
172 CPPUNIT_ASSERT(!testling.isValid()); 206 CPPUNIT_ASSERT(!testling.isValid());
173 } 207 }
174 208
209 void testConstructorWithString_DotDomain() {
210 JID testling("bar@.");
211
212 CPPUNIT_ASSERT(!testling.isValid());
213 }
214
215 void testConstructorWithString_DotDomainWithResource() {
216 JID testling("bar@./resource");
217
218 CPPUNIT_ASSERT(!testling.isValid());
219 }
220
175 void testConstructorWithString_IllegalResource() { 221 void testConstructorWithString_IllegalResource() {
176 JID testling("foo@bar.com/\xd8\xb1\xd9\x85\xd9\x82\xd9\x87\x20\xd8\xaa\xd8\xb1\xd9\x86\xd8\xb3\x20"); 222 JID testling("foo@bar.com/\xd8\xb1\xd9\x85\xd9\x82\xd9\x87\x20\xd8\xaa\xd8\xb1\xd9\x86\xd8\xb3\x20");
177 223