2011-08-04 20:32:01 +00:00
|
|
|
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
|
|
|
|
|
2014-07-08 19:31:57 +00:00
|
|
|
var test = require('tape').test;
|
2011-08-04 20:32:01 +00:00
|
|
|
|
|
|
|
var asn1 = require('asn1');
|
|
|
|
|
|
|
|
|
|
|
|
///--- Globals
|
|
|
|
|
|
|
|
var BerReader = asn1.BerReader;
|
|
|
|
var BerWriter = asn1.BerWriter;
|
|
|
|
var AddResponse;
|
|
|
|
|
|
|
|
|
|
|
|
///--- Tests
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
test('load library', function (t) {
|
2011-08-04 20:32:01 +00:00
|
|
|
AddResponse = require('../../lib/index').AddResponse;
|
|
|
|
t.ok(AddResponse);
|
|
|
|
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 AddResponse());
|
|
|
|
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 res = new AddResponse({
|
|
|
|
messageID: 123,
|
|
|
|
status: 0
|
|
|
|
});
|
|
|
|
t.ok(res);
|
|
|
|
t.equal(res.messageID, 123);
|
|
|
|
t.equal(res.status, 0);
|
|
|
|
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.writeEnumeration(0);
|
|
|
|
ber.writeString('cn=root');
|
|
|
|
ber.writeString('foo');
|
|
|
|
|
|
|
|
var res = new AddResponse();
|
|
|
|
t.ok(res._parse(new BerReader(ber.buffer)));
|
|
|
|
t.equal(res.status, 0);
|
|
|
|
t.equal(res.matchedDN, 'cn=root');
|
|
|
|
t.equal(res.errorMessage, 'foo');
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
test('toBer', function (t) {
|
2011-08-04 20:32:01 +00:00
|
|
|
var res = new AddResponse({
|
|
|
|
messageID: 123,
|
|
|
|
status: 3,
|
|
|
|
matchedDN: 'cn=root',
|
|
|
|
errorMessage: 'foo'
|
|
|
|
});
|
|
|
|
t.ok(res);
|
|
|
|
|
|
|
|
var ber = new BerReader(res.toBer());
|
|
|
|
t.ok(ber);
|
|
|
|
t.equal(ber.readSequence(), 0x30);
|
|
|
|
t.equal(ber.readInt(), 123);
|
|
|
|
t.equal(ber.readSequence(), 0x69);
|
|
|
|
t.equal(ber.readEnumeration(), 3);
|
|
|
|
t.equal(ber.readString(), 'cn=root');
|
|
|
|
t.equal(ber.readString(), 'foo');
|
|
|
|
|
|
|
|
t.end();
|
|
|
|
});
|