Skip to content

Commit

Permalink
Fixes #820: increase max path length limit to 1000 (from 250) (#853)
Browse files Browse the repository at this point in the history
  • Loading branch information
tatu-at-datastax authored Feb 2, 2024
1 parent 88e9396 commit c8b536a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 28 deletions.
2 changes: 1 addition & 1 deletion CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Here are some Stargate-relevant property groups that are necessary for correct s
|-----------------------------------------------------------------|-------|-------------|-----------------------------------------------------------------------------------------|
| `stargate.jsonapi.document.limits.max-size` | `int` | `4_000_000` | The maximum size of (in characters) a single document. |
| `stargate.jsonapi.document.limits.max-depth` | `int` | `16` | The maximum document depth (nesting). |
| `stargate.jsonapi.document.limits.max-property-path-length` | `int` | `250` | The maximum length of property paths in a document (segments and separating periods) |
| `stargate.jsonapi.document.limits.max-property-path-length` | `int` | `1000` | The maximum length of property paths in a document (segments and separating periods) |
| `stargate.jsonapi.document.limits.max-object-properties` | `int` | `1000` | The maximum number of properties any single indexable object in a document can contain. |
| `stargate.jsonapi.document.limits.max-document-properties` | `int` | `2000` | The maximum number of total indexed properties a document can contain. |
| `stargate.jsonapi.document.limits.max-number-length` | `int` | `100` | The maximum length (in characters) of a single number value in a document. |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public interface DocumentLimitsConfig {
* Defines the default maximum total length of path to individual properties in JSON documents:
* composed of individual Object property names separated by dots (".").
*/
int DEFAULT_MAX_PROPERTY_PATH_LENGTH = 250;
int DEFAULT_MAX_PROPERTY_PATH_LENGTH = 1000;

/**
* Defines the default maximum length of a single String value: 8,000 bytes with 1.0.0-BETA-6 and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -569,24 +569,25 @@ public void tryInsertTooBigArray() {
// Test for nested paths, to ensure longer paths work too.
@Test
public void insertLongestValidPath() {
// Need to hard-code knowledge of defaults here: max path is 250 (max single prop name 100)
// Since commas are also counted, let's do 4 x 60 (plus 3 commas) == 243 chars
// Need to hard-code knowledge of defaults here: max path is 1000
// Since periods are also counted, let's do 4 x 200 (plus 3 dots) == 803 chars
ObjectNode doc = MAPPER.createObjectNode();
ObjectNode prop1 = doc.putObject("a123".repeat(15));
ObjectNode prop2 = prop1.putObject("b123".repeat(15));
ObjectNode prop3 = prop2.putObject("c123".repeat(15));
prop3.put("d123".repeat(15), 42);
ObjectNode prop1 = doc.putObject("a1234".repeat(40));
ObjectNode prop2 = prop1.putObject("b1234".repeat(40));
ObjectNode prop3 = prop2.putObject("c1234".repeat(40));
prop3.put("d1234".repeat(40), 42);
doc.put(DocumentConstants.Fields.DOC_ID, "docWithLongPath");
_verifyInsert("docWithLongPath", doc);
}

@Test
public void tryInsertTooLongPath() {
// Max path: 250 characters. Exceed with 272
// Max path: 100 characters. Exceed with 4 x 250 + 3
ObjectNode doc = MAPPER.createObjectNode();
ObjectNode prop1 = doc.putObject("a".repeat(90));
ObjectNode prop2 = prop1.putObject("b".repeat(90));
prop2.put("c".repeat(90), true);
ObjectNode prop1 = doc.putObject("a".repeat(250));
ObjectNode prop2 = prop1.putObject("b".repeat(250));
ObjectNode prop3 = prop2.putObject("c".repeat(250));
prop3.put("d".repeat(250), true);
final String json =
"""
{
Expand All @@ -610,7 +611,7 @@ public void tryInsertTooLongPath() {
.body(
"errors[0].message",
startsWith(
"Document size limitation violated: property path length (272) exceeds maximum allowed (250)"));
"Document size limitation violated: property path length (1003) exceeds maximum allowed (1000)"));
}

@Test
Expand Down Expand Up @@ -675,8 +676,7 @@ public void insertLongestValidString() {
ObjectNode doc = MAPPER.createObjectNode();
final String docId = "docWithLongString";
doc.put(DocumentConstants.Fields.DOC_ID, docId);
// 1M / 8k means at most 125 max length Strings; add 63 (with _id max of 64
// properties per Object)
// 1M / 8k means at most 125 max length Strings; add 63 (with _id 64)
for (int i = 0; i < 63; ++i) {
doc.put("text" + i, createBigString(strLen));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,23 +252,24 @@ public void allowNotTooLongNames() {
@Test
public void allowNotTooLongPath() {
final ObjectNode doc = objectMapper.createObjectNode();
// Create 3-levels, 80 chars each, so 242 chars (3 names, 2 dots); below 250 max
ObjectNode ob1 = doc.putObject("abcd".repeat(20));
ObjectNode ob2 = ob1.putObject("defg".repeat(20));
ObjectNode ob3 = ob2.putObject("hijk".repeat(20));
// and then one short one, for 244 char total path
ob3.put("x", 123);
// Create 3-levels, 300 chars each, so 902 chars (3 names, 2 dots); below 1000 max
ObjectNode ob1 = doc.putObject("abcde".repeat(60));
ObjectNode ob2 = ob1.putObject("defgh".repeat(60));
ObjectNode ob3 = ob2.putObject("hijkl".repeat(60));
// and then one short one, for 992 char total path
ob3.put("xyz".repeat(30), 123);
assertThat(shredder.shred(doc)).isNotNull();
}

@Test
public void catchTooLongPaths() {
final ObjectNode doc = objectMapper.createObjectNode();
// Create 3-levels, 80 chars each, so close to 250; and then one bit longer value
ObjectNode ob1 = doc.putObject("abcd".repeat(20));
ObjectNode ob2 = ob1.putObject("defg".repeat(20));
ObjectNode ob3 = ob2.putObject("hijk".repeat(20));
ob3.put("longPropertyName", 123);
// Create 3-levels, 300 chars each, for 900 + 2 and then one last segment of 100 char
ObjectNode ob1 = doc.putObject("abcde".repeat(60));
ObjectNode ob2 = ob1.putObject("defgh".repeat(60));
ObjectNode ob3 = ob2.putObject("hijkl".repeat(60));
final String lastSegment = "a1234".repeat(20);
ob3.put(lastSegment, 123);

Exception e = catchException(() -> shredder.shred(doc));
assertThat(e)
Expand All @@ -277,9 +278,11 @@ public void catchTooLongPaths() {
.hasFieldOrPropertyWithValue("errorCode", ErrorCode.SHRED_DOC_LIMIT_VIOLATION)
.hasMessageStartingWith(ErrorCode.SHRED_DOC_LIMIT_VIOLATION.getMessage())
.hasMessageEndingWith(
"property path length (259) exceeds maximum allowed ("
"property path length (1003) exceeds maximum allowed ("
+ docLimits.maxPropertyPathLength()
+ ") (path ends with 'longPropertyName')");
+ ") (path ends with '"
+ lastSegment
+ "')");
;
}

Expand Down

0 comments on commit c8b536a

Please sign in to comment.