3 #include "stg/user_property.h"
6 #include "testsettings.h"
7 #include "testtariffs.h"
11 #include "testusers.h"
12 #include "testservices.h"
17 class TEST_STORE_LOCAL : public TEST_STORE {
23 int WriteUserConnect(const std::string & /*login*/, uint32_t /*ip*/) const override { ++connects; return 0; }
25 int WriteUserDisconnect(const std::string & /*login*/,
26 const STG::DirTraff & /*up*/,
27 const STG::DirTraff & /*down*/,
28 const STG::DirTraff & /*sessionUp*/,
29 const STG::DirTraff & /*sessionDown*/,
32 const std::string & /*reason*/) const override { ++disconnects; return 0; }
34 size_t GetConnects() const { return connects; }
35 size_t GetDisconnects() const { return disconnects; }
38 mutable size_t connects;
39 mutable size_t disconnects;
42 class TEST_SETTINGS_LOCAL : public TEST_SETTINGS {
44 TEST_SETTINGS_LOCAL(bool _disableSessionLog)
45 : disableSessionLog(_disableSessionLog)
48 bool GetDisableSessionLog() const { return disableSessionLog; }
51 bool disableSessionLog;
58 struct disable_session_log_data {
61 typedef test_group<disable_session_log_data> tg;
62 tg disable_session_log_test_group("Disable session log tests group");
64 typedef tg::object testobject;
68 void testobject::test<1>()
70 set_test_name("Check normal behaviour");
72 TEST_SETTINGS_LOCAL settings(false);
75 TEST_STORE_LOCAL store;
78 TEST_SERVICES 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 ensure_equals("user.connected = false", user.GetConnected(), false);
86 ensure_equals("connects = 0", store.GetConnects(), static_cast<size_t>(0));
87 ensure_equals("disconnects = 0", store.GetDisconnects(), static_cast<size_t>(0));
89 user.Authorize(inet_strington("127.0.0.1"), 0, &auth);
92 ensure_equals("user.authorised_by = true", user.IsAuthorizedBy(&auth), true);
94 ensure_equals("user.connected = true", user.GetConnected(), true);
95 ensure_equals("connects = 1", store.GetConnects(), static_cast<size_t>(1));
96 ensure_equals("disconnects = 0", store.GetDisconnects(), static_cast<size_t>(0));
98 user.Unauthorize(&auth);
101 ensure_equals("user.authorised_by = false", user.IsAuthorizedBy(&auth), false);
103 ensure_equals("user.connected = false", user.GetConnected(), false);
104 ensure_equals("connects = 1", store.GetConnects(), static_cast<size_t>(1));
105 ensure_equals("disconnects = 1", store.GetDisconnects(), static_cast<size_t>(1));
111 void testobject::test<2>()
113 set_test_name("Check disabled session log");
115 TEST_SETTINGS_LOCAL settings(true);
116 TEST_TARIFFS tariffs;
118 TEST_STORE_LOCAL store;
121 TEST_SERVICES services;
122 STG::UserImpl user(&settings, &store, &tariffs, &admin, &users, services);
124 STG::UserProperty<STG::UserIPs> & ips(user.GetProperties().ips);
126 ips = STG::UserIPs::parse("*");
128 ensure_equals("user.connected = false", user.GetConnected(), false);
129 ensure_equals("connects = 0", store.GetConnects(), static_cast<size_t>(0));
130 ensure_equals("disconnects = 0", store.GetDisconnects(), static_cast<size_t>(0));
132 user.Authorize(inet_strington("127.0.0.1"), 0, &auth);
135 ensure_equals("user.authorised_by = true", user.IsAuthorizedBy(&auth), true);
137 ensure_equals("user.connected = true", user.GetConnected(), true);
138 ensure_equals("connects = 0", store.GetConnects(), static_cast<size_t>(0));
139 ensure_equals("disconnects = 0", store.GetDisconnects(), static_cast<size_t>(0));
141 user.Unauthorize(&auth);
144 ensure_equals("user.authorised_by = false", user.IsAuthorizedBy(&auth), false);
146 ensure_equals("user.connected = false", user.GetConnected(), false);
147 ensure_equals("connects = 0", store.GetConnects(), static_cast<size_t>(0));
148 ensure_equals("disconnects = 0", store.GetDisconnects(), static_cast<size_t>(0));