@@ -93,6 +93,40 @@ describe('LDAP Injection Prevention', () => {
9393 } ) ;
9494 } ) ;
9595
96+ describe ( 'authData validation' , ( ) => {
97+ it ( 'should reject missing authData.id' , async done => {
98+ const server = await mockLdapServer ( port , 'uid=testuser, o=example' ) ;
99+ const options = {
100+ suffix : 'o=example' ,
101+ url : `ldap://localhost:${ port } ` ,
102+ dn : 'uid={{id}}, o=example' ,
103+ } ;
104+ try {
105+ await ldap . validateAuthData ( { password : 'secret' } , options ) ;
106+ fail ( 'Should have rejected missing id' ) ;
107+ } catch ( err ) {
108+ expect ( err . message ) . toBe ( 'LDAP: Wrong username or password' ) ;
109+ }
110+ server . close ( done ) ;
111+ } ) ;
112+
113+ it ( 'should reject non-string authData.id' , async done => {
114+ const server = await mockLdapServer ( port , 'uid=testuser, o=example' ) ;
115+ const options = {
116+ suffix : 'o=example' ,
117+ url : `ldap://localhost:${ port } ` ,
118+ dn : 'uid={{id}}, o=example' ,
119+ } ;
120+ try {
121+ await ldap . validateAuthData ( { id : 123 , password : 'secret' } , options ) ;
122+ fail ( 'Should have rejected non-string id' ) ;
123+ } catch ( err ) {
124+ expect ( err . message ) . toBe ( 'LDAP: Wrong username or password' ) ;
125+ }
126+ server . close ( done ) ;
127+ } ) ;
128+ } ) ;
129+
96130 describe ( 'DN injection prevention' , ( ) => {
97131 it ( 'should prevent DN injection via comma in authData.id' , async done => {
98132 // Mock server accepts the DN that would result from an unescaped injection
0 commit comments