2011-08-04 20:32:01 +00:00
|
|
|
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
|
|
|
|
|
2019-08-27 13:08:00 +00:00
|
|
|
var test = require('tap').test;
|
2011-08-04 20:32:01 +00:00
|
|
|
|
|
|
|
var asn1 = require('asn1');
|
|
|
|
|
|
|
|
|
|
|
|
///--- Globals
|
|
|
|
|
|
|
|
var BerReader = asn1.BerReader;
|
|
|
|
var BerWriter = asn1.BerWriter;
|
|
|
|
var BindRequest;
|
|
|
|
var dn;
|
|
|
|
|
|
|
|
///--- Tests
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
test('load library', function (t) {
|
2011-08-04 20:32:01 +00:00
|
|
|
BindRequest = require('../../lib/index').BindRequest;
|
|
|
|
dn = require('../../lib/index').dn;
|
|
|
|
t.ok(BindRequest);
|
|
|
|
t.ok(dn);
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
test('new no args', function (t) {
|
2011-08-04 20:32:01 +00:00
|
|
|
t.ok(new BindRequest());
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
test('new with args', function (t) {
|
2011-08-04 20:32:01 +00:00
|
|
|
var req = new BindRequest({
|
|
|
|
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();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
test('parse', function (t) {
|
2011-08-04 20:32:01 +00:00
|
|
|
var ber = new BerWriter();
|
|
|
|
ber.writeInt(3);
|
|
|
|
ber.writeString('cn=root');
|
|
|
|
ber.writeString('secret', 0x80);
|
|
|
|
|
|
|
|
var req = new BindRequest();
|
|
|
|
t.ok(req._parse(new BerReader(ber.buffer)));
|
|
|
|
t.equal(req.version, 3);
|
2011-08-10 17:57:58 +00:00
|
|
|
t.equal(req.dn.toString(), 'cn=root');
|
2011-08-04 20:32:01 +00:00
|
|
|
t.equal(req.credentials, 'secret');
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
test('toBer', function (t) {
|
2011-08-04 20:32:01 +00:00
|
|
|
var req = new BindRequest({
|
|
|
|
messageID: 123,
|
|
|
|
version: 3,
|
|
|
|
name: dn.parse('cn=root'),
|
|
|
|
credentials: 'secret'
|
|
|
|
});
|
|
|
|
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.readSequence(), 0x60);
|
|
|
|
t.equal(ber.readInt(), 0x03);
|
|
|
|
t.equal(ber.readString(), 'cn=root');
|
|
|
|
t.equal(ber.readString(0x80), 'secret');
|
|
|
|
|
|
|
|
t.end();
|
|
|
|
});
|