Skip to content

Commit

Permalink
[Backport 2.x] Registering disable user-agent setting with OpenSearch (
Browse files Browse the repository at this point in the history
…#16113)

* Registering disable user-agent setting with OpenSearch (#16052)

* Registering allowlist setting in user-agent

Signed-off-by: Sarat Vemulapalli <vemulapallisarat@gmail.com>

* Adding unit tests

Signed-off-by: Sarat Vemulapalli <vemulapallisarat@gmail.com>

---------

Signed-off-by: Sarat Vemulapalli <vemulapallisarat@gmail.com>
(cherry picked from commit 78860ac)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* Fixing backport 2.x

Signed-off-by: Sarat Vemulapalli <vemulapallisarat@gmail.com>

---------

Signed-off-by: Sarat Vemulapalli <vemulapallisarat@gmail.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Sarat Vemulapalli <vemulapallisarat@gmail.com>
  • Loading branch information
3 people authored Oct 10, 2024
1 parent 589f42c commit f795fdb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.maxmind.geoip2.model.AbstractResponse;

import org.opensearch.common.network.InetAddresses;
import org.opensearch.common.settings.Setting;
import org.opensearch.common.settings.Settings;
import org.opensearch.env.TestEnvironment;
import org.opensearch.ingest.Processor;
Expand Down Expand Up @@ -126,6 +127,12 @@ public void testAllowListNotSpecified() throws IOException {
}
}

public void testSettingsRegistration() {
final IngestGeoIpPlugin plugin = new IngestGeoIpPlugin();
final List<Setting<?>> settings = plugin.getSettings();
assertTrue(settings.contains(IngestGeoIpPlugin.PROCESSORS_ALLOWLIST_SETTING));
}

private void runAllowListTest(List<String> allowList) throws IOException {
Settings.Builder settingsBuilder = Settings.builder();
createDb(settingsBuilder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import java.nio.file.Path;
import java.nio.file.PathMatcher;
import java.nio.file.StandardOpenOption;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -152,6 +153,6 @@ static Map<String, UserAgentParser> createUserAgentParsers(Path userAgentConfigD

@Override
public List<Setting<?>> getSettings() {
return Collections.singletonList(CACHE_SIZE_SETTING);
return Arrays.asList(CACHE_SIZE_SETTING, PROCESSORS_ALLOWLIST_SETTING);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

package org.opensearch.ingest.useragent;

import org.opensearch.common.settings.Setting;
import org.opensearch.common.settings.Settings;
import org.opensearch.env.TestEnvironment;
import org.opensearch.ingest.Processor;
Expand Down Expand Up @@ -87,6 +88,12 @@ public void testAllowListNotSpecified() throws IOException {
}
}

public void testSettingsRegistration() {
final IngestUserAgentPlugin plugin = new IngestUserAgentPlugin();
final List<Setting<?>> settings = plugin.getSettings();
assertTrue(settings.contains(IngestUserAgentPlugin.PROCESSORS_ALLOWLIST_SETTING));
}

private void runAllowListTest(List<String> allowList) throws IOException {
final Settings settings = settingsBuilder.putList(IngestUserAgentPlugin.PROCESSORS_ALLOWLIST_SETTING.getKey(), allowList).build();
try (IngestUserAgentPlugin plugin = new IngestUserAgentPlugin()) {
Expand Down

0 comments on commit f795fdb

Please sign in to comment.