2019-08-27 21:11:49 +00:00
|
|
|
'use strict'
|
2014-09-07 19:42:31 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
const { test } = require('tap')
|
|
|
|
const { Parser, LDAPMessage, LDAP_REQ_EXTENSION } = require('../../lib')
|
2014-09-07 19:42:31 +00:00
|
|
|
|
|
|
|
test('wrong protocol error', function (t) {
|
2019-08-27 21:11:49 +00:00
|
|
|
const p = new Parser()
|
2014-09-07 19:42:31 +00:00
|
|
|
|
|
|
|
p.once('error', function (err) {
|
2019-08-27 21:11:49 +00:00
|
|
|
t.ok(err)
|
|
|
|
t.end()
|
|
|
|
})
|
2014-09-07 19:42:31 +00:00
|
|
|
|
|
|
|
// Send some bogus data to incur an error
|
2019-08-27 21:11:49 +00:00
|
|
|
p.write(Buffer.from([16, 1, 4]))
|
|
|
|
})
|
2014-09-07 19:42:31 +00:00
|
|
|
|
|
|
|
test('bad protocol op', function (t) {
|
2019-08-27 21:11:49 +00:00
|
|
|
const p = new Parser()
|
2019-08-27 18:17:33 +00:00
|
|
|
const message = new LDAPMessage({
|
2014-09-07 19:42:31 +00:00
|
|
|
protocolOp: 254 // bogus (at least today)
|
2019-08-27 21:11:49 +00:00
|
|
|
})
|
2014-09-07 19:42:31 +00:00
|
|
|
p.once('error', function (err) {
|
2019-08-27 21:11:49 +00:00
|
|
|
t.ok(err)
|
|
|
|
t.ok(/not supported$/.test(err.message))
|
|
|
|
t.end()
|
|
|
|
})
|
|
|
|
p.write(message.toBer())
|
|
|
|
})
|
2014-09-07 19:42:31 +00:00
|
|
|
|
|
|
|
test('bad message structure', function (t) {
|
2019-08-27 21:11:49 +00:00
|
|
|
const p = new Parser()
|
2014-09-07 19:42:31 +00:00
|
|
|
|
|
|
|
// message with bogus structure
|
2019-08-27 18:17:33 +00:00
|
|
|
const message = new LDAPMessage({
|
|
|
|
protocolOp: LDAP_REQ_EXTENSION
|
2019-08-27 21:11:49 +00:00
|
|
|
})
|
2014-09-07 19:42:31 +00:00
|
|
|
message._toBer = function (writer) {
|
2019-08-27 21:11:49 +00:00
|
|
|
writer.writeBuffer(Buffer.from([16, 1, 4]), 80)
|
|
|
|
return writer
|
|
|
|
}
|
2014-09-07 19:42:31 +00:00
|
|
|
|
|
|
|
p.once('error', function (err) {
|
2019-08-27 21:11:49 +00:00
|
|
|
t.ok(err)
|
|
|
|
t.end()
|
|
|
|
})
|
2014-09-07 19:42:31 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
p.write(message.toBer())
|
|
|
|
})
|