From c08fb3bdb516ffed7177c2a63110215877d24f1e Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Mon, 10 Feb 2020 13:22:31 +0100 Subject: [PATCH] fix tests --- debian/rules | 2 +- nymea.pro | 2 +- tests/auto/api.json | 34 ++++++++++++++++++++++ tests/auto/auto.pro | 3 +- tests/auto/autotests.pri | 2 +- tests/auto/usermanager/testusermanager.cpp | 6 ++++ tests/utils/pushbuttonagent.cpp | 10 ++++--- tests/utils/pushbuttonagent.h | 4 +++ 8 files changed, 55 insertions(+), 8 deletions(-) diff --git a/debian/rules b/debian/rules index a122391f..7cbfdacb 100755 --- a/debian/rules +++ b/debian/rules @@ -47,7 +47,7 @@ override_dh_install: $(PREPROCESS_FILES:.in=) cp -a $(CURDIR)/doc/html $(CURDIR)/debian/nymea-doc/usr/share/doc/nymea/ || true override_dh_auto_test: - dh_auto_test -- -k TESTARGS="-m 120 -p -o -p -,txt -p -o -p test-results.xml,xunitxml" TESTRUNNER="dbus-test-runner --bus-type=session --task" + dh_auto_test -- -k TESTARGS="-m 120 -p -o -p -,txt -p -o -p test-results.xml,xunitxml" TESTRUNNER="dbus-test-runner --bus-type=both --task" override_dh_strip: dh_strip --dbg-package=nymea-dbg diff --git a/nymea.pro b/nymea.pro index ae3df7c8..245002b9 100644 --- a/nymea.pro +++ b/nymea.pro @@ -71,7 +71,7 @@ INSTALLS += translations QMAKE_EXTRA_TARGETS += lupdate lrelease test.depends += lrelease -test.commands = LD_LIBRARY_PATH=$$top_builddir/libnymea-core:$$top_builddir/libnymea:$$top_builddir/tests/testlib make check TESTRUNNER=\"dbus-test-runner --bus-type=system --task\" +test.commands = LD_LIBRARY_PATH=$$top_builddir/libnymea-core:$$top_builddir/libnymea:$$top_builddir/tests/testlib make check TESTRUNNER=\"dbus-test-runner --bus-type=both --task\" QMAKE_EXTRA_TARGETS += test # Show doc files in project tree diff --git a/tests/auto/api.json b/tests/auto/api.json index 8c9c78ec..af9fcd5f 100644 --- a/tests/auto/api.json +++ b/tests/auto/api.json @@ -848,6 +848,7 @@ } }, "JSONRPC.Authenticate": { + "deprecated": "Use Users.Authenticate instead.", "description": "Authenticate a client to the api via user & password challenge. Provide a device name which allows the user to identify the client and revoke the token in case the device is lost or stolen. This will return a new token to be used to authorize a client at the API.", "params": { "deviceName": "String", @@ -860,6 +861,7 @@ } }, "JSONRPC.CreateUser": { + "deprecated": "Use Users.CreateUser instead.", "description": "Create a new user in the API. Currently this is only allowed to be called once when a new nymea instance is set up. Call Authenticate after this to obtain a device token for this user.", "params": { "password": "String", @@ -930,6 +932,7 @@ } }, "JSONRPC.RequestPushButtonAuth": { + "deprecated": "Use Users.RequestPushButtonAuth instead.", "description": "Authenticate a client to the api via Push Button method. Provide a device name which allows the user to identify the client and revoke the token in case the device is lost or stolen. If push button hardware is available, this will return with success and start listening for push button presses. When the push button is pressed, the PushButtonAuthFinished notification will be sent to the requesting client. The procedure will be cancelled when the connection is interrupted. If another client requests push button authentication while a procedure is still going on, the second call will take over and the first one will be notified by the PushButtonAuthFinished signal about the error. The application should make it clear to the user to not press the button when the procedure fails as this can happen for 2 reasons: a) a second user is trying to auth at the same time and only the currently active user should press the button or b) it might indicate an attacker trying to take over and snooping in for tokens.", "params": { "deviceName": "String" @@ -1467,6 +1470,18 @@ "tagError": "$ref:TagError" } }, + "Users.Authenticate": { + "description": "Authenticate a client to the api via user & password challenge. Provide a device name which allows the user to identify the client and revoke the token in case the device is lost or stolen. This will return a new token to be used to authorize a client at the API.", + "params": { + "deviceName": "String", + "password": "String", + "username": "String" + }, + "returns": { + "o:token": "String", + "success": "Bool" + } + }, "Users.ChangePassword": { "description": "Change the password for the currently logged in user.", "params": { @@ -1512,6 +1527,16 @@ "returns": { "error": "$ref:UserError" } + }, + "Users.RequestPushButtonAuth": { + "description": "Authenticate a client to the api via Push Button method. Provide a device name which allows the user to identify the client and revoke the token in case the device is lost or stolen. If push button hardware is available, this will return with success and start listening for push button presses. When the push button is pressed, the PushButtonAuthFinished notification will be sent to the requesting client. The procedure will be cancelled when the connection is interrupted. If another client requests push button authentication while a procedure is still going on, the second call will take over and the first one will be notified by the PushButtonAuthFinished signal about the error. The application should make it clear to the user to not press the button when the procedure fails as this can happen for 2 reasons: a) a second user is trying to auth at the same time and only the currently active user should press the button or b) it might indicate an attacker trying to take over and snooping in for tokens.", + "params": { + "deviceName": "String" + }, + "returns": { + "success": "Bool", + "transactionId": "Int" + } } }, "notifications": { @@ -1664,6 +1689,7 @@ } }, "JSONRPC.PushButtonAuthFinished": { + "deprecated": "Use Users.PushButtonAuthFinished instead.", "description": "Emitted when a push button authentication reaches final state. NOTE: This notification is special. It will only be emitted to connections that did actively request a push button authentication, but also it will be emitted regardless of the notification settings. ", "params": { "o:token": "String", @@ -1862,6 +1888,14 @@ "params": { "tag": "$ref:Tag" } + }, + "Users.PushButtonAuthFinished": { + "description": "Emitted when a push button authentication reaches final state. NOTE: This notification is special. It will only be emitted to connections that did actively request a push button authentication, but also it will be emitted regardless of the notification settings.", + "params": { + "o:token": "String", + "success": "Bool", + "transactionId": "Int" + } } }, "types": { diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index 65057ddb..faf4edfe 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -1,6 +1,7 @@ TEMPLATE = subdirs -SUBDIRS = versioning \ +SUBDIRS = \ + versioning \ devices \ jsonrpc \ events \ diff --git a/tests/auto/autotests.pri b/tests/auto/autotests.pri index 7acc1e39..1b516476 100644 --- a/tests/auto/autotests.pri +++ b/tests/auto/autotests.pri @@ -15,5 +15,5 @@ LIBS += -L$$top_builddir/libnymea/ -lnymea \ target.path = /usr/tests INSTALLS += target -test.commands = LD_LIBRARY_PATH=../../../libnymea:../../../libnymea-core/:../../testlib/ make check TESTRUNNER=\"dbus-test-runner --bus-type=system --task\" +test.commands = LD_LIBRARY_PATH=../../../libnymea:../../../libnymea-core/:../../testlib/ make check TESTRUNNER=\"dbus-test-runner --bus-type=both --task\" QMAKE_EXTRA_TARGETS += test diff --git a/tests/auto/usermanager/testusermanager.cpp b/tests/auto/usermanager/testusermanager.cpp index 84b595e3..e59ae766 100644 --- a/tests/auto/usermanager/testusermanager.cpp +++ b/tests/auto/usermanager/testusermanager.cpp @@ -127,6 +127,7 @@ void TestUsermanager::initTestCase() "Application.debug=true\n" "Tests.debug=true\n" "UserManager.debug=true\n" + "PushButtonAgent.debug=true\n" "MockDevice.debug=true"); } @@ -222,6 +223,7 @@ void TestUsermanager::authenticatePushButton() QVariantMap params; params.insert("deviceName", "pbtestdevice"); QVariant response = injectAndWait("Users.RequestPushButtonAuth", params); + qCDebug(dcTests()) << "Pushbutton auth response:" << qUtf8Printable(QJsonDocument::fromVariant(response).toJson(QJsonDocument::Indented)); QCOMPARE(response.toMap().value("params").toMap().value("success").toBool(), true); int transactionId = response.toMap().value("params").toMap().value("transactionId").toInt(); @@ -233,6 +235,10 @@ void TestUsermanager::authenticatePushButton() if (clientSpy.count() == 0) clientSpy.wait(); QVariantMap rsp = checkNotification(clientSpy, "Users.PushButtonAuthFinished").toMap(); + for (int i = 0; i < clientSpy.count(); i++) { + qCDebug(dcTests()) << "Notification:" << clientSpy.at(i); + } + QCOMPARE(rsp.value("params").toMap().value("transactionId").toInt(), transactionId); QVERIFY2(!rsp.value("params").toMap().value("token").toByteArray().isEmpty(), "Token not in push button auth notification"); } diff --git a/tests/utils/pushbuttonagent.cpp b/tests/utils/pushbuttonagent.cpp index fff45291..87561ca7 100644 --- a/tests/utils/pushbuttonagent.cpp +++ b/tests/utils/pushbuttonagent.cpp @@ -25,6 +25,8 @@ #include #include +Q_LOGGING_CATEGORY(dcPushButtonAgent, "PushButtonAgent") + PushButtonAgent::PushButtonAgent(QObject *parent) : QObject(parent) { } @@ -35,7 +37,7 @@ bool PushButtonAgent::init(QDBusConnection::BusType busType) bool result = bus.registerObject("/nymea/pushbuttonhandler", this, QDBusConnection::ExportScriptableContents); if (!result) { - qDebug() << "Error registering PushButton agent on D-Bus."; + qCWarning(dcPushButtonAgent()) << "Error registering PushButton agent on D-Bus" << (busType == QDBusConnection::SessionBus ? "session" : "system") << "bus."; return false; } @@ -43,15 +45,15 @@ bool PushButtonAgent::init(QDBusConnection::BusType busType) message << qVariantFromValue(QDBusObjectPath("/nymea/pushbuttonhandler")); QDBusMessage reply = bus.call(message); if (!reply.errorName().isEmpty()) { - qDebug() << "Error registering PushButton agent:" << reply.errorMessage(); + qCWarning(dcPushButtonAgent()) << "Error registering PushButton agent:" << reply.errorMessage(); return false; } - qDebug() << "PushButton agent registered."; + qCDebug(dcPushButtonAgent()) << "PushButton agent registered."; return true; } void PushButtonAgent::sendButtonPressed() { - qDebug() << "Sending button pressed event."; + qCDebug(dcPushButtonAgent()) << "Sending button pressed event."; emit PushButtonPressed(); } diff --git a/tests/utils/pushbuttonagent.h b/tests/utils/pushbuttonagent.h index fdd957d4..3b57e57e 100644 --- a/tests/utils/pushbuttonagent.h +++ b/tests/utils/pushbuttonagent.h @@ -24,6 +24,10 @@ #include #include +#include + +Q_DECLARE_LOGGING_CATEGORY(dcPushButtonAgent) + class PushButtonAgent : public QObject { Q_OBJECT