Skip to content
This repository was archived by the owner on Apr 12, 2021. It is now read-only.

Commit 5f125f7

Browse files
committed
Mock PDFSecurity methods in tests to ensure same output accross different runs or systems
1 parent 883983a commit 5f125f7

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

tests/helpers.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
11
var PDFDocument = require('../lib/document').default;
2+
var PDFSecurity = require('../lib/security').default;
3+
var CryptoJS = require('crypto-js');
24
var path = require('path');
35
var fs = require('fs');
46

7+
// manual mock for PDFSecurity to ensure stored id will be the same accross different systems
8+
PDFSecurity.generateFileID = () => {
9+
return new Buffer('mocked-pdf-id');
10+
}
11+
12+
PDFSecurity.generateRandomWordArray = (bytes) => {
13+
const words = [];
14+
for (let i = 0; i < bytes; i++) {
15+
words.push(0x00010203);
16+
}
17+
return new CryptoJS.lib.WordArray.init(words, bytes);
18+
}
19+
520
function updatePdf (pdfData, testState, snapshotChanges) {
621
const pdfDir = path.join(path.dirname(testState.testPath), '__pdfs__');
722
if (!fs.existsSync(pdfDir)) {

tests/unit/trailer.spec.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
const PDFDocument = require('../../lib/document').default;
2+
const PDFSecurity = require('../../lib/security').default;
3+
4+
// manual mock for PDFSecurity to ensure stored id will be the same accross different systems
5+
PDFSecurity.generateFileID = () => {
6+
return new Buffer('mocked-pdf-id');
7+
}
28

39
describe('Document trailer', () => {
410
let document;
@@ -28,7 +34,7 @@ describe('Document trailer', () => {
2834
],
2935
[
3036
'trailer',
31-
`<<\n/Size 11\n/Root 2 0 R\n/Info 7 0 R\n/ID [<8c72cf48ff87daac57e26bf1550e6979> <8c72cf48ff87daac57e26bf1550e6979>]\n>>`
37+
`<<\n/Size 11\n/Root 2 0 R\n/Info 7 0 R\n/ID [<6d6f636b65642d7064662d6964> <6d6f636b65642d7064662d6964>]\n>>`
3238
]
3339
];
3440
document._write = function(data) {

0 commit comments

Comments
 (0)