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

[api/silenced] allow for subscriptions containing colons *and* hyphens #1457

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/sensu/api/routes/silenced.rb
Expand Up @@ -3,7 +3,7 @@ module API
module Routes
module Silenced
SILENCED_URI = /^\/silenced$/
SILENCED_SUBSCRIPTION_URI = /^\/silenced\/subscriptions\/([\w\.-:]+)$/
SILENCED_SUBSCRIPTION_URI = /^\/silenced\/subscriptions\/([\w\.:-]+)$/

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's traditional to put a - first in a character class. Or \escape it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll escape it for clarity. 👍

SILENCED_CHECK_URI = /^\/silenced\/checks\/([\w\.-]+)$/
SILENCED_CLEAR_URI = /^\/silenced\/clear$/

Expand Down
14 changes: 7 additions & 7 deletions spec/api/process_spec.rb
Expand Up @@ -1328,11 +1328,11 @@
end
end

it "can create and retrieve silenced registry entry with a subscription containing a colon" do
it "can create and retrieve silenced registry entry with a subscription containing both a colon and a hyphen" do
api_test do
options = {
:body => {
:subscription => "client:test",
:subscription => "client:my-test-client",
:check => "test",
:expire => 3600,
:reason => "testing",
Expand All @@ -1342,20 +1342,20 @@
}
api_request("/silenced", :post, options) do |http, body|
expect(http.response_header.status).to eq(201)
redis.get("silence:client:test:test") do |silenced_info_json|
redis.get("silence:client:my-test-client:test") do |silenced_info_json|
silenced_info = Sensu::JSON.load(silenced_info_json)
expect(silenced_info[:id]).to eq("client:test:test")
expect(silenced_info[:subscription]).to eq("client:test")
expect(silenced_info[:id]).to eq("client:my-test-client:test")
expect(silenced_info[:subscription]).to eq("client:my-test-client")
expect(silenced_info[:check]).to eq("test")
expect(silenced_info[:reason]).to eq("testing")
expect(silenced_info[:creator]).to eq("rspec")
expect(silenced_info[:expire_on_resolve]).to eq(true)
redis.ttl("silence:client:test:test") do |ttl|
redis.ttl("silence:client:my-test-client:test") do |ttl|
expect(ttl).to be_within(10).of(3600)
async_done
end
end
api_request("/silenced/subscriptions/client:test") do |http, body|
api_request("/silenced/subscriptions/client:my-test-client") do |http, body|
expect(http.response_header.status).to eq(200)
expect(body).to be_kind_of(Hash)
expect(body).to eq(result_template(@check))
Expand Down