Skip to content

Commit

Permalink
fix(config) error when specifying port for cassandra_contact_point
Browse files Browse the repository at this point in the history
cassandra_contact_point does not tolerate port specification.
Issue an error when the user specifies it by mistake.
  • Loading branch information
Vermeille authored and Tieske committed Mar 28, 2017
1 parent 821df79 commit e6a44bc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
12 changes: 12 additions & 0 deletions kong/conf_loader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
14 changes: 14 additions & 0 deletions spec/01-unit/02-conf_loader_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e6a44bc

Please sign in to comment.