node-ldapjs/test/messages/modify_response.test.js

57 lines
1.2 KiB
JavaScript
Raw Normal View History

'use strict'
2011-08-04 20:32:01 +00:00
const { test } = require('tap')
const { BerReader, BerWriter } = require('asn1')
const { ModifyResponse } = require('../../lib')
2011-08-04 20:32:01 +00:00
test('new no args', function (t) {
t.ok(new ModifyResponse())
t.end()
})
2011-08-04 20:32:01 +00:00
test('new with args', function (t) {
const res = new ModifyResponse({
2011-08-04 20:32:01 +00:00
messageID: 123,
status: 0
})
t.ok(res)
t.equal(res.messageID, 123)
t.equal(res.status, 0)
t.end()
})
2011-08-04 20:32:01 +00:00
test('parse', function (t) {
const ber = new BerWriter()
ber.writeEnumeration(0)
ber.writeString('cn=root')
ber.writeString('foo')
const res = new ModifyResponse()
t.ok(res._parse(new BerReader(ber.buffer)))
t.equal(res.status, 0)
t.equal(res.matchedDN, 'cn=root')
t.equal(res.errorMessage, 'foo')
t.end()
})
2011-08-04 20:32:01 +00:00
test('toBer', function (t) {
const res = new ModifyResponse({
2011-08-04 20:32:01 +00:00
messageID: 123,
status: 3,
matchedDN: 'cn=root',
errorMessage: 'foo'
})
t.ok(res)
const ber = new BerReader(res.toBer())
t.ok(ber)
t.equal(ber.readSequence(), 0x30)
t.equal(ber.readInt(), 123)
t.equal(ber.readSequence(), 0x67)
t.equal(ber.readEnumeration(), 3)
t.equal(ber.readString(), 'cn=root')
t.equal(ber.readString(), 'foo')
t.end()
})