-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Add additional payload filter key validation (#295)
Previously, we were allowing any non-empty string value to be provided as a payload filter key. However, customers can only create a filter key with a subset of characters within the LaunchDarkly UI. In an effort to warn customers earlier about potentially invalid configurations, we are adding basic key validation as part of the start up sequence.
- Loading branch information
Showing
6 changed files
with
70 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
require "spec_helper" | ||
|
||
module LaunchDarkly | ||
module Impl | ||
describe "payload filter key validation" do | ||
let(:logger) { double } | ||
|
||
it "silently discards nil" do | ||
expect(logger).not_to receive(:warn) | ||
expect(Util.validate_payload_filter_key(nil, logger)).to be_nil | ||
end | ||
|
||
[true, 1, 1.0, [], {}].each do |value| | ||
it "returns nil for invalid type #{value.class}" do | ||
expect(logger).to receive(:warn) | ||
expect(Util.validate_payload_filter_key(value, logger)).to be_nil | ||
end | ||
end | ||
|
||
[ | ||
"", | ||
"-cannot-start-with-dash", | ||
"_cannot-start-with-underscore", | ||
"-cannot-start-with-period", | ||
"no spaces for you", | ||
"org@special/characters", | ||
].each do |value| | ||
it "returns nil for invalid value #{value}" do | ||
expect(logger).to receive(:warn) | ||
expect(Util.validate_payload_filter_key(value, logger)).to be_nil | ||
end | ||
end | ||
|
||
[ | ||
"camelCase", | ||
"snake_case", | ||
"kebab-case", | ||
"with.dots", | ||
"with_underscores", | ||
"with-hyphens", | ||
"with1234numbers", | ||
"with.many_1234-mixtures", | ||
"1start-with-number", | ||
].each do |value| | ||
it "passes for value #{value}" do | ||
expect(logger).not_to receive(:warn) | ||
expect(Util.validate_payload_filter_key(value, logger)).to eq(value) | ||
end | ||
end | ||
end | ||
end | ||
end |