]> git.stg.codes - stg.git/commitdiff
Added disabling of sessions log and filtering of params log.
authorMaxim Mamontov <faust.madf@gmail.com>
Fri, 2 Sep 2016 19:40:36 +0000 (22:40 +0300)
committerMaxim Mamontov <faust.madf@gmail.com>
Fri, 2 Sep 2016 19:40:36 +0000 (22:40 +0300)
14 files changed:
include/stg/settings.h
include/stg/user_property.h
projects/stargazer/settings_impl.cpp
projects/stargazer/settings_impl.h
projects/stargazer/user_impl.cpp
projects/stargazer/user_property.cpp
tests/Makefile
tests/Makefile.darwin
tests/test_disable_session_log.cpp [new file with mode: 0644]
tests/test_filter_params_log.cpp [new file with mode: 0644]
tests/test_reconnect_on_tariff_change.cpp
tests/testauth.h
tests/testservices.h
tests/testsettings.h

index dd13d67498ab01dcdef8d92279c9eed318ca5e78..64be687f241bc2e9c5d84561f0d74446270a792c 100644 (file)
@@ -45,6 +45,8 @@ public:
     virtual const std::string &              GetMonitorDir() const = 0;
     virtual bool                             GetMonitoring() const = 0;
     virtual const std::vector<std::string> & GetScriptParams() const = 0;
+    virtual bool                             GetDisableSessionLog() const = 0;
+    virtual const std::vector<std::string> & GetFilterParamsLog() const = 0;
 };
 //-----------------------------------------------------------------------------
 
index 20ca6fd8052fe33336a3c66b89292a6da0462239..f024f4575269d2c13f7728f8d5531a442e46e088 100644 (file)
@@ -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<varT>::USER_PROPERTY_LOGGED(varT & val,
                                                  bool isPass,
                                                  bool isSt,
                                                  STG_LOGGER & logger,
-                                                 const std::string & sd,
+                                                 const SETTINGS& s,
                                                  REGISTRY & properties)
 
     : USER_PROPERTY<varT>(val),
@@ -290,7 +291,7 @@ USER_PROPERTY_LOGGED<varT>::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 <typename varT>
@@ -377,7 +383,7 @@ void USER_PROPERTY_LOGGED<varT>::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)
     {
index c1a3951c2841017305a8ae30e820a355e0940cb8..0cf9501bced5db222ec6413721f9cf70f1b51a6d 100644 (file)
@@ -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();
     }
index 253b8bbccbcc70c0a41d4b09e464780b60c32b90..cc35393b2d18fab8d21cc705f3d1687fa031f43c 100644 (file)
@@ -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<std::string> & 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<std::string> filterParamsLog;
 
     std::vector<MODULE_SETTINGS> modulesSettings;
     MODULE_SETTINGS storeModuleSettings;
index d7bc8ea254bd37a6308b6f26a897d1a5a9259193..55a0b197968756d7addf7eb6e8e2be0aad686ba0 100644 (file)
@@ -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());
index c8b589172a95a3380848770d3f6c78457d9ccbe3..26f7b936ab23790d2d351da90f78024c28e5b782 100644 (file)
@@ -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)
 {}
index 72acdd62cdda79a0207c924fb19eb9dc616c7daf..f615b1d6df6ffb59c7de9304d8a328896182928b 100644 (file)
@@ -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 \
index 11bdd5232fe46f9b366a46bc2dea676045144f1b..8066f8772f8247999dafb42760f5f9bbc402c22f 100644 (file)
@@ -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 (file)
index 0000000..75e8156
--- /dev/null
@@ -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<disable_session_log_data> 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<USER_IPS> & ips(user.GetProperty().ips);
+
+        ips = StrToIPS("*");
+
+        ensure_equals("user.connected = false", user.GetConnected(), false);
+        ensure_equals("connects = 0", store.GetConnects(), static_cast<size_t>(0));
+        ensure_equals("disconnects = 0", store.GetDisconnects(), static_cast<size_t>(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<size_t>(1));
+        ensure_equals("disconnects = 0", store.GetDisconnects(), static_cast<size_t>(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<size_t>(1));
+        ensure_equals("disconnects = 1", store.GetDisconnects(), static_cast<size_t>(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<USER_IPS> & ips(user.GetProperty().ips);
+
+        ips = StrToIPS("*");
+
+        ensure_equals("user.connected = false", user.GetConnected(), false);
+        ensure_equals("connects = 0", store.GetConnects(), static_cast<size_t>(0));
+        ensure_equals("disconnects = 0", store.GetDisconnects(), static_cast<size_t>(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<size_t>(0));
+        ensure_equals("disconnects = 0", store.GetDisconnects(), static_cast<size_t>(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<size_t>(0));
+        ensure_equals("disconnects = 0", store.GetDisconnects(), static_cast<size_t>(0));
+    }
+}
diff --git a/tests/test_filter_params_log.cpp b/tests/test_filter_params_log.cpp
new file mode 100644 (file)
index 0000000..ab7a309
--- /dev/null
@@ -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<std::string>& GetFilterParamsLog() const { return filter; }
+
+    private:
+        std::vector<std::string> filter;
+};
+
+}
+
+namespace tut
+{
+    struct filter_params_log_data {
+    };
+
+    typedef test_group<filter_params_log_data> 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<std::string> & address(user.GetProperty().address);
+        USER_PROPERTY_LOGGED<std::string> & note(user.GetProperty().note);
+        USER_PROPERTY_LOGGED<std::string> & 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<std::string> & address(user.GetProperty().address);
+        USER_PROPERTY_LOGGED<std::string> & note(user.GetProperty().note);
+        USER_PROPERTY_LOGGED<std::string> & 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<std::string> & address(user.GetProperty().address);
+        USER_PROPERTY_LOGGED<std::string> & note(user.GetProperty().note);
+        USER_PROPERTY_LOGGED<std::string> & 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);
+    }
+}
index 2bb0438cb6b5cd8fa9ab75f94b56983e2466a379..42f76d0b3e3e0e3f1d5094a2edd87088dfb42180 100644 (file)
@@ -11,6 +11,9 @@
 #include "testusers.h"
 #include "testservices.h"
 
+namespace
+{
+
 class AFTER_CONNECTED_NOTIFIER : public PROPERTY_NOTIFIER_BASE<bool>,
                                  private NONCOPYABLE {
 public:
@@ -41,6 +44,8 @@ class TEST_SETTINGS_LOCAL : public TEST_SETTINGS {
         bool reconnectOnTariffChange;
 };
 
+}
+
 namespace tut
 {
     struct reconnect_on_tariff_change_data {
index 93ef5c268c78c8e1169f1a5f74fda5a6197b4667..7085f927202415ddfa556d2234fd2c80db5401a7 100644 (file)
@@ -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 ""; }
index 88e21769b5947cdb2a181b4835890e7144a9a51e..5827d39acb0003b42755556a1aedac1bd72c41f9 100644 (file)
@@ -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; }
 
index 51c833599282f3f67a172d80b3d002d904dac1a9..20e262714e92866f986342ab3967312648998a81 100644 (file)
@@ -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<std::string> & GetScriptParams() const { return scriptParams; }
+        bool                GetDisableSessionLog() const { return false; }
+        const std::vector<std::string>& GetFilterParamsLog() const { return filterParamsLog; }
 
     private:
         std::string dirName;
         std::string scriptsDir;
         std::string monitorDir;
         std::vector<std::string> scriptParams;
+        std::vector<std::string> filterParamsLog;
 };
 
 #endif