Commit 44e0cf8d authored by Francis Dupont's avatar Francis Dupont
Browse files

[#1247] Checkpoint: fixed for audit entries

parent 24590137
......@@ -3002,12 +3002,15 @@ MySqlConfigBackendDHCPv4::getModifiedGlobalParameters4(const db::ServerSelector&
AuditEntryCollection
MySqlConfigBackendDHCPv4::getRecentAuditEntries(const db::ServerSelector& server_selector,
const boost::posix_time::ptime& modification_time) const {
const boost::posix_time::ptime& modification_time,
const uint64_t& modification_id) const {
LOG_DEBUG(mysql_cb_logger, DBGLVL_TRACE_BASIC, MYSQL_CB_GET_RECENT_AUDIT_ENTRIES4)
.arg(util::ptimeToText(modification_time));
.arg(util::ptimeToText(modification_time))
.arg(modification_id);
AuditEntryCollection audit_entries;
impl_->getRecentAuditEntries(MySqlConfigBackendDHCPv4Impl::GET_AUDIT_ENTRIES4_TIME,
server_selector, modification_time, audit_entries);
server_selector, modification_time,
modification_id, audit_entries);
LOG_DEBUG(mysql_cb_logger, DBGLVL_TRACE_BASIC, MYSQL_CB_GET_RECENT_AUDIT_ENTRIES4_RESULT)
.arg(audit_entries.size());
return (audit_entries);
......
// Copyright (C) 2018-2019 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2018-2020 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
......@@ -230,10 +230,13 @@ public:
/// @param selector Server selector.
/// @param modification_time Timestamp being a lower limit for the returned
/// result set, i.e. entries later than specified time are returned.
/// @param modification_id Identifier being a lower limit for the returned
/// result set, used when two (or more) entries have modification_time.
/// @return Collection of audit entries.
virtual db::AuditEntryCollection
getRecentAuditEntries(const db::ServerSelector& server_selector,
const boost::posix_time::ptime& modification_time) const;
const boost::posix_time::ptime& modification_time,
const uint64_t& modification_id) const;
/// @brief Retrieves all servers.
///
......
......@@ -3476,12 +3476,15 @@ MySqlConfigBackendDHCPv6::getModifiedGlobalParameters6(const db::ServerSelector&
AuditEntryCollection
MySqlConfigBackendDHCPv6::getRecentAuditEntries(const db::ServerSelector& server_selector,
const boost::posix_time::ptime& modification_time) const {
const boost::posix_time::ptime& modification_time,
const uint64_t& modification_id) const {
LOG_DEBUG(mysql_cb_logger, DBGLVL_TRACE_BASIC, MYSQL_CB_GET_RECENT_AUDIT_ENTRIES6)
.arg(util::ptimeToText(modification_time));
.arg(util::ptimeToText(modification_time))
.arg(modification_id);
AuditEntryCollection audit_entries;
impl_->getRecentAuditEntries(MySqlConfigBackendDHCPv6Impl::GET_AUDIT_ENTRIES6_TIME,
server_selector, modification_time, audit_entries);
server_selector, modification_time,
modification_id, audit_entries);
LOG_DEBUG(mysql_cb_logger, DBGLVL_TRACE_BASIC, MYSQL_CB_GET_RECENT_AUDIT_ENTRIES6_RESULT)
.arg(audit_entries.size());
return (audit_entries);
......
// Copyright (C) 2019 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2019-2020 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
......@@ -230,10 +230,13 @@ public:
/// @param selector Server selector.
/// @param modification_time Timestamp being a lower limit for the returned
/// result set, i.e. entries later than specified time are returned.
/// @param modification_id Identifier being a lower limit for the returned
/// result set, used when two (or more) entries have modification_time.
/// @return Collection of audit entries.
virtual db::AuditEntryCollection
getRecentAuditEntries(const db::ServerSelector& server_selector,
const boost::posix_time::ptime& modification_time) const;
const boost::posix_time::ptime& modification_time,
const uint64_t& modification_id) const;
/// @brief Retrieves all servers.
///
......
......@@ -192,6 +192,7 @@ void
MySqlConfigBackendImpl::getRecentAuditEntries(const int index,
const db::ServerSelector& server_selector,
const boost::posix_time::ptime& modification_time,
const uint64_t& modification_id,
AuditEntryCollection& audit_entries) {
// Create the output bindings for receiving the data.
MySqlBindingCollection out_bindings = {
......@@ -200,6 +201,7 @@ MySqlConfigBackendImpl::getRecentAuditEntries(const int index,
MySqlBinding::createInteger<uint64_t>(), // object_id
MySqlBinding::createInteger<uint8_t>(), // modification_type
MySqlBinding::createTimestamp(), // modification_time
MySqlBinding::createInteger<uint64_t>(), // revision_id
MySqlBinding::createString(AUDIT_ENTRY_LOG_MESSAGE_BUF_LENGTH) // log_message
};
......@@ -207,10 +209,12 @@ MySqlConfigBackendImpl::getRecentAuditEntries(const int index,
for (auto tag : tags) {
// There is only one input binding, modification time.
// There are only a few input bindings
MySqlBindingCollection in_bindings = {
MySqlBinding::createString(tag.get()),
MySqlBinding::createTimestamp(modification_time)
MySqlBinding::createTimestamp(modification_time),
MySqlBinding::createTimestamp(modification_time),
MySqlBinding::createInteger<uint64_t>(modification_id)
};
// Execute select.
......@@ -227,7 +231,8 @@ MySqlConfigBackendImpl::getRecentAuditEntries(const int index,
out_bindings[2]->getInteger<uint64_t>(),
mod_type,
out_bindings[4]->getTimestamp(),
out_bindings[5]->getStringOrDefault(""));
out_bindings[5]->getInteger<uint64_t>(),
out_bindings[6]->getStringOrDefault(""));
audit_entries.insert(audit_entry);
});
}
......
// Copyright (C) 2018-2019 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2018-2020 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
......@@ -239,11 +239,14 @@ public:
/// @param server_selector Server selector.
/// @param modification_time Timestamp being a lower limit for the returned
/// result set, i.e. entries later than specified time are returned.
/// @param modification_id Identifier being a lower limit for the returned
/// result set, used when two (or more) entries have modification_time.
/// @param [out] audit_entries Reference to the container where fetched audit
/// entries will be inserted.
void getRecentAuditEntries(const int index,
const db::ServerSelector& server_selector,
const boost::posix_time::ptime& modification_time,
const uint64_t& modification_id,
db::AuditEntryCollection& audit_entries);
/// @brief Sends query to delete rows from a table.
......
// File created from ../../../../src/hooks/dhcp/mysql_cb/mysql_cb_messages.mes on Tue Jun 25 2019 16:12
// File created from ../../../../src/hooks/dhcp/mysql_cb/mysql_cb_messages.mes on Wed Jun 17 2020 02:55
#include <cstddef>
#include <log/message_types.h>
......@@ -317,9 +317,9 @@ const char* values[] = {
"MYSQL_CB_GET_OPTION_DEF6", "retrieving option definition code: %1 space: %2",
"MYSQL_CB_GET_PORT4", "get port",
"MYSQL_CB_GET_PORT6", "get port",
"MYSQL_CB_GET_RECENT_AUDIT_ENTRIES4", "retrieving audit entries from: %1",
"MYSQL_CB_GET_RECENT_AUDIT_ENTRIES4", "retrieving audit entries from: %1 %2",
"MYSQL_CB_GET_RECENT_AUDIT_ENTRIES4_RESULT", "retrieving: %1 elements",
"MYSQL_CB_GET_RECENT_AUDIT_ENTRIES6", "retrieving audit entries from: %1",
"MYSQL_CB_GET_RECENT_AUDIT_ENTRIES6", "retrieving audit entries from: %1 %2",
"MYSQL_CB_GET_RECENT_AUDIT_ENTRIES6_RESULT", "retrieving: %1 elements",
"MYSQL_CB_GET_SERVER4", "retrieving DHCPv4 server: %1",
"MYSQL_CB_GET_SERVER6", "retrieving DHCPv6 server: %1",
......
// File created from ../../../../src/hooks/dhcp/mysql_cb/mysql_cb_messages.mes on Tue Jun 25 2019 16:12
// File created from ../../../../src/hooks/dhcp/mysql_cb/mysql_cb_messages.mes on Wed Jun 17 2020 02:55
#ifndef MYSQL_CB_MESSAGES_H
#define MYSQL_CB_MESSAGES_H
......
# Copyright (C) 2018-2019 Internet Systems Consortium, Inc. ("ISC")
# Copyright (C) 2018-2020 Internet Systems Consortium, Inc. ("ISC")
$NAMESPACE isc::cb
......@@ -429,14 +429,14 @@ Debug message issued when triggered an action to retrieve port
% MYSQL_CB_GET_PORT6 get port
Debug message issued when triggered an action to retrieve port
% MYSQL_CB_GET_RECENT_AUDIT_ENTRIES4 retrieving audit entries from: %1
Debug message issued when triggered an action to retrieve audit entries from specified time
% MYSQL_CB_GET_RECENT_AUDIT_ENTRIES4 retrieving audit entries from: %1 %2
Debug message issued when triggered an action to retrieve audit entries from specified time and id.
% MYSQL_CB_GET_RECENT_AUDIT_ENTRIES4_RESULT retrieving: %1 elements
Debug message indicating the result of an action to retrieve audit entries from specified time
% MYSQL_CB_GET_RECENT_AUDIT_ENTRIES6 retrieving audit entries from: %1
Debug message issued when triggered an action to retrieve audit entries from specified time
% MYSQL_CB_GET_RECENT_AUDIT_ENTRIES6 retrieving audit entries from: %1 %2
Debug message issued when triggered an action to retrieve audit entries from specified time and id
% MYSQL_CB_GET_RECENT_AUDIT_ENTRIES6_RESULT retrieving: %1 elements
Debug message indicating the result of an action to retrieve audit entries from specified time
......
......@@ -617,13 +617,16 @@ namespace {
" a.object_id," \
" a.modification_type," \
" r.modification_ts," \
" r.id, " \
" r.log_message " \
"FROM " #table_prefix "_audit AS a " \
"INNER JOIN " #table_prefix "_audit_revision AS r " \
" ON a.revision_id = r.id " \
"INNER JOIN " #table_prefix "_server AS s" \
" ON r.server_id = s.id " \
"WHERE (s.tag = ? OR s.id = 1) AND (r.modification_ts > ?) " \
"WHERE (s.tag = ? OR s.id = 1) AND" \
" ((r.modification_ts > ?) OR " \
" ((r.modification_ts = ?) AND (r.id > ?))) " \
"ORDER BY r.modification_ts, r.id"
#endif
......
......@@ -432,7 +432,7 @@ public:
std::string logExistingAuditEntries(const std::string& server_tag) {
std::ostringstream s;
auto& mod_time_idx = audit_entries_[server_tag].get<AuditEntryModificationTimeTag>();
auto& mod_time_idx = audit_entries_[server_tag].get<AuditEntryModificationTimeIdTag>();
for (auto audit_entry_it = mod_time_idx.begin();
audit_entry_it != mod_time_idx.end();
......@@ -442,6 +442,7 @@ public:
<< audit_entry->getObjectId() << ", "
<< static_cast<int>(audit_entry->getModificationType()) << ", "
<< audit_entry->getModificationTime() << ", "
<< audit_entry->getEntryId() << ", "
<< audit_entry->getLogMessage()
<< std::endl;
}
......@@ -492,11 +493,11 @@ public:
// Audit entries for different server tags are stored in separate
// containers.
audit_entries_[tag] = cbptr_->getRecentAuditEntries(server_selector,
timestamps_["two days ago"]);
timestamps_["two days ago"], 0);
ASSERT_EQ(audit_entries_size_save + new_entries_num, audit_entries_[tag].size())
<< logExistingAuditEntries(tag);
auto& mod_time_idx = audit_entries_[tag].get<AuditEntryModificationTimeTag>();
auto& mod_time_idx = audit_entries_[tag].get<AuditEntryModificationTimeIdTag>();
// Iterate over specified number of entries starting from the most recent
// one and check they have correct values.
......
......@@ -480,7 +480,7 @@ public:
std::string logExistingAuditEntries(const std::string& server_tag) {
std::ostringstream s;
auto& mod_time_idx = audit_entries_[server_tag].get<AuditEntryModificationTimeTag>();
auto& mod_time_idx = audit_entries_[server_tag].get<AuditEntryModificationTimeIdTag>();
for (auto audit_entry_it = mod_time_idx.begin();
audit_entry_it != mod_time_idx.end();
......@@ -490,6 +490,7 @@ public:
<< audit_entry->getObjectId() << ", "
<< static_cast<int>(audit_entry->getModificationType()) << ", "
<< audit_entry->getModificationTime() << ", "
<< audit_entry->getEntryId() << ", "
<< audit_entry->getLogMessage()
<< std::endl;
}
......@@ -539,11 +540,11 @@ public:
// Audit entries for different server tags are stored in separate
// containers.
audit_entries_[tag] = cbptr_->getRecentAuditEntries(server_selector,
timestamps_["two days ago"]);
timestamps_["two days ago"], 0);
ASSERT_EQ(audit_entries_size_save + new_entries_num, audit_entries_[tag].size())
<< logExistingAuditEntries(tag);
auto& mod_time_idx = audit_entries_[tag].get<AuditEntryModificationTimeTag>();
auto& mod_time_idx = audit_entries_[tag].get<AuditEntryModificationTimeIdTag>();
// Iterate over specified number of entries starting from the most recent
// one and check they have correct values.
......
// Copyright (C) 2019 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2019-2020 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
......@@ -15,11 +15,13 @@ AuditEntry::AuditEntry(const std::string& object_type,
const uint64_t object_id,
const ModificationType& modification_type,
const boost::posix_time::ptime& modification_time,
const uint64_t id,
const std::string& log_message)
: object_type_(object_type),
object_id_(object_id),
modification_type_(modification_type),
modification_time_(modification_time),
id_(id),
log_message_(log_message) {
// Check if the provided values are sane.
validate();
......@@ -28,11 +30,13 @@ AuditEntry::AuditEntry(const std::string& object_type,
AuditEntry::AuditEntry(const std::string& object_type,
const uint64_t object_id,
const ModificationType& modification_type,
const uint64_t id,
const std::string& log_message)
: object_type_(object_type),
object_id_(object_id),
modification_type_(modification_type),
modification_time_(boost::posix_time::microsec_clock::local_time()),
id_(id),
log_message_(log_message) {
// Check if the provided values are sane.
validate();
......@@ -43,10 +47,11 @@ AuditEntry::create(const std::string& object_type,
const uint64_t object_id,
const ModificationType& modification_type,
const boost::posix_time::ptime& modification_time,
const uint64_t id,
const std::string& log_message) {
return (boost::make_shared<AuditEntry>(object_type, object_id,
modification_type,
modification_time,
modification_time, id,
log_message));
}
......@@ -54,9 +59,10 @@ AuditEntryPtr
AuditEntry::create(const std::string& object_type,
const uint64_t object_id,
const ModificationType& modification_type,
const uint64_t id,
const std::string& log_message) {
return (boost::make_shared<AuditEntry>(object_type, object_id,
modification_type,
modification_type, id,
log_message));
}
......
// Copyright (C) 2019 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2019-2020 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
......@@ -39,6 +39,8 @@ typedef boost::shared_ptr<AuditEntry> AuditEntryPtr;
/// the most recent modifications in the database it will query for all
/// entries with later modification time than stored. That way the
/// server queries only for the audit entries it hasn't fetched yet.
/// In the case two (or more) successive audit entries have the same
/// modification time the strictly increasing id is used.
///
/// When the modification type of the entry is set to
/// @c AuditEntry::ModificationType::DELETE, the corresponding
......@@ -51,6 +53,7 @@ typedef boost::shared_ptr<AuditEntry> AuditEntryPtr;
/// - object_id: 123
/// - modification_type: 3 (DELETE)
/// - modification_time: "2019-01-15 15:45:23"
/// - id: 234
/// - log_message: "DHCPv4 subnet 123 deleted"
///
/// The subnet is instantly removed from the dhcp4_subnet table. When
......@@ -72,18 +75,20 @@ public:
DELETE = 2
};
/// @brief Constructor using explicit modification time.
/// @brief Constructor using explicit modification time and id.
///
/// @param object_type name of the table where data was modified.
/// @param object_id identifier of the modified record in this table.
/// @param modification_type type of the modification, e.g. DELETE.
/// @param modification_time time of modification for that record.
/// @param id identifier of the entry itself.
/// @param log_message optional log message associated with the
/// modification.
AuditEntry(const std::string& object_type,
const uint64_t object_id,
const ModificationType& modification_type,
const boost::posix_time::ptime& modification_time,
const uint64_t id,
const std::string& log_message);
/// @brief Constructor using default modification time.
......@@ -91,11 +96,13 @@ public:
/// @param object_type name of the table where data was modified.
/// @param object_id identifier of the modified record in this table.
/// @param modification_type type of the modification, e.g. DELETE.
/// @param id identifier of the entry itself.
/// @param log_message optional log message associated with the
/// modification.
AuditEntry(const std::string& object_type,
const uint64_t object_id,
const ModificationType& modification_type,
const uint64_t id,
const std::string& log_message);
/// @brief Factory function creating an instance of @c AuditEntry.
......@@ -109,6 +116,7 @@ public:
/// @param object_id identifier of the modified record in this table.
/// @param modification_type type of the modification, e.g. DELETE.
/// @param modification_time time of modification for that record.
/// @param id identifier of the entry itself.
/// @param log_message optional log message associated with the
/// modification.
///
......@@ -117,6 +125,7 @@ public:
const uint64_t object_id,
const ModificationType& modification_type,
const boost::posix_time::ptime& modification_time,
const uint64_t id,
const std::string& log_message);
/// @brief Factory function creating an instance of @c AuditEntry.
......@@ -129,6 +138,7 @@ public:
/// @param object_type name of the table where data was modified.
/// @param object_id identifier of the modified record in this table.
/// @param modification_type type of the modification, e.g. DELETE.
/// @param id identifier of the entry itself.
/// @param log_message optional log message associated with the
/// modification.
///
......@@ -136,6 +146,7 @@ public:
static AuditEntryPtr create(const std::string& object_type,
const uint64_t object_id,
const ModificationType& modification_type,
const uint64_t id,
const std::string& log_message);
/// @brief Returns object type.
......@@ -166,6 +177,13 @@ public:
return (modification_time_);
}
/// @brief Returns entry id.
///
/// @return Identifier of the entry.
uint64_t getEntryId() const {
return (id_);
}
/// @brief Returns log message.
///
/// @return Optional log message corresponding to the changes.
......@@ -193,6 +211,9 @@ private:
/// @brief Modification time.
boost::posix_time::ptime modification_time_;
/// @brief Entry id.
uint64_t id_;
/// @brief Log message.
std::string log_message_;
};
......@@ -201,7 +222,7 @@ private:
struct AuditEntryObjectTypeTag { };
/// @brief Tag used to access index by modification time.
struct AuditEntryModificationTimeTag { };
struct AuditEntryModificationTimeIdTag { };
/// @brief Multi index container holding @c AuditEntry instances.
///
......@@ -229,13 +250,21 @@ typedef boost::multi_index_container<
>
>,
// Second index allows for accessing by the modification time.
// Second index allows for accessing by the modification time and id.
boost::multi_index::ordered_non_unique<
boost::multi_index::tag<AuditEntryModificationTimeTag>,
boost::multi_index::const_mem_fun<
boost::multi_index::tag<AuditEntryModificationTimeIdTag>,
boost::multi_index::composite_key<
AuditEntry,
boost::posix_time::ptime,
&AuditEntry::getModificationTime
boost::multi_index::const_mem_fun<
AuditEntry,
boost::posix_time::ptime,
&AuditEntry::getModificationTime
>,
boost::multi_index::const_mem_fun<
AuditEntry,
uint64_t,
&AuditEntry::getEntryId
>
>
>
>
......
// Copyright (C) 2019 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2019-2020 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
......@@ -91,11 +91,12 @@ TEST_F(AuditEntryTest, create) {
ASSERT_NO_THROW(audit_entry = AuditEntry::create
("dhcp4_subnet", 10, AuditEntry::ModificationType::DELETE,
fixedTime(), "deleted subnet 10"));
fixedTime(), 123, "deleted subnet 10"));
EXPECT_EQ("dhcp4_subnet", audit_entry->getObjectType());
EXPECT_EQ(10, audit_entry->getObjectId());
EXPECT_EQ(AuditEntry::ModificationType::DELETE, audit_entry->getModificationType());
EXPECT_EQ(fixedTime(), audit_entry->getModificationTime());
EXPECT_EQ(123, audit_entry->getEntryId());
EXPECT_EQ("deleted subnet 10", audit_entry->getLogMessage());
}
......@@ -104,11 +105,12 @@ TEST_F(AuditEntryTest, create) {
ASSERT_NO_THROW(audit_entry = AuditEntry::create
("dhcp4_option", 123, AuditEntry::ModificationType::CREATE,
""));
234, ""));
EXPECT_EQ("dhcp4_option", audit_entry->getObjectType());
EXPECT_EQ(123, audit_entry->getObjectId());
EXPECT_EQ(AuditEntry::ModificationType::CREATE, audit_entry->getModificationType());
EXPECT_TRUE(almostEqualTime(audit_entry->getModificationTime()));
EXPECT_EQ(234, audit_entry->getEntryId());
EXPECT_TRUE(audit_entry->getLogMessage().empty());
}
}
......@@ -118,7 +120,7 @@ TEST_F(AuditEntryTest, createFailures) {
{
SCOPED_TRACE("empty object type");
EXPECT_THROW(AuditEntry("", 10, AuditEntry::ModificationType::DELETE,
fixedTime(), "deleted subnet 10"),
fixedTime(), 123, "deleted subnet 10"),
BadValue);
}
......@@ -126,7 +128,8 @@ TEST_F(AuditEntryTest, createFailures) {
SCOPED_TRACE("not a date time");
EXPECT_THROW(AuditEntry("dhcp4_subnet", 10,
AuditEntry::ModificationType::DELETE,
boost::posix_time::ptime(), "deleted subnet 10"),
boost::posix_time::ptime(), 123,
"deleted subnet 10"),
BadValue);
}
}
......@@ -171,17 +174,17 @@ public:
/// the tests.
void createTestAuditEntries() {
create("dhcp4_subnet", 10, AuditEntry::ModificationType::CREATE,
diffTime(-5), "added subnet 10");
diffTime(-5), 100, "added subnet 10");
create("dhcp4_shared_network", 1, AuditEntry::ModificationType::CREATE,
diffTime(-5), "added shared network 1");
diffTime(-5), 110, "added shared network 1");
create("dhcp4_shared_network", 120, AuditEntry::ModificationType::UPDATE,
diffTime(-8), "updated shared network 120");
diffTime(-8), 90, "updated shared network 120");
create("dhcp4_subnet", 120, AuditEntry::ModificationType::DELETE,
diffTime(8), "deleted subnet 120");
diffTime(8), 130, "deleted subnet 120");
create("dhcp4_subnet", 1000, AuditEntry::ModificationType::CREATE,
diffTime(4), "created subnet 1000");
diffTime(4), 120, "created subnet 1000");
create("dhcp4_option", 15, AuditEntry::ModificationType::UPDATE,
diffTime(16), "updated option 15");
diffTime(16), 140, "updated option 15");
}
/// @brief Checks if the returned results range contains an @c AuditEntry
......@@ -237,7 +240,7 @@ TEST_F(AuditEntryCollectionTest, getByObjectType) {
// Checks that entries can be found by modification time.
TEST_F(AuditEntryCollectionTest, getByModificationTime) {
const auto& mod_time_idx = audit_entries_.get<AuditEntryModificationTimeTag>();
const auto& mod_time_idx = audit_entries_.get<AuditEntryModificationTimeIdTag>();
// Search for objects later than fixed time - 10s.
auto lb = mod_time_idx.lower_bound(diffTime(-10));
......@@ -282,4 +285,18 @@ TEST_F(AuditEntryCollectionTest, getByModificationTime) {
ASSERT_EQ(0, std::distance(lb, mod_time_idx.end()));
}
// Checks that entries can be found by modification time and id.
TEST_F(AuditEntryCollectionTest, getByModificationTimeAndId) {
const auto& mod_time_idx = audit_entries_.get<AuditEntryModificationTimeIdTag>();
// Search for objects later than added added subnet 10.
auto mod = boost::make_tuple(diffTime(-5), 100 + 1);
auto lb = mod_time_idx.lower_bound(mod);
ASSERT_EQ(4, std::distance(lb, mod_time_idx.end()));
EXPECT_TRUE(includes("dhcp4_subnet", 120, lb, mod_time_idx.end()));
EXPECT_TRUE(includes("dhcp4_subnet", 1000, lb, mod_time_idx.end()));
EXPECT_TRUE(includes("dhcp4_shared_network", 1, lb, mod_time_idx.end()));
EXPECT_TRUE(includes("dhcp4_option", 15, lb, mod_time_idx.end()));
}
}
// Copyright (C) 2018-2019 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2018-2020 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
......@@ -301,10 +301,13 @@ public:
/// @param server_selector Server selector.
/// @param modification_time Timestamp being a lower limit for the returned
/// result set, i.e. entries later than specified time are returned.
/// @param modification_id Identifier being a lower limit for the returned
/// result set, used when two (or more) entries have modification_time.
/// @return Collection of audit entries.
virtual db::AuditEntryCollection
getRecentAuditEntries(const db::ServerSelector& server_selector,
const boost::posix_time::ptime& modification_time) const = 0;
const boost::posix_time::ptime& modification_time,
const uint64_t& modification_id) const = 0;
/// @brief Retrieves all servers.
///
......
// Copyright (C) 2019 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2019-2020 Internet Systems Consortium, Inc. ("ISC")
//