Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Add test to check PDFjs headers to avoid preflight #855

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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