2019-08-27 21:11:49 +00:00
|
|
|
'use strict'
|
2011-08-04 20:32:01 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
const { test } = require('tap')
|
|
|
|
const { BerReader, BerWriter } = require('asn1')
|
|
|
|
const { ExtendedResponse } = require('../../lib')
|
2011-08-04 20:32:01 +00:00
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
test('new no args', function (t) {
|
2019-08-27 21:11:49 +00:00
|
|
|
t.ok(new ExtendedResponse())
|
|
|
|
t.end()
|
|
|
|
})
|
2011-08-04 20:32:01 +00:00
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
test('new with args', function (t) {
|
2019-08-27 18:17:33 +00:00
|
|
|
const res = new ExtendedResponse({
|
2011-08-04 20:32:01 +00:00
|
|
|
messageID: 123,
|
|
|
|
status: 0,
|
|
|
|
responseName: '1.2.3.4',
|
|
|
|
responseValue: 'test'
|
2019-08-27 21:11:49 +00:00
|
|
|
})
|
|
|
|
t.ok(res)
|
|
|
|
t.equal(res.messageID, 123)
|
|
|
|
t.equal(res.status, 0)
|
|
|
|
t.equal(res.responseName, '1.2.3.4')
|
|
|
|
t.equal(res.responseValue, 'test')
|
|
|
|
t.end()
|
|
|
|
})
|
2011-08-04 20:32:01 +00:00
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
test('parse', function (t) {
|
2019-08-27 21:11:49 +00:00
|
|
|
const ber = new BerWriter()
|
|
|
|
ber.writeEnumeration(0)
|
|
|
|
ber.writeString('cn=root')
|
|
|
|
ber.writeString('foo')
|
|
|
|
ber.writeString('1.2.3.4', 0x8a)
|
|
|
|
ber.writeString('test', 0x8b)
|
2011-08-04 20:32:01 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
const res = new ExtendedResponse()
|
|
|
|
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.equal(res.responseName, '1.2.3.4')
|
|
|
|
t.equal(res.responseValue, 'test')
|
|
|
|
t.end()
|
|
|
|
})
|
2011-08-04 20:32:01 +00:00
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
test('toBer', function (t) {
|
2019-08-27 18:17:33 +00:00
|
|
|
const res = new ExtendedResponse({
|
2011-08-04 20:32:01 +00:00
|
|
|
messageID: 123,
|
|
|
|
status: 3,
|
|
|
|
matchedDN: 'cn=root',
|
|
|
|
errorMessage: 'foo',
|
|
|
|
responseName: '1.2.3.4',
|
|
|
|
responseValue: 'test'
|
2019-08-27 21:11:49 +00:00
|
|
|
})
|
|
|
|
t.ok(res)
|
2011-08-04 20:32:01 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
const ber = new BerReader(res.toBer())
|
|
|
|
t.ok(ber)
|
|
|
|
t.equal(ber.readSequence(), 0x30)
|
|
|
|
t.equal(ber.readInt(), 123)
|
|
|
|
t.equal(ber.readSequence(), 0x78)
|
|
|
|
t.equal(ber.readEnumeration(), 3)
|
|
|
|
t.equal(ber.readString(), 'cn=root')
|
|
|
|
t.equal(ber.readString(), 'foo')
|
|
|
|
t.equal(ber.readString(0x8a), '1.2.3.4')
|
|
|
|
t.equal(ber.readString(0x8b), 'test')
|
2011-08-04 20:32:01 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
t.end()
|
|
|
|
})
|