Skip to content
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

### Changed
- Move Randomness from server to libs/common ([#20570](https://github.com/opensearch-project/OpenSearch/pull/20570))
- Relax validation for field-level `meta` ([#19884](https://github.com/opensearch-project/OpenSearch/issues/19884))
- Use env variable (OPENSEARCH_FIPS_MODE) to enable opensearch to run in FIPS enforced mode instead of checking for existence of bcFIPS jars ([#20625](https://github.com/opensearch-project/OpenSearch/pull/20625))

### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,27 +86,10 @@ public static Map<String, String> parseMeta(String name, Object metaObject) {
}
@SuppressWarnings("unchecked")
Map<String, ?> meta = (Map<String, ?>) metaObject;
if (meta.size() > 5) {
throw new MapperParsingException("[meta] can't have more than 5 entries, but got " + meta.size() + " on field [" + name + "]");
}
for (String key : meta.keySet()) {
if (key.codePointCount(0, key.length()) > 20) {
throw new MapperParsingException(
"[meta] keys can't be longer than 20 chars, but got [" + key + "] for field [" + name + "]"
);
}
}
for (Object value : meta.values()) {
if (value instanceof String) {
String sValue = (String) value;
if (sValue.codePointCount(0, sValue.length()) > 50) {
throw new MapperParsingException(
"[meta] values can't be longer than 50 chars, but got [" + value + "] for field [" + name + "]"
);
}
} else if (value == null) {
if (value == null) {
throw new MapperParsingException("[meta] values can't be null (field [" + name + "])");
} else {
} else if (!(value instanceof String)) {
throw new MapperParsingException(
"[meta] values can only be strings, but got "
+ value.getClass().getSimpleName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,23 +117,17 @@ public void testParseMeta() {
}

{
MapperParsingException e = expectThrows(
MapperParsingException.class,
() -> TypeParsers.parseMeta("foo", Collections.singletonMap("veryloooooooooooongkey", 3L))
);
assertEquals("[meta] keys can't be longer than 20 chars, but got [veryloooooooooooongkey] for field [foo]", e.getMessage());
}

{
String longString = IntStream.range(0, 51).mapToObj(Integer::toString).collect(Collectors.joining());
Map<String, String> meta = new HashMap<>();
meta.put("foo1", "3");
meta.put("foo2", "3");
meta.put("foo3", "3");
meta.put("foo4", "3");
meta.put("foo5", "3");
meta.put("foo6", "3");
MapperParsingException e = expectThrows(MapperParsingException.class, () -> TypeParsers.parseMeta("foo", meta));
assertEquals("[meta] can't have more than 5 entries, but got 6 on field [foo]", e.getMessage());
meta.put("shortKey", "someValue");
meta.put("keyWithNameLongerThan20Chars", "someValue");
meta.put("a", "someValue");
meta.put("longValueKey", longString);
meta.put("foo5", "someValue");
meta.put("foo6", "someValue");
meta.put("foo7", "someValue");
Map<String,String> result = TypeParsers.parseMeta("foo", meta);
assertEquals(meta.size(), result.size());
}

{
Expand All @@ -156,14 +150,5 @@ public void testParseMeta() {
MapperParsingException e = expectThrows(MapperParsingException.class, () -> TypeParsers.parseMeta("foo", meta));
assertEquals("[meta] values can't be null (field [foo])", e.getMessage());
}

{
String longString = IntStream.range(0, 51).mapToObj(Integer::toString).collect(Collectors.joining());
MapperParsingException e = expectThrows(
MapperParsingException.class,
() -> TypeParsers.parseMeta("foo", Collections.singletonMap("foo", longString))
);
assertThat(e.getMessage(), Matchers.startsWith("[meta] values can't be longer than 50 chars"));
}
}
}
Loading