2011-08-04 20:32:01 +00:00
|
|
|
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
|
|
|
|
|
|
|
|
var test = require('tap').test;
|
|
|
|
|
|
|
|
var asn1 = require('asn1');
|
|
|
|
|
|
|
|
|
|
|
|
///--- Globals
|
|
|
|
|
|
|
|
var BerReader = asn1.BerReader;
|
|
|
|
var BerWriter = asn1.BerWriter;
|
|
|
|
var ModifyRequest;
|
|
|
|
var Attribute;
|
|
|
|
var Change;
|
|
|
|
var dn;
|
|
|
|
|
|
|
|
///--- Tests
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
test('load library', function (t) {
|
2011-08-04 20:32:01 +00:00
|
|
|
ModifyRequest = require('../../lib/index').ModifyRequest;
|
|
|
|
Attribute = require('../../lib/index').Attribute;
|
|
|
|
Change = require('../../lib/index').Change;
|
|
|
|
dn = require('../../lib/index').dn;
|
|
|
|
t.ok(ModifyRequest);
|
|
|
|
t.ok(Attribute);
|
|
|
|
t.ok(Change);
|
|
|
|
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 ModifyRequest());
|
|
|
|
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 ModifyRequest({
|
|
|
|
object: dn.parse('cn=foo, o=test'),
|
|
|
|
changes: [new Change({
|
|
|
|
operation: 'Replace',
|
|
|
|
modification: new Attribute({type: 'objectclass', vals: ['person']})
|
|
|
|
})]
|
|
|
|
});
|
|
|
|
t.ok(req);
|
2011-08-06 20:44:26 +00:00
|
|
|
t.equal(req.dn.toString(), 'cn=foo, o=test');
|
2011-08-04 20:32:01 +00:00
|
|
|
t.equal(req.changes.length, 1);
|
2011-08-12 23:37:47 +00:00
|
|
|
t.equal(req.changes[0].operation, 'replace');
|
2011-08-04 20:32:01 +00:00
|
|
|
t.equal(req.changes[0].modification.type, 'objectclass');
|
|
|
|
t.equal(req.changes[0].modification.vals[0], 'person');
|
|
|
|
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.startSequence();
|
|
|
|
ber.writeEnumeration(0x02);
|
|
|
|
|
|
|
|
ber.startSequence();
|
|
|
|
ber.writeString('objectclass');
|
|
|
|
ber.startSequence(0x31);
|
|
|
|
ber.writeString('person');
|
|
|
|
ber.endSequence();
|
|
|
|
ber.endSequence();
|
|
|
|
|
|
|
|
ber.endSequence();
|
|
|
|
|
|
|
|
ber.endSequence();
|
|
|
|
|
|
|
|
var req = new ModifyRequest();
|
|
|
|
t.ok(req._parse(new BerReader(ber.buffer)));
|
2011-08-12 23:37:47 +00:00
|
|
|
t.equal(req.dn.toString(), 'cn=foo, o=test');
|
2011-08-04 20:32:01 +00:00
|
|
|
t.equal(req.changes.length, 1);
|
2011-08-12 23:37:47 +00:00
|
|
|
t.equal(req.changes[0].operation, 'replace');
|
2011-08-04 20:32:01 +00:00
|
|
|
t.equal(req.changes[0].modification.type, 'objectclass');
|
|
|
|
t.equal(req.changes[0].modification.vals[0], 'person');
|
|
|
|
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 ModifyRequest({
|
|
|
|
messageID: 123,
|
|
|
|
object: dn.parse('cn=foo, o=test'),
|
|
|
|
changes: [new Change({
|
|
|
|
operation: 'Replace',
|
|
|
|
modification: new Attribute({type: 'objectclass', vals: ['person']})
|
|
|
|
})]
|
|
|
|
});
|
|
|
|
|
|
|
|
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(), 0x66);
|
|
|
|
t.equal(ber.readString(), 'cn=foo, o=test');
|
|
|
|
t.ok(ber.readSequence());
|
|
|
|
t.ok(ber.readSequence());
|
|
|
|
t.equal(ber.readEnumeration(), 0x02);
|
|
|
|
|
|
|
|
t.ok(ber.readSequence());
|
|
|
|
t.equal(ber.readString(), 'objectclass');
|
|
|
|
t.equal(ber.readSequence(), 0x31);
|
|
|
|
t.equal(ber.readString(), 'person');
|
|
|
|
|
|
|
|
t.end();
|
|
|
|
});
|