Skip to content

Commit

Permalink
test: add signed_data export and import test
Browse files Browse the repository at this point in the history
Close #9
  • Loading branch information
algv committed Feb 2, 2017
1 parent 2b7095c commit cb8cae9
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion test/signed_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var DEFAULT_OUT_PATH = "test/out";

describe("SignedData", function() {
var cert, key;
var cms;

before(function() {
try {
Expand Down Expand Up @@ -56,7 +57,6 @@ describe("SignedData", function() {
});

it("load", function() {
var cms;
var signers;
var signer;
var signerId;
Expand All @@ -81,4 +81,40 @@ describe("SignedData", function() {
assert.equal(typeof signerId.issuerName, "string", "Wrong issuer name");
assert.equal(typeof signerId.serialNumber, "string", "Wrong serial number");
});

it("export PEM", function() {
var buf = cms.export(trusted.DataFormat.PEM);

assert.equal(Buffer.isBuffer(buf), true);
assert.equal(buf.length > 0, true);
assert.equal(buf.toString().indexOf("-----BEGIN CMS-----") === -1, false);
});

it("export Default", function() {
var buf = cms.export();

assert.equal(Buffer.isBuffer(buf), true);
assert.equal(buf.length > 0, true);
assert.equal(buf.toString("hex").indexOf("06092a864886f70d010702") === -1, false);
});

it("export DER", function() {
var buf = cms.export(trusted.DataFormat.DER);

assert.equal(Buffer.isBuffer(buf), true);
assert.equal(buf.length > 0, true);
assert.equal(buf.toString("hex").indexOf("06092a864886f70d010702") === -1, false);
});

it("import", function() {
var tmpCms;

var buf = cms.export(trusted.DataFormat.PEM);

tmpCms = new trusted.cms.SignedData();
tmpCms.import(buf, trusted.DataFormat.PEM);
assert.equal(tmpCms.signers().length, 1, "Wrong signers length");
assert.equal(tmpCms.certificates().length, 1, "Wrong certificates length");
assert.equal(tmpCms.isDetached(), false, "Detached");
});
});

0 comments on commit cb8cae9

Please sign in to comment.