-
Notifications
You must be signed in to change notification settings - Fork 9
/
jose-to-der.js
61 lines (46 loc) · 1.21 KB
/
jose-to-der.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
'use strict';
var expect = require('chai').expect,
mocha = require('mocha');
var describe = mocha.describe,
it = mocha.it;
var format = require('..');
describe('#joseToDer', function() {
describe('should throw for', function() {
it('no signature', function() {
function fn() {
return format.joseToDer();
}
expect(fn).to.throw(TypeError);
});
it('non buffer or base64 signature', function() {
function fn() {
return format.joseToDer(123);
}
expect(fn).to.throw(TypeError);
});
it('unknown algorithm', function() {
function fn() {
return format.joseToDer('Zm9vLmJhci5iYXo=', 'foozleberries');
}
expect(fn).to.throw(/"foozleberries"/);
});
it('incorrect signature length (ES256)', function() {
function fn() {
return format.joseToDer('Zm9vLmJhci5iYXo', 'ES256');
}
expect(fn).to.throw(/"64"/);
});
it('incorrect signature length (ES384)', function() {
function fn() {
return format.joseToDer('Zm9vLmJhci5iYXo', 'ES384');
}
expect(fn).to.throw(/"96"/);
});
it('incorrect signature length (ES512)', function() {
function fn() {
return format.joseToDer('Zm9vLmJhci5iYXo', 'ES512');
}
expect(fn).to.throw(/"132"/);
});
});
});