Commit 01e12172 authored by johan's avatar johan
Browse files

Add tests on server key bundle request.

Warning this tests do not pass on the nodejs version server for now
parent 7b783f00
......@@ -41,6 +41,7 @@ set(SOURCE_FILES_CXX
lime_crypto-tester.cpp
lime_massive_group-tester.cpp
lime_multidomains-tester.cpp
lime_server-tester.cpp
)
set(SOURCE_FILES_C
......
......@@ -43,6 +43,8 @@ std::string test_x3dh_c448_server_port{"25520"};
std::string test_x3dh_domainA_server_port{"25521"};
std::string test_x3dh_domainB_server_port{"25522"};
std::string test_x3dh_domainC_server_port{"25523"};
std::string test_x3dh_c25519_stop_on_request_limit_server_port{"25524"};
std::string test_x3dh_c448_stop_on_request_limit_server_port{"25525"};
// for testing purpose RNG, no need to be a good one
std::random_device rd;
......@@ -50,6 +52,11 @@ std::uniform_int_distribution<int> uniform_dist(0,255);
// default value for the timeout
int wait_for_timeout=4000;
// bundle request restriction timespan (as configured on stop on request limit server). 20s (in ms)
int bundle_request_limit_timespan=20000;
// bundle request limit as configured on test server
int bundle_request_limit=5;
// default value for initial OPk batch size, keep it small so not too many OPks generated
uint16_t OPkInitialBatchSize=3;
......
......@@ -40,6 +40,8 @@ extern std::string test_x3dh_c448_server_port;
extern std::string test_x3dh_domainA_server_port;
extern std::string test_x3dh_domainB_server_port;
extern std::string test_x3dh_domainC_server_port;
extern std::string test_x3dh_c25519_stop_on_request_limit_server_port;
extern std::string test_x3dh_c448_stop_on_request_limit_server_port;
// messages pattern
extern std::string shortMessage;
......@@ -51,6 +53,11 @@ extern std::vector<std::string> messages_pattern;
// default value for the timeout
extern int wait_for_timeout;
// bundle request limit as configured on test server
extern int bundle_request_limit;
// bundle request restriction timespan (as configured on stop on request limit server)
extern int bundle_request_limit_timespan;
// default value for initial OPk batch size, keep it small so not too many OPks generated
extern uint16_t OPkInitialBatchSize;
......
......@@ -61,6 +61,7 @@ void lime_tester_init(void(*ftester_printf)(int level, const char *fmt, va_list
bc_tester_add_suite(&lime_ffi_test_suite);
#endif
bc_tester_add_suite(&lime_multidomains_test_suite);
bc_tester_add_suite(&lime_server_test_suite);
}
void lime_tester_uninit(void) {
......
......@@ -39,6 +39,7 @@ extern test_suite_t lime_massive_group_test_suite;
extern test_suite_t lime_ffi_test_suite;
#endif
extern test_suite_t lime_multidomains_test_suite;
extern test_suite_t lime_server_test_suite;
void lime_tester_init(void(*ftester_printf)(int level, const char *fmt, va_list args));
void lime_tester_uninit(void);
......
......@@ -3986,90 +3986,6 @@ static void lime_multithread(void) {
}
}
/**
* Scenario: Server is set to accept 200 OPks per device
* - Create user alice with 500 OPks -> it shall fail
* - Create user alice with 100 OPks -> it shall pass
* - Add 100 OPks to alice -> it shall pass
* - Add 100 OPks to alice -> is shall fail
*/
static void lime_server_resource_limit_reached_test(const lime::CurveId curve, const std::string &dbBaseFilename, const std::string &x3dh_server_url) {
// create DB
std::string dbFilenameAlice{dbBaseFilename};
dbFilenameAlice.append(".alice.").append((curve==CurveId::c25519)?"C25519":"C448").append(".sqlite3");
remove(dbFilenameAlice.data()); // delete the database file if already exists
lime_tester::events_counters_t counters={};
int expected_success=0;
int expected_failure=0;
limeCallback callback([&counters](lime::CallbackReturn returnCode, std::string anythingToSay) {
if (returnCode == lime::CallbackReturn::success) {
counters.operation_success++;
} else {
counters.operation_failed++;
LIME_LOGE<<"Lime operation failed : "<<anythingToSay;
}
});
try {
// create Manager and device for alice
auto aliceManager = std::unique_ptr<LimeManager>(new LimeManager(dbFilenameAlice, X3DHServerPost));
auto aliceDeviceId = lime_tester::makeRandomDeviceName("alice.");
aliceManager->create_user(*aliceDeviceId, x3dh_server_url, curve, 500, callback);
BC_ASSERT_TRUE(lime_tester::wait_for(bc_stack,&counters.operation_failed, ++expected_failure,lime_tester::wait_for_timeout));
// Try again to create the device, with 100 OPks, it shall pass
aliceManager->create_user(*aliceDeviceId, x3dh_server_url, curve, 100, callback);
BC_ASSERT_TRUE(lime_tester::wait_for(bc_stack,&counters.operation_success, ++expected_success,lime_tester::wait_for_timeout));
// call the update, set the serverLimit 200 and upload an other 100
aliceManager->update(callback, 200, 100);
BC_ASSERT_TRUE(lime_tester::wait_for(bc_stack,&counters.operation_success, ++expected_success,lime_tester::wait_for_timeout));
BC_ASSERT_EQUAL((int)lime_tester::get_OPks(dbFilenameAlice, *aliceDeviceId), 200, int, "%d");
// call the update, set the serverLimit 300 and upload an other 100 -> it shall fail but we have 300 OPks in DB
aliceManager->update(callback, 300, 100);
BC_ASSERT_TRUE(lime_tester::wait_for(bc_stack,&counters.operation_failed, ++expected_failure,lime_tester::wait_for_timeout));
BC_ASSERT_EQUAL((int)lime_tester::get_OPks(dbFilenameAlice, *aliceDeviceId), 300, int, "%d");
// update again, with correct values, server already holds 200 keys, so the only effect would be to set the failed 100 OPks status to dispatched as they are not on server
aliceManager->update(callback, 125, 25);
BC_ASSERT_TRUE(lime_tester::wait_for(bc_stack,&counters.operation_success, ++expected_success,lime_tester::wait_for_timeout));
BC_ASSERT_EQUAL((int)lime_tester::get_OPks(dbFilenameAlice, *aliceDeviceId), 300, int, "%d");
// forward time by OPK_limboTime_days
aliceManager=nullptr; // destroy manager before modifying DB
lime_tester::forwardTime(dbFilenameAlice, lime::settings::OPk_limboTime_days+1);
aliceManager = std::unique_ptr<LimeManager>(new LimeManager(dbFilenameAlice, X3DHServerPost));
// update one last time, with correct values, server already holds 200 keys
// so the only effect would be to remove the OPk keys status was set to dispatch before we forward the time
// We now hold 200 keys
aliceManager->update(callback, 125, 25);
BC_ASSERT_TRUE(lime_tester::wait_for(bc_stack,&counters.operation_success, ++expected_success,lime_tester::wait_for_timeout));
BC_ASSERT_EQUAL((int)lime_tester::get_OPks(dbFilenameAlice, *aliceDeviceId), 200, int, "%d");
if (cleanDatabase) {
aliceManager->delete_user(*aliceDeviceId, callback);
BC_ASSERT_TRUE(lime_tester::wait_for(bc_stack,&counters.operation_success,++expected_success,lime_tester::wait_for_timeout));
remove(dbFilenameAlice.data());
}
} catch (BctbxException &e) {
LIME_LOGE << e;
BC_FAIL("");
}
}
static void lime_server_resource_limit_reached() {
#ifdef EC25519_ENABLED
lime_server_resource_limit_reached_test(lime::CurveId::c25519, "lime_server_resource_limit_reached", std::string("https://").append(lime_tester::test_x3dh_server_url).append(":").append(lime_tester::test_x3dh_c25519_server_port).data());
#endif
#ifdef EC448_ENABLED
lime_server_resource_limit_reached_test(lime::CurveId::c448, "lime_server_resource_limit_reached", std::string("https://").append(lime_tester::test_x3dh_server_url).append(":").append(lime_tester::test_x3dh_c448_server_port).data());
#endif
}
static test_t tests[] = {
TEST_NO_TAG("Basic", x3dh_basic),
TEST_NO_TAG("User Management", user_management),
......@@ -4091,8 +4007,7 @@ static test_t tests[] = {
TEST_NO_TAG("Encryption Policy", lime_encryptionPolicy),
TEST_NO_TAG("Encryption Policy Error", lime_encryptionPolicyError),
TEST_NO_TAG("Identity theft", lime_identity_theft),
TEST_NO_TAG("Multithread", lime_multithread),
TEST_NO_TAG("Server resource limit reached", lime_server_resource_limit_reached)
TEST_NO_TAG("Multithread", lime_multithread)
};
test_suite_t lime_lime_test_suite = {
......
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment