From e6a44bc82b1e5da41b8a810902ebae8f9f3062a4 Mon Sep 17 00:00:00 2001 From: "Guillaume \"Vermeille\" Sanchez" Date: Tue, 28 Mar 2017 20:31:13 +0200 Subject: [PATCH] fix(config) error when specifying port for cassandra_contact_point cassandra_contact_point does not tolerate port specification. Issue an error when the user specifies it by mistake. --- kong/conf_loader.lua | 12 ++++++++++++ spec/01-unit/02-conf_loader_spec.lua | 14 ++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/kong/conf_loader.lua b/kong/conf_loader.lua index 831d386f224a..ca354ef7fc7c 100644 --- a/kong/conf_loader.lua +++ b/kong/conf_loader.lua @@ -183,6 +183,18 @@ local function check_and_infer(conf) "DCAwareRoundRobin policy is in use" end + for _, contact_point in ipairs(conf.cassandra_contact_points) do + local endpoint, err = utils.normalize_ip(contact_point) + if not endpoint then + errors[#errors+1] = "bad cassandra contact point '" .. contact_point .. + "': " .. err + + elseif endpoint.port then + errors[#errors+1] = "bad cassandra contact point '" .. contact_point .. + "': port must be specified in cassandra_port" + end + end + if conf.ssl then if conf.ssl_cert and not conf.ssl_cert_key then errors[#errors+1] = "ssl_cert_key must be specified" diff --git a/spec/01-unit/02-conf_loader_spec.lua b/spec/01-unit/02-conf_loader_spec.lua index 5cb923c118d8..fe1d387828fe 100644 --- a/spec/01-unit/02-conf_loader_spec.lua +++ b/spec/01-unit/02-conf_loader_spec.lua @@ -262,6 +262,20 @@ describe("Configuration loader", function() assert.is_nil(err) assert.is_table(conf) end) + it("errors when hosts have a bad format in cassandra_contact_points", function() + local conf, err = conf_loader(nil, { + cassandra_contact_points = [[some/really\bad/host\name,addr2]] + }) + assert.equal([[bad cassandra contact point 'some/really\bad/host\name': invalid hostname: some/really\bad/host\name]], err) + assert.is_nil(conf) + end) + it("errors when specifying a port in cassandra_contact_points", function() + local conf, err = conf_loader(nil, { + cassandra_contact_points = "addr1:9042,addr2" + }) + assert.equal("bad cassandra contact point 'addr1:9042': port must be specified in cassandra_port", err) + assert.is_nil(conf) + end) it("cluster_ttl_on_failure cannot be lower than 60 seconds", function() local conf, err = conf_loader(nil, { cluster_ttl_on_failure = 40