@@ -733,6 +733,74 @@ test_cursor_new_invalid (void)
733
733
mongoc_client_destroy (client );
734
734
}
735
735
736
+
737
+ static void
738
+ test_cursor_new_invalid_filter (void )
739
+ {
740
+ mongoc_client_t * client ;
741
+ mongoc_collection_t * collection ;
742
+ mongoc_cursor_t * cursor ;
743
+ bson_error_t error ;
744
+
745
+ client = test_framework_client_new ();
746
+ collection = mongoc_client_get_collection (client , "test" , "test" );
747
+
748
+ cursor = mongoc_collection_find_with_opts (
749
+ collection , tmp_bson ("{'': 1}" ), NULL , NULL );
750
+
751
+ ASSERT (cursor );
752
+ ASSERT (mongoc_cursor_error (cursor , & error ));
753
+ ASSERT_ERROR_CONTAINS (error ,
754
+ MONGOC_ERROR_CURSOR ,
755
+ MONGOC_ERROR_CURSOR_INVALID_CURSOR ,
756
+ "Empty keys are not allowed in 'filter'." );
757
+
758
+ mongoc_cursor_destroy (cursor );
759
+ mongoc_collection_destroy (collection );
760
+ mongoc_client_destroy (client );
761
+ }
762
+
763
+
764
+ static void
765
+ test_cursor_new_invalid_opts (void )
766
+ {
767
+ mongoc_client_t * client ;
768
+ mongoc_collection_t * collection ;
769
+ mongoc_cursor_t * cursor ;
770
+ bson_error_t error ;
771
+
772
+ client = test_framework_client_new ();
773
+ collection = mongoc_client_get_collection (client , "test" , "test" );
774
+
775
+ cursor = mongoc_collection_find_with_opts (
776
+ collection , tmp_bson (NULL ), tmp_bson ("{'projection': {'': 1}}" ), NULL );
777
+
778
+ ASSERT (cursor );
779
+ ASSERT (mongoc_cursor_error (cursor , & error ));
780
+ ASSERT_ERROR_CONTAINS (error ,
781
+ MONGOC_ERROR_CURSOR ,
782
+ MONGOC_ERROR_CURSOR_INVALID_CURSOR ,
783
+ "Cannot use empty keys in 'opts'." );
784
+
785
+ mongoc_cursor_destroy (cursor );
786
+
787
+ cursor = mongoc_collection_find_with_opts (
788
+ collection , tmp_bson (NULL ), tmp_bson ("{'$invalid': 1}" ), NULL );
789
+
790
+ ASSERT (cursor );
791
+ ASSERT (mongoc_cursor_error (cursor , & error ));
792
+ ASSERT_ERROR_CONTAINS (error ,
793
+ MONGOC_ERROR_CURSOR ,
794
+ MONGOC_ERROR_CURSOR_INVALID_CURSOR ,
795
+ "Cannot use $-modifiers in 'opts'." );
796
+
797
+ mongoc_cursor_destroy (cursor );
798
+
799
+ mongoc_collection_destroy (collection );
800
+ mongoc_client_destroy (client );
801
+ }
802
+
803
+
736
804
static void
737
805
test_cursor_new_static (void )
738
806
{
@@ -1592,6 +1660,10 @@ test_cursor_install (TestSuite *suite)
1592
1660
NULL ,
1593
1661
test_framework_skip_if_max_wire_version_less_than_4 );
1594
1662
TestSuite_AddLive (suite , "/Cursor/new_invalid" , test_cursor_new_invalid );
1663
+ TestSuite_AddLive (
1664
+ suite , "/Cursor/new_invalid_filter" , test_cursor_new_invalid_filter );
1665
+ TestSuite_AddLive (
1666
+ suite , "/Cursor/new_invalid_opts" , test_cursor_new_invalid_opts );
1595
1667
TestSuite_AddLive (suite , "/Cursor/new_static" , test_cursor_new_static );
1596
1668
TestSuite_AddLive (suite , "/Cursor/hint/errors" , test_cursor_hint_errors );
1597
1669
TestSuite_Add (
0 commit comments