mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
update test and test environment
This commit is contained in:
parent
e5c37606d2
commit
6f70d4c8b8
@ -2,14 +2,17 @@
|
|||||||
|
|
||||||
#include "JSONInterface/JsonUpdateUserInfos.h"
|
#include "JSONInterface/JsonUpdateUserInfos.h"
|
||||||
#include "TestJsonUpdateUserInfos.h"
|
#include "TestJsonUpdateUserInfos.h"
|
||||||
|
#include "lib/Profiler.h"
|
||||||
|
|
||||||
|
|
||||||
void TestJsonUpdateUserInfos::SetUp()
|
void TestJsonUpdateUserInfos::SetUp()
|
||||||
{
|
{
|
||||||
auto sm = SessionManager::getInstance();
|
auto sm = SessionManager::getInstance();
|
||||||
sm->init();
|
//sm->init();
|
||||||
mUserSession = sm->getNewSession();
|
mUserSession = sm->getNewSession();
|
||||||
mUserSession->loadUser("Jeet_bb@gmail.com", "TestP4ssword&H");
|
auto user = controller::User::create();
|
||||||
|
user->getModel()->setEmail("Jeet_bb@gmail.com");
|
||||||
|
mUserSession->setUser(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestJsonUpdateUserInfos::TearDown()
|
void TestJsonUpdateUserInfos::TearDown()
|
||||||
@ -18,7 +21,6 @@ void TestJsonUpdateUserInfos::TearDown()
|
|||||||
if (!mUserSession) {
|
if (!mUserSession) {
|
||||||
sm->releaseSession(mUserSession);
|
sm->releaseSession(mUserSession);
|
||||||
}
|
}
|
||||||
sm->deinitalize();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Poco::JSON::Object::Ptr TestJsonUpdateUserInfos::chooseAccount(const Poco::JSON::Object::Ptr update)
|
Poco::JSON::Object::Ptr TestJsonUpdateUserInfos::chooseAccount(const Poco::JSON::Object::Ptr update)
|
||||||
@ -30,6 +32,7 @@ Poco::JSON::Object::Ptr TestJsonUpdateUserInfos::chooseAccount(const Poco::JSON:
|
|||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST_F(TestJsonUpdateUserInfos, EmptyOldPassword)
|
TEST_F(TestJsonUpdateUserInfos, EmptyOldPassword)
|
||||||
{
|
{
|
||||||
JsonUpdateUserInfos jsonCall;
|
JsonUpdateUserInfos jsonCall;
|
||||||
@ -42,6 +45,11 @@ TEST_F(TestJsonUpdateUserInfos, EmptyOldPassword)
|
|||||||
|
|
||||||
auto errors = result->get("errors");
|
auto errors = result->get("errors");
|
||||||
ASSERT_TRUE(errors.isArray());
|
ASSERT_TRUE(errors.isArray());
|
||||||
|
auto valid_values_obj = result->get("valid_values");
|
||||||
|
ASSERT_TRUE(valid_values_obj.isInteger());
|
||||||
|
int valid_values = 0;
|
||||||
|
valid_values_obj.convert(valid_values);
|
||||||
|
ASSERT_EQ(valid_values, 0);
|
||||||
//User.password_old not found
|
//User.password_old not found
|
||||||
Poco::JSON::Array error_array = errors.extract<Poco::JSON::Array>();
|
Poco::JSON::Array error_array = errors.extract<Poco::JSON::Array>();
|
||||||
|
|
||||||
@ -50,3 +58,54 @@ TEST_F(TestJsonUpdateUserInfos, EmptyOldPassword)
|
|||||||
|
|
||||||
delete result;
|
delete result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(TestJsonUpdateUserInfos, OnlyOldPassword)
|
||||||
|
{
|
||||||
|
JsonUpdateUserInfos jsonCall;
|
||||||
|
Poco::JSON::Object::Ptr update = new Poco::JSON::Object;
|
||||||
|
|
||||||
|
update->set("User.password_old", "TestP4ssword&H");
|
||||||
|
|
||||||
|
auto params = chooseAccount(update);
|
||||||
|
auto result = jsonCall.handle(params);
|
||||||
|
|
||||||
|
auto errors = result->get("errors");
|
||||||
|
ASSERT_TRUE(errors.isArray());
|
||||||
|
auto valid_values_obj = result->get("valid_values");
|
||||||
|
ASSERT_TRUE(valid_values_obj.isInteger());
|
||||||
|
int valid_values = 0;
|
||||||
|
valid_values_obj.convert(valid_values);
|
||||||
|
ASSERT_EQ(valid_values, 0);
|
||||||
|
Poco::JSON::Array error_array = errors.extract<Poco::JSON::Array>();
|
||||||
|
ASSERT_EQ(error_array.size(), 0);
|
||||||
|
|
||||||
|
delete result;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(TestJsonUpdateUserInfos, WrongPassword)
|
||||||
|
{
|
||||||
|
JsonUpdateUserInfos jsonCall;
|
||||||
|
mUserSession->loadUser("Jeet_bb@gmail.com", "TestP4ssword&H");
|
||||||
|
Poco::JSON::Object::Ptr update = new Poco::JSON::Object;
|
||||||
|
|
||||||
|
update->set("User.password", "newPassword");
|
||||||
|
update->set("User.password_old", "TestP4sswordH");
|
||||||
|
|
||||||
|
auto params = chooseAccount(update);
|
||||||
|
Profiler timeUsed;
|
||||||
|
auto result = jsonCall.handle(params);
|
||||||
|
ASSERT_GE(timeUsed.millis(), ServerConfig::g_FakeLoginSleepTime-200);
|
||||||
|
|
||||||
|
auto errors = result->get("errors");
|
||||||
|
ASSERT_TRUE(errors.isArray());
|
||||||
|
auto valid_values_obj = result->get("valid_values");
|
||||||
|
ASSERT_TRUE(valid_values_obj.isInteger());
|
||||||
|
int valid_values = 0;
|
||||||
|
valid_values_obj.convert(valid_values);
|
||||||
|
ASSERT_EQ(valid_values, 0);
|
||||||
|
Poco::JSON::Array error_array = errors.extract<Poco::JSON::Array>();
|
||||||
|
ASSERT_EQ(error_array.size(), 1);
|
||||||
|
ASSERT_EQ(error_array.getElement<std::string>(0), "User.password_old didn't match");
|
||||||
|
|
||||||
|
delete result;
|
||||||
|
}
|
||||||
@ -16,7 +16,7 @@ protected:
|
|||||||
Poco::JSON::Object::Ptr chooseAccount(const Poco::JSON::Object::Ptr update);
|
Poco::JSON::Object::Ptr chooseAccount(const Poco::JSON::Object::Ptr update);
|
||||||
|
|
||||||
Session* mUserSession;
|
Session* mUserSession;
|
||||||
|
std::string mEmail;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -17,6 +17,8 @@
|
|||||||
|
|
||||||
#include "../lib/Profiler.h"
|
#include "../lib/Profiler.h"
|
||||||
|
|
||||||
|
#include "Crypto/SecretKeyCryptography.h"
|
||||||
|
|
||||||
|
|
||||||
std::list<Test*> gTests;
|
std::list<Test*> gTests;
|
||||||
|
|
||||||
@ -85,6 +87,9 @@ int load(int argc, char* argv[]) {
|
|||||||
|
|
||||||
ServerConfig::g_CPUScheduler = new UniLib::controller::CPUSheduler(worker_count, "Default Worker");
|
ServerConfig::g_CPUScheduler = new UniLib::controller::CPUSheduler(worker_count, "Default Worker");
|
||||||
ServerConfig::g_CryptoCPUScheduler = new UniLib::controller::CPUSheduler(2, "Crypto Worker");
|
ServerConfig::g_CryptoCPUScheduler = new UniLib::controller::CPUSheduler(2, "Crypto Worker");
|
||||||
|
ServerConfig::g_disableEmail = true;
|
||||||
|
|
||||||
|
SessionManager::getInstance()->init();
|
||||||
|
|
||||||
// load up connection configs
|
// load up connection configs
|
||||||
// register MySQL connector
|
// register MySQL connector
|
||||||
@ -129,6 +134,13 @@ int load(int argc, char* argv[]) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
printf("measure Time for secret key generation...\n");
|
||||||
|
Profiler timeForArgon2;
|
||||||
|
SecretKeyCryptography secret_cryptografie;
|
||||||
|
secret_cryptografie.createKey("test.email@gmx.de", "skaSI2WSEIs/");
|
||||||
|
ServerConfig::g_FakeLoginSleepTime = timeForArgon2.millis();
|
||||||
|
printf("time for secret key generation: %s\n", timeForArgon2.string().data());
|
||||||
|
|
||||||
std::string log_Path = "/var/log/grd_login/";
|
std::string log_Path = "/var/log/grd_login/";
|
||||||
//#ifdef _WIN32
|
//#ifdef _WIN32
|
||||||
#if defined(_WIN32) || defined(_WIN64)
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
@ -150,7 +162,6 @@ int load(int argc, char* argv[]) {
|
|||||||
|
|
||||||
log.error("Test Error");
|
log.error("Test Error");
|
||||||
|
|
||||||
SessionManager::getInstance()->init();
|
|
||||||
|
|
||||||
//errorLog
|
//errorLog
|
||||||
|
|
||||||
@ -226,7 +237,7 @@ int run()
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ende()
|
void endegTests()
|
||||||
{
|
{
|
||||||
for (std::list<Test*>::iterator it = gTests.begin(); it != gTests.end(); it++)
|
for (std::list<Test*>::iterator it = gTests.begin(); it != gTests.end(); it++)
|
||||||
{
|
{
|
||||||
@ -236,7 +247,7 @@ void ende()
|
|||||||
|
|
||||||
}
|
}
|
||||||
gTests.clear();
|
gTests.clear();
|
||||||
SessionManager::getInstance()->deinitalize();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -254,10 +265,13 @@ int main(int argc, char** argv)
|
|||||||
//printf ("\nStack Limit = %ld and %ld max\n", limit.rlim_cur, limit.rlim_max);
|
//printf ("\nStack Limit = %ld and %ld max\n", limit.rlim_cur, limit.rlim_max);
|
||||||
|
|
||||||
run();
|
run();
|
||||||
ende();
|
endegTests();
|
||||||
::testing::InitGoogleTest(&argc, argv);
|
|
||||||
|
|
||||||
|
::testing::InitGoogleTest(&argc, argv);
|
||||||
auto result = RUN_ALL_TESTS();
|
auto result = RUN_ALL_TESTS();
|
||||||
|
|
||||||
|
SessionManager::getInstance()->deinitalize();
|
||||||
ServerConfig::unload();
|
ServerConfig::unload();
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user