diff --git a/src/audit.cpp b/src/audit.cpp index df4d9bc..4caee94 100644 --- a/src/audit.cpp +++ b/src/audit.cpp @@ -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 object) { std::ostringstream os; - os << object->get_id(); // Try to parse JSON namespace pt = boost::property_tree; @@ -121,21 +120,21 @@ std::string object_description(std::shared_ptr 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("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("displayName"); if (displayName) { - os << " " << displayName.get(); + os << displayName.get() << " (" << object->get_id() << ")"; auto owner = root.get_optional("owner.value"); if (owner) { os << " owner: " << owner.get(); @@ -145,6 +144,7 @@ std::string object_description(std::shared_ptr 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("user.value"); auto schoolUnit = root.get_optional("employedAt.value"); if (user) { @@ -156,6 +156,7 @@ std::string object_description(std::shared_ptr object) { return os.str(); } + os << object->get_id(); return os.str(); } diff --git a/src/tests/audit_tests.cpp b/src/tests/audit_tests.cpp index a897a8c..e349d56 100644 --- a/src/tests/audit_tests.cpp +++ b/src/tests/audit_tests.cpp @@ -8,19 +8,19 @@ TEST_CASE("Object description") { REQUIRE(object_description(unparsable) == "1 (unparsable JSON)"); auto student = std::make_shared("2", "Student", R"xyz({"userName": "baje"})xyz"); - REQUIRE(object_description(student) == "2 baje"); + REQUIRE(object_description(student) == "baje (2)"); auto group = std::make_shared("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("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("5", "User", R"xyz({"userName": "pejo"})xyz"); - REQUIRE(object_description(user) == "5 pejo"); + REQUIRE(object_description(user) == "pejo (5)"); auto unknownWithDisplayName = std::make_shared("6", "Unknown", R"xyz({"displayName": "foo"})xyz"); - REQUIRE(object_description(unknownWithDisplayName) == "6 foo"); + REQUIRE(object_description(unknownWithDisplayName) == "foo (6)"); auto unknownWithoutAnythingHelpful = std::make_shared("7", "Unknown", R"xyz({"foo": "bar"})xyz"); REQUIRE(object_description(unknownWithoutAnythingHelpful) == "7"); @@ -30,20 +30,20 @@ TEST_CASE("Log SCIM audit message") { auto previous = std::make_shared("1", "StudentGroup", R"xyz({"displayName": "A"})xyz"); auto current = std::make_shared("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)"); }