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

All unit tests now pass

parent 78fd719a
......@@ -27,7 +27,7 @@ void cta::MockMiddleTierAdmin::createAdminUser(
const std::string &comment) {
checkAdminUserDoesNotAlreadyExist(user);
AdminUser adminUser(user, requester.user, comment);
m_db.adminUsers[user.uid] = adminUser;
m_db.adminUsers[user.getUid()] = adminUser;
}
//------------------------------------------------------------------------------
......@@ -36,10 +36,10 @@ void cta::MockMiddleTierAdmin::createAdminUser(
void cta::MockMiddleTierAdmin::checkAdminUserDoesNotAlreadyExist(
const UserIdentity &user) const {
std::map<uint32_t, AdminUser>::const_iterator itor =
m_db.adminUsers.find(user.uid);
m_db.adminUsers.find(user.getUid());
if(itor != m_db.adminUsers.end()) {
std::ostringstream message;
message << "Administrator with uid " << user.uid <<
message << "Administrator with uid " << user.getUid() <<
" already exists";
throw(Exception(message.str()));
}
......@@ -53,7 +53,7 @@ void cta::MockMiddleTierAdmin::deleteAdminUser(
const UserIdentity &user) {
for(std::map<uint32_t, AdminUser>::iterator itor = m_db.adminUsers.begin();
itor != m_db.adminUsers.end(); itor++) {
if(user.uid == itor->first) {
if(user.getUid() == itor->first) {
m_db.adminUsers.erase(itor);
return;
}
......@@ -61,7 +61,7 @@ void cta::MockMiddleTierAdmin::deleteAdminUser(
// Reaching this point means the administrator to be deleted does not exist
std::ostringstream message;
message << "Administration with uid " << user.uid << " does not exist";
message << "Administration with uid " << user.getUid() << " does not exist";
throw Exception(message.str());
}
......
......@@ -39,8 +39,8 @@ TEST_F(cta_client_MockMiddleTierAdminTest, createAdminUser_new) {
ASSERT_NO_THROW(adminUsers = adminApi.getAdminUsers(requester));
ASSERT_EQ(1, adminUsers.size());
ASSERT_EQ(adminUser1Uid, adminUsers.front().getUser().uid);
ASSERT_EQ(adminUser1Gid, adminUsers.front().getUser().gid);
ASSERT_EQ(adminUser1Uid, adminUsers.front().getUser().getUid());
ASSERT_EQ(adminUser1Gid, adminUsers.front().getUser().getGid());
ASSERT_EQ(comment, adminUsers.front().getComment());
}
}
......@@ -69,8 +69,8 @@ TEST_F(cta_client_MockMiddleTierAdminTest, createAdminUser_already_existing) {
ASSERT_NO_THROW(adminUsers = adminApi.getAdminUsers(requester));
ASSERT_EQ(1, adminUsers.size());
ASSERT_EQ(adminUser1Uid, adminUsers.front().getUser().uid);
ASSERT_EQ(adminUser1Gid, adminUsers.front().getUser().gid);
ASSERT_EQ(adminUser1Uid, adminUsers.front().getUser().getUid());
ASSERT_EQ(adminUser1Gid, adminUsers.front().getUser().getGid());
ASSERT_EQ(comment, adminUsers.front().getComment());
}
......@@ -108,8 +108,8 @@ TEST_F(cta_client_MockMiddleTierAdminTest, deleteAdminUser_existing) {
ASSERT_NO_THROW(adminUsers = adminApi.getAdminUsers(requester));
ASSERT_EQ(1, adminUsers.size());
ASSERT_EQ(adminUser1Uid, adminUsers.front().getUser().uid);
ASSERT_EQ(adminUser1Gid, adminUsers.front().getUser().gid);
ASSERT_EQ(adminUser1Uid, adminUsers.front().getUser().getUid());
ASSERT_EQ(adminUser1Gid, adminUsers.front().getUser().getGid());
ASSERT_EQ(comment, adminUsers.front().getComment());
}
......
#include "UserIdentity.hpp"
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
cta::UserIdentity::UserIdentity() throw():
uid(0),
gid(0) {
m_uid(0),
m_gid(0) {
}
//------------------------------------------------------------------------------
......@@ -15,6 +14,34 @@ cta::UserIdentity::UserIdentity() throw():
cta::UserIdentity::UserIdentity(
const uint32_t uid,
const uint32_t gid) throw():
uid(uid),
gid(gid) {
m_uid(uid),
m_gid(gid) {
}
//------------------------------------------------------------------------------
// setUid
//------------------------------------------------------------------------------
void cta::UserIdentity::setUid(const uint32_t uid) throw() {
m_uid = uid;
}
//------------------------------------------------------------------------------
// getUid
//------------------------------------------------------------------------------
uint32_t cta::UserIdentity::getUid() const throw() {
return m_uid;
}
//------------------------------------------------------------------------------
// setGid
//------------------------------------------------------------------------------
void cta::UserIdentity::setGid(const uint32_t gid) throw() {
m_gid = gid;
}
//------------------------------------------------------------------------------
// getGid
//------------------------------------------------------------------------------
uint32_t cta::UserIdentity::getGid() const throw() {
return m_gid;
}
......@@ -8,17 +8,8 @@ namespace cta {
/**
* Class reprsenting the identity of a user.
*/
struct UserIdentity {
/**
* The user ID of the user.
*/
uint32_t uid;
/**
* The group ID of the user.
*/
uint32_t gid;
class UserIdentity {
public:
/**
* Constructor.
......@@ -35,6 +26,43 @@ struct UserIdentity {
*/
UserIdentity(const uint32_t uid, const uint32_t gid) throw();
}; // struct UserIdentity
/**
* Sets the user ID of the user.
*
* @patam uid The user ID of the user.
*/
void setUid(const uint32_t uid) throw();
/**
* Returns the user ID of the user.
*/
uint32_t getUid() const throw();
/**
* Sets the group ID of the user.
*
* @param gid The group ID of the user.
*/
void setGid(const uint32_t gid) throw();
/**
* Returns the group ID of the user.
*/
uint32_t getGid() const throw();
private:
/**
* The user ID of the user.
*/
uint32_t m_uid;
/**
* The group ID of the user.
*/
uint32_t m_gid;
}; // class UserIdentity
} // namespace cta
......@@ -69,8 +69,8 @@ int XrdProFilesystem::checkClient(const XrdSecEntity *client, XrdOucErrInfo &eIn
}
std::cout << "Request received from client. Username: " << client->name << " uid: " << pwd.pw_uid << " gid: " << pwd.pw_gid << std::endl;
requester.host = client->host;
requester.user.uid = pwd.pw_uid;
requester.user.gid = pwd.pw_gid;
requester.user.setUid(pwd.pw_uid);
requester.user.setGid(pwd.pw_gid);
free(buf);
return SFS_OK;
}
......@@ -320,7 +320,7 @@ int XrdProFilesystem::executeLsclassCommand(const ParsedRequest &req, XrdOucErrI
responseSS << "[OK] Listing of the storage class names and no of copies:";
for(std::list<cta::StorageClass>::iterator it = stgList.begin(); it != stgList.end(); it++) {
responseSS << "\n" << it->getName() << " " << it->getNbCopies() << " "
<< it->getCreator().uid << " " << it->getCreator().gid << " "
<< it->getCreator().getUid() << " " << it->getCreator().getGid() << " "
<< it->getCreationTime() << " \"" << it->getComment() << "\"";
}
eInfo.setErrInfo(responseSS.str().length()+1, responseSS.str().c_str());
......@@ -538,7 +538,7 @@ int XrdProFilesystem::executeLspoolCommand(const ParsedRequest &req, XrdOucErrIn
std::ostringstream responseSS;
responseSS << "[OK] Listing of the tape pools:";
for(std::list<cta::TapePool>::iterator it = poolList.begin(); it != poolList.end(); it++) {
responseSS << "\n" << it->getName() << " " << it->getCreator().uid << " " << it->getCreator().gid << " "
responseSS << "\n" << it->getName() << " " << it->getCreator().getUid() << " " << it->getCreator().getGid() << " "
<< it->getCreationTime() << " \"" << it->getComment() << "\"";
}
eInfo.setErrInfo(responseSS.str().length()+1, responseSS.str().c_str());
......@@ -646,8 +646,8 @@ int XrdProFilesystem::executeLsrouteCommand(const ParsedRequest &req, XrdOucErrI
for(std::list<cta::MigrationRoute>::iterator it = routeList.begin(); it != routeList.end(); it++) {
responseSS << "\n" << it->getStorageClassName() << ":" << it->getCopyNb()
<< " " << it->getTapePoolName()
<< " " << it->getCreator().uid
<< " " << it->getCreator().gid
<< " " << it->getCreator().getUid()
<< " " << it->getCreator().getGid()
<< " \"" << it->getComment() << "\"";
}
eInfo.setErrInfo(responseSS.str().length()+1, responseSS.str().c_str());
......@@ -680,8 +680,14 @@ int XrdProFilesystem::executeMkadminuserCommand(const ParsedRequest &req, XrdOuc
}
try {
cta::UserIdentity adminUser;
std::istringstream i0(req.args.at(0)); i0 >> adminUser.uid;
std::istringstream i1(req.args.at(1)); i1 >> adminUser.gid;
std::istringstream i0(req.args.at(0));
int uid = 0;
i0 >> uid;
adminUser.setUid(uid);
std::istringstream i1(req.args.at(1));
int gid = 0;
i1 >> gid;
adminUser.setGid(gid);
const std::string comment = "TO BE DONE";
m_adminApi.createAdminUser(requester, adminUser, comment);
std::ostringstream responseSS;
......@@ -717,9 +723,13 @@ int XrdProFilesystem::executeRmadminuserCommand(const ParsedRequest &req, XrdOuc
try {
cta::UserIdentity adminUser;
std::stringstream ssArg0(req.args.at(0));
ssArg0 >> adminUser.uid;
int uid = 0;
ssArg0 >> uid;
adminUser.setUid(uid);
std::stringstream ssArg1(req.args.at(1));
ssArg0 >> adminUser.gid;
int gid = 0;
ssArg0 >> gid;
adminUser.setGid(gid);
m_adminApi.deleteAdminUser(requester, adminUser);
std::ostringstream responseSS;
responseSS << "[OK] Admin user with uid " << req.args.at(0) << " and gid " << req.args.at(1) << " deleted";
......@@ -756,7 +766,7 @@ int XrdProFilesystem::executeLsadminuserCommand(const ParsedRequest &req, XrdOuc
std::ostringstream responseSS;
responseSS << "[OK] Listing of the admin user uids and gids:";
for(std::list<cta::AdminUser>::iterator it = userIdList.begin(); it != userIdList.end(); it++) {
responseSS << "\n" << it->getUser().uid << " " << it->getUser().gid;
responseSS << "\n" << it->getUser().getUid() << " " << it->getUser().getGid();
}
eInfo.setErrInfo(responseSS.str().length()+1, responseSS.str().c_str());
return SFS_DATA;
......
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