Merge branch 'cmake_cleanup' into 'master'

move files around

See merge request bartoszek/eedb!7
This commit is contained in:
Bartosz Wieczorek 2018-02-27 13:08:36 +00:00
commit b9a5402fe5
99 changed files with 833 additions and 256 deletions

View File

@ -1,7 +1,7 @@
set(SOURCES
main.cpp)
#set(SOURCES
# main.cpp)
add_executable(eedb_app ${SOURCES})
#add_executable(eedb_app ${SOURCES})
#target_link_libraries(eedb_app
# wthttp # or {Wt_HTTP_DEBUG_LIBRARY}

View File

@ -6,7 +6,7 @@
#include <eedb/db/config.hpp>
#include <eedb/db/connection.hpp>
#include <eedb/db/data/PgUsers.hpp>
#include <eedb/db/eedb/db/pg/PgUsers.hpp>
#include <eedb/widgets/BootstrapTheme.hpp>
#include <eedb/widgets/DefaultAuthPage.hpp>

View File

@ -1,3 +1,5 @@
cmake_minimum_required(VERSION 3.9)
add_subdirectory(eedb)
add_subdirectory(db)

View File

@ -1,3 +1,5 @@
project(Auth VERSION 0.1.0 DESCRIPTION "Auth library")
set(LIB auth)
file(GLOB auth_SOURCE src/*)
@ -17,10 +19,6 @@ target_link_libraries( ${LIB}
PRIVATE eedb
)
target_link_libraries( ${LIB}
PUBLIC nlohmann_json
)
# add cotire
set_target_properties( ${LIB} PROPERTIES COTIRE_ADD_UNITY_BUILD FALSE)
cotire(${LIB})

View File

@ -1,14 +1,14 @@
#include <eedb/auth/PgUserAuth.hpp>
#include <eedb/auth/Services.hpp>
#include <eedb/data/AuthIdentities.hpp>
#include <eedb/data/AuthIdentityConst.hpp>
#include <eedb/data/AuthInfoConst.hpp>
#include <eedb/data/AuthTokenConst.hpp>
#include <eedb/data/AuthTokens.hpp>
#include <eedb/data/Email.hpp>
#include <eedb/data/Password.hpp>
#include <eedb/data/Users.hpp>
#include <eedb/db/AuthIdentities.hpp>
#include <eedb/db/AuthIdentityConst.hpp>
#include <eedb/db/AuthInfoConst.hpp>
#include <eedb/db/AuthTokenConst.hpp>
#include <eedb/db/AuthTokens.hpp>
#include <eedb/db/Email.hpp>
#include <eedb/db/Password.hpp>
#include <eedb/db/Users.hpp>
#include <Wt/Auth/AuthService.h>
#include <Wt/Auth/Dbo/AuthInfo.h>

View File

@ -31,4 +31,5 @@ set_target_properties( ${LIB}
cotire(${LIB})
add_subdirectory(mock)
add_subdirectory(test)

View File

@ -1,17 +0,0 @@
#pragma once
#include <model/auth_identity.h>
#include <model/auth_info.h>
#include <model/auth_token.h>
#include <model/category.h>
#include <model/group.h>
#include <model/stat.h>
#include <model/system_info.h>
#include <model/user_audit.h>
constexpr eedb::user_audit t_user_audit;
constexpr eedb::auth_identity t_auth_identity;
constexpr eedb::auth_info t_auth_info;
constexpr eedb::auth_token t_auth_token;
constexpr eedb::group t_group;
constexpr eedb::category t_category;

View File

@ -1,7 +1,7 @@
#pragma once
#include <eedb/data/AuthIdentity.hpp>
#include <eedb/data/AuthIdentities.hpp>
#include <eedb/db/AuthIdentity.hpp>
#include <eedb/db/AuthIdentities.hpp>
#include <utils/spimpl.hpp>

View File

@ -1,7 +1,7 @@
#pragma once
#include <eedb/data/AuthToken.hpp>
#include <eedb/data/AuthTokens.hpp>
#include <eedb/db/AuthToken.hpp>
#include <eedb/db/AuthTokens.hpp>
#include <utils/spimpl.hpp>

View File

@ -1,6 +1,6 @@
#pragma once
#include <eedb/data/Category.hpp>
#include <eedb/db/Category.hpp>
#include <utils/spimpl.hpp>

View File

@ -1,6 +1,6 @@
#pragma once
#include <eedb/data/Category.hpp>
#include <eedb/db/Category.hpp>
#include <utils/spimpl.hpp>

View File

@ -1,6 +1,6 @@
#pragma once
#include <eedb/data/Category.hpp>
#include <eedb/db/Category.hpp>
#include <utils/spimpl.hpp>

View File

@ -1,8 +1,8 @@
#pragma once
#include <eedb/data/User.hpp>
#include <eedb/db/User.hpp>
#include <eedb/data/AuthInfo.hpp>
#include <eedb/db/AuthInfo.hpp>
#include <utils/spimpl.hpp>

View File

@ -1,6 +1,6 @@
#pragma once
#include <eedb/data/Users.hpp>
#include <eedb/db/Users.hpp>
#include <utils/spimpl.hpp>

View File

@ -0,0 +1,17 @@
#pragma once
#include <eedb/db/pg/model/auth_identity.h>
#include <eedb/db/pg/model/auth_info.h>
#include <eedb/db/pg/model/auth_token.h>
#include <eedb/db/pg/model/category.h>
#include <eedb/db/pg/model/group.h>
#include <eedb/db/pg/model/stat.h>
#include <eedb/db/pg/model/system_info.h>
#include <eedb/db/pg/model/user_audit.h>
constexpr eedb::user_audit t_user_audit;
constexpr eedb::auth_identity t_auth_identity;
constexpr eedb::auth_info t_auth_info;
constexpr eedb::auth_token t_auth_token;
constexpr eedb::group t_group;
constexpr eedb::category t_category;

View File

@ -0,0 +1,13 @@
set(LIB postgres_connector-mock)
# create library
add_library(${LIB} INTERFACE)
# link all
target_include_directories(${LIB} INTERFACE
include
)
target_link_libraries(${LIB} INTERFACE
eedb-mock
)

View File

@ -0,0 +1,23 @@
/*
* file generated by gmock: AuthIdentitiesMock.hpp
*/
#ifndef AUTHIDENTITIESMOCK_HPP
#define AUTHIDENTITIESMOCK_HPP
#include <gmock/gmock.h>
#include "././eedb/db/AuthIdentities.hpp"
namespace eedb {
class AuthIdentitiesMock : public AuthIdentities
{
public:
MOCK_METHOD1(addIdentity, AuthIdentity*(int));
MOCK_CONST_METHOD1(byProvider, AuthIdentity*(int));
MOCK_METHOD1(removeProvider, void(int));
};
} // namespace eedb
#endif // AUTHIDENTITIESMOCK_HPP

View File

@ -0,0 +1,23 @@
/*
* file generated by gmock: AuthInfoMock.hpp
*/
#ifndef AUTHINFOMOCK_HPP
#define AUTHINFOMOCK_HPP
#include <gmock/gmock.h>
#include "././eedb/db/AuthInfo.hpp"
namespace eedb {
class AuthInfoMock : public AuthInfo
{
public:
MOCK_CONST_METHOD0(password, const Password&());
MOCK_CONST_METHOD0(email, const Email&());
MOCK_CONST_METHOD0(emailVerified, bool());
};
} // namespace eedb
#endif // AUTHINFOMOCK_HPP

View File

@ -0,0 +1,38 @@
#ifndef AUTHTOKENMOCK_HPP
#define AUTHTOKENMOCK_HPP
#include <gmock/gmock.h>
#include <eedb/mock/db/AuthTokenMock.hpp>
#include <eedb/db/pg/connection.hpp>
#include <eedb/db/pg/model/all.hpp>
#include <sqlpp11/postgresql/insert.h>
#include <sqlpp11/sqlpp11.h>
#include <random>
namespace eedb::db {
class AuthTokenMock : public ::eedb::AuthTokenMock {
public:
void _init(PgConnection & db, ::eedb::AuthTokenRole role, ::eedb::User & user, std::string hash) {
id = db(sqlpp::postgresql::insert_into(t_auth_token) //
.set( //
t_auth_token.value = hash, //
t_auth_token.auth_info_id = user.uid(), //
t_auth_token.role = static_cast< int16_t >(role), //
t_auth_token.expires = std::chrono::system_clock::now() + std::chrono::hours{1}) //
.returning(t_auth_token.id))
.front()
.id;
}
private:
uint64_t id;
};
} // namespace eedb::db
#endif // AUTHTOKENMOCK_HPP

View File

@ -0,0 +1,21 @@
/*
* file generated by gmock: AuthTokensMock.hpp
*/
#ifndef AUTHTOKENSMOCK_HPP
#define AUTHTOKENSMOCK_HPP
#include <gmock/gmock.h>
#include "././eedb/db/AuthTokens.hpp"
namespace eedb {
class AuthTokensMock : public AuthTokens
{
public:
MOCK_METHOD1(removeToken, void(int));
};
} // namespace eedb
#endif // AUTHTOKENSMOCK_HPP

View File

@ -0,0 +1,21 @@
/*
* file generated by gmock: CategoriesMock.hpp
*/
#ifndef CATEGORIESMOCK_HPP
#define CATEGORIESMOCK_HPP
#include <gmock/gmock.h>
#include "././eedb/db/Category.hpp"
namespace eedb {
class CategoriesMock : public Categories
{
public:
MOCK_CONST_METHOD0(size, long());
};
} // namespace eedb
#endif // CATEGORIESMOCK_HPP

View File

@ -0,0 +1,21 @@
/*
* file generated by gmock: CategoryMock.hpp
*/
#ifndef CATEGORYMOCK_HPP
#define CATEGORYMOCK_HPP
#include <gmock/gmock.h>
#include "././eedb/db/Category.hpp"
namespace eedb {
class CategoryMock : public Category
{
public:
MOCK_CONST_METHOD0(parent, Category*());
};
} // namespace eedb
#endif // CATEGORYMOCK_HPP

View File

@ -0,0 +1,21 @@
/*
* file generated by gmock: ItemMock.hpp
*/
#ifndef ITEMMOCK_HPP
#define ITEMMOCK_HPP
#include <gmock/gmock.h>
#include "././eedb/db/Item.hpp"
namespace eedb {
class ItemMock : public Item
{
public:
MOCK_CONST_METHOD0(values, Values&());
};
} // namespace eedb
#endif // ITEMMOCK_HPP

View File

@ -0,0 +1,21 @@
/*
* file generated by gmock: ItemQueryFiltersMock.hpp
*/
#ifndef ITEMQUERYFILTERSMOCK_HPP
#define ITEMQUERYFILTERSMOCK_HPP
#include <gmock/gmock.h>
#include "././eedb/db/Item.hpp"
namespace eedb {
class ItemQueryFiltersMock : public ItemQueryFilters
{
public:
MOCK_CONST_METHOD0(category, Category*());
};
} // namespace eedb
#endif // ITEMQUERYFILTERSMOCK_HPP

View File

@ -0,0 +1,21 @@
/*
* file generated by gmock: ItemsMock.hpp
*/
#ifndef ITEMSMOCK_HPP
#define ITEMSMOCK_HPP
#include <gmock/gmock.h>
#include "././eedb/db/Item.hpp"
namespace eedb {
class ItemsMock : public Items
{
public:
MOCK_CONST_METHOD0(size, long());
};
} // namespace eedb
#endif // ITEMSMOCK_HPP

View File

@ -0,0 +1,21 @@
/*
* file generated by gmock: SessionMock.hpp
*/
#ifndef SESSIONMOCK_HPP
#define SESSIONMOCK_HPP
#include "././eedb/Session.hpp"
#include <gmock/gmock.h>
namespace eedb {
class SessionMock : public Session {
public:
MOCK_METHOD0(db, eedb::());
MOCK_CONST_METHOD0(enviroment, const Wt::WEnvironment &());
MOCK_METHOD0(login, Wt::Auth::Login &());
};
} // namespace eedb
#endif // SESSIONMOCK_HPP

View File

@ -0,0 +1,22 @@
/*
* file generated by gmock: SignalBaseMock.hpp
*/
#ifndef SIGNALBASEMOCK_HPP
#define SIGNALBASEMOCK_HPP
#include <gmock/gmock.h>
#include "/usr/local/include/Wt/WSignal.h"
namespace Wt {
class SignalBaseMock : public SignalBase
{
public:
MOCK_CONST_METHOD0(isConnected, bool());
MOCK_METHOD2(connect, Wt::Signals::connection(Wt::WObject *, WObject::Method));
};
} // namespace Wt
#endif // SIGNALBASEMOCK_HPP

View File

@ -0,0 +1,49 @@
#pragma once
#include <gmock/gmock.h>
#include <eedb/mock/db/UserMock.hpp>
#include <eedb/db/pg/connection.hpp>
#include <eedb/db/pg/model/all.hpp>
#include <sqlpp11/postgresql/insert.h>
#include <sqlpp11/sqlpp11.h>
#include <eedb/db/AuthIdentityConst.hpp>
namespace eedb::db {
class UserMock : public ::eedb::UserMock {
public:
/// TODO chenge to transaction
void _init(db::PgConnection & db) {
using namespace testing;
_id = db(sqlpp::postgresql::insert_into(t_auth_info)
.set( //
t_auth_info.password_hash = "$2y$07$RyytUhDhLDbAPjf0b0r2Y.dsg.FlQ7L.xzWHMmoelI81u0MfBrW7q",
t_auth_info.password_method = "bcrypt",
t_auth_info.password_salt = "OM/Z1c4WBFXvwkxh",
t_auth_info.email = "none@eedb.pl", //
t_auth_info.status = 0)
.returning(t_auth_info.id))
.front()
.id;
ON_CALL(*this, uid()).WillByDefault(Return(_id));
}
void _createIdentity(db::PgConnection & db, const ::eedb::AuthIdentityConst & id) {
db(insert_into(t_auth_identity) //
.set(t_auth_identity.auth_info_id = _id,
t_auth_identity.provider = std::string{id.provider()},
t_auth_identity.identity = std::string{id.identity()}));
}
private:
int64_t _id;
};
class PgUserMock : public UserMock {};
} // namespace eedb::db

View File

@ -0,0 +1,21 @@
/*
* file generated by gmock: UserNameMock.hpp
*/
#ifndef USERNAMEMOCK_HPP
#define USERNAMEMOCK_HPP
#include <gmock/gmock.h>
#include "././eedb/db/User.hpp"
namespace eedb {
class UserNameMock : public UserName
{
public:
MOCK_CONST_METHOD0(isValid, bool());
};
} // namespace eedb
#endif // USERNAMEMOCK_HPP

View File

@ -0,0 +1,22 @@
/*
* file generated by gmock: UsersMock.hpp
*/
#ifndef USERSMOCK_HPP
#define USERSMOCK_HPP
#include <gmock/gmock.h>
#include <eedb/db/Users.hpp>
namespace eedb {
class UsersMock : public Users
{
public:
MOCK_CONST_METHOD1(removeUser, void(int));
};
} // namespace eedb
#endif // USERSMOCK_HPP

View File

@ -1,9 +1,9 @@
#include <RawSql.hpp>
#include <eedb/db/pg/RawSql.hpp>
#include <string>
#include <fstream>
#include <connection.hpp>
#include <eedb/db/pg/connection.hpp>
#include <sqlpp11/sqlpp11.h>
namespace eedb::db{

View File

@ -1,4 +1,4 @@
#include "config.hpp"
#include "eedb/db/pg/config.hpp"
namespace eedb::db {

View File

@ -1,5 +1,5 @@
#include "config.hpp"
#include "connection.hpp"
#include "eedb/db/pg/config.hpp"
#include "eedb/db/pg/connection.hpp"
namespace eedb::db {

View File

@ -1,8 +1,8 @@
#include "data/PgAuthIdentity.hpp"
#include "eedb/db/pg/PgAuthIdentity.hpp"
#include <eedb/data/User.hpp>
#include <connection.hpp>
#include <model/auth_identity.h>
#include <eedb/db/User.hpp>
#include <eedb/db/pg/connection.hpp>
#include <eedb/db/pg/model/auth_identity.h>
#include <sqlpp11/postgresql/exception.h>
#include <sqlpp11/sqlpp11.h>

View File

@ -1,7 +1,7 @@
#pragma once
#include <eedb/data/AuthIdentity.hpp>
#include <eedb/data/AuthIdentities.hpp>
#include <eedb/db/AuthIdentity.hpp>
#include <eedb/db/AuthIdentities.hpp>
#include <utils/spimpl.hpp>

View File

@ -1,9 +1,9 @@
#include <data/PgAuthToken.hpp>
#include <eedb/db/pg/PgAuthToken.hpp>
#include <eedb/data/User.hpp>
#include <eedb/db/User.hpp>
#include <connection.hpp>
#include <model/auth_token.h>
#include <eedb/db/pg/connection.hpp>
#include <eedb/db/pg/model/auth_token.h>
#include <utils/Visitor.hpp>

View File

@ -1,7 +1,7 @@
#pragma once
#include <eedb/data/AuthToken.hpp>
#include <eedb/data/AuthTokens.hpp>
#include <eedb/db/AuthToken.hpp>
#include <eedb/db/AuthTokens.hpp>
#include <utils/spimpl.hpp>

View File

@ -1,9 +1,8 @@
#include "data/PgCategories.hpp"
#include "eedb/db/pg/PgCategories.hpp"
#include <data/PgCategory.hpp>
#include <connection.hpp>
#include <model/all.hpp>
#include <eedb/db/pg/PgCategory.hpp>
#include <eedb/db/pg/connection.hpp>
#include <eedb/db/pg/model/all.hpp>
#include <boost/iterator/transform_iterator.hpp>

View File

@ -1,6 +1,6 @@
#pragma once
#include <eedb/data/Category.hpp>
#include <eedb/db/Category.hpp>
#include <utils/spimpl.hpp>

View File

@ -1,9 +1,9 @@
#include <data/PgCategoriesRepository.hpp>
#include <eedb/db/pg/PgCategoriesRepository.hpp>
#include <data/PgCategory.hpp>
#include <eedb/db/pg/PgCategory.hpp>
#include <connection.hpp>
#include <model/all.hpp>
#include <eedb/db/pg/connection.hpp>
#include <eedb/db/pg/model/all.hpp>
namespace eedb {
struct PgCategoriesRepository::PgCategoriesRepositoryPriv {

View File

@ -1,6 +1,6 @@
#pragma once
#include <eedb/data/Category.hpp>
#include <eedb/db/Category.hpp>
#include <utils/spimpl.hpp>

View File

@ -1,10 +1,10 @@
#include <data/PgCategory.hpp>
#include <eedb/db/pg/PgCategory.hpp>
#include <connection.hpp>
#include <data/PgCategories.hpp>
#include <model/all.hpp>
#include <eedb/db/pg/PgCategories.hpp>
#include <eedb/db/pg/connection.hpp>
#include <eedb/db/pg/model/all.hpp>
#include <eedb/data/User.hpp>
#include <eedb/db/User.hpp>
#include <spdlog/spdlog.h>
#include <sqlpp11/sqlpp11.h>

View File

@ -1,6 +1,6 @@
#pragma once
#include <eedb/data/Category.hpp>
#include <eedb/db/Category.hpp>
#include <utils/spimpl.hpp>

View File

@ -1,12 +1,10 @@
#include <data/PgUser.hpp>
#include <eedb/db/pg/PgUser.hpp>
#include <connection.hpp>
#include <data/PgAuthIdentity.hpp>
#include <data/PgAuthToken.hpp>
#include <eedb/data/AuthInfoConst.hpp>
#include <model/all.hpp>
#include <eedb/db/AuthInfoConst.hpp>
#include <eedb/db/pg/PgAuthIdentity.hpp>
#include <eedb/db/pg/PgAuthToken.hpp>
#include <eedb/db/pg/connection.hpp>
#include <eedb/db/pg/model/all.hpp>
#include <sqlpp11/sqlpp11.h>

View File

@ -1,8 +1,8 @@
#pragma once
#include <eedb/data/User.hpp>
#include <eedb/db/User.hpp>
#include <eedb/data/AuthInfo.hpp>
#include <eedb/db/AuthInfo.hpp>
#include <utils/spimpl.hpp>

View File

@ -1,16 +1,16 @@
#include <data/PgUsers.hpp>
#include <eedb/db/pg/PgUsers.hpp>
#include <data/PgUser.hpp>
#include <eedb/db/pg/PgUser.hpp>
#include <eedb/data/AuthIdentity.hpp>
#include <eedb/data/AuthToken.hpp>
#include <eedb/data/Email.hpp>
#include <eedb/data/Password.hpp>
#include <eedb/db/AuthIdentity.hpp>
#include <eedb/db/AuthToken.hpp>
#include <eedb/db/Email.hpp>
#include <eedb/db/Password.hpp>
#include <connection.hpp>
#include <model/auth_identity.h>
#include <model/auth_info.h>
#include <model/auth_token.h>
#include <eedb/db/pg/connection.hpp>
#include <eedb/db/pg/model/auth_identity.h>
#include <eedb/db/pg/model/auth_info.h>
#include <eedb/db/pg/model/auth_token.h>
#include <sqlpp11/sqlpp11.h>

View File

@ -1,6 +1,6 @@
#pragma once
#include <eedb/data/Users.hpp>
#include <eedb/db/Users.hpp>
#include <utils/spimpl.hpp>

View File

@ -11,6 +11,7 @@ file(GLOB_RECURSE TEST_FILES test_*.cpp )
add_executable( ${TEST_EXECUTABLE_NAME} ${TEST_FILES})
target_link_libraries(${TEST_EXECUTABLE_NAME}
PRIVATE postgres_connector-mock
PRIVATE eedb
PRIVATE postgres_connector
PRIVATE GMock::main

View File

@ -1,8 +1,8 @@
#include <gmock/gmock.h>
#include <RawSql.hpp>
#include <config.hpp>
#include <connection.hpp>
#include <eedb/db/pg/RawSql.hpp>
#include <eedb/db/pg/config.hpp>
#include <eedb/db/pg/connection.hpp>
#include <sqlpp11/postgresql/exception.h>
#include <boost/process.hpp>

View File

@ -1,32 +1,10 @@
#include <gmock/gmock.h>
#include <data/PgAuthIdentity.hpp>
#include <eedb/data/AuthIdentityConst.hpp>
#include <eedb/data/User.hpp>
#include <eedb/data/Users.hpp>
#include <model/all.hpp>
#include <sqlpp11/sqlpp11.h>
#include <eedb/db/pg/PgAuthIdentity.hpp>
#include "DbTestBase.hpp"
namespace {
class UserMock : public eedb::User {
public:
MOCK_CONST_METHOD0(uid, int());
const eedb::UserName & name() const {}
const eedb::UserConfig & config() const override {}
eedb::AuthTokens & authTokens() const override {}
void logout() override {}
eedb::AuthIdentities & authIdentities() const {}
int64_t _uid;
// User interface
public:
eedb::AuthInfo & authInfo() const override {}
};
} // namespace
#include <eedb/mock/db/pg/UserMock.hpp>
class PgAuthIdentitiesTest : public DbTestBase< PgAuthIdentitiesTest > {
public:
@ -34,35 +12,18 @@ class PgAuthIdentitiesTest : public DbTestBase< PgAuthIdentitiesTest > {
using namespace testing;
db().native()->start_transaction();
authInfoId = db()(sqlpp::postgresql::insert_into(t_auth_info)
.set( //
t_auth_info.password_hash = "$2y$07$RyytUhDhLDbAPjf0b0r2Y.dsg.FlQ7L.xzWHMmoelI81u0MfBrW7q",
t_auth_info.password_method = "bcrypt",
t_auth_info.password_salt = "OM/Z1c4WBFXvwkxh",
t_auth_info.email = "none@eedb.pl", //
t_auth_info.status = 0)
.returning(t_auth_info.id))
.front()
.id;
user._init(db());
user._createIdentity(db(), {"identity", "provider"});
EXPECT_CALL(user, uid()).WillRepeatedly(testing::Return(authInfoId));
sut = std::make_unique< eedb::PgAuthIdentities >(db(), &user);
}
void createIdentity(const eedb::AuthIdentityConst id) {
db()(insert_into(t_auth_identity) //
.set(t_auth_identity.auth_info_id = authInfoId,
t_auth_identity.provider = std::string{id.provider()},
t_auth_identity.identity = std::string{id.identity()}));
}
~PgAuthIdentitiesTest() {
db().native()->rollback_transaction(false);
}
protected:
UserMock user;
int64_t authInfoId{0};
eedb::db::UserMock user;
std::unique_ptr< eedb::PgAuthIdentities > sut;
};
@ -77,7 +38,6 @@ TEST_F(PgAuthIdentitiesTest, searchForFalseIdentity) {
}
TEST_F(PgAuthIdentitiesTest, findIdentity) {
createIdentity({"identity", "provider"});
EXPECT_TRUE(sut->byProvider("provider"));
}
@ -87,7 +47,6 @@ TEST_F(PgAuthIdentitiesTest, addProvider) {
}
TEST_F(PgAuthIdentitiesTest, removeIdentity) {
createIdentity({"identity", "provider"});
sut->removeProvider("provider");
EXPECT_FALSE(sut->byProvider("provider"));
}

View File

@ -1,6 +1,6 @@
#include <gmock/gmock.h>
#include <data/PgAuthIdentity.hpp>
#include <eedb/db/pg/PgAuthIdentity.hpp>
#include "DbTestBase.hpp"

View File

@ -1,15 +1,16 @@
#include <gmock/gmock.h>
#include <data/PgAuthToken.hpp>
#include <eedb/db/pg/PgAuthToken.hpp>
#include <eedb/data/AuthIdentity.hpp>
#include <eedb/data/Users.hpp>
#include <eedb/db/AuthIdentity.hpp>
#include <eedb/db/Users.hpp>
#include <model/all.hpp>
#include <eedb/db/pg/model/all.hpp>
#include <sqlpp11/sqlpp11.h>
#include "DbTestBase.hpp"
#include <eedb/mock/db/pg/UserMock.hpp>
class PgAuthTokenTest : public DbTestBase< PgAuthTokenTest > {
public:
@ -17,20 +18,11 @@ class PgAuthTokenTest : public DbTestBase< PgAuthTokenTest > {
using namespace testing;
db().native()->start_transaction();
authInfoId = db()(sqlpp::postgresql::insert_into(t_auth_info)
.set( //
t_auth_info.password_hash = "$2y$07$RyytUhDhLDbAPjf0b0r2Y.dsg.FlQ7L.xzWHMmoelI81u0MfBrW7q",
t_auth_info.password_method = "bcrypt",
t_auth_info.password_salt = "OM/Z1c4WBFXvwkxh",
t_auth_info.email = "none@eedb.pl", //
t_auth_info.status = 0)
.returning(t_auth_info.id))
.front()
.id;
_user._init(db());
sutId = db()(sqlpp::postgresql::insert_into(t_auth_token) //
.set( //
t_auth_token.auth_info_id = authInfoId, //
t_auth_token.auth_info_id = _user.uid(), //
t_auth_token.expires = std::chrono::system_clock::now(), //
t_auth_token.role = static_cast< int >(eedb::AuthTokenRole::Auth), //
t_auth_token.value = "empty") //
@ -42,8 +34,8 @@ class PgAuthTokenTest : public DbTestBase< PgAuthTokenTest > {
}
void setExpireDate(std::chrono::system_clock::time_point exp) {
using namespace std::chrono;
db()(update(t_auth_token).set(t_auth_token.expires = time_point_cast< microseconds >(exp)).where(t_auth_token.id == sutId));
using namespace std::chrono;
db()(update(t_auth_token).set(t_auth_token.expires = time_point_cast< microseconds >(exp)).where(t_auth_token.id == sutId));
}
~PgAuthTokenTest() {
@ -51,7 +43,8 @@ class PgAuthTokenTest : public DbTestBase< PgAuthTokenTest > {
}
protected:
int64_t authInfoId;
eedb::db::UserMock _user;
int64_t sutId;
std::unique_ptr< eedb::PgAuthToken > sut;
};

View File

@ -1,61 +1,25 @@
#include <gmock/gmock.h>
#include <data/PgAuthToken.hpp>
#include <eedb/data/AuthIdentity.hpp>
#include <eedb/data/Users.hpp>
#include <eedb/data/User.hpp>
#include <model/all.hpp>
#include <sqlpp11/sqlpp11.h>
#include <eedb/db/pg/PgAuthToken.hpp>
#include "DbTestBase.hpp"
namespace {
class UserMock : public eedb::User {
public:
MOCK_CONST_METHOD0(uid, int());
const eedb::UserName & name() const {}
const eedb::UserConfig & config() const override {}
eedb::AuthTokens & authTokens() const override {}
void logout() override {}
eedb::AuthIdentities & authIdentities() const {}
int64_t _uid;
// User interface
public:
eedb::AuthInfo & authInfo() const override {}
};
} // namespace
#include <eedb/mock/db/pg/UserMock.hpp>
#include <eedb/mock/db/pg/AuthTokenMock.hpp>
class PgAuthTokensTest : public DbTestBase< PgAuthTokensTest > {
public:
PgAuthTokensTest() {
using namespace testing;
db().native()->start_transaction();
user._init(db());
authInfoId = db()(sqlpp::postgresql::insert_into(t_auth_info)
.set( //
t_auth_info.password_hash = "$2y$07$RyytUhDhLDbAPjf0b0r2Y.dsg.FlQ7L.xzWHMmoelI81u0MfBrW7q",
t_auth_info.password_method = "bcrypt",
t_auth_info.password_salt = "OM/Z1c4WBFXvwkxh",
t_auth_info.email = "none@eedb.pl", //
t_auth_info.status = 0)
.returning(t_auth_info.id))
.front()
.id;
EXPECT_CALL(user, uid()).WillRepeatedly(testing::Return(authInfoId));
sut = std::make_unique< eedb::PgAuthTokens >(db(), &user);
}
void createToken(std::string hash, eedb::AuthTokenRole role) {
db()(sqlpp::postgresql::insert_into(t_auth_token) //
.set( //
t_auth_token.value = hash, //
t_auth_token.auth_info_id = authInfoId, //
t_auth_token.role = static_cast< int16_t >(role), //
t_auth_token.expires = std::chrono::system_clock::now() + std::chrono::hours{1}));
eedb::db::AuthTokenMock token;
token._init(db(), role, user, hash);
}
~PgAuthTokensTest() {
@ -63,8 +27,7 @@ class PgAuthTokensTest : public DbTestBase< PgAuthTokensTest > {
}
protected:
UserMock user;
int64_t authInfoId{0};
eedb::db::UserMock user;
std::unique_ptr< eedb::PgAuthTokens > sut;
};
@ -72,7 +35,7 @@ template <>
std::unique_ptr< PgTestDatabasePrepare > DbTestBase< PgAuthTokensTest >::_test_db = {};
using namespace sqlpp;
using namespace eedb;
using namespace eedb;
TEST_F(PgAuthTokensTest, authTokenFound) {
createToken("token", AuthTokenRole::Auth);

View File

@ -1,4 +1,4 @@
#include <data/PgCategories.hpp>
#include <eedb/db/pg/PgCategories.hpp>
#include "DbTestBase.hpp"

View File

@ -1,14 +1,17 @@
#include <gtest/gtest.h>
#include <data/PgCategoriesRepository.hpp>
#include <eedb/db/pg/PgCategoriesRepository.hpp>
#include "DbTestBase.hpp"
#include <eedb/mock/db/pg/UserMock.hpp>
class PgCategoriesRepositoryTest : public DbTestBase< PgCategoriesRepositoryTest > {
public:
PgCategoriesRepositoryTest() {
db().native()->start_transaction();
sut = std::make_unique< eedb::PgCategoriesRepository >(db(), static_cast< eedb::User * >(nullptr));
_userMock._init(db());
sut = std::make_unique< eedb::PgCategoriesRepository >(db(), &_userMock);
}
~PgCategoriesRepositoryTest() {
@ -16,13 +19,17 @@ class PgCategoriesRepositoryTest : public DbTestBase< PgCategoriesRepositoryTest
}
protected:
eedb::db::UserMock _userMock;
std::unique_ptr< eedb::PgCategoriesRepository > sut;
};
template <>
std::unique_ptr< PgTestDatabasePrepare > DbTestBase< PgCategoriesRepositoryTest >::_test_db = {};
using namespace testing;
TEST_F(PgCategoriesRepositoryTest, rootNotNull) {
EXPECT_CALL(_userMock, uid()).WillOnce(Return(1));
auto root = sut->root();
ASSERT_TRUE(root);
// EXPECT_FALSE(root->detached());

View File

@ -1,28 +1,15 @@
#include <data/PgCategory.hpp>
#include <eedb/db/pg/PgCategory.hpp>
#include "DbTestBase.hpp"
#include <data/PgUsers.hpp>
#include <eedb/data/User.hpp>
#include <eedb/data/AuthIdentityConst.hpp>
#include <eedb/data/AuthInfoConst.hpp>
#include <model/all.hpp>
#include <sqlpp11/sqlpp11.h>
#include <eedb/mock/db/pg/UserMock.hpp>
class PgCategoryTest : public DbTestBase< PgCategoryTest > {
public:
PgCategoryTest() {
db().native()->start_transaction();
eedb::PgUsers(db()) //
.addUser( //
std::make_unique< eedb::AuthInfoConst >(eedb::Password{"", "", ""}, //
eedb::Email{"root@eedb.pl"}),
std::make_unique< eedb::AuthIdentityConst >("root", "loginname"));
user = eedb::PgUsers(db()).findWith(eedb::AuthIdentityConst{"root", "loginname"});
sut = std::make_unique< eedb::PgCategory >(db(), user.get());
user._init(db());
sut = std::make_unique< eedb::PgCategory >(db(), &user);
}
auto insertCategory(std::string name, int64_t parentId) {
@ -36,7 +23,7 @@ class PgCategoryTest : public DbTestBase< PgCategoryTest > {
}
protected:
std::unique_ptr< eedb::User> user;
eedb::db::UserMock user;
std::unique_ptr< eedb::PgCategory > sut;
};
@ -47,7 +34,7 @@ TEST_F(PgCategoryTest, rootCategoryHasNoParent) {
EXPECT_FALSE(sut->parent());
}
//TEST_F(PgCategoryTest, rootCategoryIsNotDetached) {
// TEST_F(PgCategoryTest, rootCategoryIsNotDetached) {
// EXPECT_FALSE(sut->detached());
//}
@ -63,7 +50,7 @@ TEST_F(PgCategoryTest, getChildren) {
EXPECT_EQ(children->size(), 0);
}
TEST_F(PgCategoryTest, childHasParent ) {
TEST_F(PgCategoryTest, childHasParent) {
sut->create("name1", "description");
sut->create("name2", "description");

View File

@ -1,10 +1,10 @@
#include <data/PgUser.hpp>
#include <eedb/db/pg/PgUser.hpp>
#include <eedb/data/AuthIdentities.hpp>
#include <eedb/data/AuthIdentityConst.hpp>
#include <eedb/data/AuthInfoConst.hpp>
#include <eedb/db/AuthIdentities.hpp>
#include <eedb/db/AuthIdentityConst.hpp>
#include <eedb/db/AuthInfoConst.hpp>
#include <eedb/db/pg/model/all.hpp>
#include <model/all.hpp>
#include <sqlpp11/sqlpp11.h>
#include "DbTestBase.hpp"

View File

@ -1,9 +1,9 @@
#include <data/PgUsers.hpp>
#include <eedb/db/pg/PgUsers.hpp>
#include <eedb/data/AuthIdentityConst.hpp>
#include <eedb/data/AuthInfoConst.hpp>
#include <eedb/db/AuthIdentityConst.hpp>
#include <eedb/db/AuthInfoConst.hpp>
#include <eedb/db/pg/model/all.hpp>
#include <model/all.hpp>
#include <sqlpp11/sqlpp11.h>
#include "DbTestBase.hpp"

View File

@ -1,6 +1,6 @@
set(LIB eedb)
file(GLOB_RECURSE eedb_SOURCE src/*)
file(GLOB_RECURSE eedb_SOURCE src/dummy*)
# find packages
find_package(nlohmann_json CONFIG REQUIRED)
@ -23,3 +23,6 @@ target_link_libraries(${LIB}
# add cotire
set_target_properties(${LIB} PROPERTIES COTIRE_ADD_UNITY_BUILD FALSE)
cotire(${LIB})
# add tests
add_subdirectory(test)

View File

@ -1,6 +1,6 @@
#pragma once
#include <eedb/data/AuthIdentities.hpp>
#include <eedb/db/AuthIdentities.hpp>
namespace eebd {

View File

@ -1,6 +1,6 @@
#pragma once
#include <eedb/data/AuthIdentity.hpp>
#include <eedb/db/AuthIdentity.hpp>
namespace eedb {
class AuthIdentityConst final : public AuthIdentity {

View File

@ -1,6 +1,6 @@
#pragma once
#include <eedb/data/User.hpp>
#include <eedb/db/User.hpp>
namespace eedb {

View File

@ -1,9 +1,9 @@
#pragma once
#include <eedb/data/AuthInfo.hpp>
#include <eedb/db/AuthInfo.hpp>
#include <eedb/data/Email.hpp>
#include <eedb/data/Password.hpp>
#include <eedb/db/Email.hpp>
#include <eedb/db/Password.hpp>
namespace eedb {
class AuthInfoConst final : public AuthInfo {

View File

@ -1,6 +1,6 @@
#pragma once
#include <eedb/data/AuthToken.hpp>
#include <eedb/db/AuthToken.hpp>
namespace eedb {

View File

@ -1,6 +1,6 @@
#pragma once
#include <eedb/data/AuthToken.hpp>
#include <eedb/db/AuthToken.hpp>
#include <variant>

View File

@ -2,7 +2,7 @@
#include <eedb/Session.hpp>
#include <eedb/auth/PgUserAuth.hpp>
#include <eedb/db/connection.hpp>
#include <eedb/db/pg/connection.hpp>
#include <eedb/widgets/AuthPage.hpp>
#include <eedb/widgets/BootstrapTheme.hpp>
#include <eedb/widgets/HomePage.hpp>

View File

@ -1,7 +1,7 @@
#include <eedb/WebSession.hpp>
#include <eedb/auth/PgUserAuth.hpp>
#include <eedb/db/connection.hpp>
#include <eedb/db/pg/connection.hpp>
namespace eedb {
WebSession::WebSession(std::unique_ptr< eedb::db::PgConnection > dbConnection, const Wt::WEnvironment & env)

View File

@ -0,0 +1,9 @@
set(LIB eedb-mock)
# create library
add_library(${LIB} INTERFACE)
# link all
target_include_directories(${LIB} INTERFACE
include
)

View File

@ -0,0 +1,23 @@
/*
* file generated by gmock: AuthIdentitiesMock.hpp
*/
#ifndef AUTHIDENTITIESMOCK_HPP
#define AUTHIDENTITIESMOCK_HPP
#include <gmock/gmock.h>
#include "././eedb/db/AuthIdentities.hpp"
namespace eedb {
class AuthIdentitiesMock : public AuthIdentities
{
public:
MOCK_METHOD1(addIdentity, AuthIdentity*(int));
MOCK_CONST_METHOD1(byProvider, AuthIdentity*(int));
MOCK_METHOD1(removeProvider, void(int));
};
} // namespace eedb
#endif // AUTHIDENTITIESMOCK_HPP

View File

@ -0,0 +1,23 @@
/*
* file generated by gmock: AuthInfoMock.hpp
*/
#ifndef AUTHINFOMOCK_HPP
#define AUTHINFOMOCK_HPP
#include <gmock/gmock.h>
#include "././eedb/db/AuthInfo.hpp"
namespace eedb {
class AuthInfoMock : public AuthInfo
{
public:
MOCK_CONST_METHOD0(password, const Password&());
MOCK_CONST_METHOD0(email, const Email&());
MOCK_CONST_METHOD0(emailVerified, bool());
};
} // namespace eedb
#endif // AUTHINFOMOCK_HPP

View File

@ -0,0 +1,17 @@
#pragma once
#include <gmock/gmock.h>
#include <eedb/db/AuthToken.hpp>
namespace eedb {
class AuthTokenMock : public AuthToken {
public:
MOCK_CONST_METHOD0(token, std::string_view());
MOCK_CONST_METHOD0(expireTimepoint, us_point());
MOCK_CONST_METHOD0(expired, bool());
MOCK_METHOD1(update, void(std::string));
};
} // namespace eedb

View File

@ -0,0 +1,21 @@
/*
* file generated by gmock: AuthTokensMock.hpp
*/
#ifndef AUTHTOKENSMOCK_HPP
#define AUTHTOKENSMOCK_HPP
#include <gmock/gmock.h>
#include "././eedb/db/AuthTokens.hpp"
namespace eedb {
class AuthTokensMock : public AuthTokens
{
public:
MOCK_METHOD1(removeToken, void(int));
};
} // namespace eedb
#endif // AUTHTOKENSMOCK_HPP

View File

@ -0,0 +1,21 @@
/*
* file generated by gmock: CategoriesMock.hpp
*/
#ifndef CATEGORIESMOCK_HPP
#define CATEGORIESMOCK_HPP
#include <gmock/gmock.h>
#include "././eedb/db/Category.hpp"
namespace eedb {
class CategoriesMock : public Categories
{
public:
MOCK_CONST_METHOD0(size, long());
};
} // namespace eedb
#endif // CATEGORIESMOCK_HPP

View File

@ -0,0 +1,21 @@
/*
* file generated by gmock: CategoryMock.hpp
*/
#ifndef CATEGORYMOCK_HPP
#define CATEGORYMOCK_HPP
#include <gmock/gmock.h>
#include "././eedb/db/Category.hpp"
namespace eedb {
class CategoryMock : public Category
{
public:
MOCK_CONST_METHOD0(parent, Category*());
};
} // namespace eedb
#endif // CATEGORYMOCK_HPP

View File

@ -0,0 +1,21 @@
/*
* file generated by gmock: ItemMock.hpp
*/
#ifndef ITEMMOCK_HPP
#define ITEMMOCK_HPP
#include <gmock/gmock.h>
#include "././eedb/db/Item.hpp"
namespace eedb {
class ItemMock : public Item
{
public:
MOCK_CONST_METHOD0(values, Values&());
};
} // namespace eedb
#endif // ITEMMOCK_HPP

View File

@ -0,0 +1,21 @@
/*
* file generated by gmock: ItemQueryFiltersMock.hpp
*/
#ifndef ITEMQUERYFILTERSMOCK_HPP
#define ITEMQUERYFILTERSMOCK_HPP
#include <gmock/gmock.h>
#include "././eedb/db/Item.hpp"
namespace eedb {
class ItemQueryFiltersMock : public ItemQueryFilters
{
public:
MOCK_CONST_METHOD0(category, Category*());
};
} // namespace eedb
#endif // ITEMQUERYFILTERSMOCK_HPP

View File

@ -0,0 +1,21 @@
/*
* file generated by gmock: ItemsMock.hpp
*/
#ifndef ITEMSMOCK_HPP
#define ITEMSMOCK_HPP
#include <gmock/gmock.h>
#include "././eedb/db/Item.hpp"
namespace eedb {
class ItemsMock : public Items
{
public:
MOCK_CONST_METHOD0(size, long());
};
} // namespace eedb
#endif // ITEMSMOCK_HPP

View File

@ -0,0 +1,21 @@
/*
* file generated by gmock: SessionMock.hpp
*/
#ifndef SESSIONMOCK_HPP
#define SESSIONMOCK_HPP
#include "././eedb/Session.hpp"
#include <gmock/gmock.h>
namespace eedb {
class SessionMock : public Session {
public:
MOCK_METHOD0(db, eedb::());
MOCK_CONST_METHOD0(enviroment, const Wt::WEnvironment &());
MOCK_METHOD0(login, Wt::Auth::Login &());
};
} // namespace eedb
#endif // SESSIONMOCK_HPP

View File

@ -0,0 +1,22 @@
/*
* file generated by gmock: SignalBaseMock.hpp
*/
#ifndef SIGNALBASEMOCK_HPP
#define SIGNALBASEMOCK_HPP
#include <gmock/gmock.h>
#include "/usr/local/include/Wt/WSignal.h"
namespace Wt {
class SignalBaseMock : public SignalBase
{
public:
MOCK_CONST_METHOD0(isConnected, bool());
MOCK_METHOD2(connect, Wt::Signals::connection(Wt::WObject *, WObject::Method));
};
} // namespace Wt
#endif // SIGNALBASEMOCK_HPP

View File

@ -0,0 +1,24 @@
#pragma once
#include <gmock/gmock.h>
#include <eedb/db/AuthIdentities.hpp>
#include <eedb/db/AuthIdentity.hpp>
#include <eedb/db/AuthInfo.hpp>
#include <eedb/db/AuthTokens.hpp>
#include <eedb/db/User.hpp>
namespace eedb {
class UserMock : public User {
public:
MOCK_CONST_METHOD0(uid, int());
MOCK_CONST_METHOD0(name, const UserName &());
MOCK_CONST_METHOD0(config, const UserConfig &());
MOCK_CONST_METHOD0(authTokens, AuthTokens &());
MOCK_CONST_METHOD0(authIdentities, AuthIdentities &());
MOCK_CONST_METHOD0(authInfo, AuthInfo &());
MOCK_METHOD0(logout, void());
};
} // namespace eedb

View File

@ -0,0 +1,21 @@
/*
* file generated by gmock: UserNameMock.hpp
*/
#ifndef USERNAMEMOCK_HPP
#define USERNAMEMOCK_HPP
#include <gmock/gmock.h>
#include "././eedb/db/User.hpp"
namespace eedb {
class UserNameMock : public UserName
{
public:
MOCK_CONST_METHOD0(isValid, bool());
};
} // namespace eedb
#endif // USERNAMEMOCK_HPP

View File

@ -0,0 +1,22 @@
/*
* file generated by gmock: UsersMock.hpp
*/
#ifndef USERSMOCK_HPP
#define USERSMOCK_HPP
#include <gmock/gmock.h>
#include <eedb/db/Users.hpp>
namespace eedb {
class UsersMock : public Users
{
public:
MOCK_CONST_METHOD1(removeUser, void(int));
};
} // namespace eedb
#endif // USERSMOCK_HPP

View File

@ -2,7 +2,7 @@
#include <functional>
#include <eedb/data/Category.hpp>
#include <eedb/db/Category.hpp>
namespace Wt {
class WContainerWidget;

View File

@ -1,6 +1,6 @@
#include <widget/DefaultCategoryTree.hpp>
#include <eedb/data/Category.hpp>
#include <eedb/db/Category.hpp>
#include <Wt/WContainerWidget.h>
#include <Wt/WTreeView.h>