From a624973028ba4d4c14ea43e7b016839d23616dad Mon Sep 17 00:00:00 2001 From: Sean Porter Date: Wed, 4 May 2016 14:18:40 -0700 Subject: [PATCH] [client-keepalives] validate client keepalives (bool) --- lib/sensu/settings/validators/client.rb | 10 ++++++++++ spec/validator_spec.rb | 22 ++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/lib/sensu/settings/validators/client.rb b/lib/sensu/settings/validators/client.rb index 0d332fc..7cb331f 100644 --- a/lib/sensu/settings/validators/client.rb +++ b/lib/sensu/settings/validators/client.rb @@ -39,6 +39,15 @@ def validate_client_socket(client) end end + # Validate client keepalives. + # Validates: keepalives + # + # @param client [Hash] sensu client definition. + def validate_client_keepalives(client) + must_be_boolean_if_set(client[:keepalives]) || + invalid(client, "client keepalives must be boolean") + end + # Validate client keepalive handlers. # Validates: keepalive (handler, handlers) # @@ -149,6 +158,7 @@ def validate_client(client) validate_client_safe_mode(client) validate_client_subscriptions(client) validate_client_socket(client) + validate_client_keepalives(client) validate_client_keepalive(client) validate_client_redact(client) validate_client_signature(client) diff --git a/spec/validator_spec.rb b/spec/validator_spec.rb index 30eb7c8..9a7fbc2 100644 --- a/spec/validator_spec.rb +++ b/spec/validator_spec.rb @@ -555,6 +555,28 @@ expect(@validator.reset).to eq(0) end + it "can validate client keepalives" do + client = { + :name => "foo", + :address => "127.0.0.1", + :subscriptions => ["bar"] + } + @validator.validate_client(client) + expect(@validator.reset).to eq(0) + client[:keepalives] = 1 + @validator.validate_client(client) + expect(@validator.reset).to eq(1) + client[:keepalives] = "true" + @validator.validate_client(client) + expect(@validator.reset).to eq(1) + client[:keepalives] = true + @validator.validate_client(client) + expect(@validator.reset).to eq(0) + client[:keepalives] = false + @validator.validate_client(client) + expect(@validator.reset).to eq(0) + end + it "can validate client keepalive" do client = { :name => "foo",