"UPDATE ZoneDNSKeys SET active = :active WHERE id = :keyid";
static const char *setTSIGKeyQueryKey = "PDNS_Set_TSIG_Key";
-static const char *setTSIGKeyQueryDefaultSQL = "insert into tsigkeys (name,algorithm,secret) values(:name,:algorithm,:secret)";
+static const char *setTSIGKeyQueryDefaultSQL =
+ "INSERT INTO TSIGKeys (name,algorithm,secret)"
+ "VALUES("
+ ":name,"
+ ":algorithm,"
+ ":secret"
+ ")";
static const char *deleteTSIGKeyQueryKey = "PDNS_Delete_TSIG_Key";
-static const char *deleteTSIGKeyQueryDefaultSQL = "delete from tsigkeys where name=:name";
+static const char *deleteTSIGKeyQueryDefaultSQL =
+ "DELETE FROM TSIGKeys "
+ "WHERE name = :name";
static const char *getTSIGKeysQueryKey = "PDNS_Get_TSIG_Keys";
-static const char *getTSIGKeysQueryDefaultSQL = "select name,algorithm,secret from tsigkeys";
+static const char *getTSIGKeysQueryDefaultSQL =
+ "SELECT name, algorithm, secret "
+ "FROM TSIGKeys";
static void
string_to_cbuf (char *buf, const string& s, size_t bufsize)
if(!d_dnssecQueries)
return -1;
- stmt = prepare_query(pooledSvcCtx, setTSIGKeyQuerySQL, setTSIGKeyQueryKey);
+ sword rc;
+ OCIStmt *stmt;
+
+ openMasterConnection();
+
+ rc = OCITransStart(masterSvcCtx, oraerr, 60, OCI_TRANS_NEW);
+
+ stmt = prepare_query(masterSvcCtx, deleteTSIGKeyQuerySQL, deleteTSIGKeyQueryKey);
+ string_to_cbuf(mQueryName, name, sizeof(mQueryName));
+ bind_str(stmt, ":name", mQueryName, sizeof(mQueryName));
+
+ rc = OCIStmtExecute(masterSvcCtx, stmt, oraerr, 1, 0, NULL, NULL, OCI_DEFAULT);
+ if (rc == OCI_ERROR) {
+ throw OracleException("Oracle setTSIGKey", oraerr);
+ }
+
+ release_query(stmt, setTSIGKeyQueryKey);
+
+ stmt = prepare_query(masterSvcCtx, setTSIGKeyQuerySQL, setTSIGKeyQueryKey);
string_to_cbuf(mQueryName, name, sizeof(mQueryName));
string_to_cbuf(mQueryType, type, sizeof(mQueryType));
string_to_cbuf(mQueryContent, content, sizeof(mQueryContent));
bind_str(stmt, ":algorithm", mQueryType, sizeof(mQueryType));
bind_str(stmt, ":secret", mQueryContent, sizeof(mQueryContent));
- rc = OCIStmtExecute(pooledSvcCtx, stmt, oraerr, 1, 0, NULL, NULL, OCI_DEFAULT);
+ rc = OCIStmtExecute(masterSvcCtx, stmt, oraerr, 1, 0, NULL, NULL, OCI_DEFAULT);
if (rc == OCI_ERROR) {
- throw OracleException("Oracle getTSIGKey", oraerr);
+ throw OracleException("Oracle setTSIGKey", oraerr);
}
release_query(stmt, setTSIGKeyQueryKey);
+
+ rc = OCITransCommit(masterSvcCtx, oraerr, OCI_DEFAULT);
+ if (rc == OCI_ERROR) {
+ throw OracleException("Oracle setTSIGKey COMMIT", oraerr);
+ }
+
return true;
}
if(!d_dnssecQueries)
return -1;
- stmt = prepare_query(pooledSvcCtx, deleteTSIGKeyQuerySQL, deleteTSIGKeyQueryKey);
+ sword rc;
+ OCIStmt *stmt;
+
+ openMasterConnection();
+ rc = OCITransStart(masterSvcCtx, oraerr, 60, OCI_TRANS_NEW);
+
+ stmt = prepare_query(masterSvcCtx, deleteTSIGKeyQuerySQL, deleteTSIGKeyQueryKey);
string_to_cbuf(mQueryName, name, sizeof(mQueryName));
bind_str(stmt, ":name", mQueryName, sizeof(mQueryName));
- rc = OCIStmtExecute(pooledSvcCtx, stmt, oraerr, 1, 0, NULL, NULL, OCI_DEFAULT);
+ rc = OCIStmtExecute(masterSvcCtx, stmt, oraerr, 1, 0, NULL, NULL, OCI_DEFAULT);
if (rc == OCI_ERROR) {
- throw OracleException("Oracle getTSIGKey", oraerr);
+ throw OracleException("Oracle deleteTSIGKey", oraerr);
}
release_query(stmt, setTSIGKeyQueryKey);
+
+ rc = OCITransCommit(masterSvcCtx, oraerr, OCI_DEFAULT);
+ if (rc == OCI_ERROR) {
+ throw OracleException("Oracle deleteTSIGKey COMMIT", oraerr);
+ }
return true;
}
BOOST_CHECK_EQUAL(after, "stop");
}
+BOOST_AUTO_TEST_CASE(test_method_setTSIGKey) {
+ std::string algorithm, content;
+ BOOST_TEST_MESSAGE("Testing setTSIGKey method");
+ BOOST_CHECK_MESSAGE(be->setTSIGKey("unit.test","hmac-md5","kp4/24gyYsEzbuTVJRUMoqGFmN3LYgVDzJ/3oRSP7ys="), "did not return true");
+}
+
BOOST_AUTO_TEST_CASE(test_method_getTSIGKey) {
std::string algorithm, content;
BOOST_TEST_MESSAGE("Testing getTSIGKey method");
be->getTSIGKey("unit.test",&algorithm,&content);
- BOOST_CHECK_EQUAL(algorithm, "NULL");
- BOOST_CHECK_EQUAL(content, "NULL");
+ BOOST_CHECK_EQUAL(algorithm, "hmac-md5");
+ BOOST_CHECK_EQUAL(content, "kp4/24gyYsEzbuTVJRUMoqGFmN3LYgVDzJ/3oRSP7ys=");
+}
+
+BOOST_AUTO_TEST_CASE(test_method_deleteTSIGKey) {
+ std::string algorithm, content;
+ BOOST_TEST_MESSAGE("Testing deleteTSIGKey method");
+ BOOST_CHECK_MESSAGE(be->deleteTSIGKey("unit.test"), "did not return true");
+}
+
+BOOST_AUTO_TEST_CASE(test_method_getTSIGKeys) {
+ std::vector<struct TSIGKey> keys;
+ BOOST_TEST_MESSAGE("Testing getTSIGKeys method");
+ be->getTSIGKeys(keys);
+ BOOST_CHECK(keys.size() > 0)
+ if (keys.size() > 0) {
+ BOOST_CHECK_EQUAL(keys[0].name, "test");
+ BOOST_CHECK_EQUAL(keys[0].algorithm, "NULL");
+ BOOST_CHECK_EQUAL(keys[0].key, "NULL");
+ }
}
BOOST_AUTO_TEST_CASE(test_method_setNotified) {