@@ -487,3 +487,36 @@ func TestBrokenPipe(t *testing.T) {
487487 args = append (args , "--db" , dbName , "--collection" , collName )
488488 testutil .AssertBrokenPipeHandled (t , exec .Command ("go" , args ... ))
489489}
490+
491+ // TestExportNamespaceValidation verifies that mongoexport rejects invalid DB
492+ // names and accepts system collections (from namespace_validation.js).
493+ func TestExportNamespaceValidation (t * testing.T ) {
494+ testtype .SkipUnlessTestType (t , testtype .IntegrationTestType )
495+ log .SetWriter (io .Discard )
496+
497+ for _ , dbName := range []string {"test.bar" , `test"bar` } {
498+ toolOptions , err := testutil .GetToolOptions ()
499+ require .NoError (t , err )
500+ toolOptions .Namespace = & options.Namespace {DB : dbName , Collection : "foo" }
501+ _ , err = New (Options {
502+ ToolOptions : toolOptions ,
503+ OutputFormatOptions : & OutputFormatOptions {Type : "json" , JSONFormat : "canonical" },
504+ InputOptions : & InputOptions {},
505+ })
506+ assert .Error (t , err , "db name %q should be rejected" , dbName )
507+ }
508+
509+ toolOptions , err := testutil .GetToolOptions ()
510+ require .NoError (t , err )
511+ toolOptions .Namespace = & options.Namespace {DB : "test" , Collection : "system.foobar" }
512+ me , err := New (Options {
513+ ToolOptions : toolOptions ,
514+ OutputFormatOptions : & OutputFormatOptions {Type : "json" , JSONFormat : "canonical" },
515+ InputOptions : & InputOptions {},
516+ })
517+ assert .NoError (t , err , "system collection should be accepted" )
518+ if me != nil {
519+ me .Close ()
520+ }
521+ }
522+
0 commit comments