[SCM] ktp-common-internals packaging branch, master, updated. debian/15.12.1-2-1839-gf0635e9

Maximiliano Curia maxy at moszumanska.debian.org
Mon May 9 09:08:20 UTC 2016


Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-common-internals.git;a=commitdiff;h=e68ba86

The following commit has been merged in the master branch:
commit e68ba8634fc43dadf48ce72229a970ece9ac6baa
Author: Marcin Ziemiński <zieminn at gmail.com>
Date:   Sat Jul 26 22:16:34 2014 +0200

    Add tests of invalid and more complex conversation.
    
    Signed-off-by: Marcin Ziemiński <zieminn at gmail.com>
---
 otr-proxy/KTpProxy/otr-manager.cpp                 |   8 +-
 otr-proxy/KTpProxy/otr-message.cpp                 |   6 +-
 otr-proxy/KTpProxy/otr-message.h                   |   4 +-
 otr-proxy/KTpProxy/otr-session.cpp                 |   4 +-
 otr-proxy/test/otr-test.cpp                        | 137 ++++++++++++++++++++-
 .../resources/{bob_id_instags => john_id_instags}  |   2 +-
 otr-proxy/test/resources/john_id_privkeys          |  15 +++
 7 files changed, 163 insertions(+), 13 deletions(-)

