Skip to content

Commit

Permalink
Registering disable user-agent setting with OpenSearch (#16052)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
saratvemulapalli authored Sep 27, 2024
1 parent 0363a64 commit 78860ac
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 IngestGeoIpModulePlugin plugin = new IngestGeoIpModulePlugin();
final List<Setting<?>> settings = plugin.getSettings();
assertTrue(settings.contains(IngestGeoIpModulePlugin.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 @@ -89,6 +90,12 @@ public void testAllowListNotSpecified() throws IOException {
}
}

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

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

0 comments on commit 78860ac

Please sign in to comment.