Skip to content

Commit

Permalink
Rearranged the order of things on audit object descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
joesiltberg committed Nov 14, 2024
1 parent 42c8596 commit 73170c3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
9 changes: 5 additions & 4 deletions src/audit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ std::string scim_operation_audit_message(bool success,
// Assumes object is not a nullptr
std::string object_description(std::shared_ptr<rendered_object> object) {
std::ostringstream os;
os << object->get_id();

// Try to parse JSON
namespace pt = boost::property_tree;
Expand All @@ -121,21 +120,21 @@ std::string object_description(std::shared_ptr<rendered_object> object) {
json_stream << object->get_json();
pt::read_json(json_stream, root);
} catch (const pt::ptree_error&) {
os << " (unparsable JSON)";
os << object->get_id() << " (unparsable JSON)";
return os.str();
}

// If there's a userName attribute, use that
auto userName = root.get_optional<std::string>("userName");
if (userName) {
os << " " << userName.get();
os << userName.get() << " (" << object->get_id() << ")";
return os.str();
}

// Otherwise if there's a displayName, use that
auto displayName = root.get_optional<std::string>("displayName");
if (displayName) {
os << " " << displayName.get();
os << displayName.get() << " (" << object->get_id() << ")";
auto owner = root.get_optional<std::string>("owner.value");
if (owner) {
os << " owner: " << owner.get();
Expand All @@ -145,6 +144,7 @@ std::string object_description(std::shared_ptr<rendered_object> object) {

// Otherwise if type == Employment, use UUIDs for user and school unit
if (object->get_type() == "Employment") {
os << object->get_id();
auto user = root.get_optional<std::string>("user.value");
auto schoolUnit = root.get_optional<std::string>("employedAt.value");
if (user) {
Expand All @@ -156,6 +156,7 @@ std::string object_description(std::shared_ptr<rendered_object> object) {
return os.str();
}

os << object->get_id();
return os.str();
}

Expand Down
28 changes: 14 additions & 14 deletions src/tests/audit_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ TEST_CASE("Object description") {
REQUIRE(object_description(unparsable) == "1 (unparsable JSON)");

auto student = std::make_shared<rendered_object>("2", "Student", R"xyz({"userName": "baje"})xyz");
REQUIRE(object_description(student) == "2 baje");
REQUIRE(object_description(student) == "baje (2)");

auto group = std::make_shared<rendered_object>("3", "StudentGroup", R"xyz({"displayName": "6A", "owner": { "value": "0" }})xyz");
REQUIRE(object_description(group) == "3 6A owner: 0");
REQUIRE(object_description(group) == "6A (3) owner: 0");

auto employment = std::make_shared<rendered_object>("4", "Employment", R"xyz({"user": { "value": "2" }, "employedAt": { "value": "0"}})xyz");
REQUIRE(object_description(employment) == "4 user: 2 employed at: 0");

auto user = std::make_shared<rendered_object>("5", "User", R"xyz({"userName": "pejo"})xyz");
REQUIRE(object_description(user) == "5 pejo");
REQUIRE(object_description(user) == "pejo (5)");

auto unknownWithDisplayName = std::make_shared<rendered_object>("6", "Unknown", R"xyz({"displayName": "foo"})xyz");
REQUIRE(object_description(unknownWithDisplayName) == "6 foo");
REQUIRE(object_description(unknownWithDisplayName) == "foo (6)");

auto unknownWithoutAnythingHelpful = std::make_shared<rendered_object>("7", "Unknown", R"xyz({"foo": "bar"})xyz");
REQUIRE(object_description(unknownWithoutAnythingHelpful) == "7");
Expand All @@ -30,20 +30,20 @@ TEST_CASE("Log SCIM audit message") {
auto previous = std::make_shared<rendered_object>("1", "StudentGroup", R"xyz({"displayName": "A"})xyz");
auto current = std::make_shared<rendered_object>("1", "StudentGroup", R"xyz({"displayName": "B"})xyz");

REQUIRE(scim_operation_audit_message(true, SCIM_OTHER_FAILURE, SCIM_CREATE, "StudentGroup", "1", nullptr, current) == "Created StudentGroup 1 B");
REQUIRE(scim_operation_audit_message(false, SCIM_OTHER_FAILURE, SCIM_CREATE, "StudentGroup", "1", nullptr, current) == "Failed to create StudentGroup 1 B");
REQUIRE(scim_operation_audit_message(true, SCIM_OTHER_FAILURE, SCIM_CREATE, "StudentGroup", "1", nullptr, current) == "Created StudentGroup B (1)");
REQUIRE(scim_operation_audit_message(false, SCIM_OTHER_FAILURE, SCIM_CREATE, "StudentGroup", "1", nullptr, current) == "Failed to create StudentGroup B (1)");
REQUIRE(scim_operation_audit_message(false, SCIM_OTHER_FAILURE, SCIM_CREATE, "StudentGroup", "1", nullptr, nullptr) == "Failed to create StudentGroup 1");
REQUIRE(scim_operation_audit_message(false, SCIM_CONFLICT_FAILURE, SCIM_CREATE, "StudentGroup", "1", nullptr, current) == "Failed to create (conflict) StudentGroup 1 B");
REQUIRE(scim_operation_audit_message(false, SCIM_CONFLICT_FAILURE, SCIM_CREATE, "StudentGroup", "1", nullptr, current) == "Failed to create (conflict) StudentGroup B (1)");

REQUIRE(scim_operation_audit_message(true, SCIM_OTHER_FAILURE, SCIM_UPDATE, "StudentGroup", "1", nullptr, current) == "Updated StudentGroup 1 B");
REQUIRE(scim_operation_audit_message(true, SCIM_OTHER_FAILURE, SCIM_UPDATE, "StudentGroup", "1", previous, current) == "Updated StudentGroup 1 B");
REQUIRE(scim_operation_audit_message(false, SCIM_OTHER_FAILURE, SCIM_UPDATE, "StudentGroup", "1", nullptr, current) == "Failed to update StudentGroup 1 B");
REQUIRE(scim_operation_audit_message(true, SCIM_OTHER_FAILURE, SCIM_UPDATE, "StudentGroup", "1", nullptr, current) == "Updated StudentGroup B (1)");
REQUIRE(scim_operation_audit_message(true, SCIM_OTHER_FAILURE, SCIM_UPDATE, "StudentGroup", "1", previous, current) == "Updated StudentGroup B (1)");
REQUIRE(scim_operation_audit_message(false, SCIM_OTHER_FAILURE, SCIM_UPDATE, "StudentGroup", "1", nullptr, current) == "Failed to update StudentGroup B (1)");
REQUIRE(scim_operation_audit_message(false, SCIM_OTHER_FAILURE, SCIM_UPDATE, "StudentGroup", "1", nullptr, nullptr) == "Failed to update StudentGroup 1");
REQUIRE(scim_operation_audit_message(false, SCIM_NOT_FOUND_FAILURE, SCIM_UPDATE, "StudentGroup", "1", previous, current) == "Failed to update (not found) StudentGroup 1 B");
REQUIRE(scim_operation_audit_message(false, SCIM_NOT_FOUND_FAILURE, SCIM_UPDATE, "StudentGroup", "1", previous, current) == "Failed to update (not found) StudentGroup B (1)");

REQUIRE(scim_operation_audit_message(true, SCIM_OTHER_FAILURE, SCIM_DELETE, "StudentGroup", "1", previous, nullptr) == "Deleted StudentGroup 1 A");
REQUIRE(scim_operation_audit_message(true, SCIM_OTHER_FAILURE, SCIM_DELETE, "StudentGroup", "1", previous, nullptr) == "Deleted StudentGroup A (1)");
REQUIRE(scim_operation_audit_message(true, SCIM_OTHER_FAILURE, SCIM_DELETE, "StudentGroup", "1", nullptr, nullptr) == "Deleted StudentGroup 1");
REQUIRE(scim_operation_audit_message(false, SCIM_OTHER_FAILURE, SCIM_DELETE, "StudentGroup", "1", previous, nullptr) == "Failed to delete StudentGroup 1 A");
REQUIRE(scim_operation_audit_message(false, SCIM_OTHER_FAILURE, SCIM_DELETE, "StudentGroup", "1", previous, nullptr) == "Failed to delete StudentGroup A (1)");
REQUIRE(scim_operation_audit_message(false, SCIM_OTHER_FAILURE, SCIM_DELETE, "StudentGroup", "1", nullptr, nullptr) == "Failed to delete StudentGroup 1");
REQUIRE(scim_operation_audit_message(false, SCIM_NOT_FOUND_FAILURE, SCIM_DELETE, "StudentGroup", "1", previous, nullptr) == "Failed to delete (not found) StudentGroup 1 A");
REQUIRE(scim_operation_audit_message(false, SCIM_NOT_FOUND_FAILURE, SCIM_DELETE, "StudentGroup", "1", previous, nullptr) == "Failed to delete (not found) StudentGroup A (1)");
}

0 comments on commit 73170c3

Please sign in to comment.