From 4ebbd1b03befb64012ccb9b8d75ea6db31796d9a Mon Sep 17 00:00:00 2001 From: Wu Tao Date: Mon, 25 May 2020 15:14:15 +0800 Subject: [PATCH] fix(dup): reject add_dup if remote address incorrect (#472) --- .../meta_server/duplication/meta_duplication_service.cpp | 9 ++++++++- .../replication/test/meta_test/unit_test/config-test.ini | 5 +++++ .../unit_test/meta_duplication_service_test.cpp | 4 ++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/dist/replication/meta_server/duplication/meta_duplication_service.cpp b/src/dist/replication/meta_server/duplication/meta_duplication_service.cpp index fb57ae9b37..dd6ab16ce8 100644 --- a/src/dist/replication/meta_server/duplication/meta_duplication_service.cpp +++ b/src/dist/replication/meta_server/duplication/meta_duplication_service.cpp @@ -141,7 +141,6 @@ void meta_duplication_service::add_duplication(duplication_add_rpc rpc) response.__set_hint("illegal operation: adding duplication to itself"); return; } - auto remote_cluster_id = get_duplication_cluster_id(request.remote_cluster_name); if (!remote_cluster_id.is_ok()) { response.err = ERR_INVALID_PARAMETERS; @@ -150,6 +149,14 @@ void meta_duplication_service::add_duplication(duplication_add_rpc rpc) remote_cluster_id.get_error())); return; } + std::vector clusters; + dsn_config_get_all_keys("pegasus.clusters", clusters); + if (std::find(clusters.begin(), clusters.end(), request.remote_cluster_name) == + clusters.end()) { + response.err = ERR_INVALID_PARAMETERS; + response.__set_hint("failed to find cluster address in config [pegasus.clusters]"); + return; + } auto app = _state->get_app(request.app_name); if (!app || app->status != app_status::AS_AVAILABLE) { diff --git a/src/dist/replication/test/meta_test/unit_test/config-test.ini b/src/dist/replication/test/meta_test/unit_test/config-test.ini index 98edc71b0e..b2215bec42 100644 --- a/src/dist/replication/test/meta_test/unit_test/config-test.ini +++ b/src/dist/replication/test/meta_test/unit_test/config-test.ini @@ -111,3 +111,8 @@ args = [duplication-group] master-cluster = 1 slave-cluster = 2 +cluster_without_address_for_test = 3 + +[pegasus.clusters] +master-cluster = 127.0.0.1:34601 +slave-cluster = 127.0.0.1:35601 diff --git a/src/dist/replication/test/meta_test/unit_test/meta_duplication_service_test.cpp b/src/dist/replication/test/meta_test/unit_test/meta_duplication_service_test.cpp index 495c927be4..8415f2b8ad 100644 --- a/src/dist/replication/test/meta_test/unit_test/meta_duplication_service_test.cpp +++ b/src/dist/replication/test/meta_test/unit_test/meta_duplication_service_test.cpp @@ -309,6 +309,8 @@ class meta_duplication_service_test : public meta_test_base std::string invalid_remote = "test-invalid-remote"; std::string ok_remote = "slave-cluster"; + std::string cluster_without_address = "cluster_without_address_for_test"; + create_app(test_app); create_app(test_app_invalid_ver); @@ -328,6 +330,8 @@ class meta_duplication_service_test : public meta_test_base {test_app, invalid_remote, ERR_INVALID_PARAMETERS}, {test_app, get_current_cluster_name(), ERR_INVALID_PARAMETERS}, + + {test_app, cluster_without_address, ERR_INVALID_PARAMETERS}, }; for (auto tt : tests) {