diff --git a/otr-proxy/KTpProxy/otr-manager.cpp b/otr-proxy/KTpProxy/otr-manager.cpp
index 4fb63ec..f4230fc 100644
--- a/otr-proxy/KTpProxy/otr-manager.cpp
+++ b/otr-proxy/KTpProxy/otr-manager.cpp
@@ -271,14 +271,14 @@ namespace {
                 {
                     case GPG_ERR_INV_VALUE:
                         {
-                            msg.setOTRHeader(QLatin1String("otr-error"), QLatin1String("Malformed message received"));
+                            msg.setOTRheader(QLatin1String("otr-error"), QLatin1String("Malformed message received"));
                             msg.setText(QLatin1String("Error setting up private conversation: "
                                         "Malformed message received"));
                             break;
                         }
                     default:
                         {
-                            msg.setOTRHeader(QLatin1String("otr-error"), QLatin1String(gcry_strerror(err)));
+                            msg.setOTRheader(QLatin1String("otr-error"), QLatin1String(gcry_strerror(err)));
                             msg.setText(QString::fromLatin1("Error setting up private conversation: %1")
                                     .arg(QLatin1String(gcry_strerror(err))));
                             break;
@@ -318,12 +318,12 @@ namespace {
             case OTRL_MSGEVENT_LOG_HEARTBEAT_SENT:
                 break;
             case OTRL_MSGEVENT_RCVDMSG_GENERAL_ERR:
-                msg.setOTRHeader(QLatin1String("otr-error"), QLatin1String(message));
+                msg.setOTRheader(QLatin1String("otr-error"), QLatin1String(message));
                 msg.setText(QString::fromLatin1("OTR error: %1").arg(QLatin1String(message)));
                 msg.setDirection(MessageDirection::INTERNAL);
                 break;
             case OTRL_MSGEVENT_RCVDMSG_UNENCRYPTED:
-                msg.setOTRHeader(QLatin1String("otr-unencrypted-message"), QLatin1String(message));
+                msg.setOTRheader(QLatin1String("otr-unencrypted-message"), QLatin1String(message));
                 msg.setText(QString::fromLatin1("The following message received from %1 was not encrypted: [%2]")
                         .arg(QLatin1String(context->username), QLatin1String(message)));
                 msg.setDirection(MessageDirection::FROM_PEER);
diff --git a/otr-proxy/KTpProxy/otr-message.cpp b/otr-proxy/KTpProxy/otr-message.cpp
index 1df1322..f35ab9c 100644
--- a/otr-proxy/KTpProxy/otr-message.cpp
+++ b/otr-proxy/KTpProxy/otr-message.cpp
@@ -95,15 +95,15 @@ namespace OTR
 
     OtrlMessageEvent Message::getOTRevent() const
     {
-        return static_cast<OtrlMessageEvent>(message[0]["otr-message-event"].variant().toUInt(NULL));
+        return static_cast<OtrlMessageEvent>(message[0][QLatin1String("otr-message-event")].variant().toUInt(NULL));
     }
 
-    void Message::setOTRHeader(const QString &header, const QString &text)
+    void Message::setOTRheader(const QString &header, const QString &text)
     {
         message[0].insert(header, QDBusVariant(text));
     }
 
-    QString Message::getOTRHeader(const QString &header)
+    QString Message::getOTRheader(const QString &header)
     {
         auto it = message[0].find(header);
         if(it == message[0].end()) {
diff --git a/otr-proxy/KTpProxy/otr-message.h b/otr-proxy/KTpProxy/otr-message.h
index ddb95d4..0f0ef90 100644
--- a/otr-proxy/KTpProxy/otr-message.h
+++ b/otr-proxy/KTpProxy/otr-message.h
@@ -55,8 +55,8 @@ namespace OTR
             void setOTRevent(OtrlMessageEvent msgEvent);
             OtrlMessageEvent getOTRevent() const;
 
-            void setOTRHeader(const QString &header, const QString &text);
-            QString getOTRHeader(const QString &header);
+            void setOTRheader(const QString &header, const QString &text);
+            QString getOTRheader(const QString &header);
 
         private:
             MessageDirection dir;
diff --git a/otr-proxy/KTpProxy/otr-session.cpp b/otr-proxy/KTpProxy/otr-session.cpp
index 0af2bd0..fa97a62 100644
--- a/otr-proxy/KTpProxy/otr-session.cpp
+++ b/otr-proxy/KTpProxy/otr-session.cpp
@@ -165,7 +165,7 @@ namespace OTR
                 message.setType(Tp::ChannelTextMessageTypeNormal);
                 if(context->active_fingerprint != NULL) {
                     const QString hrFingerprint = OTR::utils::humanReadable(context->active_fingerprint->fingerprint);
-                    message.setOTRHeader(QLatin1String("otr-remote-fingerprint"), hrFingerprint);
+                    message.setOTRheader(QLatin1String("otr-remote-fingerprint"), hrFingerprint);
                 }
                 otrl_message_free(encMessage);
 
@@ -207,7 +207,7 @@ namespace OTR
                 message.setText(QLatin1String(decMsg));
                 if(context->active_fingerprint != NULL) {
                     const QString hrFingerprint = OTR::utils::humanReadable(context->active_fingerprint->fingerprint);
-                    message.setOTRHeader(QLatin1String("otr-remote-fingerprint"), hrFingerprint);
+                    message.setOTRheader(QLatin1String("otr-remote-fingerprint"), hrFingerprint);
                 }
                 result = CryptResult::CHANGED;
             } else {
diff --git a/otr-proxy/test/otr-test.cpp b/otr-proxy/test/otr-test.cpp
index 823c7c9..9d4c138 100644
--- a/otr-proxy/test/otr-test.cpp
+++ b/otr-proxy/test/otr-test.cpp
@@ -56,6 +56,22 @@ namespace tst {
         QLatin1String("talk")
     };
 
+    const SessionContext aliceJCtx =
+    {
+        QLatin1String("alice_id"),
+        QLatin1String("Alice"),
+        QLatin1String("John"),
+        QLatin1String("talk")
+    };
+    const SessionContext johnCtx =
+    {
+        QLatin1String("john_id"),
+        QLatin1String("John"),
+        QLatin1String("Alice"),
+        QLatin1String("talk")
+    };
+
+
     class SessionEnv : public QObject
     {
         Q_OBJECT;
@@ -115,10 +131,15 @@ class OTRTest : public QObject
         void testSessionPolicyNever();
         void testSessionPolicyOpportunistic();
         void testSessionPolicyAlways();
+        void testEncUnencryptedErrors();
+        void testDoubleConversation();
 
         void cleanup();
 
     private:
+
+        void startSession(TestSession& alice, TestSession &bob);
+
         TestConfig aliceConfig;
         TestConfig bobConfig;
         Manager *aliceMan;
@@ -299,7 +320,7 @@ void OTRTest::testSessionPolicyAlways()
     QCOMPARE(alice.decrypt(helloMsg), CryptResult::OTR);
     QVERIFY(alice.mesQueue.empty());
     QVERIFY(!alice.eventQueue.empty());
-    QCOMPARE(alice.eventQueue.back().getOTRHeader("otr-unencrypted-message"), heyText);
+    QCOMPARE(alice.eventQueue.back().getOTRheader("otr-unencrypted-message"), heyText);
     QCOMPARE(alice.eventQueue.back().getOTRevent(), OTRL_MSGEVENT_RCVDMSG_UNENCRYPTED);
 
     aliceEnv->reset();
@@ -332,6 +353,119 @@ void OTRTest::testSessionPolicyAlways()
     QCOMPARE(alice.trustLevel(), TrustLevel::UNVERIFIED);
 }
 
+void OTRTest::startSession(TestSession& alice, TestSession &bob)
+{
+    Message mes = alice.startSession();
+    QCOMPARE(mes.direction(), MessageDirection::TO_PEER);
+    QVERIFY(alice.mesQueue.empty());
+
+    QCOMPARE(bob.decrypt(mes), CryptResult::OTR);
+    QVERIFY(!bob.mesQueue.empty());
+    while(!bob.mesQueue.empty() || !alice.mesQueue.empty()) {
+        if(!bob.mesQueue.empty()) {
+            QCOMPARE(bob.mesQueue.back().direction(), MessageDirection::TO_PEER);
+            QCOMPARE(alice.decrypt(bob.mesQueue.back()), CryptResult::OTR);
+            bob.mesQueue.pop_back();
+        }
+        if(!alice.mesQueue.empty()) {
+            QCOMPARE(alice.mesQueue.back().direction(), MessageDirection::TO_PEER);
+            QCOMPARE(bob.decrypt(alice.mesQueue.back()), CryptResult::OTR);
+            alice.mesQueue.pop_back();
+        }
+    }
+    QVERIFY(alice.mesQueue.empty());
+    QVERIFY(alice.eventQueue.empty());
+    QVERIFY(bob.mesQueue.empty());
+    QVERIFY(bob.eventQueue.empty());
+
+    QCOMPARE(bob.trustLevel(), TrustLevel::UNVERIFIED);
+    QCOMPARE(alice.trustLevel(), TrustLevel::UNVERIFIED);
+}
+
+void OTRTest::testEncUnencryptedErrors()
+{
+    TestSession &alice = aliceEnv->ses;
+    TestSession &bob = bobEnv->ses;
+    startSession(alice, bob);
+
+    Message mes;
+    const QString text = QLatin1String("Unencrypted text");
+    mes.setText(text);
+
+    QCOMPARE(alice.decrypt(mes), CryptResult::OTR);
+    QVERIFY(alice.mesQueue.empty());
+    QVERIFY(!alice.eventQueue.empty());
+
+    Message eventMsg = alice.eventQueue.back();
+    alice.eventQueue.clear();
+
+    QCOMPARE(eventMsg.getOTRevent(), OTRL_MSGEVENT_RCVDMSG_UNENCRYPTED);
+    QCOMPARE(eventMsg.getOTRheader(QLatin1String("otr-unencrypted-message")), text);
+
+    mes.setText(text);
+    QCOMPARE(bob.encrypt(mes), CryptResult::CHANGED);
+
+    alice.mesQueue.clear();
+    alice.stopSession();
+    QCOMPARE(alice.trustLevel(), TrustLevel::NOT_PRIVATE);
+    QCOMPARE(alice.decrypt(mes), CryptResult::OTR);
+    QVERIFY(!alice.eventQueue.empty());
+    QVERIFY(!alice.mesQueue.empty());
+
+    eventMsg = alice.eventQueue.back();
+    QCOMPARE(eventMsg.getOTRevent(), OTRL_MSGEVENT_RCVDMSG_NOT_IN_PRIVATE);
+
+    QCOMPARE(bob.decrypt(alice.mesQueue.back()), CryptResult::OTR);
+    QVERIFY(bob.mesQueue.empty());
+    QVERIFY(bob.eventQueue.empty());
+    QCOMPARE(bob.trustLevel(), TrustLevel::FINISHED);
+}
+
+void OTRTest::testDoubleConversation()
+{
+    tst::SessionEnv johnEnv(tst::johnCtx, bobMan);
+    tst::SessionEnv aliceJEnv(tst::aliceJCtx, aliceMan);
+
+    TestSession &alice = aliceEnv->ses;
+    TestSession &aliceJ = aliceJEnv.ses;
+    TestSession &bob = bobEnv->ses;
+    TestSession &john = johnEnv.ses;
+
+    startSession(alice, bob);
+    startSession(aliceJ, john);
+
+    Message aliceToBob;
+    const QString aliceToBobText = QLatin1String("Hey Bob");
+    aliceToBob.setText(aliceToBobText);
+    QCOMPARE(alice.encrypt(aliceToBob), CryptResult::CHANGED);
+
+    Message aliceToJohn;
+    const QString aliceToJohnText = QLatin1String("Hello John");
+    aliceToJohn.setText(aliceToJohnText);
+    QCOMPARE(aliceJ.encrypt(aliceToJohn), CryptResult::CHANGED);
+
+    QCOMPARE(bob.decrypt(aliceToBob), CryptResult::CHANGED);
+    QCOMPARE(aliceToBob.text(), aliceToBobText);
+    QCOMPARE(john.decrypt(aliceToJohn), CryptResult::CHANGED);
+    QCOMPARE(aliceToJohn.text(), aliceToJohnText);
+
+    bob.stopSession();
+    QCOMPARE(alice.decrypt(bob.mesQueue.back()), CryptResult::OTR);
+    // john with alice still should have encrypted conversation
+
+    Message johnToAlice;
+    const QString johnToAliceText = QLatin1String("Hi Alice!!!");
+    johnToAlice.setText(johnToAliceText);
+    QCOMPARE(john.encrypt(johnToAlice), CryptResult::CHANGED);
+    QCOMPARE(aliceJ.decrypt(johnToAlice), CryptResult::CHANGED);
+    QCOMPARE(johnToAlice.text(), johnToAliceText);
+
+    QCOMPARE(aliceJ.trustLevel(), TrustLevel::UNVERIFIED);
+    QCOMPARE(john.trustLevel(), TrustLevel::UNVERIFIED);
+    QCOMPARE(bob.trustLevel(), TrustLevel::NOT_PRIVATE);
+    QCOMPARE(alice.trustLevel(), TrustLevel::FINISHED);
+}
+
 void OTRTest::cleanup()
 {
     delete aliceEnv;
@@ -340,6 +474,7 @@ void OTRTest::cleanup()
     delete aliceMan;
     QFile(aliceConfig.saveLocation() + tst::aliceCtx.accountId + QLatin1String("_fingerprints")).remove();
     QFile(bobConfig.saveLocation() + tst::bobCtx.accountId + QLatin1String("_fingerprints")).remove();
+    QFile(bobConfig.saveLocation() + tst::johnCtx.accountId + QLatin1String("_fingerprints")).remove();
     aliceConfig.setPolicy(OTRL_POLICY_MANUAL);
     bobConfig.setPolicy(OTRL_POLICY_MANUAL);
 }
diff --git a/otr-proxy/test/resources/bob_id_instags b/otr-proxy/test/resources/john_id_instags
similarity index 84%
copy from otr-proxy/test/resources/bob_id_instags
copy to otr-proxy/test/resources/john_id_instags
index 37ba6ff..e5fc12a 100644
--- a/otr-proxy/test/resources/bob_id_instags
+++ b/otr-proxy/test/resources/john_id_instags
@@ -1,2 +1,2 @@
 # WARNING! You shouldn't copy this file to another computer. It is unnecessary and can cause problems.
-Bob	talk	81439343
+John	talk	081526f7
diff --git a/otr-proxy/test/resources/john_id_privkeys b/otr-proxy/test/resources/john_id_privkeys
new file mode 100644
index 0000000..6009cf0
--- /dev/null
+++ b/otr-proxy/test/resources/john_id_privkeys
@@ -0,0 +1,15 @@
+(privkeys
+ (account
+(name John)
+(protocol talk)
+(private-key 
+ (dsa 
+  (p #00DE77EEA289F7569E0A0FEEF26DE81638CE4EA458EBAC82619AB60AADD046F8327509CABA3D4A6D38A98B806FE102294DA622D87D6FA1AF4D0CFEA825230855F312DD5AC14080B1159583412C8C678D76BA51EB17792D3DB7996AA5CEFC1AF0683603BD6D24C4532D5D7D0EF4BDDF6E1CFE85B1E3D2F67D6F82B5CD9C73837F3F#)
+  (q #00F440358BA2DF9527B67B371669BD27F7EC591E71#)
+  (g #738FC8B7992FD0A166DEF8BBAC5C82A0337582D9D1D08ED12E3A1990C0CAC0A45985BBDA52CEAE48079EF6173DAB293BB287476ABAC6649D09B77553259CD1D212578723B396E103AE85A07E28BA30B3FCDD27DB29935CB11AE7CD936F56CB17716C0B754F2140DD8A9EE5FA492E08FD7153FB913A638C82AB65616FB8579879#)
+  (y #0733C7337D540661BF284497D7FE6B63153C042FFF09C052AEB54EC428448F4E2EE89C3B364EF4AA3A6072C03AF65036B4943D354679631B53AC434375E01DFC0CCCA43797F84B13039DF058871174B086E95BA2B0FF0BFC5F9B2D897F5F80E6AF91C4F1754219F3EBEEDD9E0CCD71BAF2FBA33763C0DE63D10E61341151C227#)
+  (x #70E83822B06032797FCA0527B045374F76C22DBD#)
+  )
+ )
+ )
+)

-- 
ktp-common-internals packaging



More information about the pkg-kde-commits mailing list