Skip to content

Commit 13cb98f

Browse files
Shraya Ramanihanumantmk
authored andcommitted
CDRIVER-471 Validation for wt opts for collection
Added in validation for wiredtiger storage options to createCollection. Closes #127
1 parent 44c345e commit 13cb98f

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

src/mongoc/mongoc-database.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -930,8 +930,47 @@ mongoc_database_create_collection (mongoc_database_t *database,
930930
return NULL;
931931
}
932932
}
933+
934+
if (bson_iter_init_find (&iter, options, "storage")) {
935+
if (!BSON_ITER_HOLDS_DOCUMENT (&iter)) {
936+
bson_set_error (error,
937+
MONGOC_ERROR_COMMAND,
938+
MONGOC_ERROR_COMMAND_INVALID_ARG,
939+
"The \"storage\" parameter must be a document");
940+
941+
return NULL;
942+
}
943+
944+
if (bson_iter_find (&iter, "wiredtiger")) {
945+
if (!BSON_ITER_HOLDS_DOCUMENT (&iter)) {
946+
bson_set_error (error,
947+
MONGOC_ERROR_COMMAND,
948+
MONGOC_ERROR_COMMAND_INVALID_ARG,
949+
"The \"wiredtiger\" option must take a document argument with a \"configString\" field");
950+
return NULL;
951+
}
952+
953+
if (bson_iter_find (&iter, "configString")) {
954+
if (!BSON_ITER_HOLDS_UTF8 (&iter)) {
955+
bson_set_error (error,
956+
MONGOC_ERROR_COMMAND,
957+
MONGOC_ERROR_COMMAND_INVALID_ARG,
958+
"The \"configString\" parameter must be a string");
959+
return NULL;
960+
}
961+
} else {
962+
bson_set_error (error,
963+
MONGOC_ERROR_COMMAND,
964+
MONGOC_ERROR_COMMAND_INVALID_ARG,
965+
"The \"wiredtiger\" option must take a document argument with a \"configString\" field");
966+
return NULL;
967+
}
968+
}
969+
}
970+
933971
}
934972

973+
935974
bson_init (&cmd);
936975
BSON_APPEND_UTF8 (&cmd, "create", name);
937976

tests/test-mongoc-database.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ test_create_collection (void)
140140
mongoc_client_t *client;
141141
bson_error_t error = { 0 };
142142
bson_t options;
143+
bson_t storage_opts;
144+
bson_t wt_opts;
145+
143146
char *dbname;
144147
char *name;
145148
bool r;
@@ -158,6 +161,13 @@ test_create_collection (void)
158161
BSON_APPEND_BOOL (&options, "capped", true);
159162
BSON_APPEND_BOOL (&options, "autoIndexId", true);
160163

164+
BSON_APPEND_DOCUMENT_BEGIN(&options, "storage", &storage_opts);
165+
BSON_APPEND_DOCUMENT_BEGIN(&storage_opts, "wiredtiger", &wt_opts);
166+
BSON_APPEND_UTF8(&wt_opts, "configString", "block_compressor=zlib");
167+
bson_append_document_end(&storage_opts, &wt_opts);
168+
bson_append_document_end(&options, &storage_opts);
169+
170+
161171
name = gen_collection_name ("create_collection");
162172
collection = mongoc_database_create_collection (database, name, &options, &error);
163173
assert (collection);

0 commit comments

Comments
 (0)