@@ -702,6 +702,74 @@ test_cursor_new_invalid (void)
702
702
mongoc_client_destroy (client );
703
703
}
704
704
705
+
706
+ static void
707
+ test_cursor_new_invalid_filter (void )
708
+ {
709
+ mongoc_client_t * client ;
710
+ mongoc_collection_t * collection ;
711
+ mongoc_cursor_t * cursor ;
712
+ bson_error_t error ;
713
+
714
+ client = test_framework_client_new ();
715
+ collection = mongoc_client_get_collection (client , "test" , "test" );
716
+
717
+ cursor = mongoc_collection_find_with_opts (
718
+ collection , tmp_bson ("{'': 1}" ), NULL , NULL );
719
+
720
+ ASSERT (cursor );
721
+ ASSERT (mongoc_cursor_error (cursor , & error ));
722
+ ASSERT_ERROR_CONTAINS (error ,
723
+ MONGOC_ERROR_CURSOR ,
724
+ MONGOC_ERROR_CURSOR_INVALID_CURSOR ,
725
+ "Empty keys are not allowed in 'filter'." );
726
+
727
+ mongoc_cursor_destroy (cursor );
728
+ mongoc_collection_destroy (collection );
729
+ mongoc_client_destroy (client );
730
+ }
731
+
732
+
733
+ static void
734
+ test_cursor_new_invalid_opts (void )
735
+ {
736
+ mongoc_client_t * client ;
737
+ mongoc_collection_t * collection ;
738
+ mongoc_cursor_t * cursor ;
739
+ bson_error_t error ;
740
+
741
+ client = test_framework_client_new ();
742
+ collection = mongoc_client_get_collection (client , "test" , "test" );
743
+
744
+ cursor = mongoc_collection_find_with_opts (
745
+ collection , tmp_bson (NULL ), tmp_bson ("{'projection': {'': 1}}" ), NULL );
746
+
747
+ ASSERT (cursor );
748
+ ASSERT (mongoc_cursor_error (cursor , & error ));
749
+ ASSERT_ERROR_CONTAINS (error ,
750
+ MONGOC_ERROR_CURSOR ,
751
+ MONGOC_ERROR_CURSOR_INVALID_CURSOR ,
752
+ "Cannot use empty keys in 'opts'." );
753
+
754
+ mongoc_cursor_destroy (cursor );
755
+
756
+ cursor = mongoc_collection_find_with_opts (
757
+ collection , tmp_bson (NULL ), tmp_bson ("{'$invalid': 1}" ), NULL );
758
+
759
+ ASSERT (cursor );
760
+ ASSERT (mongoc_cursor_error (cursor , & error ));
761
+ ASSERT_ERROR_CONTAINS (error ,
762
+ MONGOC_ERROR_CURSOR ,
763
+ MONGOC_ERROR_CURSOR_INVALID_CURSOR ,
764
+ "Cannot use $-modifiers in 'opts'." );
765
+
766
+ mongoc_cursor_destroy (cursor );
767
+
768
+ mongoc_collection_destroy (collection );
769
+ mongoc_client_destroy (client );
770
+ }
771
+
772
+
705
773
static void
706
774
test_cursor_new_static (void )
707
775
{
@@ -1521,6 +1589,10 @@ test_cursor_install (TestSuite *suite)
1521
1589
test_cursor_new_from_find_batches , NULL , NULL ,
1522
1590
test_framework_skip_if_max_wire_version_less_than_4 );
1523
1591
TestSuite_AddLive (suite , "/Cursor/new_invalid" , test_cursor_new_invalid );
1592
+ TestSuite_AddLive (
1593
+ suite , "/Cursor/new_invalid_filter" , test_cursor_new_invalid_filter );
1594
+ TestSuite_AddLive (
1595
+ suite , "/Cursor/new_invalid_opts" , test_cursor_new_invalid_opts );
1524
1596
TestSuite_AddLive (suite , "/Cursor/new_static" , test_cursor_new_static );
1525
1597
TestSuite_AddLive (suite , "/Cursor/hint/errors" , test_cursor_hint_errors );
1526
1598
TestSuite_Add (suite , "/Cursor/hint/single/secondary" , test_hint_single_secondary );
0 commit comments