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

Conversation

cwjohnston
Copy link
Contributor

@cwjohnston cwjohnston commented Sep 20, 2016

Description

In #1450 we introduced a change to the regexp for validating requests to the /silenced/subscriptions/:subscription endpoint, but this change introduced a regression preventing the handling of subscriptions that also contain a hyphen (e.g. HTTP GET against /silenced/subscriptions/client:foo works but HTTP GET agains /silenced/subscriptions/client:foo-bar does not).

Transposing the positions of - and : in the regex seems to solve the problem.

In the interests of clarity and readability I've opted to escape the hyphen rather than change its position.

Related Issue

Closes #1449

Motivation and Context

The regexp for matching valid subscriptions under /silenced/subscriptions route
excludes valid subscriptions containing colons and hyphens, e.g. client:foo-bar.

How Has This Been Tested?

Expanded the unit test coverage to test a variety of subscriptions using colons, hyphens and underscores in various combinations.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@cwjohnston cwjohnston added this to the 0.26.3 milestone Sep 20, 2016
@@ -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. 👍

@cwjohnston cwjohnston mentioned this pull request Sep 21, 2016
8 tasks
…criptions

Some of the test assertions already committed weren't running because they were
not nested within a single block and async_done was being called too early.

This change ensures those assertions run, removes some assertions that aren't
particularly relevant to this test, and creates test examples for a variety of
subscription names using colons, hyphens and underscores to exercise the regexp
used by the /silenced/subscriptions/:subscription API endpoint.
…RI regexps

I think we should escape the hyphen here for purposes of indicating that we want
to match a hyphen and not to indicate a range.
"load-balancer",
"load_balancer",
"loadbalancer"
].each do |sub|
Copy link
Contributor

Choose a reason for hiding this comment

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

The only criticism that I have for you, why not subscription? We've avoided the use of short and single character variables when possible.

Copy link
Contributor

Choose a reason for hiding this comment

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

Other then changing this variable, 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed ✅

@cwjohnston
Copy link
Contributor Author

@portertech ready for merge

@cwjohnston cwjohnston merged commit a433f77 into master Sep 22, 2016
@cwjohnston cwjohnston deleted the fix/api-silenced-signature-regexp branch September 22, 2016 00:33
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

silence api usage
3 participants