[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:19 UTC 2016
Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-common-internals.git;a=commitdiff;h=c4f089b
The following commit has been merged in the master branch:
commit c4f089b65f6ce0b0b1c4f2f37f70178d521d4b5b
Author: Marcin Ziemiński <zieminn at gmail.com>
Date: Fri Jul 25 21:20:55 2014 +0200
Added basic tests for OTR and fixed bugs in Session.
Signed-off-by: Marcin Ziemiński <zieminn at gmail.com>
---
otr-proxy/CMakeLists.txt | 2 +
otr-proxy/KTpProxy/CMakeLists.txt | 9 +-
otr-proxy/KTpProxy/otr-config.h | 2 +-
otr-proxy/KTpProxy/otr-constants.h | 8 +-
otr-proxy/KTpProxy/otr-handler.h | 69 -------
otr-proxy/KTpProxy/otr-manager.cpp | 30 +--
otr-proxy/KTpProxy/otr-manager.h | 2 +-
otr-proxy/KTpProxy/otr-session.cpp | 57 +++---
otr-proxy/KTpProxy/otr-session.h | 5 +-
otr-proxy/test/CMakeLists.txt | 10 +-
otr-proxy/test/example-test.cpp | 16 --
otr-proxy/test/lib/CMakeLists.txt | 7 +
.../otr-config.h => test/lib/test-config.cpp} | 40 ++--
.../otr-config.h => test/lib/test-config.h} | 24 +--
.../otr-constants.h => test/lib/test-session.cpp} | 47 ++---
.../otr-config.h => test/lib/test-session.h} | 29 +--
otr-proxy/test/otr-test.cpp | 212 +++++++++++++++++++++
otr-proxy/test/resources/alice_id_instags | 2 +
otr-proxy/test/resources/alice_id_privkeys | 15 ++
otr-proxy/test/resources/bob_id_instags | 2 +
otr-proxy/test/resources/bob_id_privkeys | 15 ++
21 files changed, 397 insertions(+), 206 deletions(-)
diff --git a/otr-proxy/CMakeLists.txt b/otr-proxy/CMakeLists.txt
index 2077832..26fc0d0 100644
--- a/otr-proxy/CMakeLists.txt
+++ b/otr-proxy/CMakeLists.txt
@@ -11,6 +11,7 @@ set(CMAKE_MODULE_PATH
find_package (KDE4 ${KDE_MIN_VERSION} REQUIRED)
find_package (TelepathyQt4 0.9.1 REQUIRED)
find_package (TelepathyQt4Service 0.9.2.1 REQUIRED)
+find_package (LibOTR 4.0.0 REQUIRED)
find_package (Libgcrypt REQUIRED)
FIND_LIBRARY (LIBGCRYPT_LIBS NAMES gcrypt)
@@ -28,6 +29,7 @@ add_definitions (-std=c++11)
configure_file(version.h.in ${CMAKE_CURRENT_BINARY_DIR}/version.h @ONLY)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
+include_directories(${CMAKE_CURRENT_SOURCE_DIR})
add_subdirectory(KTpProxy)
add_subdirectory(data)
diff --git a/otr-proxy/KTpProxy/CMakeLists.txt b/otr-proxy/KTpProxy/CMakeLists.txt
index a3ea9d4..5c220e7 100644
--- a/otr-proxy/KTpProxy/CMakeLists.txt
+++ b/otr-proxy/KTpProxy/CMakeLists.txt
@@ -1,5 +1,4 @@
set(ktp-proxy_SRCS
- main.cpp
proxy-observer.cpp
proxy-service-adaptee.cpp
proxy-service.cpp
@@ -13,6 +12,8 @@ set(ktp-proxy_SRCS
otr-message.cpp
)
+kde4_add_library(ktp-proxy-lib STATIC ${ktp-proxy_SRCS})
+
set(ktp-proxy_LIBS
${KDE4_KDECORE_LIBS}
${KDE4_KDEUI_LIBS}
@@ -23,7 +24,9 @@ set(ktp-proxy_LIBS
${LIBGCRYPT_LIBRARIES}
)
-kde4_add_executable(ktp-proxy ${ktp-proxy_SRCS})
+target_link_libraries(ktp-proxy-lib ${ktp-proxy_LIBS})
+
+kde4_add_executable(ktp-proxy main.cpp)
+target_link_libraries(ktp-proxy ktp-proxy-lib)
-target_link_libraries(ktp-proxy ${ktp-proxy_LIBS})
install(TARGETS ktp-proxy DESTINATION ${LIBEXEC_INSTALL_DIR})
diff --git a/otr-proxy/KTpProxy/otr-config.h b/otr-proxy/KTpProxy/otr-config.h
index de110ac..d86824b 100644
--- a/otr-proxy/KTpProxy/otr-config.h
+++ b/otr-proxy/KTpProxy/otr-config.h
@@ -32,7 +32,7 @@ namespace OTR
class Config
{
public:
- virtual ~Config() = 0;
+ virtual ~Config() = default;
virtual QString saveLocation() = 0;
virtual OtrlPolicy getPolicy() const = 0;
diff --git a/otr-proxy/KTpProxy/otr-constants.h b/otr-proxy/KTpProxy/otr-constants.h
index 0501413..16a442a 100644
--- a/otr-proxy/KTpProxy/otr-constants.h
+++ b/otr-proxy/KTpProxy/otr-constants.h
@@ -39,10 +39,10 @@ namespace OTR
enum class CryptResult : unsigned int
{
- UNCHANGED,
- CHANGED,
- INGORE,
- ERROR
+ UNCHANGED, // message was returned untouched
+ CHANGED, // message was either encrypted or decrypted
+ OTR, // message is an OTR specific message
+ ERROR // error during encryption or decryption operation
};
template <typename T> unsigned int toUInt(T &&t)
diff --git a/otr-proxy/KTpProxy/otr-handler.h b/otr-proxy/KTpProxy/otr-handler.h
deleted file mode 100644
index abb8448..0000000
--- a/otr-proxy/KTpProxy/otr-handler.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/***************************************************************************
- * Copyright (C) 2014 by Marcin Ziemiński <zieminn at gmail.com> *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2.1 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the *
- * Free Software Foundation, Inc., *
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
- ***************************************************************************/
-
-#ifndef KTP_PROXY_OTR_HANDLER_HEADER
-#define KTP_PROXY_OTR_HANDLER_HEADER
-
-#include "otr-message.h"
-
-#include <QSharedPointer>
-
-extern "C" {
-#include <gcrypt.h>
-#include <libotr/privkey.h>
-#include <libotr/proto.h>
-#include <libotr/message.h>
-#include <libotr/userstate.h>
-}
-
-namespace OTR
-{
- struct SessionContext
- {
- const QString accountId;
- const QString accountName;
- const QString recipientName;
- const QString protocol;
- };
-
- class Handler
- {
- public:
- virtual ~Handler();
- virtual const SessionContext& context() const = 0;
-
- virtual void handleMessage(const Message &message) = 0;
- virtual void handleSmpEvent(OtrlSMPEvent smpEvent) = 0;
- /**
- * State of the recipient
- * 1 - logged in
- * 0 - not logged in
- * -1 - not sure if logged in
- */
- virtual int recipientStatus() const = 0;
- virtual unsigned int maxMessageSize() const = 0;
-
- virtual void onTrustLevelChanged(TrustLevel trustLevel) = 0;
- virtual void onSessionRefreshed() = 0;
- virtual void onNewFingeprintReceived(const QString &fingeprint) = 0;
- };
- typedef QSharedPointer<Handler> HandlerPtr;
-}
-
-#endif
diff --git a/otr-proxy/KTpProxy/otr-manager.cpp b/otr-proxy/KTpProxy/otr-manager.cpp
index ce04e69..4fb63ec 100644
--- a/otr-proxy/KTpProxy/otr-manager.cpp
+++ b/otr-proxy/KTpProxy/otr-manager.cpp
@@ -29,7 +29,7 @@ namespace {
{
if(context == NULL) return;
- TrustLevel level;
+ TrustLevel level = TrustLevel::NOT_PRIVATE;
switch(context->msgstate) {
case OTRL_MSGSTATE_PLAINTEXT:
level = TrustLevel::NOT_PRIVATE;
@@ -37,9 +37,9 @@ namespace {
case OTRL_MSGSTATE_ENCRYPTED:
{
if(otrl_context_is_fingerprint_trusted(context->active_fingerprint)) {
- level = TrustLevel::UNVERIFIED;
- } else {
level = TrustLevel::VERIFIED;
+ } else {
+ level = TrustLevel::UNVERIFIED;
}
break;
}
@@ -157,9 +157,9 @@ namespace {
char *err_msg = 0;
switch (err_code)
{
- case OTRL_ERRCODE_NONE :
+ case OTRL_ERRCODE_NONE:
break;
- case OTRL_ERRCODE_ENCRYPTION_ERROR :
+ case OTRL_ERRCODE_ENCRYPTION_ERROR:
{
QString message = QLatin1String("Error occurred encrypting message.");
err_msg = new char[message.length() + 1];
@@ -167,7 +167,7 @@ namespace {
memcpy(err_msg, message.toUtf8().data(), message.length());
break;
}
- case OTRL_ERRCODE_MSG_NOT_IN_PRIVATE :
+ case OTRL_ERRCODE_MSG_NOT_IN_PRIVATE:
if (context) {
QString message = QString::fromLatin1("You sent encrypted data to %1, who wasn't expecting it.").
arg(QLatin1String(context->accountname));
@@ -176,7 +176,7 @@ namespace {
memcpy(err_msg, message.toUtf8().data(), message.length());
}
break;
- case OTRL_ERRCODE_MSG_UNREADABLE :
+ case OTRL_ERRCODE_MSG_UNREADABLE:
{
QString message = QLatin1String("You transmitted an unreadable encrypted message.");
err_msg = new char[message.length() + 1];
@@ -184,7 +184,7 @@ namespace {
memcpy(err_msg, message.toUtf8().data(), message.length());
break;
}
- case OTRL_ERRCODE_MSG_MALFORMED :
+ case OTRL_ERRCODE_MSG_MALFORMED:
{
QString message = QLatin1String("You transmitted a malformed data message.");
err_msg = new char[message.length() + 1];
@@ -361,7 +361,7 @@ namespace {
} /* anonymous namespace */
/** OTR ops struct ---------------------------------------------------------------------------- */
-namespace global
+namespace global
{
const OtrlMessageAppOps appOps = {
policy,
@@ -434,9 +434,9 @@ void Manager::setPolicy(OtrlPolicy policy)
void Manager::createNewPrivateKey(Session *session)
{
const QString path = config->saveLocation() + session->context().accountId + QLatin1String("_privkeys");
- otrl_privkey_generate(session->userStateBox()->userState(),
- path.toLocal8Bit(),
- session->context().accountName.toLocal8Bit(),
+ otrl_privkey_generate(session->userStateBox()->userState(),
+ path.toLocal8Bit(),
+ session->context().accountName.toLocal8Bit(),
session->context().protocol.toLocal8Bit());
}
@@ -449,9 +449,9 @@ void Manager::saveFingerprints(Session *session)
void Manager::createInstag(Session *session)
{
const QString path = config->saveLocation() + session->context().accountId + QLatin1String("_instags");
- otrl_instag_generate(session->userStateBox()->userState(),
- path.toLocal8Bit(),
- session->context().accountName.toLocal8Bit(),
+ otrl_instag_generate(session->userStateBox()->userState(),
+ path.toLocal8Bit(),
+ session->context().accountName.toLocal8Bit(),
session->context().protocol.toLocal8Bit());
}
diff --git a/otr-proxy/KTpProxy/otr-manager.h b/otr-proxy/KTpProxy/otr-manager.h
index 4e5f384..81261d9 100644
--- a/otr-proxy/KTpProxy/otr-manager.h
+++ b/otr-proxy/KTpProxy/otr-manager.h
@@ -33,7 +33,7 @@ extern "C" {
namespace OTR
{
-namespace global
+namespace global
{
extern const OtrlMessageAppOps appOps;
}
diff --git a/otr-proxy/KTpProxy/otr-session.cpp b/otr-proxy/KTpProxy/otr-session.cpp
index 17879f8..0af2bd0 100644
--- a/otr-proxy/KTpProxy/otr-session.cpp
+++ b/otr-proxy/KTpProxy/otr-session.cpp
@@ -94,9 +94,9 @@ namespace OTR
QString Session::remoteFingerprint() const
{
- ConnContext *context = otrl_context_find(userstate->userState(),
+ ConnContext *context = otrl_context_find(userstate->userState(),
ctx.recipientName.toLocal8Bit(),
- ctx.accountName.toLocal8Bit(),
+ ctx.accountName.toLocal8Bit(),
ctx.protocol.toLocal8Bit(),
instance, 0, NULL, NULL, NULL);
@@ -120,10 +120,8 @@ namespace OTR
return msg;
}
- Message Session::stopSession()
+ void Session::stopSession()
{
- Message msg;
-
otrl_message_disconnect(
userstate->userState(),
&global::appOps,
@@ -133,14 +131,11 @@ namespace OTR
ctx.recipientName.toLocal8Bit(),
instance);
- emit sessionStopped();
- return msg;
+ onTrustLevelChanged(TrustLevel::NOT_PRIVATE, NULL);
}
CryptResult Session::encrypt(Message &message)
{
- return CryptResult::UNCHANGED;
-
if(otrl_proto_message_type(message.text().toLocal8Bit()) == OTRL_MSGTYPE_NOTOTR) {
char *encMessage = 0;
@@ -175,7 +170,7 @@ namespace OTR
otrl_message_free(encMessage);
return CryptResult::CHANGED;
- }
+ }
}
return CryptResult::UNCHANGED;
@@ -183,11 +178,13 @@ namespace OTR
CryptResult Session::decrypt(Message &message)
{
- CryptResult result = CryptResult::INGORE;
+ CryptResult result = CryptResult::OTR;
char *decMsg = NULL;
OtrlTLV *tlvs = NULL;
ConnContext *context = NULL;
+ bool isFinished = false;
+
int ignore = otrl_message_receiving(
userstate->userState(),
&global::appOps,
@@ -197,32 +194,35 @@ namespace OTR
ctx.recipientName.toLocal8Bit(),
message.text().toLocal8Bit(),
&decMsg,
- &tlvs,
+ &tlvs,
&context, NULL, NULL);
if(otrl_tlv_find(tlvs, OTRL_TLV_DISCONNECTED) != NULL) {
- // TODO contact finished the conversation with us
+ isFinished = true;
}
otrl_tlv_free(tlvs);
- if(!ignore && decMsg != NULL) {
-
- 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);
+ if(!ignore) {
+ if(decMsg != NULL) {
+ 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);
+ }
+ result = CryptResult::CHANGED;
+ } else {
+ result = CryptResult::UNCHANGED;
}
- result = CryptResult::CHANGED;
- } else if(decMsg == NULL) {
-
- result = CryptResult::UNCHANGED;
} else {
-
- result = CryptResult::INGORE;
+ result = CryptResult::OTR;
}
if(decMsg != NULL) {
- otrl_message_free(decMsg);
+ otrl_message_free(decMsg);
+ }
+
+ if(isFinished) {
+ onTrustLevelChanged(TrustLevel::FINISHED, NULL);
}
return result;
@@ -230,7 +230,9 @@ namespace OTR
void Session::onTrustLevelChanged(TrustLevel trustLevel, const ConnContext *context)
{
- instance = context->their_instance;
+ if(context != NULL) {
+ instance = context->their_instance;
+ }
tlevel = trustLevel;
emit trustLevelChanged(trustLevel);
}
@@ -242,6 +244,7 @@ namespace OTR
void Session::onNewFingerprintReceived(const QString &fingerprint)
{
+ //qDebug() << "Received";
emit newFingeprintReceived(fingerprint);
}
diff --git a/otr-proxy/KTpProxy/otr-session.h b/otr-proxy/KTpProxy/otr-session.h
index b708d63..d37c21e 100644
--- a/otr-proxy/KTpProxy/otr-session.h
+++ b/otr-proxy/KTpProxy/otr-session.h
@@ -69,6 +69,7 @@ namespace OTR
public:
Session(const SessionContext &context, Manager *parent);
+ virtual ~Session() = default;
UserStateBox* userStateBox();
Manager* parent();
@@ -78,8 +79,7 @@ namespace OTR
/** Returns OTR init message */
Message startSession();
- /** Returns OTR disconnect message */
- Message stopSession();
+ void stopSession();
CryptResult encrypt(Message &message);
CryptResult decrypt(Message &message);
void verifyFingerprint();
@@ -98,7 +98,6 @@ namespace OTR
Q_SIGNALS:
void trustLevelChanged(TrustLevel trustLevel);
void sessionRefreshed();
- void sessionStopped();
void newFingeprintReceived(const QString &fingeprint);
private:
diff --git a/otr-proxy/test/CMakeLists.txt b/otr-proxy/test/CMakeLists.txt
index e822795..38f08f7 100644
--- a/otr-proxy/test/CMakeLists.txt
+++ b/otr-proxy/test/CMakeLists.txt
@@ -1,3 +1,5 @@
+add_subdirectory(lib)
+
set(ktp-proxy-test_LIBS
${KDE4_KDECORE_LIBS}
${KDE4_KDEUI_LIBS}
@@ -5,6 +7,7 @@ set(ktp-proxy-test_LIBS
${QT_QTTEST_LIBRARY}
${TELEPATHY_QT4_LIBRARIES}
${TELEPATHY_QT4_SERVICE_LIBRARIES}
+ ktp-proxy-test-lib
)
message("-- Adding test files:")
@@ -28,4 +31,9 @@ foreach(test ${TEST_NAMES})
message("-- " ${test})
endforeach()
-ADD_CUSTOM_TARGET(check COMMAND ${CMAKE_CTEST_COMMAND} DEPENDS ${TEST_NAMES})
+add_custom_target(copy_resources)
+add_custom_command(TARGET copy_resources PRE_BUILD
+ COMMAND ${CMAKE_COMMAND} -E copy_directory
+ ${CMAKE_CURRENT_SOURCE_DIR}/resources ${CMAKE_CURRENT_BINARY_DIR}/resources)
+
+ADD_CUSTOM_TARGET(check COMMAND ${CMAKE_CTEST_COMMAND} DEPENDS ${TEST_NAMES} copy_resources)
diff --git a/otr-proxy/test/example-test.cpp b/otr-proxy/test/example-test.cpp
deleted file mode 100644
index 2e0473f..0000000
--- a/otr-proxy/test/example-test.cpp
+++ /dev/null
@@ -1,16 +0,0 @@
-#include <QtCore>
-#include <QtTest>
-
-class ExampleTest : public QObject
-{
- Q_OBJECT
-
-private Q_SLOTS:
- void testDummy()
- {
- QVERIFY(true);
- }
-};
-
-QTEST_MAIN(ExampleTest)
-#include "example-test.moc"
diff --git a/otr-proxy/test/lib/CMakeLists.txt b/otr-proxy/test/lib/CMakeLists.txt
new file mode 100644
index 0000000..5f94766
--- /dev/null
+++ b/otr-proxy/test/lib/CMakeLists.txt
@@ -0,0 +1,7 @@
+set(ktp-proxy-test-lib_SRCS
+ test-session.cpp
+ test-config.cpp
+)
+
+kde4_add_library(ktp-proxy-test-lib STATIC ${ktp-proxy-test-lib_SRCS})
+target_link_libraries(ktp-proxy-test-lib ktp-proxy-lib)
diff --git a/otr-proxy/KTpProxy/otr-config.h b/otr-proxy/test/lib/test-config.cpp
similarity index 74%
copy from otr-proxy/KTpProxy/otr-config.h
copy to otr-proxy/test/lib/test-config.cpp
index de110ac..cf62fea 100644
--- a/otr-proxy/KTpProxy/otr-config.h
+++ b/otr-proxy/test/lib/test-config.cpp
@@ -17,29 +17,35 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
-#ifndef KTP_PROXY_OTR_CONFIG_HEADER
-#define KTP_PROXY_OTR_CONFIG_HEADER
-
-#include <QString>
-
-extern "C" {
-#include <libotr/proto.h>
-}
+#include "test-config.h"
namespace OTR
{
- class Config
+ TestConfig::TestConfig()
+ : sloc(QLatin1String("./resources/")),
+ policy(OTRL_POLICY_MANUAL)
{
- public:
- virtual ~Config() = 0;
+ }
- virtual QString saveLocation() = 0;
- virtual OtrlPolicy getPolicy() const = 0;
- virtual void setPolicy(OtrlPolicy policy) = 0;
+ QString TestConfig::saveLocation()
+ {
+ return sloc;
+ }
- };
+ void TestConfig::setSaveLocation(const QString &sloc)
+ {
+ this->sloc = sloc;
+ }
-} /* namespace OTR */
+ OtrlPolicy TestConfig::getPolicy() const
+ {
+ return policy;
+ }
+
+ void TestConfig::setPolicy(OtrlPolicy policy)
+ {
+ this->policy = policy;
+ }
-#endif
+} /* namespace OTR */
diff --git a/otr-proxy/KTpProxy/otr-config.h b/otr-proxy/test/lib/test-config.h
similarity index 76%
copy from otr-proxy/KTpProxy/otr-config.h
copy to otr-proxy/test/lib/test-config.h
index de110ac..d1dacf0 100644
--- a/otr-proxy/KTpProxy/otr-config.h
+++ b/otr-proxy/test/lib/test-config.h
@@ -17,27 +17,27 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
-#ifndef KTP_PROXY_OTR_CONFIG_HEADER
-#define KTP_PROXY_OTR_CONFIG_HEADER
+#ifndef KTP_PROXY_OTR_TEST_CONFIG_HEADER
+#define KTP_PROXY_OTR_TEST_CONFIG_HEADER
-#include <QString>
-
-extern "C" {
-#include <libotr/proto.h>
-}
+#include <KTpProxy/otr-config.h>
namespace OTR
{
- class Config
+ class TestConfig : public Config
{
public:
- virtual ~Config() = 0;
+ TestConfig();
- virtual QString saveLocation() = 0;
- virtual OtrlPolicy getPolicy() const = 0;
- virtual void setPolicy(OtrlPolicy policy) = 0;
+ virtual QString saveLocation();
+ void setSaveLocation(const QString &sloc);
+ virtual OtrlPolicy getPolicy() const;
+ virtual void setPolicy(OtrlPolicy policy);
+ private:
+ QString sloc;
+ OtrlPolicy policy;
};
} /* namespace OTR */
diff --git a/otr-proxy/KTpProxy/otr-constants.h b/otr-proxy/test/lib/test-session.cpp
similarity index 68%
copy from otr-proxy/KTpProxy/otr-constants.h
copy to otr-proxy/test/lib/test-session.cpp
index 0501413..2f442b7 100644
--- a/otr-proxy/KTpProxy/otr-constants.h
+++ b/otr-proxy/test/lib/test-session.cpp
@@ -17,38 +17,39 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
-#ifndef KTP_PROXY_OTR_CONSTANTS_HEADER
-#define KTP_PROXY_OTR_CONSTANTS_HEADER
+#include "test-session.h"
namespace OTR
{
- enum class TrustLevel : unsigned int
+
+ TestSession::TestSession(const SessionContext &context, Manager *parent)
+ : Session(context, parent)
+ {
+ }
+
+ void TestSession::handleMessage(const Message &message)
{
- NOT_PRIVATE = 0,
- UNVERIFIED = 1,
- VERIFIED = 2,
- FINISHED = 3
- };
+ if(message.isOTRevent()) {
+ eventQueue.push_back(message);
+ } else {
+ mesQueue.push_back(message);
+ }
+ }
- enum class MessageDirection : unsigned int
+ void TestSession::handleSmpEvent(OtrlSMPEvent smpEvent)
{
- TO_PEER,
- FROM_PEER,
- INTERNAL
- };
+ // NOT implemented yet
+ Q_UNUSED(smpEvent);
+ }
- enum class CryptResult : unsigned int
+ int TestSession::recipientStatus() const
{
- UNCHANGED,
- CHANGED,
- INGORE,
- ERROR
- };
+ // user is online
+ return 1;
+ }
- template <typename T> unsigned int toUInt(T &&t)
+ unsigned int TestSession::maxMessageSize() const
{
- return static_cast<unsigned int>(t);
+ return maxSize;
}
}
-
-#endif
diff --git a/otr-proxy/KTpProxy/otr-config.h b/otr-proxy/test/lib/test-session.h
similarity index 69%
copy from otr-proxy/KTpProxy/otr-config.h
copy to otr-proxy/test/lib/test-session.h
index de110ac..516c2aa 100644
--- a/otr-proxy/KTpProxy/otr-config.h
+++ b/otr-proxy/test/lib/test-session.h
@@ -17,29 +17,30 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
-#ifndef KTP_PROXY_OTR_CONFIG_HEADER
-#define KTP_PROXY_OTR_CONFIG_HEADER
+#ifndef KTP_PROXY_OTR_TEST_SESSION_HEADER
+#define KTP_PROXY_OTR_TEST_SESSION_HEADER
-#include <QString>
+#include <KTpProxy/otr-session.h>
+#include <KTpProxy/otr-message.h>
-extern "C" {
-#include <libotr/proto.h>
-}
+#include <QList>
namespace OTR
{
-
- class Config
+ class TestSession : public Session
{
public:
- virtual ~Config() = 0;
+ TestSession(const SessionContext &context, Manager *parent);
- virtual QString saveLocation() = 0;
- virtual OtrlPolicy getPolicy() const = 0;
- virtual void setPolicy(OtrlPolicy policy) = 0;
+ virtual void handleMessage(const Message &message);
+ virtual void handleSmpEvent(OtrlSMPEvent smpEvent);
+ virtual int recipientStatus() const;
+ virtual unsigned int maxMessageSize() const;
+ uint maxSize = 1000000;
+ QList<Message> mesQueue;
+ QList<Message> eventQueue;
};
-
-} /* namespace OTR */
+}
#endif
diff --git a/otr-proxy/test/otr-test.cpp b/otr-proxy/test/otr-test.cpp
new file mode 100644
index 0000000..8f086a8
--- /dev/null
+++ b/otr-proxy/test/otr-test.cpp
@@ -0,0 +1,212 @@
+/***************************************************************************
+ * Copyright (C) 2014 by Marcin Ziemiński <zieminn at gmail.com> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2.1 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
+ ***************************************************************************/
+
+#include "lib/test-config.h"
+#include "lib/test-session.h"
+
+#include <KTpProxy/otr-manager.h>
+
+#include <QtCore>
+#include <QtTest>
+#include <QtDebug>
+#include <QEventLoop>
+#include <QMap>
+#include <QFile>
+
+extern "C" {
+#include <libotr/privkey.h>
+#include <libotr/proto.h>
+#include <libotr/message.h>
+#include <libotr/userstate.h>
+}
+
+using namespace OTR;
+
+namespace tst {
+
+ const SessionContext aliceCtx =
+ {
+ QLatin1String("alice_id"),
+ QLatin1String("Alice"),
+ QLatin1String("Bob"),
+ QLatin1String("talk")
+ };
+
+ const SessionContext bobCtx =
+ {
+ QLatin1String("bob_id"),
+ QLatin1String("Bob"),
+ QLatin1String("Alice"),
+ QLatin1String("talk")
+ };
+
+ class SessionEnv : public QObject
+ {
+ Q_OBJECT;
+
+ public:
+ SessionEnv(const SessionContext &ctx, Manager *manager)
+ : ses(ctx, manager)
+ {
+ }
+
+ void reset()
+ {
+ lastFpRcv.clear();
+ sessionRefreshed = false;
+ lastTlevel = TrustLevel::NOT_PRIVATE;
+ }
+
+ public Q_SLOTS:
+ void onNewFingerprintReceived(const QString &fp)
+ {
+ lastFpRcv = fp;
+ }
+ void onSessionRefreshed()
+ {
+ sessionRefreshed = true;
+ }
+
+ void onTrustLevelChanged(TrustLevel tlevel)
+ {
+ lastTlevel = tlevel;
+ }
+
+ public:
+ TestSession ses;
+ QString lastFpRcv;
+ bool sessionRefreshed;
+ TrustLevel lastTlevel;
+ };
+
+} /* namespace tst */
+
+
+class OTRTest : public QObject
+{
+ Q_OBJECT
+
+ public:
+ OTRTest();
+
+ private Q_SLOTS:
+ void initTestCase();
+ void testSimpleSession();
+
+ void cleanup();
+
+ private:
+ TestConfig config;
+ Manager manager;
+};
+
+OTRTest::OTRTest()
+: manager(&config)
+{
+}
+
+void OTRTest::initTestCase()
+{
+ OTRL_INIT;
+}
+
+void OTRTest::testSimpleSession()
+{
+ tst::SessionEnv aliceEnv(tst::aliceCtx, &manager);
+ tst::SessionEnv bobEnv(tst::bobCtx, &manager);
+ TestSession &alice = aliceEnv.ses;
+ TestSession &bob = bobEnv.ses;
+
+ QVERIFY(connect(&alice, SIGNAL(newFingeprintReceived(const QString&)),
+ &aliceEnv, SLOT(onNewFingerprintReceived(const QString&))));
+ QVERIFY(connect(&bob, SIGNAL(newFingeprintReceived(const QString&)),
+ &bobEnv, SLOT(onNewFingerprintReceived(const QString&))));
+
+ Message mes = alice.startSession();
+ QCOMPARE(mes.direction(), MessageDirection::TO_PEER);
+ QVERIFY(alice.mesQueue.empty());
+
+ QCOMPARE(bob.decrypt(mes), CryptResult::OTR);
+ QVERIFY(!bob.mesQueue.empty());
+ // session initialization
+ 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());
+
+ QVERIFY(!bobEnv.lastFpRcv.isEmpty());
+ QVERIFY(!aliceEnv.lastFpRcv.isEmpty());
+
+ QCOMPARE(bob.trustLevel(), TrustLevel::UNVERIFIED);
+ QCOMPARE(alice.trustLevel(), TrustLevel::UNVERIFIED);
+ // now the session is instantiated
+ // everything should be encrypted from now on
+
+ Message helloMsg;
+ const QString helloText = QLatin1String("No witej chopie!");
+ helloMsg.setText(helloText);
+ QCOMPARE(bob.encrypt(helloMsg), CryptResult::CHANGED);
+ QVERIFY(bob.eventQueue.empty());
+
+ QCOMPARE(alice.decrypt(helloMsg), CryptResult::CHANGED);
+ QVERIFY(alice.eventQueue.empty());
+ QCOMPARE(helloMsg.text(), helloText);
+
+ Message responseMsg;
+ const QString responseText = QLatin1String("Siema leszczu!");
+ responseMsg.setText(responseText);
+ QCOMPARE(alice.encrypt(responseMsg), CryptResult::CHANGED);
+ QVERIFY(alice.eventQueue.empty());
+
+ QCOMPARE(bob.decrypt(responseMsg), CryptResult::CHANGED);
+ QVERIFY(bob.eventQueue.empty());
+ QCOMPARE(responseMsg.text(), responseText);
+
+ bob.stopSession();
+ QVERIFY(!bob.mesQueue.empty());
+ QCOMPARE(alice.decrypt(bob.mesQueue.back()), CryptResult::OTR);
+ bob.mesQueue.pop_back();
+ QCOMPARE(bob.trustLevel(), TrustLevel::NOT_PRIVATE);
+ QCOMPARE(alice.trustLevel(), TrustLevel::FINISHED);
+ QVERIFY(alice.eventQueue.empty());
+ QVERIFY(bob.eventQueue.empty());
+}
+
+void OTRTest::cleanup()
+{
+ QFile(config.saveLocation() + tst::aliceCtx.accountId + QLatin1String("_fingerprints")).remove();
+ QFile(config.saveLocation() + tst::bobCtx.accountId + QLatin1String("_fingerprints")).remove();
+ manager.setPolicy(OTRL_POLICY_MANUAL); // default policy
+}
+
+
+QTEST_MAIN(OTRTest)
+#include "otr-test.moc"
diff --git a/otr-proxy/test/resources/alice_id_instags b/otr-proxy/test/resources/alice_id_instags
new file mode 100644
index 0000000..7a120ef
--- /dev/null
+++ b/otr-proxy/test/resources/alice_id_instags
@@ -0,0 +1,2 @@
+# WARNING! You shouldn't copy this file to another computer. It is unnecessary and can cause problems.
+Alice talk 8aedd696
diff --git a/otr-proxy/test/resources/alice_id_privkeys b/otr-proxy/test/resources/alice_id_privkeys
new file mode 100644
index 0000000..ab58e63
--- /dev/null
+++ b/otr-proxy/test/resources/alice_id_privkeys
@@ -0,0 +1,15 @@
+(privkeys
+ (account
+(name Alice)
+(protocol talk)
+(private-key
+ (dsa
+ (p #00AC6389656E8AC4D951385DAD680EEDD7C19F9474B65DE4DA208A29D2D06E4250BEAA218B8D8BF3FBCC04BA270A89D1F685F51041F6CB70D79F417B96716FFD838668EC88D9A76AEAD03CF9BAAC302220609AAF3460B3749DB8E6F1B9F375C1DAEED6C6FBFE892388A738335D3CCF789B4880673EAA8F9F5C7E693ED0E591359B#)
+ (q #00C9125F0514D9FA25D1AE818F6E23A32AD6D63963#)
+ (g #00A1EB9B80F5EA65CAA4B88C77E7577F68957A1A0F5E657A17B0E03094CD735F4A16313514B33BB6F7DCD5FE069F67D72ADF5293C3BDBC4C68FE0D87600348EB1463BC7F1E6F7510F3B50C2FC4A79BA8D8487B87AEB72BFB4B61656C59A7E38881061F42B171F6F2D1E48657955F75D158739ACDAC997CDFB6CE9D496DBCD2B181#)
+ (y #7DE0865AE98EA252C1C08336727AF6C90B4C28CC59012EE47606A6FDABC1A2F0D8D592F78169B7C1ED7AD5D0722EBCFE94C9E5A6F2499CD90996C94C8D3671C60C7AD0666B2A644C46604A2E3F739257717C364CC0D901B231E82F2BC66A34C3B6B726C911048F37869EE629179B9E2B19024DEB381D78ADC226774C0CC4AFAE#)
+ (x #00AA2A420B8366770CD0781AFDB3516934ACB08C6E#)
+ )
+ )
+ )
+)
diff --git a/otr-proxy/test/resources/bob_id_instags b/otr-proxy/test/resources/bob_id_instags
new file mode 100644
index 0000000..37ba6ff
--- /dev/null
+++ b/otr-proxy/test/resources/bob_id_instags
@@ -0,0 +1,2 @@
+# WARNING! You shouldn't copy this file to another computer. It is unnecessary and can cause problems.
+Bob talk 81439343
diff --git a/otr-proxy/test/resources/bob_id_privkeys b/otr-proxy/test/resources/bob_id_privkeys
new file mode 100644
index 0000000..81f87a8
--- /dev/null
+++ b/otr-proxy/test/resources/bob_id_privkeys
@@ -0,0 +1,15 @@
+(privkeys
+ (account
+(name Bob)
+(protocol talk)
+(private-key
+ (dsa
+ (p #00CD1235CB9CB32B2D568768BFE1461D1238B43DA198C76632FA4623F755B3AD2C0682590487F74E9C3BD52E5D18309BE7BF41740D07FCF2DA13D7AEF79689D367C12EFB6ECDF4BCD4E65B8DEF902E72A292A30A8FB803846539706BF736D61327FF052623ECC377BD934089FB9EC7EB6AE83DDBFBB28869388E718314AAEB342F#)
+ (q #00C3823F2389F6B9D68DC261DC7A5408220ED8BFE3#)
+ (g #008E79570C916709D1FE4EBD344042673DFD6B10DC9839F01C49E18CE7CF56D01CE5C8FFE4045B53A7DAF97CAE4552A14D32555809C8A1F70D281AEA0B175A5F31B23824513AEBE558A0175C2F0E17C65AD9B9801562569E2C96AD71135274CC0E6AB631DB7218566EF45BC16AEF27FA2E7B106F228324A370E50153E78AD87C1D#)
+ (y #00C23D43B9F03978101FC215C7201F1ADE7E8563AEF5A42ED0CA718E3E1831CB6B190DCB30A6294C3A85D11B38A6701CB6E5E9E7366B5988DCF17D064E1D2EC3BB1AEE3AA813CDD65EC7652B592365594AAF584FEFBA6C749571D50288BA5A1D580449456CBCEC6E86EE9F9BEADAC04DCE1E7B48121282295D740BBDF43E9BB931#)
+ (x #3F1A6BBED3F652AD881C0D38272F2C2C945B316F#)
+ )
+ )
+ )
+)
--
ktp-common-internals packaging
More information about the pkg-kde-commits
mailing list