From f8258df50088e0835895c17d8cfee52a6397c51a Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Fri, 2 Sep 2016 22:40:36 +0300 Subject: [PATCH 1/1] Added disabling of sessions log and filtering of params log. --- include/stg/settings.h | 2 + include/stg/user_property.h | 20 ++- projects/stargazer/settings_impl.cpp | 24 +++- projects/stargazer/settings_impl.h | 4 + projects/stargazer/user_impl.cpp | 12 +- projects/stargazer/user_property.cpp | 70 ++++----- tests/Makefile | 4 +- tests/Makefile.darwin | 2 + tests/test_disable_session_log.cpp | 152 ++++++++++++++++++++ tests/test_filter_params_log.cpp | 166 ++++++++++++++++++++++ tests/test_reconnect_on_tariff_change.cpp | 5 + tests/testauth.h | 2 +- tests/testservices.h | 6 +- tests/testsettings.h | 5 +- 14 files changed, 418 insertions(+), 56 deletions(-) create mode 100644 tests/test_disable_session_log.cpp create mode 100644 tests/test_filter_params_log.cpp diff --git a/include/stg/settings.h b/include/stg/settings.h index dd13d674..64be687f 100644 --- a/include/stg/settings.h +++ b/include/stg/settings.h @@ -45,6 +45,8 @@ public: virtual const std::string & GetMonitorDir() const = 0; virtual bool GetMonitoring() const = 0; virtual const std::vector & GetScriptParams() const = 0; + virtual bool GetDisableSessionLog() const = 0; + virtual const std::vector & GetFilterParamsLog() const = 0; }; //----------------------------------------------------------------------------- diff --git a/include/stg/user_property.h b/include/stg/user_property.h index 20ca6fd8..f024f457 100644 --- a/include/stg/user_property.h +++ b/include/stg/user_property.h @@ -18,6 +18,7 @@ $Author: faust $ #include "stg/logger.h" #include "stg/locker.h" +#include "stg/settings.h" #include "stg/scriptexecuter.h" #include "stg/common.h" @@ -76,7 +77,7 @@ public: bool isPassword, bool isStat, STG_LOGGER & logger, - const std::string & sd, + const SETTINGS & s, REGISTRY & properties); virtual ~USER_PROPERTY_LOGGED() {} @@ -112,7 +113,7 @@ private: bool isPassword; bool isStat; std::string name; - const std::string scriptsDir; + const SETTINGS& settings; }; //----------------------------------------------------------------------------- class USER_PROPERTIES : private NONCOPYABLE { @@ -130,7 +131,7 @@ private: REGISTRY properties; public: - USER_PROPERTIES(const std::string & sd); + USER_PROPERTIES(const SETTINGS& s); USER_STAT & Stat() { return stat; } USER_CONF & Conf() { return conf; } @@ -282,7 +283,7 @@ USER_PROPERTY_LOGGED::USER_PROPERTY_LOGGED(varT & val, bool isPass, bool isSt, STG_LOGGER & logger, - const std::string & sd, + const SETTINGS& s, REGISTRY & properties) : USER_PROPERTY(val), @@ -290,7 +291,7 @@ USER_PROPERTY_LOGGED::USER_PROPERTY_LOGGED(varT & val, isPassword(isPass), isStat(isSt), name(n), - scriptsDir(sd) + settings(s) { properties.insert(std::make_pair(ToLower(name), this)); } @@ -367,7 +368,12 @@ stgLogger("%s User \'%s\': \'%s\' parameter changed from \'%s\' to \'%s\'. %s", newValue.c_str(), msg.c_str()); -store->WriteUserChgLog(login, admin->GetLogin(), admin->GetIP(), parameter, oldValue, newValue, msg); +for (size_t i = 0; i < settings.GetFilterParamsLog().size(); ++i) + if (settings.GetFilterParamsLog()[i] == "*" || strcasecmp(settings.GetFilterParamsLog()[i].c_str(), parameter.c_str()) == 0) + { + store->WriteUserChgLog(login, admin->GetLogin(), admin->GetIP(), parameter, oldValue, newValue, msg); + return; + } } //------------------------------------------------------------------------- template @@ -377,7 +383,7 @@ void USER_PROPERTY_LOGGED::OnChange(const std::string & login, const std::string & newValue, const ADMIN * admin) { -std::string filePath = scriptsDir + "/OnChange"; +static std::string filePath = settings.GetScriptsDir() + "/OnChange"; if (access(filePath.c_str(), X_OK) == 0) { diff --git a/projects/stargazer/settings_impl.cpp b/projects/stargazer/settings_impl.cpp index c1a3951c..0cf9501b 100644 --- a/projects/stargazer/settings_impl.cpp +++ b/projects/stargazer/settings_impl.cpp @@ -62,8 +62,10 @@ SETTINGS_IMPL::SETTINGS_IMPL(const std::string & cd) messageTimeout(0), feeChargeType(0), reconnectOnTariffChange(false), + disableSessionLog(false), logger(GetStgLogger()) { + filterParamsLog.push_back("*"); } //----------------------------------------------------------------------------- SETTINGS_IMPL::SETTINGS_IMPL(const SETTINGS_IMPL & rval) @@ -93,6 +95,8 @@ SETTINGS_IMPL::SETTINGS_IMPL(const SETTINGS_IMPL & rval) messageTimeout(rval.messageTimeout), feeChargeType(rval.feeChargeType), reconnectOnTariffChange(rval.reconnectOnTariffChange), + disableSessionLog(rval.disableSessionLog), + filterParamsLog(rval.filterParamsLog), modulesSettings(rval.modulesSettings), storeModuleSettings(rval.storeModuleSettings), logger(GetStgLogger()) @@ -126,6 +130,8 @@ SETTINGS_IMPL & SETTINGS_IMPL::operator=(const SETTINGS_IMPL & rhs) messageTimeout = rhs.messageTimeout; feeChargeType = rhs.feeChargeType; reconnectOnTariffChange = rhs.reconnectOnTariffChange; + disableSessionLog = rhs.disableSessionLog; + filterParamsLog = rhs.filterParamsLog; modulesSettings = rhs.modulesSettings; storeModuleSettings = rhs.storeModuleSettings; @@ -385,6 +391,22 @@ while (node) } } + if (strcasecmp(node->getName(), "DisableSessionLog") == 0) + { + if (ParseYesNo(node->getValue(0), &disableSessionLog) != 0) + { + strError = "Incorrect DisableSessionLog value: \'" + std::string(node->getValue(0)) + "\'"; + return -1; + } + } + + if (strcasecmp(node->getName(), "FilterParamsLog") == 0) + { + filterParamsLog.clear(); + for (int i = 0; node->getValue(i) != NULL; ++i) + filterParamsLog.push_back(node->getValue(i)); + } + if (strcasecmp(node->getName(), "DirNames") == 0) { const DOTCONFDocumentNode * child = node->getChildNode(); @@ -454,9 +476,7 @@ while (node) if (strcasecmp(node->getName(), "ScriptParams") == 0) { for (int i = 0; node->getValue(i) != NULL; ++i) - { scriptParams.push_back(node->getValue(i)); - } } node = node->getNextNode(); } diff --git a/projects/stargazer/settings_impl.h b/projects/stargazer/settings_impl.h index 253b8bbc..cc35393b 100644 --- a/projects/stargazer/settings_impl.h +++ b/projects/stargazer/settings_impl.h @@ -92,6 +92,8 @@ public: unsigned GetMessageTimeout() const { return messageTimeout * 3600 * 24; } unsigned GetFeeChargeType() const { return feeChargeType; } bool GetReconnectOnTariffChange() const { return reconnectOnTariffChange; } + bool GetDisableSessionLog() const { return disableSessionLog; } + const std::vector & GetFilterParamsLog() const { return filterParamsLog; } const std::string & GetModulesPath() const { return modulesPath; } const MODULE_SETTINGS & GetStoreModuleSettings() const @@ -135,6 +137,8 @@ private: unsigned messageTimeout; unsigned feeChargeType; bool reconnectOnTariffChange; + bool disableSessionLog; + std::vector filterParamsLog; std::vector modulesSettings; MODULE_SETTINGS storeModuleSettings; diff --git a/projects/stargazer/user_impl.cpp b/projects/stargazer/user_impl.cpp index d7bc8ea2..55a0b197 100644 --- a/projects/stargazer/user_impl.cpp +++ b/projects/stargazer/user_impl.cpp @@ -80,7 +80,7 @@ USER_IMPL::USER_IMPL(const SETTINGS * s, const USERS * u, const SERVICES & svcs) : users(u), - property(s->GetScriptsDir()), + property(*s), WriteServLog(GetStgLogger()), lastScanMessages(0), id(0), @@ -150,7 +150,7 @@ USER_IMPL::USER_IMPL(const SETTINGS_IMPL * s, const USERS * u, const SERVICES & svcs) : users(u), - property(s->GetScriptsDir()), + property(*s), WriteServLog(GetStgLogger()), lastScanMessages(0), id(0), @@ -237,7 +237,7 @@ pthread_mutex_init(&mutex, &attr); USER_IMPL::USER_IMPL(const USER_IMPL & u) : USER(), users(u.users), - property(u.settings->GetScriptsDir()), + property(*u.settings), WriteServLog(GetStgLogger()), lastScanMessages(0), login(u.login), @@ -621,7 +621,7 @@ if (!fakeConnect) connected = true; } -if (store->WriteUserConnect(login, currIP)) +if (!settings->GetDisableSessionLog() && store->WriteUserConnect(login, currIP)) { WriteServLog("Cannot write connect for user %s.", login.c_str()); WriteServLog("%s", store->GetStrError().c_str()); @@ -685,8 +685,8 @@ std::string reasonMessage(reason); if (!lastDisconnectReason.empty()) reasonMessage += ": " + lastDisconnectReason; -if (store->WriteUserDisconnect(login, up, down, sessionUpload, sessionDownload, - cash, freeMb, reasonMessage)) +if (!settings->GetDisableSessionLog() && store->WriteUserDisconnect(login, up, down, sessionUpload, sessionDownload, + cash, freeMb, reasonMessage)) { WriteServLog("Cannot write disconnect for user %s.", login.c_str()); WriteServLog("%s", store->GetStrError().c_str()); diff --git a/projects/stargazer/user_property.cpp b/projects/stargazer/user_property.cpp index c8b58917..26f7b936 100644 --- a/projects/stargazer/user_property.cpp +++ b/projects/stargazer/user_property.cpp @@ -1,41 +1,41 @@ #include "stg/user_property.h" -USER_PROPERTIES::USER_PROPERTIES(const std::string & sd) +USER_PROPERTIES::USER_PROPERTIES(const SETTINGS& s) : stat(), conf(), - cash (stat.cash, "cash", false, true, GetStgLogger(), sd, properties), - up (stat.monthUp, "upload", false, true, GetStgLogger(), sd, properties), - down (stat.monthDown, "download", false, true, GetStgLogger(), sd, properties), - lastCashAdd (stat.lastCashAdd, "lastCashAdd", false, true, GetStgLogger(), sd, properties), - passiveTime (stat.passiveTime, "passiveTime", false, true, GetStgLogger(), sd, properties), - lastCashAddTime (stat.lastCashAddTime, "lastCashAddTime", false, true, GetStgLogger(), sd, properties), - freeMb (stat.freeMb, "freeMb", false, true, GetStgLogger(), sd, properties), - lastActivityTime(stat.lastActivityTime, "lastActivityTime", false, true, GetStgLogger(), sd, properties), + cash (stat.cash, "cash", false, true, GetStgLogger(), s, properties), + up (stat.monthUp, "upload", false, true, GetStgLogger(), s, properties), + down (stat.monthDown, "download", false, true, GetStgLogger(), s, properties), + lastCashAdd (stat.lastCashAdd, "lastCashAdd", false, true, GetStgLogger(), s, properties), + passiveTime (stat.passiveTime, "passiveTime", false, true, GetStgLogger(), s, properties), + lastCashAddTime (stat.lastCashAddTime, "lastCashAddTime", false, true, GetStgLogger(), s, properties), + freeMb (stat.freeMb, "freeMb", false, true, GetStgLogger(), s, properties), + lastActivityTime(stat.lastActivityTime, "lastActivityTime", false, true, GetStgLogger(), s, properties), - password (conf.password, "password", true, false, GetStgLogger(), sd, properties), - passive (conf.passive, "passive", false, false, GetStgLogger(), sd, properties), - disabled (conf.disabled, "disabled", false, false, GetStgLogger(), sd, properties), - disabledDetailStat(conf.disabledDetailStat, "DisabledDetailStat", false, false, GetStgLogger(), sd, properties), - alwaysOnline(conf.alwaysOnline, "alwaysOnline", false, false, GetStgLogger(), sd, properties), - tariffName (conf.tariffName, "tariffName", false, false, GetStgLogger(), sd, properties), - nextTariff (conf.nextTariff, "nextTariff", false, false, GetStgLogger(), sd, properties), - address (conf.address, "address", false, false, GetStgLogger(), sd, properties), - note (conf.note, "note", false, false, GetStgLogger(), sd, properties), - group (conf.group, "group", false, false, GetStgLogger(), sd, properties), - email (conf.email, "email", false, false, GetStgLogger(), sd, properties), - phone (conf.phone, "phone", false, false, GetStgLogger(), sd, properties), - realName (conf.realName, "realName", false, false, GetStgLogger(), sd, properties), - credit (conf.credit, "credit", false, false, GetStgLogger(), sd, properties), - creditExpire(conf.creditExpire, "creditExpire", false, false, GetStgLogger(), sd, properties), - ips (conf.ips, "ips", false, false, GetStgLogger(), sd, properties), - userdata0 (conf.userdata[0], "userdata0", false, false, GetStgLogger(), sd, properties), - userdata1 (conf.userdata[1], "userdata1", false, false, GetStgLogger(), sd, properties), - userdata2 (conf.userdata[2], "userdata2", false, false, GetStgLogger(), sd, properties), - userdata3 (conf.userdata[3], "userdata3", false, false, GetStgLogger(), sd, properties), - userdata4 (conf.userdata[4], "userdata4", false, false, GetStgLogger(), sd, properties), - userdata5 (conf.userdata[5], "userdata5", false, false, GetStgLogger(), sd, properties), - userdata6 (conf.userdata[6], "userdata6", false, false, GetStgLogger(), sd, properties), - userdata7 (conf.userdata[7], "userdata7", false, false, GetStgLogger(), sd, properties), - userdata8 (conf.userdata[8], "userdata8", false, false, GetStgLogger(), sd, properties), - userdata9 (conf.userdata[9], "userdata9", false, false, GetStgLogger(), sd, properties) + password (conf.password, "password", true, false, GetStgLogger(), s, properties), + passive (conf.passive, "passive", false, false, GetStgLogger(), s, properties), + disabled (conf.disabled, "disabled", false, false, GetStgLogger(), s, properties), + disabledDetailStat(conf.disabledDetailStat, "DisabledDetailStat", false, false, GetStgLogger(), s, properties), + alwaysOnline(conf.alwaysOnline, "alwaysOnline", false, false, GetStgLogger(), s, properties), + tariffName (conf.tariffName, "tariffName", false, false, GetStgLogger(), s, properties), + nextTariff (conf.nextTariff, "nextTariff", false, false, GetStgLogger(), s, properties), + address (conf.address, "address", false, false, GetStgLogger(), s, properties), + note (conf.note, "note", false, false, GetStgLogger(), s, properties), + group (conf.group, "group", false, false, GetStgLogger(), s, properties), + email (conf.email, "email", false, false, GetStgLogger(), s, properties), + phone (conf.phone, "phone", false, false, GetStgLogger(), s, properties), + realName (conf.realName, "realName", false, false, GetStgLogger(), s, properties), + credit (conf.credit, "credit", false, false, GetStgLogger(), s, properties), + creditExpire(conf.creditExpire, "creditExpire", false, false, GetStgLogger(), s, properties), + ips (conf.ips, "ips", false, false, GetStgLogger(), s, properties), + userdata0 (conf.userdata[0], "userdata0", false, false, GetStgLogger(), s, properties), + userdata1 (conf.userdata[1], "userdata1", false, false, GetStgLogger(), s, properties), + userdata2 (conf.userdata[2], "userdata2", false, false, GetStgLogger(), s, properties), + userdata3 (conf.userdata[3], "userdata3", false, false, GetStgLogger(), s, properties), + userdata4 (conf.userdata[4], "userdata4", false, false, GetStgLogger(), s, properties), + userdata5 (conf.userdata[5], "userdata5", false, false, GetStgLogger(), s, properties), + userdata6 (conf.userdata[6], "userdata6", false, false, GetStgLogger(), s, properties), + userdata7 (conf.userdata[7], "userdata7", false, false, GetStgLogger(), s, properties), + userdata8 (conf.userdata[8], "userdata8", false, false, GetStgLogger(), s, properties), + userdata9 (conf.userdata[9], "userdata9", false, false, GetStgLogger(), s, properties) {} diff --git a/tests/Makefile b/tests/Makefile index 72acdd62..f615b1d6 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -8,7 +8,7 @@ INCS = -I . \ -I ../projects/stargazer DEFS = -DLINUX \ -DUSE_ABSTRACT_SETTINGS -CFLAGS += -g3 -Wall -W -Wextra $(INCS) $(DEFS) +CFLAGS += -g3 -Wall -W -Wextra -Wno-unused-function $(INCS) $(DEFS) CXXFLAGS += $(CFLAGS) LIBS = -lpthread PROG = tests @@ -20,6 +20,8 @@ SOURCES = main.cpp \ test_conffiles.cpp \ test_fee_charge_rules.cpp \ test_reconnect_on_tariff_change.cpp \ + test_disable_session_log.cpp \ + test_filter_params_log.cpp \ test_crypto.cpp \ test_bfstream.cpp \ ../projects/stargazer/tariff_impl.cpp \ diff --git a/tests/Makefile.darwin b/tests/Makefile.darwin index 11bdd523..8066f877 100644 --- a/tests/Makefile.darwin +++ b/tests/Makefile.darwin @@ -20,6 +20,8 @@ SOURCES = main.cpp \ test_conffiles.cpp \ test_fee_charge_rules.cpp \ test_reconnect_on_tariff_change.cpp \ + test_disable_session_log.cpp \ + test_filter_params_log.cpp \ test_crypto.cpp \ test_bfstream.cpp \ ../projects/stargazer/tariff_impl.cpp \ diff --git a/tests/test_disable_session_log.cpp b/tests/test_disable_session_log.cpp new file mode 100644 index 00000000..75e81568 --- /dev/null +++ b/tests/test_disable_session_log.cpp @@ -0,0 +1,152 @@ +#include "tut/tut.hpp" + +#include "stg/user_property.h" +#include "user_impl.h" + +#include "testsettings.h" +#include "testtariffs.h" +#include "testadmin.h" +#include "teststore.h" +#include "testauth.h" +#include "testusers.h" +#include "testservices.h" + +namespace +{ + +class TEST_STORE_LOCAL : public TEST_STORE, + private NONCOPYABLE { +public: + TEST_STORE_LOCAL() + : connects(0), + disconnects(0) + {} + int WriteUserConnect(const std::string & /*login*/, uint32_t /*ip*/) const { ++connects; return 0; } + + int WriteUserDisconnect(const std::string & /*login*/, + const DIR_TRAFF & /*up*/, + const DIR_TRAFF & /*down*/, + const DIR_TRAFF & /*sessionUp*/, + const DIR_TRAFF & /*sessionDown*/, + double /*cash*/, + double /*freeMb*/, + const std::string & /*reason*/) const { ++disconnects; return 0; } + + size_t GetConnects() const { return connects; } + size_t GetDisconnects() const { return disconnects; } + +private: + mutable size_t connects; + mutable size_t disconnects; +}; + +class TEST_SETTINGS_LOCAL : public TEST_SETTINGS { + public: + TEST_SETTINGS_LOCAL(bool _disableSessionLog) + : TEST_SETTINGS(), + disableSessionLog(_disableSessionLog) + {} + + bool GetDisableSessionLog() const { return disableSessionLog; } + + private: + bool disableSessionLog; +}; + +} + +namespace tut +{ + struct disable_session_log_data { + }; + + typedef test_group tg; + tg disable_session_log_test_group("Disable session log tests group"); + + typedef tg::object testobject; + + template<> + template<> + void testobject::test<1>() + { + set_test_name("Check normal behaviour"); + + TEST_SETTINGS_LOCAL settings(false); + TEST_TARIFFS tariffs; + TEST_ADMIN admin; + TEST_STORE_LOCAL store; + TEST_AUTH auth; + TEST_USERS users; + TEST_SERVICES services; + USER_IMPL user(&settings, &store, &tariffs, &admin, &users, services); + + USER_PROPERTY & ips(user.GetProperty().ips); + + ips = StrToIPS("*"); + + ensure_equals("user.connected = false", user.GetConnected(), false); + ensure_equals("connects = 0", store.GetConnects(), static_cast(0)); + ensure_equals("disconnects = 0", store.GetDisconnects(), static_cast(0)); + + user.Authorize(inet_strington("127.0.0.1"), 0, &auth); + user.Run(); + + ensure_equals("user.authorised_by = true", user.IsAuthorizedBy(&auth), true); + + ensure_equals("user.connected = true", user.GetConnected(), true); + ensure_equals("connects = 1", store.GetConnects(), static_cast(1)); + ensure_equals("disconnects = 0", store.GetDisconnects(), static_cast(0)); + + user.Unauthorize(&auth); + user.Run(); + + ensure_equals("user.authorised_by = false", user.IsAuthorizedBy(&auth), false); + + ensure_equals("user.connected = false", user.GetConnected(), false); + ensure_equals("connects = 1", store.GetConnects(), static_cast(1)); + ensure_equals("disconnects = 1", store.GetDisconnects(), static_cast(1)); + } + + + template<> + template<> + void testobject::test<2>() + { + set_test_name("Check disabled session log"); + + TEST_SETTINGS_LOCAL settings(true); + TEST_TARIFFS tariffs; + TEST_ADMIN admin; + TEST_STORE_LOCAL store; + TEST_AUTH auth; + TEST_USERS users; + TEST_SERVICES services; + USER_IMPL user(&settings, &store, &tariffs, &admin, &users, services); + + USER_PROPERTY & ips(user.GetProperty().ips); + + ips = StrToIPS("*"); + + ensure_equals("user.connected = false", user.GetConnected(), false); + ensure_equals("connects = 0", store.GetConnects(), static_cast(0)); + ensure_equals("disconnects = 0", store.GetDisconnects(), static_cast(0)); + + user.Authorize(inet_strington("127.0.0.1"), 0, &auth); + user.Run(); + + ensure_equals("user.authorised_by = true", user.IsAuthorizedBy(&auth), true); + + ensure_equals("user.connected = true", user.GetConnected(), true); + ensure_equals("connects = 0", store.GetConnects(), static_cast(0)); + ensure_equals("disconnects = 0", store.GetDisconnects(), static_cast(0)); + + user.Unauthorize(&auth); + user.Run(); + + ensure_equals("user.authorised_by = false", user.IsAuthorizedBy(&auth), false); + + ensure_equals("user.connected = false", user.GetConnected(), false); + ensure_equals("connects = 0", store.GetConnects(), static_cast(0)); + ensure_equals("disconnects = 0", store.GetDisconnects(), static_cast(0)); + } +} diff --git a/tests/test_filter_params_log.cpp b/tests/test_filter_params_log.cpp new file mode 100644 index 00000000..ab7a3097 --- /dev/null +++ b/tests/test_filter_params_log.cpp @@ -0,0 +1,166 @@ +#include "tut/tut.hpp" + +#include "stg/user_property.h" +#include "user_impl.h" + +#include "testsettings.h" +#include "testtariffs.h" +#include "testadmin.h" +#include "teststore.h" +#include "testauth.h" +#include "testusers.h" +#include "testservices.h" + +namespace +{ + +class TEST_STORE_LOCAL : public TEST_STORE, + private NONCOPYABLE { +public: + TEST_STORE_LOCAL() + : entries(0) + {} + + int WriteUserChgLog(const std::string & /*login*/, + const std::string & /*admLogin*/, + uint32_t /*admIP*/, + const std::string & /*paramName*/, + const std::string & /*oldValue*/, + const std::string & /*newValue*/, + const std::string & /*message*/) const { ++entries; return 0; } + + size_t GetEntries() const { return entries; } + +private: + mutable size_t entries; +}; + +class TEST_SETTINGS_LOCAL : public TEST_SETTINGS { + public: + void addFilter(const std::string& field) { filter.push_back(field); } + + const std::vector& GetFilterParamsLog() const { return filter; } + + private: + std::vector filter; +}; + +} + +namespace tut +{ + struct filter_params_log_data { + }; + + typedef test_group tg; + tg filter_params_log_test_group("Filter params log tests group"); + + typedef tg::object testobject; + + template<> + template<> + void testobject::test<1>() + { + set_test_name("Check normal behaviour"); + + TEST_SETTINGS_LOCAL settings; + settings.addFilter("*"); // Allow everything by default. + TEST_TARIFFS tariffs; + TEST_ADMIN admin; + TEST_STORE_LOCAL store; + TEST_AUTH auth; + TEST_USERS users; + TEST_SERVICES services; + USER_IMPL user(&settings, &store, &tariffs, &admin, &users, services); + + USER_PROPERTY_LOGGED & address(user.GetProperty().address); + USER_PROPERTY_LOGGED & note(user.GetProperty().note); + USER_PROPERTY_LOGGED & group(user.GetProperty().group); + + address.Set("address", &admin, "", &store, ""); + note.Set("note", &admin, "", &store, ""); + group.Set("group", &admin, "", &store, ""); + + ensure_equals("entries = 3", store.GetEntries(), 3); + + note.Set("another note", &admin, "", &store, ""); + + ensure_equals("entries = 4", store.GetEntries(), 4); + } + + + template<> + template<> + void testobject::test<2>() + { + set_test_name("Check single filter entry."); + + TEST_SETTINGS_LOCAL settings; + settings.addFilter("address"); // Allow everything by default. + TEST_TARIFFS tariffs; + TEST_ADMIN admin; + TEST_STORE_LOCAL store; + TEST_AUTH auth; + TEST_USERS users; + TEST_SERVICES services; + USER_IMPL user(&settings, &store, &tariffs, &admin, &users, services); + + USER_PROPERTY_LOGGED & address(user.GetProperty().address); + USER_PROPERTY_LOGGED & note(user.GetProperty().note); + USER_PROPERTY_LOGGED & group(user.GetProperty().group); + + address.Set("address", &admin, "", &store, ""); + note.Set("note", &admin, "", &store, ""); + group.Set("group", &admin, "", &store, ""); + + ensure_equals("entries = 1", store.GetEntries(), 1); + + note.Set("another note", &admin, "", &store, ""); + + ensure_equals("entries = 1", store.GetEntries(), 1); + + address.Set("new address", &admin, "", &store, ""); + + ensure_equals("entries = 2", store.GetEntries(), 2); + } + + template<> + template<> + void testobject::test<3>() + { + set_test_name("Check multiple filter entries."); + + TEST_SETTINGS_LOCAL settings; + settings.addFilter("address"); // Allow everything by default. + settings.addFilter("group"); // Allow everything by default. + TEST_TARIFFS tariffs; + TEST_ADMIN admin; + TEST_STORE_LOCAL store; + TEST_AUTH auth; + TEST_USERS users; + TEST_SERVICES services; + USER_IMPL user(&settings, &store, &tariffs, &admin, &users, services); + + USER_PROPERTY_LOGGED & address(user.GetProperty().address); + USER_PROPERTY_LOGGED & note(user.GetProperty().note); + USER_PROPERTY_LOGGED & group(user.GetProperty().group); + + address.Set("address", &admin, "", &store, ""); + note.Set("note", &admin, "", &store, ""); + group.Set("group", &admin, "", &store, ""); + + ensure_equals("entries = 2", store.GetEntries(), 2); + + note.Set("another note", &admin, "", &store, ""); + + ensure_equals("entries = 2", store.GetEntries(), 2); + + address.Set("new address", &admin, "", &store, ""); + + ensure_equals("entries = 3", store.GetEntries(), 3); + + group.Set("administrative group", &admin, "", &store, ""); + + ensure_equals("entries = 4", store.GetEntries(), 4); + } +} diff --git a/tests/test_reconnect_on_tariff_change.cpp b/tests/test_reconnect_on_tariff_change.cpp index 2bb0438c..42f76d0b 100644 --- a/tests/test_reconnect_on_tariff_change.cpp +++ b/tests/test_reconnect_on_tariff_change.cpp @@ -11,6 +11,9 @@ #include "testusers.h" #include "testservices.h" +namespace +{ + class AFTER_CONNECTED_NOTIFIER : public PROPERTY_NOTIFIER_BASE, private NONCOPYABLE { public: @@ -41,6 +44,8 @@ class TEST_SETTINGS_LOCAL : public TEST_SETTINGS { bool reconnectOnTariffChange; }; +} + namespace tut { struct reconnect_on_tariff_change_data { diff --git a/tests/testauth.h b/tests/testauth.h index 93ef5c26..7085f927 100644 --- a/tests/testauth.h +++ b/tests/testauth.h @@ -18,7 +18,7 @@ class TEST_AUTH : public AUTH { int Start() { return 0; } int Stop() { return 0; } - int Reload() { return 0; } + int Reload(const MODULE_SETTINGS&) { return 0; } bool IsRunning() { return true; } const std::string & GetStrError() const { return strError; } std::string GetVersion() const { return ""; } diff --git a/tests/testservices.h b/tests/testservices.h index 88e21769..5827d39a 100644 --- a/tests/testservices.h +++ b/tests/testservices.h @@ -9,9 +9,9 @@ class TEST_SERVICES : public SERVICES virtual int Add(const SERVICE_CONF & /*service*/, const ADMIN * /*admin*/) { return 0; } virtual int Del(const std::string & /*name*/, const ADMIN * /*admin*/) { return 0; } virtual int Change(const SERVICE_CONF & /*service*/, const ADMIN * /*admin*/) { return 0; } - virtual bool Find(const std::string & name, SERVICE_CONF * service) const { return false; } - virtual bool Find(const std::string & name, SERVICE_CONF_RES * service) const { return false; } - virtual bool Exists(const std::string & name) const { return false; } + virtual bool Find(const std::string & /*name*/, SERVICE_CONF * /*service*/) const { return false; } + virtual bool Find(const std::string & /*name*/, SERVICE_CONF_RES * /*service*/) const { return false; } + virtual bool Exists(const std::string & /*name*/) const { return false; } virtual const std::string & GetStrError() const { return m_errorStr; } virtual size_t Count() const { return 0; } diff --git a/tests/testsettings.h b/tests/testsettings.h index 51c83359..20e26271 100644 --- a/tests/testsettings.h +++ b/tests/testsettings.h @@ -5,7 +5,7 @@ class TEST_SETTINGS : public SETTINGS { public: - TEST_SETTINGS() {} + TEST_SETTINGS() { filterParamsLog.push_back("*"); } const std::string & GetDirName(size_t) const { return dirName; } const std::string & GetScriptsDir() const { return scriptsDir; } @@ -25,12 +25,15 @@ class TEST_SETTINGS : public SETTINGS { const std::string & GetMonitorDir() const { return monitorDir; } bool GetMonitoring() const { return false; } const std::vector & GetScriptParams() const { return scriptParams; } + bool GetDisableSessionLog() const { return false; } + const std::vector& GetFilterParamsLog() const { return filterParamsLog; } private: std::string dirName; std::string scriptsDir; std::string monitorDir; std::vector scriptParams; + std::vector filterParamsLog; }; #endif -- 2.44.2