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 CompareRequest;
|
|
|
|
var dn;
|
|
|
|
|
|
|
|
///--- Tests
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
test('load library', function (t) {
|
2011-08-04 20:32:01 +00:00
|
|
|
CompareRequest = require('../../lib/index').CompareRequest;
|
|
|
|
dn = require('../../lib/index').dn;
|
|
|
|
t.ok(CompareRequest);
|
|
|
|
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 CompareRequest());
|
|
|
|
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 CompareRequest({
|
|
|
|
entry: dn.parse('cn=foo, o=test'),
|
|
|
|
attribute: 'sn',
|
|
|
|
value: 'testy'
|
|
|
|
});
|
|
|
|
t.ok(req);
|
2014-09-30 23:39:19 +00:00
|
|
|
t.equal(req.dn.toString(), 'cn=foo, o=test');
|
2011-08-04 20:32:01 +00:00
|
|
|
t.equal(req.attribute, 'sn');
|
|
|
|
t.equal(req.value, 'testy');
|
|
|
|
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();
|
2013-10-24 23:27:42 +00:00
|
|
|
ber.writeString('cn=foo, o=test');
|
2011-08-04 20:32:01 +00:00
|
|
|
|
|
|
|
ber.startSequence();
|
|
|
|
ber.writeString('sn');
|
|
|
|
ber.writeString('testy');
|
|
|
|
ber.endSequence();
|
|
|
|
|
|
|
|
|
|
|
|
var req = new CompareRequest();
|
|
|
|
t.ok(req._parse(new BerReader(ber.buffer)));
|
|
|
|
t.equal(req.dn, 'cn=foo, o=test');
|
|
|
|
t.equal(req.attribute, 'sn');
|
|
|
|
t.equal(req.value, 'testy');
|
|
|
|
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 CompareRequest({
|
|
|
|
messageID: 123,
|
|
|
|
entry: dn.parse('cn=foo, o=test'),
|
|
|
|
attribute: 'sn',
|
|
|
|
value: 'testy'
|
|
|
|
});
|
|
|
|
|
|
|
|
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(), 0x6e);
|
|
|
|
t.equal(ber.readString(), 'cn=foo, o=test');
|
|
|
|
t.ok(ber.readSequence());
|
|
|
|
|
|
|
|
t.equal(ber.readString(), 'sn');
|
|
|
|
t.equal(ber.readString(), 'testy');
|
|
|
|
|
|
|
|
t.end();
|
|
|
|
});
|