Skip to content

Commit

Permalink
Test: tl.filter, tl.concatinate, eutl.CheckSignature
Browse files Browse the repository at this point in the history
  • Loading branch information
microshine committed May 12, 2016
1 parent ee68c8d commit b1fd5ec
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 26 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/.vscode
/node_modules
/typings
/test/test.js
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ Valid Mozilla trust purposes
Available ouptut format
```
js
pkijs
pem
```
Default ouput format is 'js'
Expand Down
35 changes: 30 additions & 5 deletions test/eutl.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,50 @@
/// <reference path="../typings/node/node.d.ts" />
/// <reference path="../typings/mocha/mocha.d.ts" />

var DOMParser = require("xmldom").DOMParser;
global.DOMParser = require("xmldom").DOMParser;
var xadesjs = require("xadesjs");
global.xadesjs = xadesjs;
var tl_create = require("../built/tl-create");
console.log("tl_createt", tl_create);
var assert = require("assert");

var fs = require("fs");

describe("EUTL format", function () {

it("Test 1", function () {
it("TrustServiceStatusList LoadXML", function () {
// get static file
var eutlText = fs.readFileSync("./test/static/eitl.xml", "utf8");
var eutlText = fs.readFileSync("./test/static/eutl.xml", "utf8");

var eutl = new tl_create.TrustServiceStatusList();
var xml = new DOMParser().parseFromString(eutlText, "application/xml");
eutl.LoadXml(xml);

assert.equal(eutl.SchemaInformation.Pointers.length, 48);
assert.equal(eutl.SchemaInformation.Pointers[0].X509Certificates.length, 2);
})

it("TrustServiceStatusList check signature", function (done) {
// get static file
var eutlText = fs.readFileSync("./test/static/eutl.xml", "utf8");

var eutl = new tl_create.TrustServiceStatusList();
var xml = new DOMParser().parseFromString(eutlText, "application/xml");
eutl.LoadXml(xml);

eutl.CheckSignature()
.then(function (v) {
assert.equal(v, true, "Wrong signature");
done();
})
.catch(done);
});

it("EUTL parse", function () {
// get static file
var eutlText = fs.readFileSync("./test/static/eutl.xml", "utf8");

var eutl = new tl_create.EUTL();
var tl = eutl.parse(eutlText);
assert.equal(tl.Certificates.length, 101);
});

})
5 changes: 2 additions & 3 deletions test/mozilla.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,20 @@
var xadesjs = require("xadesjs");
global.xadesjs = xadesjs;
var tl_create = require("../built/tl-create");
console.log("tl_createt", tl_create);
var assert = require("assert");

var fs = require("fs");

describe("Mozilla format", function () {

it("Test 1", function () {
it("Parse incoming text", function () {
// get static file
var mozText = fs.readFileSync("./test/static/mozilla.txt", "utf8");

var moz = new tl_create.Mozilla();
var tl = moz.parse(mozText);

assert.equal(tl.Certificates.length, 177);
})
});

})
70 changes: 52 additions & 18 deletions test/tl.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
/// <reference path="../typings/mocha/mocha.d.ts" />

var xadesjs = require("xadesjs");
global.xadesjs = xadesjs;
global.xadesjs = xadesjs;
var tl_create = require("../built/tl-create");
console.log("tl_createt", tl_create);
var assert = require("assert");

describe("TrustedList format", function () {
Expand All @@ -14,36 +13,71 @@ describe("TrustedList format", function () {

assert.equal(tl.Certificates.length, 0, "Wrong Certificates length");

tl.AddCertificate({ raw: new Uint8Array([1]) });
tl.AddCertificate({ raw: new Uint8Array([2]) });
tl.AddCertificate({ raw: new Uint8Array([3]) });
tl.AddCertificate({ raw: "A1==" });
tl.AddCertificate({ raw: "A2==" });
tl.AddCertificate({ raw: "A3==" });

assert.equal(tl.Certificates.length, 3, "Wrong Certificates length");
})
it("Convert trusted list to JSON", function(){

it("Convert trusted list to JSON", function () {
var tl = new tl_create.TrustedList();

assert.equal(tl.Certificates.length, 0, "Wrong Certificates length");

tl.AddCertificate({ raw: new Uint8Array([1]) });
tl.AddCertificate({ raw: "AQ==" });

var json = JSON.stringify(tl);
assert.equal(json, "[\"AQ==\"]");

assert.equal(json, "[{\"raw\":\"AQ==\"}]");
})
it("Convert trusted list to String", function(){

it("Convert trusted list to String", function () {
var tl = new tl_create.TrustedList();

assert.equal(tl.Certificates.length, 0, "Wrong Certificates length");

tl.AddCertificate({ raw: new Uint8Array([1]) });
tl.AddCertificate({ raw: new Uint8Array([2]) });

tl.AddCertificate({ raw: "A1==", operator: "Operator 1", trust: ["FILTER1"], source: "Source1", });

var text = tl.toString();

assert.equal(text, "AQ==\nAg==");

assert.equal(text, "Operator: Operator 1\nSource: Source1\n-----BEGIN CERTIFICATE-----\nA1==\n-----END CERTIFICATE-----");
})

it("Filter", function () {
var tl = new tl_create.TrustedList();

assert.equal(tl.Certificates.length, 0, "Wrong Certificates length");

tl.AddCertificate({ raw: "A1==", operator: "Operator 1", trust: ["FILTER1"], source: "Source1", });
tl.AddCertificate({ raw: "A2==", operator: "Operator 2", trust: ["FILTER2"], source: "Source2", });

var filtered_tl = tl.filter(function(item, index) {
return item.source === "Source1";
})

assert.equal(filtered_tl.Certificates.length, 1);
assert.equal(tl.Certificates.length, 1);
})

it("Concatinate trusted lists", function () {
var tl1 = new tl_create.TrustedList();

assert.equal(tl1.Certificates.length, 0, "Wrong Certificates length");

tl1.AddCertificate({ raw: new Uint8Array([1]) });
tl1.AddCertificate({ raw: new Uint8Array([2]) });

var tl2 = new tl_create.TrustedList();

assert.equal(tl2.Certificates.length, 0, "Wrong Certificates length");

tl2.AddCertificate({ raw: new Uint8Array([1]) });
tl2.AddCertificate({ raw: new Uint8Array([2]) });

var tl = tl1.concat(tl2);
assert.equal(tl.Certificates.length, 4, "Wrong Certificates length, should be 4");
assert.equal(tl1.Certificates.length, 4, "Wrong Certificates length, should be 4");
})

})

0 comments on commit b1fd5ec

Please sign in to comment.