1 #define BOOST_TEST_MODULE STGAdminConf
4 #include "stg/user_property.h"
7 #include "testsettings.h"
8 #include "testtariffs.h"
11 #include "testusers.h"
12 #include "testservices.h"
14 #pragma GCC diagnostic push
15 #pragma GCC diagnostic ignored "-Wold-style-cast"
16 #pragma GCC diagnostic ignored "-Wunused-parameter"
17 #pragma GCC diagnostic ignored "-Wsign-compare"
18 #pragma GCC diagnostic ignored "-Wparentheses"
19 #include <boost/test/unit_test.hpp>
20 #pragma GCC diagnostic pop
22 volatile time_t stgTime = 0;
27 class Store : public TestStore
34 int WriteUserConnect(const std::string& /*login*/, uint32_t /*ip*/) const override { ++m_connects; return 0; }
36 int WriteUserDisconnect(const std::string& /*login*/,
37 const STG::DirTraff& /*up*/,
38 const STG::DirTraff& /*down*/,
39 const STG::DirTraff& /*sessionUp*/,
40 const STG::DirTraff& /*sessionDown*/,
43 const std::string& /*reason*/) const override { ++m_disconnects; return 0; }
45 size_t connects() const { return m_connects; }
46 size_t disconnects() const { return m_disconnects; }
49 mutable size_t m_connects;
50 mutable size_t m_disconnects;
53 class Settings : public TestSettings
56 Settings(bool disableSessionLog)
57 : m_disableSessionLog(disableSessionLog)
60 bool GetDisableSessionLog() const { return m_disableSessionLog; }
63 bool m_disableSessionLog;
68 BOOST_AUTO_TEST_SUITE(DisableSessionLog)
70 BOOST_AUTO_TEST_CASE(NormalBehavior)
72 Settings settings(false);
74 STG::Admin admin(STG::Priv(0xFFFF), {}, {});
78 TestServices services;
79 STG::UserImpl user(&settings, &store, &tariffs, &admin, &users, services);
81 STG::UserProperty<STG::UserIPs> & ips(user.GetProperties().ips);
83 ips = STG::UserIPs::parse("*");
85 BOOST_CHECK_EQUAL(user.GetConnected(), false);
86 BOOST_CHECK_EQUAL(store.connects(), static_cast<size_t>(0));
87 BOOST_CHECK_EQUAL(store.disconnects(), static_cast<size_t>(0));
89 user.Authorize(inet_strington("127.0.0.1"), 0, &auth);
92 BOOST_CHECK_EQUAL(user.IsAuthorizedBy(&auth), true);
94 BOOST_CHECK_EQUAL(user.GetConnected(), true);
95 BOOST_CHECK_EQUAL(store.connects(), static_cast<size_t>(1));
96 BOOST_CHECK_EQUAL(store.disconnects(), static_cast<size_t>(0));
98 user.Unauthorize(&auth);
101 BOOST_CHECK_EQUAL(user.IsAuthorizedBy(&auth), false);
103 BOOST_CHECK_EQUAL(user.GetConnected(), false);
104 BOOST_CHECK_EQUAL(store.connects(), static_cast<size_t>(1));
105 BOOST_CHECK_EQUAL(store.disconnects(), static_cast<size_t>(1));
108 BOOST_AUTO_TEST_CASE(DisabledSessionLog)
110 Settings settings(true);
112 STG::Admin admin(STG::Priv(0xFFFF), {}, {});
116 TestServices services;
117 STG::UserImpl user(&settings, &store, &tariffs, &admin, &users, services);
119 STG::UserProperty<STG::UserIPs> & ips(user.GetProperties().ips);
121 ips = STG::UserIPs::parse("*");
123 BOOST_CHECK_EQUAL(user.GetConnected(), false);
124 BOOST_CHECK_EQUAL(store.connects(), static_cast<size_t>(0));
125 BOOST_CHECK_EQUAL(store.disconnects(), static_cast<size_t>(0));
127 user.Authorize(inet_strington("127.0.0.1"), 0, &auth);
130 BOOST_CHECK_EQUAL(user.IsAuthorizedBy(&auth), true);
132 BOOST_CHECK_EQUAL(user.GetConnected(), true);
133 BOOST_CHECK_EQUAL(store.connects(), static_cast<size_t>(0));
134 BOOST_CHECK_EQUAL(store.disconnects(), static_cast<size_t>(0));
136 user.Unauthorize(&auth);
139 BOOST_CHECK_EQUAL(user.IsAuthorizedBy(&auth), false);
141 BOOST_CHECK_EQUAL(user.GetConnected(), false);
142 BOOST_CHECK_EQUAL(store.connects(), static_cast<size_t>(0));
143 BOOST_CHECK_EQUAL(store.disconnects(), static_cast<size_t>(0));
146 BOOST_AUTO_TEST_SUITE_END()