diff --git a/catalogue/Catalogue.hpp b/catalogue/Catalogue.hpp index 91356f3c888405fde35ff47c766cd2a5cbd1e2c0..153d0a6e1e60c377277dc095a139f5031ca8625a 100644 --- a/catalogue/Catalogue.hpp +++ b/catalogue/Catalogue.hpp @@ -184,7 +184,6 @@ public: // END OF METHODS DIRECTLY INVOLVED DATA TRANSFER AND SCHEDULING //////////////////////////////////////////////////////////////// - virtual void createBootstrapAdminAndHostNoAuth(const common::dataStructures::SecurityIdentity &admin, const std::string &username, const std::string &hostName, const std::string &comment) = 0; virtual void createAdminUser(const common::dataStructures::SecurityIdentity &admin, const std::string &username, const std::string &comment) = 0; virtual void deleteAdminUser(const std::string &username) = 0; virtual std::list<common::dataStructures::AdminUser> getAdminUsers() const = 0; diff --git a/catalogue/CatalogueFactoryTest.cpp b/catalogue/CatalogueFactoryTest.cpp index 7eb2b654636fe128ca4a80f2c10be7d7ae517fce..8a4c3e5e73110684179eaaa889fcc8c56e2568e9 100644 --- a/catalogue/CatalogueFactoryTest.cpp +++ b/catalogue/CatalogueFactoryTest.cpp @@ -27,13 +27,11 @@ namespace unitTests { class cta_catalogue_CatalogueFactoryTest : public ::testing::Test { public: - cta_catalogue_CatalogueFactoryTest(): - m_bootstrapComment("bootstrap") { + cta_catalogue_CatalogueFactoryTest() { + m_localAdmin.username = "local_admin_user"; + m_localAdmin.host = "local_admin_host"; - m_bootstrapAdminSI.username = "bootstrap_admin_user_name"; - m_bootstrapAdminSI.host = "bootstrap_host"; - - m_admin.username = "admin_user_name"; + m_admin.username = "admin_user"; m_admin.host = "admin_host"; } @@ -45,8 +43,7 @@ protected: virtual void TearDown() { } - const std::string m_bootstrapComment; - cta::common::dataStructures::SecurityIdentity m_bootstrapAdminSI; + cta::common::dataStructures::SecurityIdentity m_localAdmin; cta::common::dataStructures::SecurityIdentity m_admin; }; @@ -62,8 +59,11 @@ TEST_F(cta_catalogue_CatalogueFactoryTest, instance_in_memory) { ASSERT_TRUE(catalogue->getAdminUsers().empty()); ASSERT_TRUE(catalogue->getAdminHosts().empty()); - catalogue->createBootstrapAdminAndHostNoAuth( - m_admin, m_bootstrapAdminSI.username, m_bootstrapAdminSI.host, m_bootstrapComment); + const std::string createAdminUserComment = "Create admin user"; + catalogue->createAdminUser(m_localAdmin, m_admin.username, createAdminUserComment); + + const std::string createAdminHostComment = "Create admin host"; + catalogue->createAdminHost(m_localAdmin, m_admin.host, createAdminHostComment); { std::list<common::dataStructures::AdminUser> admins; @@ -71,14 +71,13 @@ TEST_F(cta_catalogue_CatalogueFactoryTest, instance_in_memory) { ASSERT_EQ(1, admins.size()); const common::dataStructures::AdminUser admin = admins.front(); - ASSERT_EQ(m_bootstrapComment, admin.comment); + ASSERT_EQ(createAdminUserComment, admin.comment); const common::dataStructures::EntryLog creationLog = admin.creationLog; - ASSERT_EQ(m_admin.username, creationLog.username); - ASSERT_EQ(m_admin.host, creationLog.host); + ASSERT_EQ(m_localAdmin.username, creationLog.username); + ASSERT_EQ(m_localAdmin.host, creationLog.host); - const common::dataStructures::EntryLog lastModificationLog = - admin.lastModificationLog; + const common::dataStructures::EntryLog lastModificationLog = admin.lastModificationLog; ASSERT_EQ(creationLog, lastModificationLog); } @@ -88,14 +87,13 @@ TEST_F(cta_catalogue_CatalogueFactoryTest, instance_in_memory) { ASSERT_EQ(1, hosts.size()); const common::dataStructures::AdminHost host = hosts.front(); - ASSERT_EQ(m_bootstrapComment, host.comment); + ASSERT_EQ(createAdminHostComment, host.comment); const common::dataStructures::EntryLog creationLog = host.creationLog; - ASSERT_EQ(m_admin.username, creationLog.username); - ASSERT_EQ(m_admin.host, creationLog.host); + ASSERT_EQ(m_localAdmin.username, creationLog.username); + ASSERT_EQ(m_localAdmin.host, creationLog.host); - const common::dataStructures::EntryLog lastModificationLog = - host.lastModificationLog; + const common::dataStructures::EntryLog lastModificationLog = host.lastModificationLog; ASSERT_EQ(creationLog, lastModificationLog); } } diff --git a/catalogue/CatalogueTest.cpp b/catalogue/CatalogueTest.cpp index 555c2bf32220ce4939129a5829251d31838688f6..2819f82cc79b8118b37d09537e34d0230e7b3698 100644 --- a/catalogue/CatalogueTest.cpp +++ b/catalogue/CatalogueTest.cpp @@ -35,11 +35,9 @@ namespace unitTests { //------------------------------------------------------------------------------ // constructor //------------------------------------------------------------------------------ -cta_catalogue_CatalogueTest::cta_catalogue_CatalogueTest(): - m_bootstrapComment("bootstrap") { - - m_bootstrapAdmin.username = "bootstrap_admin_user_name"; - m_bootstrapAdmin.host = "bootstrap_host"; +cta_catalogue_CatalogueTest::cta_catalogue_CatalogueTest() { + m_localAdmin.username = "local_admin_user"; + m_localAdmin.host = "local_admin_host"; m_admin.username = "admin_user_name"; m_admin.host = "admin_host"; @@ -236,120 +234,27 @@ std::map<std::string, cta::common::dataStructures::AdminHost> cta_catalogue_Cata } } -TEST_P(cta_catalogue_CatalogueTest, createBootstrapAdminAndHostNoAuth) { - using namespace cta; - - ASSERT_TRUE(m_catalogue->getAdminUsers().empty()); - ASSERT_TRUE(m_catalogue->getAdminHosts().empty()); - - m_catalogue->createBootstrapAdminAndHostNoAuth( - m_admin, m_bootstrapAdmin.username, m_bootstrapAdmin.host, m_bootstrapComment); - - { - std::list<common::dataStructures::AdminUser> admins; - admins = m_catalogue->getAdminUsers(); - ASSERT_EQ(1, admins.size()); - - const common::dataStructures::AdminUser admin = admins.front(); - ASSERT_EQ(m_bootstrapComment, admin.comment); - - const common::dataStructures::EntryLog creationLog = admin.creationLog; - ASSERT_EQ(m_admin.username, creationLog.username); - ASSERT_EQ(m_admin.host, creationLog.host); - - const common::dataStructures::EntryLog lastModificationLog = - admin.lastModificationLog; - ASSERT_EQ(creationLog, lastModificationLog); - } - - { - std::list<common::dataStructures::AdminHost> hosts; - hosts = m_catalogue->getAdminHosts(); - ASSERT_EQ(1, hosts.size()); - - const common::dataStructures::AdminHost host = hosts.front(); - ASSERT_EQ(m_bootstrapComment, host.comment); - - const common::dataStructures::EntryLog creationLog = host.creationLog; - ASSERT_EQ(m_admin.username, creationLog.username); - ASSERT_EQ(m_admin.host, creationLog.host); - - const common::dataStructures::EntryLog lastModificationLog = - host.lastModificationLog; - ASSERT_EQ(creationLog, lastModificationLog); - } -} - TEST_P(cta_catalogue_CatalogueTest, createAdminUser) { using namespace cta; ASSERT_TRUE(m_catalogue->getAdminUsers().empty()); - m_catalogue->createBootstrapAdminAndHostNoAuth( - m_admin, m_bootstrapAdmin.username, m_bootstrapAdmin.host, m_bootstrapComment); + const std::string createAdminUserComment = "Create admin user"; + m_catalogue->createAdminUser(m_localAdmin, m_admin.username, createAdminUserComment); { std::list<common::dataStructures::AdminUser> admins; admins = m_catalogue->getAdminUsers(); ASSERT_EQ(1, admins.size()); - const common::dataStructures::AdminUser admin = admins.front(); - ASSERT_EQ(m_bootstrapComment, admin.comment); - - const common::dataStructures::EntryLog creationLog = admin.creationLog; - ASSERT_EQ(m_admin.username, creationLog.username); - ASSERT_EQ(m_admin.host, creationLog.host); - - const common::dataStructures::EntryLog lastModificationLog = - admin.lastModificationLog; - ASSERT_EQ(creationLog, lastModificationLog); - } - - const std::string createAdminUserComment = "Create admin user"; - m_catalogue->createAdminUser(m_bootstrapAdmin, m_admin.username, createAdminUserComment); + const common::dataStructures::AdminUser a = admins.front(); - { - std::list<common::dataStructures::AdminUser> admins; - admins = m_catalogue->getAdminUsers(); - ASSERT_EQ(2, admins.size()); - - const common::dataStructures::AdminUser a1 = admins.front(); - admins.pop_front(); - const common::dataStructures::AdminUser a2 = admins.front(); - - ASSERT_NE(a1, a2); - ASSERT_TRUE((a1.name == m_bootstrapAdmin.username && a2.name == m_admin.username) || - (a2.name == m_bootstrapAdmin.username && a1.name == m_admin.username)); - - if(a1.name == m_bootstrapAdmin.username) { - ASSERT_EQ(m_bootstrapAdmin.username, a1.name); - ASSERT_EQ(m_bootstrapComment, a1.comment); - ASSERT_EQ(m_admin.username, a1.creationLog.username); - ASSERT_EQ(m_admin.host, a1.creationLog.host); - ASSERT_EQ(m_admin.username, a1.lastModificationLog.username); - ASSERT_EQ(m_admin.host, a1.lastModificationLog.host); - - ASSERT_EQ(m_admin.username, a2.name); - ASSERT_EQ(createAdminUserComment, a2.comment); - ASSERT_EQ(m_bootstrapAdmin.username, a2.creationLog.username); - ASSERT_EQ(m_bootstrapAdmin.host, a2.creationLog.host); - ASSERT_EQ(m_bootstrapAdmin.username, a2.lastModificationLog.username); - ASSERT_EQ(m_bootstrapAdmin.host, a2.lastModificationLog.host); - } else { - ASSERT_EQ(m_bootstrapAdmin.username, a2.name); - ASSERT_EQ(m_bootstrapComment, a2.comment); - ASSERT_EQ(m_admin.username, a2.creationLog.username); - ASSERT_EQ(m_admin.host, a2.creationLog.host); - ASSERT_EQ(m_admin.username, a2.lastModificationLog.username); - ASSERT_EQ(m_admin.host, a2.lastModificationLog.host); - - ASSERT_EQ(m_admin.username, a1.name); - ASSERT_EQ(createAdminUserComment, a1.comment); - ASSERT_EQ(m_bootstrapAdmin.username, a1.creationLog.username); - ASSERT_EQ(m_bootstrapAdmin.host, a1.creationLog.host); - ASSERT_EQ(m_bootstrapAdmin.username, a1.lastModificationLog.username); - ASSERT_EQ(m_bootstrapAdmin.host, a1.lastModificationLog.host); - } + ASSERT_EQ(m_admin.username, a.name); + ASSERT_EQ(createAdminUserComment, a.comment); + ASSERT_EQ(m_localAdmin.username, a.creationLog.username); + ASSERT_EQ(m_localAdmin.host, a.creationLog.host); + ASSERT_EQ(m_localAdmin.username, a.lastModificationLog.username); + ASSERT_EQ(m_localAdmin.host, a.lastModificationLog.host); } } @@ -358,29 +263,9 @@ TEST_P(cta_catalogue_CatalogueTest, createAdminUser_same_twice) { ASSERT_TRUE(m_catalogue->getAdminUsers().empty()); - m_catalogue->createBootstrapAdminAndHostNoAuth( - m_admin, m_bootstrapAdmin.username, m_bootstrapAdmin.host, m_bootstrapComment); - - { - std::list<common::dataStructures::AdminUser> admins; - admins = m_catalogue->getAdminUsers(); - ASSERT_EQ(1, admins.size()); - - const common::dataStructures::AdminUser admin = admins.front(); - ASSERT_EQ(m_bootstrapComment, admin.comment); - - const common::dataStructures::EntryLog creationLog = admin.creationLog; - ASSERT_EQ(m_admin.username, creationLog.username); - ASSERT_EQ(m_admin.host, creationLog.host); - - const common::dataStructures::EntryLog lastModificationLog = - admin.lastModificationLog; - ASSERT_EQ(creationLog, lastModificationLog); - } - - m_catalogue->createAdminUser(m_bootstrapAdmin, m_admin.username, "comment 1"); + m_catalogue->createAdminUser(m_localAdmin, m_admin.username, "comment 1"); - ASSERT_THROW(m_catalogue->createAdminUser(m_bootstrapAdmin, m_admin.username, + ASSERT_THROW(m_catalogue->createAdminUser(m_localAdmin, m_admin.username, "comment 2"), exception::UserError); } @@ -389,27 +274,25 @@ TEST_P(cta_catalogue_CatalogueTest, deleteAdminUser) { ASSERT_TRUE(m_catalogue->getAdminUsers().empty()); - m_catalogue->createBootstrapAdminAndHostNoAuth( - m_admin, m_bootstrapAdmin.username, m_bootstrapAdmin.host, m_bootstrapComment); + const std::string createAdminUserComment = "Create admin user"; + m_catalogue->createAdminUser(m_localAdmin, m_admin.username, createAdminUserComment); { std::list<common::dataStructures::AdminUser> admins; admins = m_catalogue->getAdminUsers(); ASSERT_EQ(1, admins.size()); - const common::dataStructures::AdminUser admin = admins.front(); - ASSERT_EQ(m_bootstrapComment, admin.comment); - - const common::dataStructures::EntryLog creationLog = admin.creationLog; - ASSERT_EQ(m_admin.username, creationLog.username); - ASSERT_EQ(m_admin.host, creationLog.host); + const common::dataStructures::AdminUser a = admins.front(); - const common::dataStructures::EntryLog lastModificationLog = - admin.lastModificationLog; - ASSERT_EQ(creationLog, lastModificationLog); + ASSERT_EQ(m_admin.username, a.name); + ASSERT_EQ(createAdminUserComment, a.comment); + ASSERT_EQ(m_localAdmin.username, a.creationLog.username); + ASSERT_EQ(m_localAdmin.host, a.creationLog.host); + ASSERT_EQ(m_localAdmin.username, a.lastModificationLog.username); + ASSERT_EQ(m_localAdmin.host, a.lastModificationLog.host); } - m_catalogue->deleteAdminUser(m_bootstrapAdmin.username); + m_catalogue->deleteAdminUser(m_admin.username); ASSERT_TRUE(m_catalogue->getAdminUsers().empty()); } @@ -418,7 +301,7 @@ TEST_P(cta_catalogue_CatalogueTest, deleteAdminUser_non_existant) { using namespace cta; ASSERT_TRUE(m_catalogue->getAdminUsers().empty()); - ASSERT_THROW(m_catalogue->deleteAdminUser("non_existant_sdmin_user"), exception::UserError); + ASSERT_THROW(m_catalogue->deleteAdminUser("non_existant_admin_user"), exception::UserError); } TEST_P(cta_catalogue_CatalogueTest, modifyAdminUserComment) { @@ -426,50 +309,40 @@ TEST_P(cta_catalogue_CatalogueTest, modifyAdminUserComment) { ASSERT_TRUE(m_catalogue->getAdminUsers().empty()); - m_catalogue->createBootstrapAdminAndHostNoAuth( - m_admin, m_bootstrapAdmin.username, m_bootstrapAdmin.host, m_bootstrapComment); + const std::string createAdminUserComment = "Create admin user"; + m_catalogue->createAdminUser(m_localAdmin, m_admin.username, createAdminUserComment); { std::list<common::dataStructures::AdminUser> admins; admins = m_catalogue->getAdminUsers(); ASSERT_EQ(1, admins.size()); - const common::dataStructures::AdminUser admin = admins.front(); - ASSERT_EQ(m_bootstrapComment, admin.comment); + const common::dataStructures::AdminUser a = admins.front(); - const common::dataStructures::EntryLog creationLog = admin.creationLog; - ASSERT_EQ(m_admin.username, creationLog.username); - ASSERT_EQ(m_admin.host, creationLog.host); - - const common::dataStructures::EntryLog lastModificationLog = - admin.lastModificationLog; - ASSERT_EQ(creationLog, lastModificationLog); - } - - const std::string createAdminUserComment = "Create admin user"; - m_catalogue->createAdminUser(m_bootstrapAdmin, m_admin.username, createAdminUserComment); - - { - std::map<std::string, common::dataStructures::AdminUser> admins = adminUserListToMap(m_catalogue->getAdminUsers()); - ASSERT_EQ(2, admins.size()); - - const auto itor = admins.find(m_admin.username); - ASSERT_FALSE(admins.end() == itor); - - ASSERT_EQ(createAdminUserComment, itor->second.comment); + ASSERT_EQ(m_admin.username, a.name); + ASSERT_EQ(createAdminUserComment, a.comment); + ASSERT_EQ(m_localAdmin.username, a.creationLog.username); + ASSERT_EQ(m_localAdmin.host, a.creationLog.host); + ASSERT_EQ(m_localAdmin.username, a.lastModificationLog.username); + ASSERT_EQ(m_localAdmin.host, a.lastModificationLog.host); } const std::string modifiedComment = "Modified comment"; - m_catalogue->modifyAdminUserComment(m_bootstrapAdmin, m_admin.username, modifiedComment); + m_catalogue->modifyAdminUserComment(m_localAdmin, m_admin.username, modifiedComment); { - std::map<std::string, common::dataStructures::AdminUser> admins = adminUserListToMap(m_catalogue->getAdminUsers()); - ASSERT_EQ(2, admins.size()); + std::list<common::dataStructures::AdminUser> admins; + admins = m_catalogue->getAdminUsers(); + ASSERT_EQ(1, admins.size()); - const auto itor = admins.find(m_admin.username); - ASSERT_FALSE(admins.end() == itor); + const common::dataStructures::AdminUser a = admins.front(); - ASSERT_EQ(modifiedComment, itor->second.comment); + ASSERT_EQ(m_admin.username, a.name); + ASSERT_EQ(modifiedComment, a.comment); + ASSERT_EQ(m_localAdmin.username, a.creationLog.username); + ASSERT_EQ(m_localAdmin.host, a.creationLog.host); + ASSERT_EQ(m_localAdmin.username, a.lastModificationLog.username); + ASSERT_EQ(m_localAdmin.host, a.lastModificationLog.host); } } @@ -479,7 +352,7 @@ TEST_P(cta_catalogue_CatalogueTest, modifyAdminUserComment_nonExtistentAdminUser ASSERT_TRUE(m_catalogue->getAdminUsers().empty()); const std::string modifiedComment = "Modified comment"; - ASSERT_THROW(m_catalogue->modifyAdminUserComment(m_bootstrapAdmin, m_admin.username, modifiedComment), + ASSERT_THROW(m_catalogue->modifyAdminUserComment(m_localAdmin, m_admin.username, modifiedComment), exception::UserError); } @@ -488,108 +361,49 @@ TEST_P(cta_catalogue_CatalogueTest, createAdminHost) { ASSERT_TRUE(m_catalogue->getAdminHosts().empty()); - m_catalogue->createBootstrapAdminAndHostNoAuth( - m_admin, m_bootstrapAdmin.username, m_bootstrapAdmin.host, m_bootstrapComment); - - { - std::list<common::dataStructures::AdminUser> admins; - admins = m_catalogue->getAdminUsers(); - ASSERT_EQ(1, admins.size()); - - const common::dataStructures::AdminUser admin = admins.front(); - ASSERT_EQ(m_bootstrapComment, admin.comment); - - const common::dataStructures::EntryLog creationLog = admin.creationLog; - ASSERT_EQ(m_admin.username, creationLog.username); - ASSERT_EQ(m_admin.host, creationLog.host); - - const common::dataStructures::EntryLog lastModificationLog = - admin.lastModificationLog; - ASSERT_EQ(creationLog, lastModificationLog); - } - - const std::string createAdminHostComment = "Create host user"; - const std::string anotherAdminHost = "another_admin_host"; - m_catalogue->createAdminHost(m_bootstrapAdmin, - anotherAdminHost, createAdminHostComment); + const std::string createAdminHostComment = "Create admin host"; + m_catalogue->createAdminHost(m_localAdmin, m_admin.host, createAdminHostComment); { std::list<common::dataStructures::AdminHost> hosts; hosts = m_catalogue->getAdminHosts(); - ASSERT_EQ(2, hosts.size()); - - const common::dataStructures::AdminHost h1 = hosts.front(); - hosts.pop_front(); - const common::dataStructures::AdminHost h2 = hosts.front(); - - ASSERT_NE(h1, h2); - ASSERT_TRUE( - (h1.name == m_bootstrapAdmin.host && h2.name == anotherAdminHost) - || - (h2.name == anotherAdminHost && h1.name == m_bootstrapAdmin.host) - ); - - if(h1.name == m_bootstrapAdmin.host) { - ASSERT_EQ(m_bootstrapAdmin.host, h1.name); - ASSERT_EQ(m_bootstrapComment, h1.comment); - ASSERT_EQ(m_admin.username, h1.creationLog.username); - ASSERT_EQ(m_admin.host, h1.creationLog.host); - ASSERT_EQ(m_admin.username, h1.lastModificationLog.username); - ASSERT_EQ(m_admin.host, h1.lastModificationLog.host); - - ASSERT_EQ(anotherAdminHost, h2.name); - ASSERT_EQ(createAdminHostComment, h2.comment); - ASSERT_EQ(m_bootstrapAdmin.username, h2.creationLog.username); - ASSERT_EQ(m_bootstrapAdmin.host, h2.creationLog.host); - ASSERT_EQ(m_bootstrapAdmin.username, h2.lastModificationLog.username); - ASSERT_EQ(m_bootstrapAdmin.host, h2.lastModificationLog.host); - } else { - ASSERT_EQ(m_bootstrapAdmin.host, h2.name); - ASSERT_EQ(m_bootstrapComment, h2.comment); - ASSERT_EQ(m_admin.username, h2.creationLog.username); - ASSERT_EQ(m_admin.host, h2.creationLog.host); - ASSERT_EQ(m_admin.username, h2.lastModificationLog.username); - ASSERT_EQ(m_admin.host, h2.lastModificationLog.host); - - ASSERT_EQ(anotherAdminHost, h1.name); - ASSERT_EQ(createAdminHostComment, h1.comment); - ASSERT_EQ(m_bootstrapAdmin.username, h1.creationLog.username); - ASSERT_EQ(m_bootstrapAdmin.host, h1.creationLog.host); - ASSERT_EQ(m_bootstrapAdmin.username, h1.lastModificationLog.username); - ASSERT_EQ(m_bootstrapAdmin.host, h1.lastModificationLog.host); - } + ASSERT_EQ(1, hosts.size()); + + const common::dataStructures::AdminHost h = hosts.front(); + + ASSERT_EQ(m_admin.host, h.name); + ASSERT_EQ(createAdminHostComment, h.comment); + ASSERT_EQ(m_localAdmin.username, h.creationLog.username); + ASSERT_EQ(m_localAdmin.host, h.creationLog.host); + ASSERT_EQ(m_localAdmin.username, h.lastModificationLog.username); + ASSERT_EQ(m_localAdmin.host, h.lastModificationLog.host); } } TEST_P(cta_catalogue_CatalogueTest, createAdminHost_same_twice) { using namespace cta; - m_catalogue->createBootstrapAdminAndHostNoAuth( - m_admin, m_bootstrapAdmin.username, m_bootstrapAdmin.host, m_bootstrapComment); + ASSERT_TRUE(m_catalogue->getAdminHosts().empty()); + + const std::string createAdminHostComment = "Create admin host"; + m_catalogue->createAdminHost(m_localAdmin, m_admin.host, createAdminHostComment); { - std::list<common::dataStructures::AdminUser> admins; - admins = m_catalogue->getAdminUsers(); - ASSERT_EQ(1, admins.size()); - - const common::dataStructures::AdminUser admin = admins.front(); - ASSERT_EQ(m_bootstrapComment, admin.comment); + std::list<common::dataStructures::AdminHost> hosts; + hosts = m_catalogue->getAdminHosts(); + ASSERT_EQ(1, hosts.size()); - const common::dataStructures::EntryLog creationLog = admin.creationLog; - ASSERT_EQ(m_admin.username, creationLog.username); - ASSERT_EQ(m_admin.host, creationLog.host); + const common::dataStructures::AdminHost h = hosts.front(); - const common::dataStructures::EntryLog lastModificationLog = - admin.lastModificationLog; - ASSERT_EQ(creationLog, lastModificationLog); + ASSERT_EQ(m_admin.host, h.name); + ASSERT_EQ(createAdminHostComment, h.comment); + ASSERT_EQ(m_localAdmin.username, h.creationLog.username); + ASSERT_EQ(m_localAdmin.host, h.creationLog.host); + ASSERT_EQ(m_localAdmin.username, h.lastModificationLog.username); + ASSERT_EQ(m_localAdmin.host, h.lastModificationLog.host); } - const std::string anotherAdminHost = "another_admin_host"; - - m_catalogue->createAdminHost(m_bootstrapAdmin, anotherAdminHost, "comment 1"); - - ASSERT_THROW(m_catalogue->createAdminHost(m_bootstrapAdmin, - anotherAdminHost, "comment 2"), exception::UserError); + ASSERT_THROW(m_catalogue->createAdminHost(m_localAdmin, m_admin.host, "comment 2"), exception::UserError); } TEST_P(cta_catalogue_CatalogueTest, deleteAdminHost) { @@ -597,27 +411,25 @@ TEST_P(cta_catalogue_CatalogueTest, deleteAdminHost) { ASSERT_TRUE(m_catalogue->getAdminHosts().empty()); - m_catalogue->createBootstrapAdminAndHostNoAuth( - m_admin, m_bootstrapAdmin.username, m_bootstrapAdmin.host, m_bootstrapComment); + const std::string createAdminHostComment = "Create admin host"; + m_catalogue->createAdminHost(m_localAdmin, m_admin.host, createAdminHostComment); { - std::list<common::dataStructures::AdminUser> admins; - admins = m_catalogue->getAdminUsers(); - ASSERT_EQ(1, admins.size()); + std::list<common::dataStructures::AdminHost> hosts; + hosts = m_catalogue->getAdminHosts(); + ASSERT_EQ(1, hosts.size()); - const common::dataStructures::AdminUser admin = admins.front(); - ASSERT_EQ(m_bootstrapComment, admin.comment); + const common::dataStructures::AdminHost h = hosts.front(); - const common::dataStructures::EntryLog creationLog = admin.creationLog; - ASSERT_EQ(m_admin.username, creationLog.username); - ASSERT_EQ(m_admin.host, creationLog.host); - - const common::dataStructures::EntryLog lastModificationLog = - admin.lastModificationLog; - ASSERT_EQ(creationLog, lastModificationLog); + ASSERT_EQ(m_admin.host, h.name); + ASSERT_EQ(createAdminHostComment, h.comment); + ASSERT_EQ(m_localAdmin.username, h.creationLog.username); + ASSERT_EQ(m_localAdmin.host, h.creationLog.host); + ASSERT_EQ(m_localAdmin.username, h.lastModificationLog.username); + ASSERT_EQ(m_localAdmin.host, h.lastModificationLog.host); } - m_catalogue->deleteAdminHost(m_bootstrapAdmin.host); + m_catalogue->deleteAdminHost(m_admin.host); ASSERT_TRUE(m_catalogue->getAdminHosts().empty()); } @@ -634,49 +446,40 @@ TEST_P(cta_catalogue_CatalogueTest, modifyAdminHostComment) { ASSERT_TRUE(m_catalogue->getAdminHosts().empty()); - m_catalogue->createBootstrapAdminAndHostNoAuth( - m_admin, m_bootstrapAdmin.username, m_bootstrapAdmin.host, m_bootstrapComment); + const std::string createAdminHostComment = "Create admin host"; + m_catalogue->createAdminHost(m_localAdmin, m_admin.host, createAdminHostComment); { - const std::list<common::dataStructures::AdminHost> hosts = m_catalogue->getAdminHosts(); + std::list<common::dataStructures::AdminHost> hosts; + hosts = m_catalogue->getAdminHosts(); ASSERT_EQ(1, hosts.size()); - const common::dataStructures::AdminHost host = hosts.front(); - ASSERT_EQ(m_bootstrapComment, host.comment); + const common::dataStructures::AdminHost h = hosts.front(); - const common::dataStructures::EntryLog creationLog = host.creationLog; - ASSERT_EQ(m_admin.username, creationLog.username); - ASSERT_EQ(m_admin.host, creationLog.host); - - const common::dataStructures::EntryLog lastModificationLog = host.lastModificationLog; - ASSERT_EQ(creationLog, lastModificationLog); - } - - const std::string createAdminHostComment = "Create host user"; - const std::string anotherAdminHost = "another_admin_host"; - m_catalogue->createAdminHost(m_bootstrapAdmin, anotherAdminHost, createAdminHostComment); - - { - std::map<std::string, common::dataStructures::AdminHost> hosts = adminHostListToMap(m_catalogue->getAdminHosts()); - ASSERT_EQ(2, hosts.size()); - - const auto itor = hosts.find(anotherAdminHost); - ASSERT_FALSE(hosts.end() == itor); - - ASSERT_EQ(createAdminHostComment, itor->second.comment); + ASSERT_EQ(m_admin.host, h.name); + ASSERT_EQ(createAdminHostComment, h.comment); + ASSERT_EQ(m_localAdmin.username, h.creationLog.username); + ASSERT_EQ(m_localAdmin.host, h.creationLog.host); + ASSERT_EQ(m_localAdmin.username, h.lastModificationLog.username); + ASSERT_EQ(m_localAdmin.host, h.lastModificationLog.host); } const std::string modifiedComment = "Modified comment"; - m_catalogue->modifyAdminHostComment(m_bootstrapAdmin, anotherAdminHost, modifiedComment); + m_catalogue->modifyAdminHostComment(m_localAdmin, m_admin.host, modifiedComment); { - std::map<std::string, common::dataStructures::AdminHost> hosts = adminHostListToMap(m_catalogue->getAdminHosts()); - ASSERT_EQ(2, hosts.size()); + std::list<common::dataStructures::AdminHost> hosts; + hosts = m_catalogue->getAdminHosts(); + ASSERT_EQ(1, hosts.size()); - const auto itor = hosts.find(anotherAdminHost); - ASSERT_FALSE(hosts.end() == itor); + const common::dataStructures::AdminHost h = hosts.front(); - ASSERT_EQ(modifiedComment, itor->second.comment); + ASSERT_EQ(m_admin.host, h.name); + ASSERT_EQ(modifiedComment, h.comment); + ASSERT_EQ(m_localAdmin.username, h.creationLog.username); + ASSERT_EQ(m_localAdmin.host, h.creationLog.host); + ASSERT_EQ(m_localAdmin.username, h.lastModificationLog.username); + ASSERT_EQ(m_localAdmin.host, h.lastModificationLog.host); } } @@ -689,10 +492,47 @@ TEST_P(cta_catalogue_CatalogueTest, isAdmin_false) { TEST_P(cta_catalogue_CatalogueTest, isAdmin_true) { using namespace cta; - m_catalogue->createBootstrapAdminAndHostNoAuth( - m_admin, m_bootstrapAdmin.username, m_bootstrapAdmin.host, m_bootstrapComment); + ASSERT_TRUE(m_catalogue->getAdminUsers().empty()); + + const std::string createAdminUserComment = "Create admin user"; + m_catalogue->createAdminUser(m_localAdmin, m_admin.username, createAdminUserComment); + + { + std::list<common::dataStructures::AdminUser> admins; + admins = m_catalogue->getAdminUsers(); + ASSERT_EQ(1, admins.size()); + + const common::dataStructures::AdminUser a = admins.front(); + + ASSERT_EQ(m_admin.username, a.name); + ASSERT_EQ(createAdminUserComment, a.comment); + ASSERT_EQ(m_localAdmin.username, a.creationLog.username); + ASSERT_EQ(m_localAdmin.host, a.creationLog.host); + ASSERT_EQ(m_localAdmin.username, a.lastModificationLog.username); + ASSERT_EQ(m_localAdmin.host, a.lastModificationLog.host); + } + + ASSERT_TRUE(m_catalogue->getAdminHosts().empty()); + + const std::string createAdminHostComment = "Create admin host"; + m_catalogue->createAdminHost(m_localAdmin, m_admin.host, createAdminHostComment); + + { + std::list<common::dataStructures::AdminHost> hosts; + hosts = m_catalogue->getAdminHosts(); + ASSERT_EQ(1, hosts.size()); + + const common::dataStructures::AdminHost h = hosts.front(); + + ASSERT_EQ(m_admin.host, h.name); + ASSERT_EQ(createAdminHostComment, h.comment); + ASSERT_EQ(m_localAdmin.username, h.creationLog.username); + ASSERT_EQ(m_localAdmin.host, h.creationLog.host); + ASSERT_EQ(m_localAdmin.username, h.lastModificationLog.username); + ASSERT_EQ(m_localAdmin.host, h.lastModificationLog.host); + } - ASSERT_TRUE(m_catalogue->isAdmin(m_bootstrapAdmin)); + ASSERT_TRUE(m_catalogue->isAdmin(m_admin)); } TEST_P(cta_catalogue_CatalogueTest, createStorageClass) { diff --git a/catalogue/CatalogueTest.hpp b/catalogue/CatalogueTest.hpp index 4f898ae3a663b36926babe8ab02075538fee7014..5ef2601ca5857c1bc8c964814895c52253c3321c 100644 --- a/catalogue/CatalogueTest.hpp +++ b/catalogue/CatalogueTest.hpp @@ -39,8 +39,7 @@ public: protected: std::unique_ptr<cta::catalogue::Catalogue> m_catalogue; - const std::string m_bootstrapComment; - cta::common::dataStructures::SecurityIdentity m_bootstrapAdmin; + cta::common::dataStructures::SecurityIdentity m_localAdmin; cta::common::dataStructures::SecurityIdentity m_admin; /** diff --git a/catalogue/RdbmsCatalogue.cpp b/catalogue/RdbmsCatalogue.cpp index 4d7a8bdb0550ad776a450e25f204e8d99d9b097c..ec7cb7863dd02cb3246d7a28283f107af9562b98 100644 --- a/catalogue/RdbmsCatalogue.cpp +++ b/catalogue/RdbmsCatalogue.cpp @@ -48,24 +48,6 @@ RdbmsCatalogue::RdbmsCatalogue(std::unique_ptr<rdbms::ConnFactory> connFactory, RdbmsCatalogue::~RdbmsCatalogue() { } -//------------------------------------------------------------------------------ -// createBootstrapAdminAndHostNoAuth -//------------------------------------------------------------------------------ -void RdbmsCatalogue::createBootstrapAdminAndHostNoAuth( - const common::dataStructures::SecurityIdentity &admin, - const std::string &username, - const std::string &hostName, - const std::string &comment) { - try { - createAdminUser(admin, username, comment); - createAdminHost(admin, hostName, comment); - } catch(exception::UserError &) { - throw; - } catch (exception::Exception &ex) { - throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); - } -} - //------------------------------------------------------------------------------ // createAdminUser //------------------------------------------------------------------------------ diff --git a/catalogue/RdbmsCatalogue.hpp b/catalogue/RdbmsCatalogue.hpp index 7b14d3294a7db76b080ac51c04a0e2cb7483d2af..7bff9e3f7fe53f7a13faad773bea03ef7d6c253c 100644 --- a/catalogue/RdbmsCatalogue.hpp +++ b/catalogue/RdbmsCatalogue.hpp @@ -172,8 +172,6 @@ public: // END OF METHODS DIRECTLY INVOLVED IN DATA TRANSFER AND SCHEDULING /////////////////////////////////////////////////////////////////// - void createBootstrapAdminAndHostNoAuth(const common::dataStructures::SecurityIdentity &admin, const std::string &username, const std::string &hostName, const std::string &comment) override; - void createAdminUser(const common::dataStructures::SecurityIdentity &admin, const std::string &username, const std::string &comment) override; void deleteAdminUser(const std::string &username) override; std::list<common::dataStructures::AdminUser> getAdminUsers() const override;