Commit 9a4619a0 authored by JINMEI Tatuya's avatar JINMEI Tatuya

[1891] implemented sqlite3 deleteNSEC3RecordInZone.

parent fb7201b9
...@@ -75,7 +75,8 @@ enum StatementID { ...@@ -75,7 +75,8 @@ enum StatementID {
NSEC3_LAST = 18, NSEC3_LAST = 18,
ADD_NSEC3_RECORD = 19, ADD_NSEC3_RECORD = 19,
DEL_ZONE_NSEC3_RECORDS = 20, DEL_ZONE_NSEC3_RECORDS = 20,
NUM_STATEMENTS = 21 DEL_NSEC3_RECORD = 21,
NUM_STATEMENTS = 22
}; };
const char* const text_statements[NUM_STATEMENTS] = { const char* const text_statements[NUM_STATEMENTS] = {
...@@ -154,7 +155,10 @@ const char* const text_statements[NUM_STATEMENTS] = { ...@@ -154,7 +155,10 @@ const char* const text_statements[NUM_STATEMENTS] = {
"INSERT INTO nsec3 (zone_id, hash, owner, ttl, rdtype, rdata) " "INSERT INTO nsec3 (zone_id, hash, owner, ttl, rdtype, rdata) "
"VALUES (?1, ?2, ?3, ?4, ?5, ?6)", "VALUES (?1, ?2, ?3, ?4, ?5, ?6)",
// DEL_ZONE_NSEC3_RECORDS: delete all NSEC3-related records from the zone // DEL_ZONE_NSEC3_RECORDS: delete all NSEC3-related records from the zone
"DELETE FROM nsec3 WHERE zone_id=?1" "DELETE FROM nsec3 WHERE zone_id=?1",
// DEL_NSEC3_RECORD: delete specified NSEC3-related records
"DELETE FROM nsec3 WHERE zone_id=?1 AND hash=?2 "
"AND rdtype=?3 AND rdata=?4"
}; };
struct SQLite3Parameters { struct SQLite3Parameters {
...@@ -1191,9 +1195,13 @@ SQLite3Accessor::deleteRecordInZone(const string (&params)[DEL_PARAM_COUNT]) { ...@@ -1191,9 +1195,13 @@ SQLite3Accessor::deleteRecordInZone(const string (&params)[DEL_PARAM_COUNT]) {
void void
SQLite3Accessor::deleteNSEC3RecordInZone( SQLite3Accessor::deleteNSEC3RecordInZone(
const string (&/*params*/)[DEL_PARAM_COUNT]) const string (&params)[DEL_PARAM_COUNT])
{ {
isc_throw(NotImplemented, "not yet implemented"); // TBD: no transaction check
doUpdate<const string (&)[DEL_PARAM_COUNT]>(
*dbparameters_, DEL_NSEC3_RECORD, params,
"delete NSEC3 record from zone");
} }
void void
......
...@@ -742,7 +742,7 @@ const char* const deleted_data[] = { ...@@ -742,7 +742,7 @@ const char* const deleted_data[] = {
"foo.bar.example.com.", "A", "192.0.2.1" "foo.bar.example.com.", "A", "192.0.2.1"
}; };
const char* const nsec3_data[DatabaseAccessor::ADD_NSEC3_COLUMN_COUNT] = { const char* const nsec3_data[DatabaseAccessor::ADD_NSEC3_COLUMN_COUNT] = {
// example NSEC parameters. Using "apex_hash" just as a convenient // example NSEC3 parameters. Using "apex_hash" just as a convenient
// shortcut; otherwise it has nothing to do with the zone apex for the // shortcut; otherwise it has nothing to do with the zone apex for the
// purpose of this test. // purpose of this test.
apex_hash, "3600", "NSEC3", apex_hash, "3600", "NSEC3",
...@@ -753,6 +753,11 @@ const char* const nsec3_sig_data[DatabaseAccessor::ADD_NSEC3_COLUMN_COUNT] = { ...@@ -753,6 +753,11 @@ const char* const nsec3_sig_data[DatabaseAccessor::ADD_NSEC3_COLUMN_COUNT] = {
"NSEC3 5 3 3600 20000101000000 20000201000000 12345 " "NSEC3 5 3 3600 20000101000000 20000201000000 12345 "
"example.com. FAKEFAKEFAKE" "example.com. FAKEFAKEFAKE"
}; };
const char* const nsec3_deleted_data[] = {
// Delete parameters for nsec3_data
apex_hash, nsec3_data[DatabaseAccessor::ADD_NSEC3_TYPE],
nsec3_data[DatabaseAccessor::ADD_NSEC3_RDATA]
};
class SQLite3Update : public SQLite3AccessorTest { class SQLite3Update : public SQLite3AccessorTest {
protected: protected:
...@@ -994,6 +999,7 @@ TEST_F(SQLite3Update, addNSEC3Record) { ...@@ -994,6 +999,7 @@ TEST_F(SQLite3Update, addNSEC3Record) {
copy(nsec3_data, nsec3_data + DatabaseAccessor::ADD_NSEC3_COLUMN_COUNT, copy(nsec3_data, nsec3_data + DatabaseAccessor::ADD_NSEC3_COLUMN_COUNT,
add_nsec3_columns); add_nsec3_columns);
accessor->addNSEC3RecordToZone(add_nsec3_columns); accessor->addNSEC3RecordToZone(add_nsec3_columns);
// Add an RRSIG for NSEC3 // Add an RRSIG for NSEC3
copy(nsec3_sig_data, copy(nsec3_sig_data,
nsec3_sig_data + DatabaseAccessor::ADD_NSEC3_COLUMN_COUNT, nsec3_sig_data + DatabaseAccessor::ADD_NSEC3_COLUMN_COUNT,
...@@ -1102,6 +1108,32 @@ TEST_F(SQLite3Update, deleteRecord) { ...@@ -1102,6 +1108,32 @@ TEST_F(SQLite3Update, deleteRecord) {
checkRecords(*accessor, zone_id, "foo.bar.example.com.", empty_stored); checkRecords(*accessor, zone_id, "foo.bar.example.com.", empty_stored);
} }
TEST_F(SQLite3Update, deleteNSEC3Record) {
// Similar to the previous test, but for NSEC3.
zone_id = accessor->startUpdateZone("example.com.", false).second;
checkNSEC3Records(*accessor, zone_id, apex_hash, empty_stored);
// We first need to add some record.
copy(nsec3_data, nsec3_data + DatabaseAccessor::ADD_NSEC3_COLUMN_COUNT,
add_nsec3_columns);
accessor->addNSEC3RecordToZone(add_nsec3_columns);
// Now it should exist.
expected_stored.clear();
expected_stored.push_back(nsec3_data);
checkNSEC3Records(*accessor, zone_id, apex_hash, expected_stored);
// Delete it, and confirm that.
copy(nsec3_deleted_data,
nsec3_deleted_data + DatabaseAccessor::DEL_PARAM_COUNT, del_params);
accessor->deleteNSEC3RecordInZone(del_params);
checkNSEC3Records(*accessor, zone_id, apex_hash, empty_stored);
// Commit the change, and confirm the deleted data still isn't there.
accessor->commit();
checkNSEC3Records(*accessor, zone_id, apex_hash, empty_stored);
}
TEST_F(SQLite3Update, deleteThenRollback) { TEST_F(SQLite3Update, deleteThenRollback) {
zone_id = accessor->startUpdateZone("example.com.", false).second; zone_id = accessor->startUpdateZone("example.com.", false).second;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment