2019-08-27 21:11:49 +00:00
|
|
|
'use strict'
|
2011-08-04 20:32:01 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
const { test } = require('tap')
|
|
|
|
const { BerReader, BerWriter } = require('asn1')
|
|
|
|
const { ModifyDNRequest, dn } = require('../../lib')
|
2011-08-04 20:32:01 +00:00
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
test('new no args', function (t) {
|
2019-08-27 21:11:49 +00:00
|
|
|
t.ok(new ModifyDNRequest())
|
|
|
|
t.end()
|
|
|
|
})
|
2011-08-04 20:32:01 +00:00
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
test('new with args', function (t) {
|
2019-08-27 18:17:33 +00:00
|
|
|
const req = new ModifyDNRequest({
|
2011-08-04 20:32:01 +00:00
|
|
|
entry: dn.parse('cn=foo, o=test'),
|
|
|
|
newRdn: dn.parse('cn=foo2'),
|
|
|
|
deleteOldRdn: true
|
2019-08-27 21:11:49 +00:00
|
|
|
})
|
|
|
|
t.ok(req)
|
|
|
|
t.equal(req.dn.toString(), 'cn=foo, o=test')
|
|
|
|
t.equal(req.newRdn.toString(), 'cn=foo2')
|
|
|
|
t.equal(req.deleteOldRdn, true)
|
|
|
|
t.end()
|
|
|
|
})
|
2011-08-04 20:32:01 +00:00
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
test('parse', function (t) {
|
2019-08-27 21:11:49 +00:00
|
|
|
const ber = new BerWriter()
|
|
|
|
ber.writeString('cn=foo, o=test')
|
|
|
|
ber.writeString('cn=foo2')
|
|
|
|
ber.writeBoolean(true)
|
2011-08-04 20:32:01 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
const req = new ModifyDNRequest()
|
|
|
|
t.ok(req._parse(new BerReader(ber.buffer)))
|
|
|
|
t.equal(req.dn.toString(), 'cn=foo, o=test')
|
|
|
|
t.equal(req.newRdn.toString(), 'cn=foo2')
|
|
|
|
t.equal(req.deleteOldRdn, true)
|
2011-08-04 20:32:01 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
t.end()
|
|
|
|
})
|
2011-08-04 20:32:01 +00:00
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
test('toBer', function (t) {
|
2019-08-27 18:17:33 +00:00
|
|
|
const req = new ModifyDNRequest({
|
2011-08-04 20:32:01 +00:00
|
|
|
messageID: 123,
|
|
|
|
entry: dn.parse('cn=foo, o=test'),
|
|
|
|
newRdn: dn.parse('cn=foo2'),
|
|
|
|
deleteOldRdn: true
|
2019-08-27 21:11:49 +00:00
|
|
|
})
|
2011-08-04 20:32:01 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
t.ok(req)
|
2011-08-04 20:32:01 +00:00
|
|
|
|
2019-08-27 21:11:49 +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(), 0x6c)
|
|
|
|
t.equal(ber.readString(), 'cn=foo, o=test')
|
|
|
|
t.equal(ber.readString(), 'cn=foo2')
|
|
|
|
t.equal(ber.readBoolean(), true)
|
2011-08-04 20:32:01 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
t.end()
|
|
|
|
})
|