summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2010-06-03 18:11:02 (GMT)
committerRemko Tronçon <git@el-tramo.be>2010-06-03 18:11:02 (GMT)
commitc3fa606c7ac060c4929e7082e0e24531b093112f (patch)
tree394cf72c0b43fa706319592dfdb1438335b6116a /Swiften/Serializer
parent8406d818fcb2a511b1e4264a10fd9069ec020d72 (diff)
downloadswift-contrib-c3fa606c7ac060c4929e7082e0e24531b093112f.zip
swift-contrib-c3fa606c7ac060c4929e7082e0e24531b093112f.tar.bz2
Distinguish an empty SASL message from no SASL message.
Diffstat (limited to 'Swiften/Serializer')
-rw-r--r--Swiften/Serializer/AuthChallengeSerializer.cpp13
-rw-r--r--Swiften/Serializer/AuthRequestSerializer.cpp11
-rw-r--r--Swiften/Serializer/AuthResponseSerializer.cpp15
-rw-r--r--Swiften/Serializer/AuthSuccessSerializer.cpp13
-rw-r--r--Swiften/Serializer/UnitTest/AuthChallengeSerializerTest.cpp55
-rw-r--r--Swiften/Serializer/UnitTest/AuthRequestSerializerTest.cpp55
-rw-r--r--Swiften/Serializer/UnitTest/AuthResponseSerializerTest.cpp55
-rw-r--r--Swiften/Serializer/UnitTest/AuthSuccessSerializerTest.cpp55
8 files changed, 264 insertions, 8 deletions
diff --git a/Swiften/Serializer/AuthChallengeSerializer.cpp b/Swiften/Serializer/AuthChallengeSerializer.cpp
index 00b5058..883763f 100644
--- a/Swiften/Serializer/AuthChallengeSerializer.cpp
+++ b/Swiften/Serializer/AuthChallengeSerializer.cpp
@@ -15,8 +15,17 @@ AuthChallengeSerializer::AuthChallengeSerializer() {
}
String AuthChallengeSerializer::serialize(boost::shared_ptr<Element> element) const {
- boost::shared_ptr<AuthChallenge> authRequest(boost::dynamic_pointer_cast<AuthChallenge>(element));
- String value = (authRequest->getValue().isEmpty() ? "=" : Base64::encode(authRequest->getValue()));
+ boost::shared_ptr<AuthChallenge> authChallenge(boost::dynamic_pointer_cast<AuthChallenge>(element));
+ String value;
+ boost::optional<ByteArray> message = authChallenge->getValue();
+ if (message) {
+ if ((*message).isEmpty()) {
+ value = "=";
+ }
+ else {
+ value = Base64::encode(*message);
+ }
+ }
return "<challenge xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">" + value + "</challenge>";
}
diff --git a/Swiften/Serializer/AuthRequestSerializer.cpp b/Swiften/Serializer/AuthRequestSerializer.cpp
index 32d733a..45b6503 100644
--- a/Swiften/Serializer/AuthRequestSerializer.cpp
+++ b/Swiften/Serializer/AuthRequestSerializer.cpp
@@ -16,7 +16,16 @@ AuthRequestSerializer::AuthRequestSerializer() {
String AuthRequestSerializer::serialize(boost::shared_ptr<Element> element) const {
boost::shared_ptr<AuthRequest> authRequest(boost::dynamic_pointer_cast<AuthRequest>(element));
- String value = (authRequest->getMessage().isEmpty() ? "=" : Base64::encode(authRequest->getMessage()));
+ String value;
+ boost::optional<ByteArray> message = authRequest->getMessage();
+ if (message) {
+ if ((*message).isEmpty()) {
+ value = "=";
+ }
+ else {
+ value = Base64::encode(*message);
+ }
+ }
return "<auth xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\" mechanism=\"" + authRequest->getMechanism() + "\">" + value + "</auth>";
}
diff --git a/Swiften/Serializer/AuthResponseSerializer.cpp b/Swiften/Serializer/AuthResponseSerializer.cpp
index ffa3963..d2d5616 100644
--- a/Swiften/Serializer/AuthResponseSerializer.cpp
+++ b/Swiften/Serializer/AuthResponseSerializer.cpp
@@ -14,9 +14,18 @@ namespace Swift {
AuthResponseSerializer::AuthResponseSerializer() {
}
-String AuthResponseSerializer::serialize(boost::shared_ptr<Element> element) const {
- boost::shared_ptr<AuthResponse> authRequest(boost::dynamic_pointer_cast<AuthResponse>(element));
- String value = (authRequest->getValue().isEmpty() ? "=" : Base64::encode(authRequest->getValue()));
+String AuthResponseSerializer::serialize(boost::shared_ptr<Element> element) const {
+ boost::shared_ptr<AuthResponse> authResponse(boost::dynamic_pointer_cast<AuthResponse>(element));
+ String value;
+ boost::optional<ByteArray> message = authResponse->getValue();
+ if (message) {
+ if ((*message).isEmpty()) {
+ value = "=";
+ }
+ else {
+ value = Base64::encode(*message);
+ }
+ }
return "<response xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">" + value + "</response>";
}
diff --git a/Swiften/Serializer/AuthSuccessSerializer.cpp b/Swiften/Serializer/AuthSuccessSerializer.cpp
index f27b2cb..6e9103b 100644
--- a/Swiften/Serializer/AuthSuccessSerializer.cpp
+++ b/Swiften/Serializer/AuthSuccessSerializer.cpp
@@ -15,8 +15,17 @@ AuthSuccessSerializer::AuthSuccessSerializer() {
}
String AuthSuccessSerializer::serialize(boost::shared_ptr<Element> element) const {
- boost::shared_ptr<AuthSuccess> authRequest(boost::dynamic_pointer_cast<AuthSuccess>(element));
- String value = (authRequest->getValue().isEmpty() ? "=" : Base64::encode(authRequest->getValue()));
+ boost::shared_ptr<AuthSuccess> authSuccess(boost::dynamic_pointer_cast<AuthSuccess>(element));
+ String value;
+ boost::optional<ByteArray> message = authSuccess->getValue();
+ if (message) {
+ if ((*message).isEmpty()) {
+ value = "=";
+ }
+ else {
+ value = Base64::encode(*message);
+ }
+ }
return "<success xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">" + value + "</success>";
}
diff --git a/Swiften/Serializer/UnitTest/AuthChallengeSerializerTest.cpp b/Swiften/Serializer/UnitTest/AuthChallengeSerializerTest.cpp
new file mode 100644
index 0000000..dc828e0
--- /dev/null
+++ b/Swiften/Serializer/UnitTest/AuthChallengeSerializerTest.cpp
@@ -0,0 +1,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/Serializer/AuthChallengeSerializer.h"
+#include "Swiften/Elements/AuthChallenge.h"
+
+using namespace Swift;
+
+class AuthChallengeSerializerTest : public CppUnit::TestFixture {
+ CPPUNIT_TEST_SUITE(AuthChallengeSerializerTest);
+ CPPUNIT_TEST(testSerialize);
+ CPPUNIT_TEST(testSerialize_NoMessage);
+ CPPUNIT_TEST(testSerialize_EmptyMessage);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ void testSerialize() {
+ AuthChallengeSerializer testling;
+ boost::shared_ptr<AuthChallenge> authChallenge(new AuthChallenge());
+ authChallenge->setValue("foo");
+
+ CPPUNIT_ASSERT_EQUAL(String(
+ "<challenge xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">"
+ "Zm9v"
+ "</challenge>"), testling.serialize(authChallenge));
+ }
+
+ void testSerialize_NoMessage() {
+ AuthChallengeSerializer testling;
+ boost::shared_ptr<AuthChallenge> authChallenge(new AuthChallenge());
+
+ CPPUNIT_ASSERT_EQUAL(String(
+ "<challenge xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">"
+ "</challenge>"), testling.serialize(authChallenge));
+ }
+
+ void testSerialize_EmptyMessage() {
+ AuthChallengeSerializer testling;
+ boost::shared_ptr<AuthChallenge> authChallenge(new AuthChallenge());
+ authChallenge->setValue(ByteArray());
+
+ CPPUNIT_ASSERT_EQUAL(String(
+ "<challenge xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">"
+ "="
+ "</challenge>"), testling.serialize(authChallenge));
+ }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(AuthChallengeSerializerTest);
diff --git a/Swiften/Serializer/UnitTest/AuthRequestSerializerTest.cpp b/Swiften/Serializer/UnitTest/AuthRequestSerializerTest.cpp
new file mode 100644
index 0000000..f63db90
--- /dev/null
+++ b/Swiften/Serializer/UnitTest/AuthRequestSerializerTest.cpp
@@ -0,0 +1,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/Serializer/AuthRequestSerializer.h"
+#include "Swiften/Elements/AuthRequest.h"
+
+using namespace Swift;
+
+class AuthRequestSerializerTest : public CppUnit::TestFixture {
+ CPPUNIT_TEST_SUITE(AuthRequestSerializerTest);
+ CPPUNIT_TEST(testSerialize);
+ CPPUNIT_TEST(testSerialize_NoMessage);
+ CPPUNIT_TEST(testSerialize_EmptyMessage);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ void testSerialize() {
+ AuthRequestSerializer testling;
+ boost::shared_ptr<AuthRequest> authRequest(new AuthRequest("PLAIN"));
+ authRequest->setMessage("foo");
+
+ CPPUNIT_ASSERT_EQUAL(String(
+ "<auth xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\" mechanism=\"PLAIN\">"
+ "Zm9v"
+ "</auth>"), testling.serialize(authRequest));
+ }
+
+ void testSerialize_NoMessage() {
+ AuthRequestSerializer testling;
+ boost::shared_ptr<AuthRequest> authRequest(new AuthRequest("PLAIN"));
+
+ CPPUNIT_ASSERT_EQUAL(String(
+ "<auth xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\" mechanism=\"PLAIN\">"
+ "</auth>"), testling.serialize(authRequest));
+ }
+
+ void testSerialize_EmptyMessage() {
+ AuthRequestSerializer testling;
+ boost::shared_ptr<AuthRequest> authRequest(new AuthRequest("PLAIN"));
+ authRequest->setMessage(ByteArray());
+
+ CPPUNIT_ASSERT_EQUAL(String(
+ "<auth xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\" mechanism=\"PLAIN\">"
+ "="
+ "</auth>"), testling.serialize(authRequest));
+ }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(AuthRequestSerializerTest);
diff --git a/Swiften/Serializer/UnitTest/AuthResponseSerializerTest.cpp b/Swiften/Serializer/UnitTest/AuthResponseSerializerTest.cpp
new file mode 100644
index 0000000..fabe834
--- /dev/null
+++ b/Swiften/Serializer/UnitTest/AuthResponseSerializerTest.cpp
@@ -0,0 +1,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/Serializer/AuthResponseSerializer.h"
+#include "Swiften/Elements/AuthResponse.h"
+
+using namespace Swift;
+
+class AuthResponseSerializerTest : public CppUnit::TestFixture {
+ CPPUNIT_TEST_SUITE(AuthResponseSerializerTest);
+ CPPUNIT_TEST(testSerialize);
+ CPPUNIT_TEST(testSerialize_NoMessage);
+ CPPUNIT_TEST(testSerialize_EmptyMessage);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ void testSerialize() {
+ AuthResponseSerializer testling;
+ boost::shared_ptr<AuthResponse> authResponse(new AuthResponse());
+ authResponse->setValue("foo");
+
+ CPPUNIT_ASSERT_EQUAL(String(
+ "<response xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">"
+ "Zm9v"
+ "</response>"), testling.serialize(authResponse));
+ }
+
+ void testSerialize_NoMessage() {
+ AuthResponseSerializer testling;
+ boost::shared_ptr<AuthResponse> authResponse(new AuthResponse());
+
+ CPPUNIT_ASSERT_EQUAL(String(
+ "<response xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">"
+ "</response>"), testling.serialize(authResponse));
+ }
+
+ void testSerialize_EmptyMessage() {
+ AuthResponseSerializer testling;
+ boost::shared_ptr<AuthResponse> authResponse(new AuthResponse());
+ authResponse->setValue(ByteArray());
+
+ CPPUNIT_ASSERT_EQUAL(String(
+ "<response xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">"
+ "="
+ "</response>"), testling.serialize(authResponse));
+ }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(AuthResponseSerializerTest);
diff --git a/Swiften/Serializer/UnitTest/AuthSuccessSerializerTest.cpp b/Swiften/Serializer/UnitTest/AuthSuccessSerializerTest.cpp
new file mode 100644
index 0000000..a9b602f
--- /dev/null
+++ b/Swiften/Serializer/UnitTest/AuthSuccessSerializerTest.cpp
@@ -0,0 +1,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/Serializer/AuthSuccessSerializer.h"
+#include "Swiften/Elements/AuthSuccess.h"
+
+using namespace Swift;
+
+class AuthSuccessSerializerTest : public CppUnit::TestFixture {
+ CPPUNIT_TEST_SUITE(AuthSuccessSerializerTest);
+ CPPUNIT_TEST(testSerialize);
+ CPPUNIT_TEST(testSerialize_NoMessage);
+ CPPUNIT_TEST(testSerialize_EmptyMessage);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ void testSerialize() {
+ AuthSuccessSerializer testling;
+ boost::shared_ptr<AuthSuccess> authSuccess(new AuthSuccess());
+ authSuccess->setValue("foo");
+
+ CPPUNIT_ASSERT_EQUAL(String(
+ "<success xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">"
+ "Zm9v"
+ "</success>"), testling.serialize(authSuccess));
+ }
+
+ void testSerialize_NoMessage() {
+ AuthSuccessSerializer testling;
+ boost::shared_ptr<AuthSuccess> authSuccess(new AuthSuccess());
+
+ CPPUNIT_ASSERT_EQUAL(String(
+ "<success xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">"
+ "</success>"), testling.serialize(authSuccess));
+ }
+
+ void testSerialize_EmptyMessage() {
+ AuthSuccessSerializer testling;
+ boost::shared_ptr<AuthSuccess> authSuccess(new AuthSuccess());
+ authSuccess->setValue(ByteArray());
+
+ CPPUNIT_ASSERT_EQUAL(String(
+ "<success xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">"
+ "="
+ "</success>"), testling.serialize(authSuccess));
+ }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(AuthSuccessSerializerTest);