From ce001ffe0d598c75df5719b9a6aa0e544594408a Mon Sep 17 00:00:00 2001
From: Peter Burgess <pete.burgess@isode.com>
Date: Tue, 27 Mar 2018 13:30:56 +0100
Subject: Fix empty marking colour handling in MUCController

When there is a room security marking and the colours have the value ""
they should be set to the default black and white. Instead they were
being set to "", so I have updated this and uncommented the relevant unit
test.

Test-Information:
The uncommented unit test is now passing, and all other related unit
tests still pass. A MUC room with a marking but blank colour values has
been tested on a test server and works as expected.

Change-Id: I1138ca1f035f8b7c0367c36ec3a65cc857721b8c

diff --git a/Swift/Controllers/Chat/MUCController.cpp b/Swift/Controllers/Chat/MUCController.cpp
index 4c3f524..139f425 100644
--- a/Swift/Controllers/Chat/MUCController.cpp
+++ b/Swift/Controllers/Chat/MUCController.cpp
@@ -1285,10 +1285,10 @@ void MUCController::requestSecurityMarking() {
             auto markingBackgroundColor = roomInfoForm->getField("x-isode#roominfo_marking_bg_color");
             std::string markingForegroundColorValue = "Black";
             std::string markingBackgroundColorValue = "White";
-            if (markingForegroundColor) {
+            if (markingForegroundColor && markingForegroundColor->getTextSingleValue() != "") {
                 markingForegroundColorValue = markingForegroundColor->getTextSingleValue();
             }
-            if (markingBackgroundColor) {
+            if (markingBackgroundColor && markingBackgroundColor->getTextSingleValue() != "") {
                 markingBackgroundColorValue = markingBackgroundColor->getTextSingleValue();
             }
             setMUCSecurityMarking(markingValue, markingForegroundColorValue, markingBackgroundColorValue);
diff --git a/Swift/Controllers/Chat/UnitTest/MUCControllerTest.cpp b/Swift/Controllers/Chat/UnitTest/MUCControllerTest.cpp
index 012bcd0..05ab3a7 100644
--- a/Swift/Controllers/Chat/UnitTest/MUCControllerTest.cpp
+++ b/Swift/Controllers/Chat/UnitTest/MUCControllerTest.cpp
@@ -674,31 +674,31 @@ TEST_F(MUCControllerTest, testSecurityMarkingRequestCompleteMarkingWithExtraForm
     ASSERT_EQ(std::string("Red"), window_->markingBackgroundColorValue_);
 }
 
-// TEST_F(MUCControllerTest, testSecurityMarkingRequestNoColorsInMarking) {
-//     auto formTypeField = std::make_shared<FormField>(FormField::Type::HiddenType, "http://jabber.org/protocol/muc#roominfo");
-//     auto markingField = std::make_shared<FormField>(FormField::Type::TextSingleType, "Test|Highest Possible Security");
-//     auto markingForegroundColorField = std::make_shared<FormField>(FormField::Type::TextSingleType, "");
-//     auto markingBackgroundColorField = std::make_shared<FormField>(FormField::Type::TextSingleType, "");
-//     formTypeField->setName("FORM_TYPE");
-//     markingField->setName("x-isode#roominfo_marking");
-//     markingForegroundColorField->setName("x-isode#roominfo_marking_fg_color");
-//     markingBackgroundColorField->setName("x-isode#roominfo_marking_bg_color");
-
-//     auto form = std::make_shared<Form>(Form::Type::ResultType);
-//     form->addField(formTypeField);
-//     form->addField(markingField);
-//     form->addField(markingForegroundColorField);
-//     form->addField(markingBackgroundColorField);
-
-//     auto discoInfoRef = std::make_shared<DiscoInfo>();
-//     discoInfoRef->addExtension(form);
-
-//     auto infoResponse = IQ::createResult(self_, mucJID_, "test-id", discoInfoRef);
-//     iqChannel_->onIQReceived(infoResponse);
-//     ASSERT_EQ(std::string("Test|Highest Possible Security"), window_->markingValue_);
-//     ASSERT_EQ(std::string("Black"), window_->markingForegroundColorValue_);
-//     ASSERT_EQ(std::string("White"), window_->markingBackgroundColorValue_);
-// }
+TEST_F(MUCControllerTest, testSecurityMarkingRequestNoColorsInMarking) {
+    auto formTypeField = std::make_shared<FormField>(FormField::Type::HiddenType, "http://jabber.org/protocol/muc#roominfo");
+    auto markingField = std::make_shared<FormField>(FormField::Type::TextSingleType, "Test|Highest Possible Security");
+    auto markingForegroundColorField = std::make_shared<FormField>(FormField::Type::TextSingleType, "");
+    auto markingBackgroundColorField = std::make_shared<FormField>(FormField::Type::TextSingleType, "");
+    formTypeField->setName("FORM_TYPE");
+    markingField->setName("x-isode#roominfo_marking");
+    markingForegroundColorField->setName("x-isode#roominfo_marking_fg_color");
+    markingBackgroundColorField->setName("x-isode#roominfo_marking_bg_color");
+
+    auto form = std::make_shared<Form>(Form::Type::ResultType);
+    form->addField(formTypeField);
+    form->addField(markingField);
+    form->addField(markingForegroundColorField);
+    form->addField(markingBackgroundColorField);
+
+    auto discoInfoRef = std::make_shared<DiscoInfo>();
+    discoInfoRef->addExtension(form);
+
+    auto infoResponse = IQ::createResult(self_, mucJID_, "test-id", discoInfoRef);
+    iqChannel_->onIQReceived(infoResponse);
+    ASSERT_EQ(std::string("Test|Highest Possible Security"), window_->markingValue_);
+    ASSERT_EQ(std::string("Black"), window_->markingForegroundColorValue_);
+    ASSERT_EQ(std::string("White"), window_->markingBackgroundColorValue_);
+}
 
 TEST_F(MUCControllerTest, testSecurityMarkingRequestEmptyMarking) {
     setMUCSecurityMarking("", "", "", true);
-- 
cgit v0.10.2-6-g49f6