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

73 lines
1.3 KiB
JavaScript
Raw Normal View History

2011-08-04 20:32:01 +00:00
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var asn1 = require('asn1');
2012-02-18 19:47:58 +00:00
var Logger = require('bunyan');
var test = require('tap').test;
2011-08-04 20:32:01 +00:00
///--- Globals
var BerReader = asn1.BerReader;
var BerWriter = asn1.BerWriter;
var DeleteRequest;
var dn;
///--- Tests
test('load library', function (t) {
2011-08-04 20:32:01 +00:00
DeleteRequest = require('../../lib/index').DeleteRequest;
dn = require('../../lib/index').dn;
t.ok(DeleteRequest);
t.end();
});
test('new no args', function (t) {
2011-08-04 20:32:01 +00:00
t.ok(new DeleteRequest());
t.end();
});
test('new with args', function (t) {
2011-08-04 20:32:01 +00:00
var req = new DeleteRequest({
entry: dn.parse('cn=test')
});
t.ok(req);
t.equal(req.dn.toString(), 'cn=test');
2011-08-04 20:32:01 +00:00
t.end();
});
test('parse', function (t) {
2011-08-04 20:32:01 +00:00
var ber = new BerWriter();
ber.writeString('cn=test', 0x4a);
2012-02-18 19:47:58 +00:00
var req = new DeleteRequest({
log: new Logger({name: 'del_request.test.js'})
});
2011-08-04 20:32:01 +00:00
var reader = new BerReader(ber.buffer);
reader.readSequence(0x4a);
2011-11-11 18:08:48 +00:00
t.ok(req.parse(reader, reader.length));
t.equal(req.dn.toString(), 'cn=test');
2011-08-04 20:32:01 +00:00
t.end();
});
test('toBer', function (t) {
2011-08-04 20:32:01 +00:00
var req = new DeleteRequest({
messageID: 123,
entry: dn.parse('cn=test')
});
t.ok(req);
var ber = new BerReader(req.toBer());
t.ok(ber);
t.equal(ber.readSequence(), 0x30);
t.equal(ber.readInt(), 123);
t.equal(ber.readString(0x4a), 'cn=test');
t.end();
});