Skip to content

Commit

Permalink
Rewrite one audit test to not add a temporary descriptor
Browse files Browse the repository at this point in the history
We'll no longer support adding descriptors on the fly

Change-Id: I3ee64d5602a4e5cb5ca9a9ed213811becd87e554
Reviewed-on: https://review.couchbase.org/c/kv_engine/+/181636
Tested-by: Build Bot <build@couchbase.com>
Reviewed-by: James H <james.harrison@couchbase.com>
Reviewed-by: Vesko Karaganev <vesko.karaganev@couchbase.com>
  • Loading branch information
trondn committed Oct 26, 2022
1 parent 17cd56a commit 9b54504
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 27 deletions.
1 change: 1 addition & 0 deletions auditd/tests/CMakeLists.txt
Expand Up @@ -22,6 +22,7 @@ add_test(NAME memcached-audit-test
add_sanitizers(memcached_audit_test)

cb_add_test_executable(memcached_auditd_tests testauditd.cc)
target_include_directories(memcached_auditd_tests PRIVATE ${Memcached_BINARY_DIR})
kv_enable_pch(memcached_auditd_tests)
target_link_libraries(memcached_auditd_tests PRIVATE
auditd memcached_logger mcd_util mcd_time platform GTest::gtest)
Expand Down
39 changes: 12 additions & 27 deletions auditd/tests/testauditd.cc
Expand Up @@ -8,6 +8,7 @@
* software will be governed by the Apache License, Version 2.0, included in
* the file licenses/APL2.txt.
*/
#include <auditd/couchbase_audit_events.h>
#include <folly/portability/GTest.h>
#include <getopt.h>
#include <logger/logger.h>
Expand Down Expand Up @@ -264,24 +265,6 @@ class AuditDaemonFilteringTest : public AuditDaemonTest {

config.public_set_disabled_userids(disabled_userids);
}

// Adds a new event that has the filtering_permitted attribute set according
// to the input parameter.
// @param filteringPermitted indicates whether the event being added can
// be filtered or not
void addEvent(bool filteringPermitted) {
nlohmann::json json;
// We normally expect this to be an unsigned integer so we need to
// explicitly pass a unsigned int to json[].
size_t id = 1234;
json["id"] = id;
json["name"] = "newEvent";
json["description"] = "description";
json["sync"] = false;
json["enabled"] = true;
json["filtering_permitted"] = filteringPermitted;
dynamic_cast<AuditImpl*>(auditHandle.get())->add_event_descriptor(json);
}
};

/**
Expand All @@ -296,22 +279,24 @@ TEST_P(AuditDaemonFilteringTest, AuditFilteringTest) {
bool eventFilteringPermitted = std::get<1>(GetParam());
bool foundJohndoe{false};

const std::string payloadjohndoe =
R"({"id": 1234, "timestamp": "test", "real_userid":
auto id = eventFilteringPermitted ? MEMCACHED_AUDIT_INVALID_PACKET
: MEMCACHED_AUDIT_AUTHENTICATION_FAILED;

const std::string payloadjohndoe = R"({"id": )" + std::to_string(id) +
R"(, "timestamp": "test", "real_userid":
{"source": "internal", "user": "johndoe"}})";

const std::string payloadanother =
R"({"id": 1234, "timestamp": "test", "real_userid":
const std::string payloadanother = R"({"id": )" + std::to_string(id) +
R"(, "timestamp": "test", "real_userid":
{"source": "internal", "user": "another"}})";

config.set_filtering_enabled(globalFilterSetting);
enable();
addEvent(eventFilteringPermitted);

// generate the 1234 event with real_userid:user = johndoe
auditHandle->put_event(1234, payloadjohndoe);
// generate the 1234 event with real_userid:user = another
auditHandle->put_event(1234, payloadanother);
// generate the event with real_userid:user = johndoe
auditHandle->put_event(id, payloadjohndoe);
// generate the event with real_userid:user = another
auditHandle->put_event(id, payloadanother);

// Check the audit log exists
assertNumberOfFiles(1);
Expand Down

0 comments on commit 9b54504

Please sign in to comment.