Commit f14e3bc9 authored by Steven Murray's avatar Steven Murray
Browse files

Improved SqliteCatalogue tests

parent 2a1d9542
......@@ -41,29 +41,29 @@ void cta::catalogue::SqliteCatalogue::createDbSchema() {
"GROUP_NAME TEXT,"
"COMMENT TEXT,"
"CREATOR_USER TEXT,"
"CREATOR_GROUP TEXT,"
"CREATOR_HOST TEXT,"
"CREATION_TIME INTEGER,"
"CREATION_LOG_USER_NAME TEXT,"
"CREATION_LOG_GROUP_NAME TEXT,"
"CREATION_LOG_HOST_NAME TEXT,"
"CREATION_LOG_TIME INTEGER,"
"UPDATER_USER TEXT,"
"UPDATER_GROUP TEXT,"
"UPDATER_HOST TEXT,"
"UPDATE_TIME INTEGER);"
"LAST_MODIFICATION_USER_NAME TEXT,"
"LAST_MODIFICATION_GROUP_NAME TEXT,"
"LAST_MODIFICATION_HOST_NAME TEXT,"
"LAST_MODIFICATION_TIME INTEGER);"
"CREATE TABLE ADMIN_HOST("
"HOST_NAME TEXT,"
"COMMENT TEXT,"
"CREATOR_USER TEXT,"
"CREATOR_GROUP TEXT,"
"CREATOR_HOST TEXT,"
"CREATION_TIME INTEGER,"
"CREATION_LOG_USER_NAME TEXT,"
"CREATION_LOG_GROUP_NAME TEXT,"
"CREATION_LOG_HOST_NAME TEXT,"
"CREATION_LOG_TIME INTEGER,"
"UPDATER_USER TEXT,"
"UPDATER_GROUP TEXT,"
"UPDATER_HOST TEXT,"
"UPDATE_TIME INTEGER);");
"LAST_MODIFICATION_USER_NAME TEXT,"
"LAST_MODIFICATION_GROUP_NAME TEXT,"
"LAST_MODIFICATION_HOST_NAME TEXT,"
"LAST_MODIFICATION_TIME INTEGER);");
}
//------------------------------------------------------------------------------
......@@ -89,39 +89,39 @@ void cta::catalogue::SqliteCatalogue::createBootstrapAdminAndHostNoAuth(
"GROUP_NAME,"
"COMMENT,"
"CREATOR_USER,"
"CREATOR_GROUP,"
"CREATOR_HOST,"
"CREATION_TIME,"
"CREATION_LOG_USER_NAME,"
"CREATION_LOG_GROUP_NAME,"
"CREATION_LOG_HOST_NAME,"
"CREATION_LOG_TIME,"
"UPDATER_USER,"
"UPDATER_GROUP,"
"UPDATER_HOST,"
"UPDATE_TIME)"
"LAST_MODIFICATION_USER_NAME,"
"LAST_MODIFICATION_GROUP_NAME,"
"LAST_MODIFICATION_HOST_NAME,"
"LAST_MODIFICATION_TIME)"
"VALUES("
":USER_NAME,"
":GROUP_NAME,"
":COMMENT,"
":CREATOR_USER,"
":CREATOR_GROUP,"
":CREATOR_HOST,"
":CREATION_TIME,"
":CREATION_LOG_USER_NAME,"
":CREATION_LOG_GROUP_NAME,"
":CREATION_LOG_HOST_NAME,"
":CREATION_LOG_TIME,"
":CREATOR_USER,"
":CREATOR_GROUP,"
":CREATOR_HOST,"
":CREATION_TIME);";
":CREATION_LOG_USER_NAME,"
":CREATION_LOG_GROUP_NAME,"
":CREATION_LOG_HOST_NAME,"
":CREATION_LOG_TIME);";
SqliteStmt stmt(m_conn, sql);
stmt.bind(":USER_NAME", user.name);
stmt.bind(":GROUP_NAME", user.group);
stmt.bind(":COMMENT", comment);
stmt.bind(":CREATOR_USER", cliIdentity.user.name);
stmt.bind(":CREATOR_GROUP", cliIdentity.user.group);
stmt.bind(":CREATOR_HOST", cliIdentity.host);
stmt.bind(":CREATION_TIME", now);
stmt.bind(":CREATION_LOG_USER_NAME", cliIdentity.user.name);
stmt.bind(":CREATION_LOG_GROUP_NAME", cliIdentity.user.group);
stmt.bind(":CREATION_LOG_HOST_NAME", cliIdentity.host);
stmt.bind(":CREATION_LOG_TIME", now);
stmt.step();
}
......@@ -132,37 +132,37 @@ void cta::catalogue::SqliteCatalogue::createBootstrapAdminAndHostNoAuth(
"HOST_NAME,"
"COMMENT,"
"CREATOR_USER,"
"CREATOR_GROUP,"
"CREATOR_HOST,"
"CREATION_TIME,"
"CREATION_LOG_USER_NAME,"
"CREATION_LOG_GROUP_NAME,"
"CREATION_LOG_HOST_NAME,"
"CREATION_LOG_TIME,"
"UPDATER_USER,"
"UPDATER_GROUP,"
"UPDATER_HOST,"
"UPDATE_TIME)"
"LAST_MODIFICATION_USER_NAME,"
"LAST_MODIFICATION_GROUP_NAME,"
"LAST_MODIFICATION_HOST_NAME,"
"LAST_MODIFICATION_TIME)"
"VALUES("
":HOST_NAME,"
":COMMENT,"
":CREATOR_USER,"
":CREATOR_GROUP,"
":CREATOR_HOST,"
":CREATION_TIME,"
":CREATION_LOG_USER_NAME,"
":CREATION_LOG_GROUP_NAME,"
":CREATION_LOG_HOST_NAME,"
":CREATION_LOG_TIME,"
":CREATOR_USER,"
":CREATOR_GROUP,"
":CREATOR_HOST,"
":CREATION_TIME);";
":CREATION_LOG_USER_NAME,"
":CREATION_LOG_GROUP_NAME,"
":CREATION_LOG_HOST_NAME,"
":CREATION_LOG_TIME);";
SqliteStmt stmt(m_conn, sql);
stmt.bind(":HOST_NAME", hostName);
stmt.bind(":COMMENT", comment);
stmt.bind(":CREATOR_USER", cliIdentity.user.name);
stmt.bind(":CREATOR_GROUP", cliIdentity.user.group);
stmt.bind(":CREATOR_HOST", cliIdentity.host);
stmt.bind(":CREATION_TIME", now);
stmt.bind(":CREATION_LOG_USER_NAME", cliIdentity.user.name);
stmt.bind(":CREATION_LOG_GROUP_NAME", cliIdentity.user.group);
stmt.bind(":CREATION_LOG_HOST_NAME", cliIdentity.host);
stmt.bind(":CREATION_LOG_TIME", now);
stmt.step();
}
......@@ -179,39 +179,39 @@ void cta::catalogue::SqliteCatalogue::createAdminUser(const common::dataStructur
"GROUP_NAME,"
"COMMENT,"
"CREATOR_USER,"
"CREATOR_GROUP,"
"CREATOR_HOST,"
"CREATION_TIME,"
"CREATION_LOG_USER_NAME,"
"CREATION_LOG_GROUP_NAME,"
"CREATION_LOG_HOST_NAME,"
"CREATION_LOG_TIME,"
"UPDATER_USER,"
"UPDATER_GROUP,"
"UPDATER_HOST,"
"UPDATE_TIME)"
"LAST_MODIFICATION_USER_NAME,"
"LAST_MODIFICATION_GROUP_NAME,"
"LAST_MODIFICATION_HOST_NAME,"
"LAST_MODIFICATION_TIME)"
"VALUES("
":USER_NAME,"
":GROUP_NAME,"
":COMMENT,"
":CREATOR_USER,"
":CREATOR_GROUP,"
":CREATOR_HOST,"
":CREATION_TIME,"
":CREATION_LOG_USER_NAME,"
":CREATION_LOG_GROUP_NAME,"
":CREATION_LOG_HOST_NAME,"
":CREATION_LOG_TIME,"
":CREATOR_USER,"
":CREATER_GROUP,"
":CREATER_HOST,"
":CREATION_TIME);";
":CREATION_LOG_USER_NAME,"
":CREATION_LOG_GROUP_NAME,"
":CREATION_LOG_HOST_NAME,"
":CREATION_LOG_TIME);";
SqliteStmt stmt(m_conn, sql);
stmt.bind(":USER_NAME", user.name);
stmt.bind(":GROUP_NAME", user.group);
stmt.bind(":COMMENT", comment);
stmt.bind(":CREATOR_USER", cliIdentity.user.name);
stmt.bind(":CREATOR_GROUP", cliIdentity.user.group);
stmt.bind(":CREATOR_HOST", cliIdentity.host);
stmt.bind(":CREATION_TIME", now);
stmt.bind(":CREATION_LOG_USER_NAME", cliIdentity.user.name);
stmt.bind(":CREATION_LOG_GROUP_NAME", cliIdentity.user.group);
stmt.bind(":CREATION_LOG_HOST_NAME", cliIdentity.host);
stmt.bind(":CREATION_LOG_TIME", now);
stmt.step();
}
......@@ -232,15 +232,15 @@ std::list<cta::common::dataStructures::AdminUser> cta::catalogue::SqliteCatalogu
"GROUP_NAME AS GROUP_NAME,"
"COMMENT AS COMMENT,"
"CREATOR_USER AS CREATOR_USER,"
"CREATOR_GROUP AS CREATOR_GROUP,"
"CREATOR_HOST AS CREATOR_HOST,"
"CREATION_TIME AS CREATION_TIME,"
"CREATION_LOG_USER_NAME AS CREATION_LOG_USER_NAME,"
"CREATION_LOG_GROUP_NAME AS CREATION_LOG_GROUP_NAME,"
"CREATION_LOG_HOST_NAME AS CREATION_LOG_HOST_NAME,"
"CREATION_LOG_TIME AS CREATION_LOG_TIME,"
"UPDATER_USER AS UPDATER_USER,"
"UPDATER_GROUP AS UPDATER_GROUP,"
"UPDATER_HOST AS UPDATER_HOST,"
"UPDATE_TIME AS UPDATE_TIME "
"LAST_MODIFICATION_USER_NAME AS LAST_MODIFICATION_USER_NAME,"
"LAST_MODIFICATION_GROUP_NAME AS LAST_MODIFICATION_GROUP_NAME,"
"LAST_MODIFICATION_HOST_NAME AS LAST_MODIFICATION_HOST_NAME,"
"LAST_MODIFICATION_TIME AS LAST_MODIFICATION_TIME "
"FROM ADMIN_USER";
SqliteStmt stmt(m_conn, sql);
ColumnNameToIdx nameToIdx;
......@@ -258,23 +258,23 @@ std::list<cta::common::dataStructures::AdminUser> cta::catalogue::SqliteCatalogu
admin.comment = stmt.columnText(nameToIdx["COMMENT"]);
common::dataStructures::UserIdentity creatorUI;
creatorUI.name = stmt.columnText(nameToIdx["CREATOR_USER"]);
creatorUI.group = stmt.columnText(nameToIdx["CREATOR_GROUP"]);
creatorUI.name = stmt.columnText(nameToIdx["CREATION_LOG_USER_NAME"]);
creatorUI.group = stmt.columnText(nameToIdx["CREATION_LOG_GROUP_NAME"]);
common::dataStructures::EntryLog creationLog;
creationLog.user = creatorUI;
creationLog.host = stmt.columnText(nameToIdx["CREATOR_HOST"]);
creationLog.time = stmt.columnUint64(nameToIdx["CREATION_TIME"]);
creationLog.host = stmt.columnText(nameToIdx["CREATION_LOG_HOST_NAME"]);
creationLog.time = stmt.columnUint64(nameToIdx["CREATION_LOG_TIME"]);
admin.creationLog = creationLog;
common::dataStructures::UserIdentity updaterUI;
updaterUI.name = stmt.columnText(nameToIdx["UPDATER_USER"]);
updaterUI.group = stmt.columnText(nameToIdx["UPDATER_GROUP"]);
updaterUI.name = stmt.columnText(nameToIdx["LAST_MODIFICATION_USER_NAME"]);
updaterUI.group = stmt.columnText(nameToIdx["LAST_MODIFICATION_GROUP_NAME"]);
common::dataStructures::EntryLog updateLog;
updateLog.user = updaterUI;
updateLog.host = stmt.columnText(nameToIdx["UPDATER_HOST"]);
updateLog.time = stmt.columnUint64(nameToIdx["UPDATE_TIME"]);
updateLog.host = stmt.columnText(nameToIdx["LAST_MODIFICATION_HOST_NAME"]);
updateLog.time = stmt.columnUint64(nameToIdx["LAST_MODIFICATION_TIME"]);
admin.lastModificationLog = updateLog;
admins.push_back(admin);
}
......
......@@ -20,29 +20,29 @@
#include <gtest/gtest.h>
#include <memory>
#include <set>
namespace unitTests {
class cta_catalogue_SqliteCatalogueTest : public ::testing::Test {
public:
cta_catalogue_SqliteCatalogueTest() {
cta::common::dataStructures::UserIdentity user;
user.group = "1";
user.name = "2";
m_cliIdentity.user = user;
m_cliIdentity.host = "cliIdentityHost";
cta::common::dataStructures::UserIdentity user1;
user1.group = "3";
user1.name = "4";
m_admin1.user = user1;
m_admin1.host = "admin1Host";
cta::common::dataStructures::UserIdentity user2;
user2.group = "5";
user2.name = "6";
m_admin2.user = user2;
m_admin2.host = "admin2Host";
cta_catalogue_SqliteCatalogueTest():
m_bootstrapComment("bootstrap comment") {
m_cliUI.group = "cli_group_name";
m_cliUI.name = "cli_user_name";
m_cliSI.user = m_cliUI;
m_cliSI.host = "cli_host";
m_bootstrapAdminUI.group = "bootstrap_admin_group_name";
m_bootstrapAdminUI.name = "bootstrap_admin_user_name";
m_bootstrapAdminSI.user = m_bootstrapAdminUI;
m_bootstrapAdminSI.host = "bootstrap_host";
m_adminUI.group = "admin_group_name";
m_adminUI.name = "admin_user_name";
m_adminSI.user = m_adminUI;
m_adminSI.host = "admin_host";
}
protected:
......@@ -53,9 +53,13 @@ protected:
virtual void TearDown() {
}
cta::common::dataStructures::SecurityIdentity m_cliIdentity;
cta::common::dataStructures::SecurityIdentity m_admin1;
cta::common::dataStructures::SecurityIdentity m_admin2;
const std::string m_bootstrapComment;
cta::common::dataStructures::UserIdentity m_cliUI;
cta::common::dataStructures::SecurityIdentity m_cliSI;
cta::common::dataStructures::UserIdentity m_bootstrapAdminUI;
cta::common::dataStructures::SecurityIdentity m_bootstrapAdminSI;
cta::common::dataStructures::UserIdentity m_adminUI;
cta::common::dataStructures::SecurityIdentity m_adminSI;
};
TEST_F(cta_catalogue_SqliteCatalogueTest, constructor) {
......@@ -71,23 +75,21 @@ TEST_F(cta_catalogue_SqliteCatalogueTest, createBootstrapAdminAndHostNoAuth) {
std::unique_ptr<catalogue::Catalogue> catalogue;
ASSERT_NO_THROW(catalogue.reset(new catalogue::SqliteCatalogue()));
common::dataStructures::UserIdentity admin1User = m_admin1.user;
const std::string bootstrapComment = "createBootstrapAdminAndHostNoAuth";
ASSERT_NO_THROW(catalogue->createBootstrapAdminAndHostNoAuth(
m_cliIdentity, admin1User, m_admin1.host, bootstrapComment));
catalogue->createBootstrapAdminAndHostNoAuth(
m_cliSI, m_bootstrapAdminUI, m_bootstrapAdminSI.host, m_bootstrapComment);
{
std::list<common::dataStructures::AdminUser> admins;
ASSERT_NO_THROW(admins = catalogue->getAdminUsers(m_admin1));
ASSERT_NO_THROW(admins = catalogue->getAdminUsers(m_bootstrapAdminSI));
ASSERT_EQ(1, admins.size());
const common::dataStructures::AdminUser admin = admins.front();
ASSERT_EQ(bootstrapComment, admin.comment);
ASSERT_EQ(m_bootstrapComment, admin.comment);
const common::dataStructures::EntryLog creationLog = admin.creationLog;
ASSERT_EQ(m_cliIdentity.user.name, creationLog.user.name);
ASSERT_EQ(m_cliIdentity.user.group, creationLog.user.group);
ASSERT_EQ(m_cliIdentity.host, creationLog.host);
ASSERT_EQ(m_cliSI.user.name, creationLog.user.name);
ASSERT_EQ(m_cliSI.user.group, creationLog.user.group);
ASSERT_EQ(m_cliSI.host, creationLog.host);
const common::dataStructures::EntryLog lastModificationLog =
admin.lastModificationLog;
......@@ -101,38 +103,73 @@ TEST_F(cta_catalogue_SqliteCatalogueTest, createAdminUser) {
std::unique_ptr<catalogue::Catalogue> catalogue;
ASSERT_NO_THROW(catalogue.reset(new catalogue::SqliteCatalogue()));
common::dataStructures::UserIdentity admin1User = m_admin1.user;
const std::string bootstrapComment = "createBootstrapAdminAndHostNoAuth";
ASSERT_NO_THROW(catalogue->createBootstrapAdminAndHostNoAuth(
m_cliIdentity, admin1User, m_admin1.host, bootstrapComment));
m_cliSI, m_bootstrapAdminUI, m_bootstrapAdminSI.host, m_bootstrapComment));
{
std::list<common::dataStructures::AdminUser> admins;
ASSERT_NO_THROW(admins = catalogue->getAdminUsers(m_admin1));
ASSERT_NO_THROW(admins = catalogue->getAdminUsers(m_bootstrapAdminSI));
ASSERT_EQ(1, admins.size());
const common::dataStructures::AdminUser admin = admins.front();
ASSERT_EQ(bootstrapComment, admin.comment);
ASSERT_EQ(m_bootstrapComment, admin.comment);
const common::dataStructures::EntryLog creationLog = admin.creationLog;
ASSERT_EQ(m_cliIdentity.user.name, creationLog.user.name);
ASSERT_EQ(m_cliIdentity.user.group, creationLog.user.group);
ASSERT_EQ(m_cliIdentity.host, creationLog.host);
ASSERT_EQ(m_cliSI.user.name, creationLog.user.name);
ASSERT_EQ(m_cliSI.user.group, creationLog.user.group);
ASSERT_EQ(m_cliSI.host, creationLog.host);
const common::dataStructures::EntryLog lastModificationLog =
admin.lastModificationLog;
ASSERT_EQ(creationLog, lastModificationLog);
}
const std::string createAdminUserComment = "createAdminUser";
common::dataStructures::UserIdentity admin2User = m_admin2.user;
ASSERT_NO_THROW(catalogue->createAdminUser(m_admin1, admin2User,
const std::string createAdminUserComment = "create admin user comment";
ASSERT_NO_THROW(catalogue->createAdminUser(m_bootstrapAdminSI, m_adminUI,
createAdminUserComment));
{
std::list<common::dataStructures::AdminUser> admins;
admins = catalogue->getAdminUsers(m_admin1);
ASSERT_EQ(2, admins.size());
std::list<common::dataStructures::AdminUser> adminList;
adminList = catalogue->getAdminUsers(m_bootstrapAdminSI);
ASSERT_EQ(2, adminList.size());
const common::dataStructures::AdminUser elem1 = adminList.front();
adminList.pop_front();
const common::dataStructures::AdminUser elem2 = adminList.front();
ASSERT_NE(elem1, elem2);
ASSERT_TRUE((elem1.user == m_bootstrapAdminUI && elem2.user == m_adminUI) ||
(elem2.user == m_bootstrapAdminUI && elem1.user == m_adminUI));
if(elem1.user == m_bootstrapAdminUI) {
ASSERT_EQ(m_bootstrapAdminUI, elem1.user);
ASSERT_EQ(m_bootstrapComment, elem1.comment);
ASSERT_EQ(m_cliSI.user, elem1.creationLog.user);
ASSERT_EQ(m_cliSI.host, elem1.creationLog.host);
ASSERT_EQ(m_cliSI.user, elem1.lastModificationLog.user);
ASSERT_EQ(m_cliSI.host, elem1.lastModificationLog.host);
ASSERT_EQ(m_adminUI, elem2.user);
ASSERT_EQ(createAdminUserComment, elem2.comment);
ASSERT_EQ(m_bootstrapAdminSI.user, elem2.creationLog.user);
ASSERT_EQ(m_bootstrapAdminSI.host, elem2.creationLog.host);
ASSERT_EQ(m_bootstrapAdminSI.user, elem2.lastModificationLog.user);
ASSERT_EQ(m_bootstrapAdminSI.host, elem2.lastModificationLog.host);
} else {
ASSERT_EQ(m_bootstrapAdminUI, elem2.user);
ASSERT_EQ(m_bootstrapComment, elem2.comment);
ASSERT_EQ(m_cliSI.user, elem2.creationLog.user);
ASSERT_EQ(m_cliSI.host, elem2.creationLog.host);
ASSERT_EQ(m_cliSI.user, elem2.lastModificationLog.user);
ASSERT_EQ(m_cliSI.host, elem2.lastModificationLog.host);
ASSERT_EQ(m_adminUI, elem1.user);
ASSERT_EQ(createAdminUserComment, elem1.comment);
ASSERT_EQ(m_bootstrapAdminSI.user, elem1.creationLog.user);
ASSERT_EQ(m_bootstrapAdminSI.host, elem1.creationLog.host);
ASSERT_EQ(m_bootstrapAdminSI.user, elem1.lastModificationLog.user);
ASSERT_EQ(m_bootstrapAdminSI.host, elem1.lastModificationLog.host);
}
}
}
......@@ -142,7 +179,7 @@ TEST_F(cta_catalogue_SqliteCatalogueTest, isAdmin_notAdmin) {
std::unique_ptr<catalogue::Catalogue> catalogue;
ASSERT_NO_THROW(catalogue.reset(new catalogue::SqliteCatalogue()));
ASSERT_FALSE(catalogue->isAdmin(m_cliIdentity));
ASSERT_FALSE(catalogue->isAdmin(m_cliSI));
}
} // namespace unitTests
......@@ -90,6 +90,9 @@ public:
/**
* Convenience wrapper around sqlite3_column_text().
*
* If sqlite3_column_text() returns NULL then this method returns an empty
* string.
*
* @param The index of the column.
* @return The value of the specified column.
*/
......
Supports Markdown
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