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

87 lines
2.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 { ModifyRequest, Attribute, Change, dn } = require('../../lib')
2011-08-04 20:32:01 +00:00
test('new no args', function (t) {
t.ok(new ModifyRequest())
t.end()
})
2011-08-04 20:32:01 +00:00
test('new with args', function (t) {
const req = new ModifyRequest({
2011-08-04 20:32:01 +00:00
object: dn.parse('cn=foo, o=test'),
changes: [new Change({
operation: 'Replace',
modification: new Attribute({ type: 'objectclass', vals: ['person'] })
2011-08-04 20:32:01 +00:00
})]
})
t.ok(req)
t.equal(req.dn.toString(), 'cn=foo, o=test')
t.equal(req.changes.length, 1)
t.equal(req.changes[0].operation, 'replace')
t.equal(req.changes[0].modification.type, 'objectclass')
t.equal(req.changes[0].modification.vals[0], 'person')
t.end()
})
2011-08-04 20:32:01 +00:00
test('parse', function (t) {
const ber = new BerWriter()
ber.writeString('cn=foo, o=test')
ber.startSequence()
2011-08-04 20:32:01 +00:00
ber.startSequence()
ber.writeEnumeration(0x02)
2011-08-04 20:32:01 +00:00
ber.startSequence()
ber.writeString('objectclass')
ber.startSequence(0x31)
ber.writeString('person')
ber.endSequence()
ber.endSequence()
2011-08-04 20:32:01 +00:00
ber.endSequence()
2011-08-04 20:32:01 +00:00
ber.endSequence()
2011-08-04 20:32:01 +00:00
const req = new ModifyRequest()
t.ok(req._parse(new BerReader(ber.buffer)))
t.equal(req.dn.toString(), 'cn=foo, o=test')
t.equal(req.changes.length, 1)
t.equal(req.changes[0].operation, 'replace')
t.equal(req.changes[0].modification.type, 'objectclass')
t.equal(req.changes[0].modification.vals[0], 'person')
t.end()
})
2011-08-04 20:32:01 +00:00
test('toBer', function (t) {
const req = new ModifyRequest({
2011-08-04 20:32:01 +00:00
messageID: 123,
object: dn.parse('cn=foo, o=test'),
changes: [new Change({
operation: 'Replace',
modification: new Attribute({ type: 'objectclass', vals: ['person'] })
2011-08-04 20:32:01 +00:00
})]
})
2011-08-04 20:32:01 +00:00
t.ok(req)
2011-08-04 20:32:01 +00:00
const ber = new BerReader(req.toBer())
t.ok(ber)
t.equal(ber.readSequence(), 0x30)
t.equal(ber.readInt(), 123)
t.equal(ber.readSequence(), 0x66)
t.equal(ber.readString(), 'cn=foo, o=test')
t.ok(ber.readSequence())
t.ok(ber.readSequence())
t.equal(ber.readEnumeration(), 0x02)
2011-08-04 20:32:01 +00:00
t.ok(ber.readSequence())
t.equal(ber.readString(), 'objectclass')
t.equal(ber.readSequence(), 0x31)
t.equal(ber.readString(), 'person')
2011-08-04 20:32:01 +00:00
t.end()
})