0

传递不正确的过滤器数据时,ldapjs 客户端 API 未引发正确的错误。

下面是代码片段:

var ldap = require('ldapjs')
var client = ldap.createClient({
  url: 'ldap://<<ldap host>>:389'
})

client.bind(<<LDAP Admin User>>, <<Password>>, function(err) {
  if (err) {
      console.log('Error :  ', err)
  } else {
    let searchOpts = {
        scope: 'sub',
        filter: 'cn',
        attributes: []
    }
    client.search('dc=test,dc=com', searchOpts, function(err, res) {
      if (err) {
        console.log('error***************', err)
      } else {
        let count = 1
        res.on('searchEntry', function(entry) {
          console.log('entry  : ' + JSON.stringify(entry.object))
        })
        res.on('page', function(result, cb) {
          console.log('page end', result.controls)
        })
        res.on('error', function(err) {
          console.error('error: ' + err.message)
        })
        res.on('end', function(result) {
          console.log('result: ' + result)
          client.unbind(function(err) {
            if (err) {
                console.log('error unbind : ', err)
            } else {
                console.log('unbind is success')
            }
          })
        })
      }
    })
  }
})

在这里,我们传递了错误的过滤器参数。

D:\node_modules\ldap-filter\lib\index.js:200
      throw new Error(expr + ' is invalid');
      ^

Error: cn is invalid
    at _buildFilterTree (D:\node_modules\ldap-filter\lib\index.js:200:13)
    at _parseString (D:\node_modules\ldap-filter\lib\index.js:411:17)
    at Object.parse (D:\node_modules\ldap-filter\lib\index.js:422:12)
    at Object.parseString (D:\node_modules\ldapjs\lib\filters\index.js:176:25)
    at Client.search (D:\node_modules\ldapjs\lib\client\client.js:769:30)
    at D:\ApacheDS\apacheds_test_retrieve.js:29:12
    at sendResult (D:\node_modules\ldapjs\lib\client\client.js:1395:12)
    at messageCallback (D:\node_modules\ldapjs\lib\client\client.js:1421:16)
    at Parser.onMessage (D:\node_modules\ldapjs\lib\client\client.js:1089:14)
    at Parser.emit (events.js:198:13)

在这里,它不会从 ldapjs 错误http://ldapjs.org/errors.html引发任何错误。似乎错误处理没有正确实施。

4

0 回答 0