From: Krzysztof Jackiewicz Date: Fri, 28 Jun 2019 16:00:22 +0000 (+0200) Subject: Stop ode.socket together with ode.service X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=81df705544bba0c29c0318412121497739c2c34e;p=platform%2Fcore%2Ftest%2Fsecurity-tests.git Stop ode.socket together with ode.service Oded became socket activated. To test the connection refusal the socket has to be put down as well. Change-Id: Ifec50d1198ceeee7e5ac131715cbd8ca642427e5 --- diff --git a/src/ode/ode-tests-common.cpp b/src/ode/ode-tests-common.cpp index 651ded75..fd827034 100644 --- a/src/ode/ode-tests-common.cpp +++ b/src/ode/ode-tests-common.cpp @@ -18,8 +18,11 @@ * @brief Tests for the ODE API */ +#include + #include #include +#include #include @@ -83,3 +86,24 @@ HelperInternalEncryption::~HelperInternalEncryption() { ode_internal_encryption_umount(); ode_internal_encryption_clean_password(pass); } + +std::unique_ptr> createScopedOdeStopper() { + auto sm_start = [](ServiceManager* sm) { + try { + sm->startService(true); + delete sm; + sleep(1); + //TODO: startService should wait until the sm is really started but it does not + // because of that the sleep is needed + } catch (...) { + RUNNER_ERROR_MSG("Unexpected exception during service startup"); + } + }; + std::unique_ptr sm_stop( + new ServiceManager("ode.service", { "ode.socket" }), + std::move(sm_start)); + + sm_stop->stopService(true); + + return sm_stop; +} diff --git a/src/ode/ode-tests-common.h b/src/ode/ode-tests-common.h index b15440c2..0151b9cc 100644 --- a/src/ode/ode-tests-common.h +++ b/src/ode/ode-tests-common.h @@ -21,6 +21,10 @@ #pragma once #include +#include +#include + +#include #include @@ -120,3 +124,5 @@ public: HelperInternalEncryption(const char* password); ~HelperInternalEncryption(); }; + +std::unique_ptr> createScopedOdeStopper(); diff --git a/src/ode/ode-tests-internal-encryption.cpp b/src/ode/ode-tests-internal-encryption.cpp index 61559eda..881ecaa4 100644 --- a/src/ode/ode-tests-internal-encryption.cpp +++ b/src/ode/ode-tests-internal-encryption.cpp @@ -236,15 +236,7 @@ RUNNER_TEST(T1019_internal_encryption_get_state_1_invalid_parameter) RUNNER_TEST(T1020_internal_encryption_connection_refused) { - auto sm_start = [](ServiceManager* sm) { - sm->startService(true); - delete sm; - sleep(1); - //TODO: startService should wait until the sm is really started but it does not - // because of that the sleep is needed - }; - std::unique_ptr sm_stop(new ServiceManager("ode.service"), sm_start); - sm_stop->stopService(true); + auto sm_stop = createScopedOdeStopper(); unsigned int options = 0; bool result; diff --git a/src/ode/ode-tests-keys.cpp b/src/ode/ode-tests-keys.cpp index 0fd8d7b6..3596a296 100644 --- a/src/ode/ode-tests-keys.cpp +++ b/src/ode/ode-tests-keys.cpp @@ -26,7 +26,6 @@ #include #include #include -#include #include #include "ode-tests-common.h" @@ -292,12 +291,7 @@ RUNNER_TEST(T2016_ode_keys_connection_refused) { HelperKeys helper(device1, password); - auto sm_start = [](ServiceManager* sm) { - sm->startService(true); - delete sm; - }; - std::unique_ptr sm_stop(new ServiceManager("ode.service"), sm_start); - sm_stop->stopService(true); + auto sm_stop = createScopedOdeStopper(); bool result;