mirror of
https://github.com/alam00000/bentopdf.git
synced 2026-11-07 08:31:01 +01:00
Merge pull request #869 from carminezac/fix/timestamp-default-cors-proxy
fix(timestamp): fall back to the default CORS proxy on official domains
This commit is contained in:
@@ -143,7 +143,11 @@ describe('timestampPdf', () => {
|
||||
vi.stubEnv('VITE_CORS_PROXY_URL', '');
|
||||
Object.defineProperty(window, 'location', {
|
||||
configurable: true,
|
||||
value: { protocol: 'https:', origin: 'https://www.bentopdf.com' },
|
||||
value: {
|
||||
protocol: 'https:',
|
||||
origin: 'https://selfhost.example.com',
|
||||
hostname: 'selfhost.example.com',
|
||||
},
|
||||
});
|
||||
vi.resetModules();
|
||||
const { timestampPdf: freshTimestamp } =
|
||||
@@ -153,4 +157,32 @@ describe('timestampPdf', () => {
|
||||
freshTimestamp(samplePdfBytes, 'http://timestamp.digicert.com')
|
||||
).rejects.toThrow(/HTTPS page|VITE_CORS_PROXY_URL/);
|
||||
});
|
||||
|
||||
it('should fall back to the default proxy on official domains', async () => {
|
||||
vi.stubEnv('VITE_CORS_PROXY_URL', '');
|
||||
Object.defineProperty(window, 'location', {
|
||||
configurable: true,
|
||||
value: {
|
||||
protocol: 'https:',
|
||||
origin: 'https://www.bentopdf.com',
|
||||
hostname: 'www.bentopdf.com',
|
||||
},
|
||||
});
|
||||
vi.resetModules();
|
||||
const { timestampPdf: freshTimestamp } =
|
||||
await import('@/js/logic/digital-sign-pdf');
|
||||
|
||||
mockSign.mockResolvedValueOnce(new Uint8Array([1]));
|
||||
await freshTimestamp(samplePdfBytes, 'http://timestamp.digicert.com');
|
||||
|
||||
const callArg = vi.mocked(PdfSigner).mock.calls[0][0] as {
|
||||
signdate: { url: string };
|
||||
};
|
||||
expect(callArg.signdate.url).toMatch(
|
||||
/^https:\/\/bentopdf-cors-proxy\.bentopdf\.workers\.dev\?url=/
|
||||
);
|
||||
expect(callArg.signdate.url).toContain(
|
||||
encodeURIComponent('http://timestamp.digicert.com')
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user