Skip to content

Commit

Permalink
Fixes #776: Update max object, document properties limits
Browse files Browse the repository at this point in the history
  • Loading branch information
tatu-at-datastax committed Jan 8, 2024
1 parent 587a6b9 commit dc20b9d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ public interface DocumentLimitsConfig {
/**
* Defines the default maximum number of properties any single Object in JSON document can contain
*/
int DEFAULT_MAX_OBJECT_PROPERTIES = 64;
int DEFAULT_MAX_OBJECT_PROPERTIES = 1000;

/**
* Defines the default maximum number of properties the whole JSON document can contain (including
* Object- and Array-valued properties).
*/
int DEFAULT_MAX_DOC_PROPERTIES = 1000;
int DEFAULT_MAX_DOC_PROPERTIES = 2000;

/** Defines the default maximum length of a single Number value (in characters) */
int DEFAULT_MAX_NUMBER_LENGTH = 50;
Expand Down Expand Up @@ -84,7 +84,7 @@ public interface DocumentLimitsConfig {

/**
* @return Defines the maximum number of properties any single Object in JSON document can
* contain, defaults to {@code 64} (note: this is not the total number of properties in the
* contain, defaults to {@code 1,000} (note: this is not the total number of properties in the
* whole document, only on individual main or sub-document)
*/
@Positive
Expand All @@ -93,16 +93,15 @@ public interface DocumentLimitsConfig {

/**
* @return Defines the maximum number of properties the whole JSON document can contain, defaults
* to {@code 1000}, including Object- and Array-valued properties.
* to {@code 2,000}, including Object- and Array-valued properties.
*/
@Positive
@WithDefault("" + DEFAULT_MAX_DOC_PROPERTIES)
int maxDocumentProperties();

/**
* @return Defines the max size of filter fields, defaults to {@code 64}, which is tha same as the
* maximum number of properties of a single Json object. (note: this does not count the fields
* in '$operation' such as $in, $all)
* @return Defines the max size of filter fields, defaults to {@code 64}. (note: this does not
* count the fields in '$operation' such as $in, $all)
*/
@Positive
@WithDefault("" + DEFAULT_MAX_FILTER_SIZE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,17 @@ public void catchTooDeepDoc() {
class ValidationDocCountViolations {
@Test
public void allowDocWithManyObjectProps() {
// Max allowed is 64, so add 50
final ObjectNode doc = docWithNProps(50);
// Max allowed is 1,000
final ObjectNode doc = docWithNProps(docLimits.maxObjectProperties());
assertThat(shredder.shred(doc)).isNotNull();
}

@Test
public void catchTooManyObjectProps() {
// Max allowed 64, so fail with 100
final ObjectNode doc = docWithNProps(100);
// Max allowed 100, so fail with just one above
final int maxObProps = docLimits.maxObjectProperties();
final int tooManyProps = maxObProps + 1;
final ObjectNode doc = docWithNProps(tooManyProps);

Exception e = catchException(() -> shredder.shred(doc));
assertThat(e)
Expand All @@ -128,8 +130,10 @@ public void catchTooManyObjectProps() {
.hasFieldOrPropertyWithValue("errorCode", ErrorCode.SHRED_DOC_LIMIT_VIOLATION)
.hasMessageStartingWith(ErrorCode.SHRED_DOC_LIMIT_VIOLATION.getMessage())
.hasMessageEndingWith(
" number of properties an Object has (100) exceeds maximum allowed ("
+ docLimits.maxObjectProperties()
" number of properties an Object has ("
+ tooManyProps
+ ") exceeds maximum allowed ("
+ maxObProps
+ ")");
}

Expand All @@ -145,8 +149,8 @@ private ObjectNode docWithNProps(int count) {

@Test
public void catchTooManyDocProps() {
// Max allowed 1000, create one with ~1200
final ObjectNode doc = docWithNestedProps(40, 30);
// Max allowed 2000, create one with bit more
final ObjectNode doc = docWithNestedProps(50, 41);

Exception e = catchException(() -> shredder.shred(doc));
assertThat(e)
Expand All @@ -155,7 +159,7 @@ public void catchTooManyDocProps() {
.hasFieldOrPropertyWithValue("errorCode", ErrorCode.SHRED_DOC_LIMIT_VIOLATION)
.hasMessageStartingWith(ErrorCode.SHRED_DOC_LIMIT_VIOLATION.getMessage())
.hasMessageEndingWith(
" total number of properties (1241) in document exceeds maximum allowed ("
" total number of properties (2101) in document exceeds maximum allowed ("
+ docLimits.maxDocumentProperties()
+ ")");
}
Expand Down

0 comments on commit dc20b9d

Please sign in to comment.