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,
24 int WriteUserConnect(const std::string & /*login*/, uint32_t /*ip*/) const { ++connects; return 0; }
26 int WriteUserDisconnect(const std::string & /*login*/,
27 const DIR_TRAFF & /*up*/,
28 const DIR_TRAFF & /*down*/,
29 const DIR_TRAFF & /*sessionUp*/,
30 const DIR_TRAFF & /*sessionDown*/,
33 const std::string & /*reason*/) const { ++disconnects; return 0; }
35 size_t GetConnects() const { return connects; }
36 size_t GetDisconnects() const { return disconnects; }
39 mutable size_t connects;
40 mutable size_t disconnects;
43 class TEST_SETTINGS_LOCAL : public TEST_SETTINGS {
45 TEST_SETTINGS_LOCAL(bool _disableSessionLog)
47 disableSessionLog(_disableSessionLog)
50 bool GetDisableSessionLog() const { return disableSessionLog; }
53 bool disableSessionLog;
60 struct disable_session_log_data {
63 typedef test_group<disable_session_log_data> tg;
64 tg disable_session_log_test_group("Disable session log tests group");
66 typedef tg::object testobject;
70 void testobject::test<1>()
72 set_test_name("Check normal behaviour");
74 TEST_SETTINGS_LOCAL settings(false);
77 TEST_STORE_LOCAL store;
80 TEST_SERVICES services;
81 USER_IMPL user(&settings, &store, &tariffs, &admin, &users, services);
83 USER_PROPERTY<USER_IPS> & ips(user.GetProperty().ips);
87 ensure_equals("user.connected = false", user.GetConnected(), false);
88 ensure_equals("connects = 0", store.GetConnects(), static_cast<size_t>(0));
89 ensure_equals("disconnects = 0", store.GetDisconnects(), static_cast<size_t>(0));
91 user.Authorize(inet_strington("127.0.0.1"), 0, &auth);
94 ensure_equals("user.authorised_by = true", user.IsAuthorizedBy(&auth), true);
96 ensure_equals("user.connected = true", user.GetConnected(), true);
97 ensure_equals("connects = 1", store.GetConnects(), static_cast<size_t>(1));
98 ensure_equals("disconnects = 0", store.GetDisconnects(), static_cast<size_t>(0));
100 user.Unauthorize(&auth);
103 ensure_equals("user.authorised_by = false", user.IsAuthorizedBy(&auth), false);
105 ensure_equals("user.connected = false", user.GetConnected(), false);
106 ensure_equals("connects = 1", store.GetConnects(), static_cast<size_t>(1));
107 ensure_equals("disconnects = 1", store.GetDisconnects(), static_cast<size_t>(1));
113 void testobject::test<2>()
115 set_test_name("Check disabled session log");
117 TEST_SETTINGS_LOCAL settings(true);
118 TEST_TARIFFS tariffs;
120 TEST_STORE_LOCAL store;
123 TEST_SERVICES services;
124 USER_IMPL user(&settings, &store, &tariffs, &admin, &users, services);
126 USER_PROPERTY<USER_IPS> & ips(user.GetProperty().ips);
130 ensure_equals("user.connected = false", user.GetConnected(), false);
131 ensure_equals("connects = 0", store.GetConnects(), static_cast<size_t>(0));
132 ensure_equals("disconnects = 0", store.GetDisconnects(), static_cast<size_t>(0));
134 user.Authorize(inet_strington("127.0.0.1"), 0, &auth);
137 ensure_equals("user.authorised_by = true", user.IsAuthorizedBy(&auth), true);
139 ensure_equals("user.connected = true", user.GetConnected(), true);
140 ensure_equals("connects = 0", store.GetConnects(), static_cast<size_t>(0));
141 ensure_equals("disconnects = 0", store.GetDisconnects(), static_cast<size_t>(0));
143 user.Unauthorize(&auth);
146 ensure_equals("user.authorised_by = false", user.IsAuthorizedBy(&auth), false);
148 ensure_equals("user.connected = false", user.GetConnected(), false);
149 ensure_equals("connects = 0", store.GetConnects(), static_cast<size_t>(0));
150 ensure_equals("disconnects = 0", store.GetDisconnects(), static_cast<size_t>(0));