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

59 lines
1.3 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 { BindRequest, dn } = require('../../lib');
2011-08-04 20:32:01 +00:00
test('new no args', function (t) {
2011-08-04 20:32:01 +00:00
t.ok(new BindRequest());
t.end();
});
test('new with args', function (t) {
const req = new BindRequest({
2011-08-04 20:32:01 +00:00
version: 3,
name: dn.parse('cn=root'),
credentials: 'secret'
});
t.ok(req);
t.equal(req.version, 3);
t.equal(req.name.toString(), 'cn=root');
t.equal(req.credentials, 'secret');
t.end();
});
test('parse', function (t) {
const ber = new BerWriter();
2011-08-04 20:32:01 +00:00
ber.writeInt(3);
ber.writeString('cn=root');
ber.writeString('secret', 0x80);
const req = new BindRequest();
2011-08-04 20:32:01 +00:00
t.ok(req._parse(new BerReader(ber.buffer)));
t.equal(req.version, 3);
t.equal(req.dn.toString(), 'cn=root');
2011-08-04 20:32:01 +00:00
t.equal(req.credentials, 'secret');
t.end();
});
test('toBer', function (t) {
const req = new BindRequest({
2011-08-04 20:32:01 +00:00
messageID: 123,
version: 3,
name: dn.parse('cn=root'),
credentials: 'secret'
});
t.ok(req);
const ber = new BerReader(req.toBer());
2011-08-04 20:32:01 +00:00
t.ok(ber);
t.equal(ber.readSequence(), 0x30);
t.equal(ber.readInt(), 123);
t.equal(ber.readSequence(), 0x60);
t.equal(ber.readInt(), 0x03);
t.equal(ber.readString(), 'cn=root');
t.equal(ber.readString(0x80), 'secret');
t.end();
});