Skip to content
This repository has been archived by the owner on Mar 6, 2020. It is now read-only.

Validate client keepalives (bool) #27

Merged
merged 1 commit into from
May 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/sensu/settings/validators/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
#
Expand Down Expand Up @@ -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)
Expand Down
22 changes: 22 additions & 0 deletions spec/validator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down