Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix _host based require filters #38173

Merged
merged 1 commit into from
Feb 1, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,7 @@ public boolean match(DiscoveryNode node) {
}
} else if ("_host".equals(attr)) {
for (String value : values) {
if (Regex.simpleMatch(value, node.getHostName())) {
if (opType == OpType.OR) {
return true;
}
} else {
if (opType == OpType.AND) {
return false;
}
}
if (Regex.simpleMatch(value, node.getHostAddress())) {
if (Regex.simpleMatch(value, node.getHostName()) || Regex.simpleMatch(value, node.getHostAddress())) {
if (opType == OpType.OR) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,26 @@ public void testIpPublishFilteringMatchingOr() {
assertThat(filters.match(node), equalTo(true));
}

public void testHostNameFilteringMatchingAnd() {
Settings settings = shuffleSettings(Settings.builder()
.put("xxx._host", "A")
.build());
DiscoveryNodeFilters filters = buildFromSettings(AND, "xxx.", settings);

DiscoveryNode node = new DiscoveryNode("", "", "", "A", "192.1.1.54", localAddress, emptyMap(), emptySet(), null);
assertThat(filters.match(node), equalTo(true));
}

public void testHostAddressFilteringMatchingAnd() {
Settings settings = shuffleSettings(Settings.builder()
.put("xxx._host", "192.1.1.54")
.build());
DiscoveryNodeFilters filters = buildFromSettings(AND, "xxx.", settings);

DiscoveryNode node = new DiscoveryNode("", "", "", "A", "192.1.1.54", localAddress, emptyMap(), emptySet(), null);
assertThat(filters.match(node), equalTo(true));
}

public void testIpPublishFilteringNotMatchingOr() {
Settings settings = shuffleSettings(Settings.builder()
.put("xxx.tag", "A")
Expand Down