Consistently clean actuator endpoint ids
Closes gh-18649
This commit is contained in:
@@ -20,6 +20,7 @@ import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Member predicate that matches based on {@code include} and {@code exclude} sets.
|
||||
@@ -54,12 +55,12 @@ class IncludeExcludeGroupMemberPredicate implements Predicate<String> {
|
||||
if (names == null) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
Set<String> cleaned = new LinkedHashSet<>(names);
|
||||
Set<String> cleaned = names.stream().map(this::clean).collect(Collectors.toCollection(LinkedHashSet::new));
|
||||
return Collections.unmodifiableSet(cleaned);
|
||||
}
|
||||
|
||||
private String clean(String name) {
|
||||
return name.trim().toLowerCase();
|
||||
return name.trim();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -68,6 +68,24 @@ class IncludeExcludeGroupMemberPredicateTests {
|
||||
assertThat(predicate).rejects("a", "b", "c", "d");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testWhenCamelCaseIncludeAcceptsOnlyIncluded() {
|
||||
Predicate<String> predicate = include("myEndpoint").exclude();
|
||||
assertThat(predicate).accepts("myEndpoint").rejects("d");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testWhenHyphenCaseIncludeAcceptsOnlyIncluded() {
|
||||
Predicate<String> predicate = include("my-endpoint").exclude();
|
||||
assertThat(predicate).accepts("my-endpoint").rejects("d");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testWhenExtraWhitespaceAcceptsTrimmedVersion() {
|
||||
Predicate<String> predicate = include(" myEndpoint ").exclude();
|
||||
assertThat(predicate).accepts("myEndpoint").rejects("d");
|
||||
}
|
||||
|
||||
private Builder include(String... include) {
|
||||
return new Builder(include);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user