Skip to content

Commit

Permalink
Chore: Add test to check PDFjs headers to avoid preflight (#855)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinHoldstock authored Oct 25, 2018
1 parent 3f8ee16 commit d8077f5
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/lib/viewers/doc/__tests__/DocBaseViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ let docBase;
let containerEl;
let stubs = {};

const STANDARD_HEADERS = [
'Accept',
'Accept-Language',
'Content-Language',
'Content-Type',
'DPR',
'Downlink',
'Save-Data',
'Viewport-Width',
'Width'
];

describe('src/lib/viewers/doc/DocBaseViewer', () => {
const setupFunc = BaseViewer.prototype.setup;

Expand Down Expand Up @@ -932,6 +944,29 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => {
});
});

it('should avoid preflight requests by not adding non-standard headers', (done) => {
docBase.options.location = {
locale: 'en-US'
};
// Excluding IOS for If-None-Match cache busting
sandbox.stub(Browser, 'isIOS').returns(false);
sandbox.stub(PDFJS, 'getDocument').callsFake((docInitParams) => {
return new Promise(() => {
const { httpHeaders = {} } = docInitParams;
const headerKeys = Object.keys(httpHeaders);

const containsNonStandardHeader = headerKeys.some((header) => {
return !STANDARD_HEADERS.includes(header);
});

expect(containsNonStandardHeader).to.be.false;
done();
});
});

return docBase.initViewer('');
});

it('should append encoding query parameter for gzip content when range requests are disabled', () => {
// en-US allows for disabled range requests
docBase.options.location = {
Expand Down

0 comments on commit d8077f5

Please sign in to comment.