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 { Control, getControl } = 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 Control())
|
|
|
|
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 c = new Control({
|
2011-08-04 20:32:01 +00:00
|
|
|
type: '2.16.840.1.113730.3.4.2',
|
|
|
|
criticality: true
|
2019-08-27 21:11:49 +00:00
|
|
|
})
|
|
|
|
t.ok(c)
|
|
|
|
t.equal(c.type, '2.16.840.1.113730.3.4.2')
|
|
|
|
t.ok(c.criticality)
|
|
|
|
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.startSequence()
|
|
|
|
ber.writeString('2.16.840.1.113730.3.4.2')
|
|
|
|
ber.writeBoolean(true)
|
|
|
|
ber.writeString('foo')
|
|
|
|
ber.endSequence()
|
|
|
|
|
|
|
|
const c = getControl(new BerReader(ber.buffer))
|
|
|
|
|
|
|
|
t.ok(c)
|
|
|
|
t.equal(c.type, '2.16.840.1.113730.3.4.2')
|
|
|
|
t.ok(c.criticality)
|
|
|
|
t.equal(c.value.toString('utf8'), 'foo')
|
|
|
|
t.end()
|
|
|
|
})
|
2012-01-06 16:51:54 +00:00
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
test('parse no value', function (t) {
|
2019-08-27 21:11:49 +00:00
|
|
|
const ber = new BerWriter()
|
|
|
|
ber.startSequence()
|
|
|
|
ber.writeString('2.16.840.1.113730.3.4.2')
|
|
|
|
ber.endSequence()
|
|
|
|
|
|
|
|
const c = getControl(new BerReader(ber.buffer))
|
|
|
|
|
|
|
|
t.ok(c)
|
|
|
|
t.equal(c.type, '2.16.840.1.113730.3.4.2')
|
|
|
|
t.equal(c.criticality, false)
|
|
|
|
t.notOk(c.value, null)
|
|
|
|
t.end()
|
|
|
|
})
|