#include <algorithm>
#include <fstream>
+#include <regex>
#include <string>
#include <unordered_set>
Api::uninstall(requestUninst);
}
-void setupPriviligeGroups(const privileges_t &priviliges, const std::vector<std::string> &groups)
+void setupPrivilegeGroups(const privileges_t &privileges, const std::vector<std::string> &groups)
{
TestSecurityManagerDatabase db;
- for (const auto &privilege : priviliges) {
+ for (const auto &privilege : privileges) {
db.setup_privilege_groups(privilege, groups);
}
}
+std::vector<std::string> readPrivilegeGroups()
+{
+ std::vector<std::string> groups;
+ const static std::string privilegeGroupMappingPath("/usr/share/security-manager/policy/privilege-group.list");
+ std::ifstream mappingFile(privilegeGroupMappingPath);
+
+ RUNNER_ASSERT_MSG(mappingFile.is_open(),
+ "Unable to read group mapping file " << privilegeGroupMappingPath);
+
+ std::string line;
+ std::regex r("^[^ #]+ +(.*)");
+ while (std::getline(mappingFile, line)) {
+ std::smatch m;
+ if (std::regex_search(line, m, r))
+ groups.push_back(m[1]);
+ }
+
+ return groups;
+}
+
RUNNER_TEST(security_manager_48_groups_get)
{
- const auto &groups = SM_ALLOWED_GROUPS;
- const auto &priviliges = SM_ALLOWED_PRIVILEGES;
- setupPriviligeGroups(priviliges, groups);
+ setupPrivilegeGroups(SM_ALLOWED_PRIVILEGES, SM_ALLOWED_GROUPS);
+
+ std::unordered_set<std::string> groups;
+ auto tmp = readPrivilegeGroups();
+ groups.insert(tmp.begin(), tmp.end());
+ groups.insert(SM_ALLOWED_GROUPS.begin(), SM_ALLOWED_GROUPS.end());
char ** c_groups;
size_t count = 0;
break;
}
}
- RUNNER_ASSERT_MSG(found, "PriviligeGroup: " << group << " was not found");
+ RUNNER_ASSERT_MSG(found, "PrivilegeGroup: " << group << " was not found");
}
security_manager_groups_free(c_groups, count);
}