-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Permit a timestamp response without a status string.
- Loading branch information
Showing
3 changed files
with
75 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
var _ = require("../../lib/underscore") | ||
var X509Asn = require("../../lib/x509_asn") | ||
var Timestamp = require("../../lib/timestamp") | ||
var TimestampResponse = Timestamp.TimestampResponse | ||
|
@@ -6,7 +7,8 @@ var TimestampRequestAsn = TimestampAsn.TimestampRequest | |
var TimestampResponseAsn = TimestampAsn.TimestampResponse | ||
var wait = require("../../lib/promise").wait | ||
var parseBody = require("../mitm").parseBody | ||
var TIMESTAMP_URL = "http://example.com/tsa" | ||
var parse = TimestampResponseAsn.decode.bind(TimestampResponseAsn) | ||
var serialize = TimestampResponseAsn.encode.bind(TimestampResponseAsn) | ||
var DIGEST = Buffer.from("foobar") | ||
var SIGNED_DATA_OID = TimestampAsn.SIGNED_DATA_OID | ||
|
||
|
@@ -15,7 +17,7 @@ describe("Timestamp", function() { | |
require("../mitm")() | ||
|
||
it("must respond with timestamp", function*() { | ||
var timestamp = Timestamp.read(TIMESTAMP_URL, DIGEST) | ||
var timestamp = Timestamp.read("http://example.com/tsa", DIGEST) | ||
|
||
var req = yield wait(this.mitm, "request") | ||
req.headers.host.must.equal("example.com") | ||
|
@@ -45,10 +47,66 @@ describe("Timestamp", function() { | |
timestamp.status.must.equal("granted") | ||
timestamp.token.must.eql(TimestampAsn.ContentInfo.encode(token)) | ||
}) | ||
|
||
it("must request with basic auth if given a password", function*() { | ||
Timestamp.read("http://foo:[email protected]/tsa", DIGEST) | ||
|
||
var req = yield wait(this.mitm, "request") | ||
req.headers.host.must.equal("example.com") | ||
parseBasicAuth(req.headers.authorization).must.eql(["foo", "bar"]) | ||
req.headers["content-type"].must.equal("application/timestamp-query") | ||
req.headers.accept.must.equal("application/timestamp-reply") | ||
req.method.must.equal("POST") | ||
req.url.must.equal("/tsa") | ||
}) | ||
}) | ||
|
||
describe("TimestampResponse", function() { | ||
it("must parse minimal response", function() { | ||
var token = { | ||
contentType: SIGNED_DATA_OID, | ||
content: TimestampAsn.SignedData.encode(Buffer.from("xyz")) | ||
} | ||
|
||
var res = new TimestampResponse(parse(serialize({ | ||
status: {status: "granted"}, | ||
timeStampToken: token | ||
}))) | ||
|
||
res.status.must.equal("granted") | ||
res.must.have.property("message", null) | ||
res.token.must.eql(TimestampAsn.ContentInfo.encode(token)) | ||
}) | ||
|
||
it("must parse statusString", function() { | ||
var token = { | ||
contentType: SIGNED_DATA_OID, | ||
content: TimestampAsn.SignedData.encode(Buffer.from("xyz")) | ||
} | ||
|
||
var res = new TimestampResponse(parse(serialize({ | ||
status: { | ||
status: "granted", | ||
statusString: ["Operation Okay", "Life is Good"] | ||
}, | ||
|
||
timeStampToken: token | ||
}))) | ||
|
||
res.status.must.equal("granted") | ||
res.message.must.equal("Operation Okay; Life is Good") | ||
res.token.must.eql(TimestampAsn.ContentInfo.encode(token)) | ||
}) | ||
}) | ||
}) | ||
|
||
function respond(timestamp, req) { | ||
req.res.setHeader("Content-Type", "application/timestamp-reply") | ||
req.res.end(TimestampResponseAsn.encode(timestamp)) | ||
} | ||
|
||
function parseBasicAuth(line) { | ||
var auth = _.split2(line, " ") | ||
if (auth[0] != "Basic") return null | ||
return _.split2(_.parseBase64(auth[1]).toString(), ":") | ||
} |