@@ -594,7 +594,7 @@ describe('Connection model builder', () => {
594594 const error = c . validate ( attrs ) ;
595595
596596 expect ( c . isValid ( ) ) . to . be . equal ( false ) ;
597- expect ( error . message ) . to . include ( 'mongodbUsername field is required' ) ;
597+ expect ( error . message ) . to . include ( 'The \'Username\' field is required when using \'Username/Password\' or \'SCRAM-SHA-256\' for authentication. ' ) ;
598598 } ) ;
599599
600600 it ( 'should throw the error if auth is SCRAM-SHA-256 and mongodbPassword is missing' , ( ) => {
@@ -606,7 +606,7 @@ describe('Connection model builder', () => {
606606 const error = c . validate ( attrs ) ;
607607
608608 expect ( c . isValid ( ) ) . to . be . equal ( false ) ;
609- expect ( error . message ) . to . include ( 'mongodbPassword field is required') ;
609+ expect ( error . message ) . to . equal ( 'The \'Password\' field is required when using \'Username/Password\' or \'SCRAM-SHA-256\' for authentication. ') ;
610610 } ) ;
611611
612612 it ( 'should throw the error if MONGODB auth receives non-applicable fields' , ( ) => {
@@ -619,8 +619,8 @@ describe('Connection model builder', () => {
619619 const error = c . validate ( attrs ) ;
620620
621621 expect ( c . isValid ( ) ) . to . be . equal ( false ) ;
622- expect ( error . message ) . to . include (
623- 'kerberosServiceName field does not apply'
622+ expect ( error . message ) . to . equal (
623+ 'The Kerberos \'Service Name\' field does not apply when using MONGODB for authentication. '
624624 ) ;
625625 } ) ;
626626
@@ -683,7 +683,7 @@ describe('Connection model builder', () => {
683683 const error = c . validate ( attrs ) ;
684684
685685 expect ( c . isValid ( ) ) . to . be . equal ( false ) ;
686- expect ( error . message ) . to . include ( 'mongodbUsername field is required' ) ;
686+ expect ( error . message ) . to . include ( 'The \'Username\' field is required when using \'Username/Password\' or \'SCRAM-SHA-256\' for authentication. ' ) ;
687687 } ) ;
688688
689689 it ( 'should throw the error if auth is MONGODB and mongodbPassword is missing' , ( done ) => {
@@ -734,7 +734,7 @@ describe('Connection model builder', () => {
734734 const error = c . validate ( attrs ) ;
735735
736736 expect ( c . isValid ( ) ) . to . be . equal ( false ) ;
737- expect ( error . message ) . to . include ( 'ldapUsername field is required') ;
737+ expect ( error . message ) . to . equal ( 'The \'Username\' field is required when using \'LDAP\' for authentication. ') ;
738738 } ) ;
739739
740740 it ( 'should throw the error if auth is LDAP and ldapPassword is missing' , ( ) => {
@@ -743,7 +743,7 @@ describe('Connection model builder', () => {
743743 const error = c . validate ( attrs ) ;
744744
745745 expect ( c . isValid ( ) ) . to . be . equal ( false ) ;
746- expect ( error . message ) . to . include ( 'ldapPassword field is required') ;
746+ expect ( error . message ) . to . equal ( 'The \'Password\' field is required when using LDAP for authentication. ') ;
747747 } ) ;
748748
749749 it ( 'should set authStrategy to X509' , ( done ) => {
@@ -760,13 +760,28 @@ describe('Connection model builder', () => {
760760 } ) ;
761761 } ) ;
762762
763- it ( 'should throw the error if auth is X509 and x509Username is missing' , ( ) => {
764- const attrs = { authStrategy : 'X509' } ;
763+ it ( 'should not throw the error if auth is X509 and x509Username is missing' , ( ) => {
764+ const attrs = {
765+ authStrategy : 'X509' ,
766+ sslMethod : 'ALL' ,
767+ sslCA : [ fixture . ssl . ca ] ,
768+ sslCert : fixture . ssl . server ,
769+ sslKey : fixture . ssl . server
770+ } ;
771+ const c = new Connection ( attrs ) ;
772+
773+ expect ( c . isValid ( ) ) . to . be . equal ( true ) ;
774+ } ) ;
775+
776+ it ( 'should throw a validation error if auth is X509 and sslMethod is not "ALL"' , ( ) => {
777+ const attrs = {
778+ authStrategy : 'X509'
779+ } ;
765780 const c = new Connection ( attrs ) ;
766781 const error = c . validate ( attrs ) ;
767782
768783 expect ( c . isValid ( ) ) . to . be . equal ( false ) ;
769- expect ( error . message ) . to . include ( 'x509Username field is required') ;
784+ expect ( error . message ) . to . equal ( 'SSL method is required to be set to \'Server and Client Validation\' when using X.509 authentication. ') ;
770785 } ) ;
771786
772787 it ( 'should set default mongodb gssapiServiceName when using KERBEROS auth' , ( done ) => {
@@ -803,7 +818,7 @@ describe('Connection model builder', () => {
803818 const error = c . validate ( attrs ) ;
804819
805820 expect ( c . isValid ( ) ) . to . be . equal ( false ) ;
806- expect ( error . message ) . to . include ( 'kerberosPrincipal field is required') ;
821+ expect ( error . message ) . to . equal ( 'The Kerberos \'Principal\' field is required when using \'Kerberos\' for authentication. ') ;
807822 } ) ;
808823
809824 it ( 'should *only* require a kerberosPrincipal' , ( ) => {
@@ -936,7 +951,7 @@ describe('Connection model builder', () => {
936951 const error = c . validate ( attrs ) ;
937952
938953 expect ( c . isValid ( ) ) . to . be . equal ( false ) ;
939- expect ( error . message ) . to . include ( 'mongodbPassword field is required') ;
954+ expect ( error . message ) . to . equal ( 'The \'Password\' field is required when using \'Username/Password\' or \'SCRAM-SHA-256\' for authentication. ') ;
940955 } ) ;
941956
942957 it ( 'should generate the local port when using a ssh tunne and bind to local port does not exist' , ( ) => {
0 commit comments