diff --git a/packages/core/src/discovery.js b/packages/core/src/discovery.js index a028d0dc5..ae22a58be 100644 --- a/packages/core/src/discovery.js +++ b/packages/core/src/discovery.js @@ -86,7 +86,8 @@ export function createRequestFinishedHandler(network, { if (mimeType?.includes('font')) { // font responses from the browser may not be properly encoded, so request them directly - body = await makeRequest(response.url, { buffer: true }); + log.debug('- Requesting asset directly'); + body = await makeRequest(response.url, { buffer: true, headers: request.headers }); } resource = createResource(url, body, mimeType, { diff --git a/packages/core/test/discovery.test.js b/packages/core/test/discovery.test.js index bbf20d62c..ca975e7a4 100644 --- a/packages/core/test/discovery.test.js +++ b/packages/core/test/discovery.test.js @@ -871,6 +871,58 @@ describe('Discovery', () => { ])); }); + it('captures fonts with valid auth credentials', async () => { + percy.loglevel('debug'); + + const fontAuthDOM = dedent` + + + + + +

Hello Percy!

+ ${' '.repeat(1000)} + + + `; + + server.reply('/font-auth/font.woff', ({ headers: { authorization } }) => { + if (authorization === 'Basic dGVzdDo=') { + return [200, 'font/woff', '']; + } else { + return [401, { + 'WWW-Authenticate': 'Basic', + 'Content-Type': 'text/plain' + }, '401 Unauthorized']; + } + }); + + await percy.snapshot({ + name: 'font auth snapshot', + url: 'http://localhost:8000/font-auth', + domSnapshot: fontAuthDOM, + discovery: { + requestHeaders: { Authorization: 'Basic dGVzdDo=' } + } + }); + + await percy.idle(); + + expect(logger.stderr).toContain( + '[percy:core:discovery] - Requesting asset directly' + ); + expect(captured[0]).toEqual(jasmine.arrayContaining([ + jasmine.objectContaining({ + attributes: jasmine.objectContaining({ + 'resource-url': 'http://localhost:8000/font-auth/font.woff' + }) + }) + ])); + }); + it('does not capture without auth credentials', async () => { await percy.snapshot({ name: 'auth snapshot',