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 Attribute;
|
|
|
|
var Change;
|
|
|
|
|
|
|
|
|
|
|
|
///--- Tests
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
test('load library', function (t) {
|
2011-08-04 20:32:01 +00:00
|
|
|
Attribute = require('../lib/index').Attribute;
|
|
|
|
Change = require('../lib/index').Change;
|
|
|
|
t.ok(Attribute);
|
|
|
|
t.ok(Change);
|
|
|
|
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 Change());
|
|
|
|
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 change = new Change({
|
|
|
|
operation: 0x00,
|
|
|
|
modification: new Attribute({
|
|
|
|
type: 'cn',
|
|
|
|
vals: ['foo', 'bar']
|
|
|
|
})
|
|
|
|
});
|
|
|
|
t.ok(change);
|
|
|
|
|
2011-08-12 23:37:47 +00:00
|
|
|
t.equal(change.operation, 'add');
|
2011-08-04 20:32:01 +00:00
|
|
|
t.equal(change.modification.type, 'cn');
|
|
|
|
t.equal(change.modification.vals.length, 2);
|
|
|
|
t.equal(change.modification.vals[0], 'foo');
|
|
|
|
t.equal(change.modification.vals[1], 'bar');
|
|
|
|
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
test('GH-31 (multiple attributes per Change)', function (t) {
|
2011-11-08 21:31:00 +00:00
|
|
|
try {
|
2012-02-18 08:15:52 +00:00
|
|
|
t.notOk(new Change({
|
2011-11-08 21:31:00 +00:00
|
|
|
operation: 'replace',
|
|
|
|
modification: {
|
|
|
|
cn: 'foo',
|
|
|
|
sn: 'bar'
|
|
|
|
}
|
2012-02-18 08:15:52 +00:00
|
|
|
}), 'should have thrown');
|
2011-11-08 21:31:00 +00:00
|
|
|
} catch (e) {
|
|
|
|
t.ok(e);
|
|
|
|
t.end();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
test('toBer', function (t) {
|
2011-08-04 20:32:01 +00:00
|
|
|
var change = new Change({
|
|
|
|
operation: 'Add',
|
|
|
|
modification: new Attribute({
|
|
|
|
type: 'cn',
|
|
|
|
vals: ['foo', 'bar']
|
|
|
|
})
|
|
|
|
});
|
|
|
|
t.ok(change);
|
|
|
|
|
|
|
|
var ber = new BerWriter();
|
|
|
|
change.toBer(ber);
|
|
|
|
var reader = new BerReader(ber.buffer);
|
|
|
|
t.ok(reader.readSequence());
|
|
|
|
t.equal(reader.readEnumeration(), 0x00);
|
|
|
|
t.ok(reader.readSequence());
|
|
|
|
t.equal(reader.readString(), 'cn');
|
|
|
|
t.equal(reader.readSequence(), 0x31); // lber set
|
|
|
|
t.equal(reader.readString(), 'foo');
|
|
|
|
t.equal(reader.readString(), 'bar');
|
|
|
|
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.startSequence();
|
|
|
|
ber.writeEnumeration(0x00);
|
|
|
|
ber.startSequence();
|
|
|
|
ber.writeString('cn');
|
|
|
|
ber.startSequence(0x31);
|
|
|
|
ber.writeStringArray(['foo', 'bar']);
|
|
|
|
ber.endSequence();
|
|
|
|
ber.endSequence();
|
|
|
|
ber.endSequence();
|
|
|
|
|
|
|
|
var change = new Change();
|
|
|
|
t.ok(change);
|
|
|
|
t.ok(change.parse(new BerReader(ber.buffer)));
|
|
|
|
|
2011-08-12 23:37:47 +00:00
|
|
|
t.equal(change.operation, 'add');
|
2011-08-04 20:32:01 +00:00
|
|
|
t.equal(change.modification.type, 'cn');
|
|
|
|
t.equal(change.modification.vals.length, 2);
|
|
|
|
t.equal(change.modification.vals[0], 'foo');
|
|
|
|
t.equal(change.modification.vals[1], 'bar');
|
|
|
|
|
|
|
|
t.end();
|
|
|
|
});
|