@@ -375,6 +375,7 @@ describe('server', () => {
375375 } )
376376
377377 describe ( 'image asset paths' , ( ) => {
378+ const localImageCacheBustBasePathRegex = / ^ \/ a s s e t s \/ c b - \d + \/ i m a g e s \/ /
378379 const localImageBasePath = '/assets/images'
379380 const legacyImageBasePath = '/assets/enterprise'
380381 const latestEnterprisePath = `/en/enterprise/${ enterpriseServerReleases . latest } `
@@ -384,7 +385,10 @@ describe('server', () => {
384385 const $ = await getDOM (
385386 '/en/github/authenticating-to-github/configuring-two-factor-authentication'
386387 )
387- expect ( $ ( 'img' ) . first ( ) . attr ( 'src' ) . startsWith ( localImageBasePath ) ) . toBe ( true )
388+ const imageSrc = $ ( 'img' ) . first ( ) . attr ( 'src' )
389+ expect (
390+ localImageCacheBustBasePathRegex . test ( imageSrc ) || imageSrc . startsWith ( localImageBasePath )
391+ ) . toBe ( true )
388392 } )
389393
390394 test ( 'github articles on GHE have images that point to local assets dir' , async ( ) => {
@@ -393,7 +397,9 @@ describe('server', () => {
393397 )
394398 const imageSrc = $ ( 'img' ) . first ( ) . attr ( 'src' )
395399 expect (
396- imageSrc . startsWith ( localImageBasePath ) || imageSrc . startsWith ( legacyImageBasePath )
400+ localImageCacheBustBasePathRegex . test ( imageSrc ) ||
401+ imageSrc . startsWith ( localImageBasePath ) ||
402+ imageSrc . startsWith ( legacyImageBasePath )
397403 ) . toBe ( true )
398404 } )
399405
@@ -403,7 +409,9 @@ describe('server', () => {
403409 )
404410 const imageSrc = $ ( 'img' ) . first ( ) . attr ( 'src' )
405411 expect (
406- imageSrc . startsWith ( localImageBasePath ) || imageSrc . startsWith ( legacyImageBasePath )
412+ localImageCacheBustBasePathRegex . test ( imageSrc ) ||
413+ imageSrc . startsWith ( localImageBasePath ) ||
414+ imageSrc . startsWith ( legacyImageBasePath )
407415 ) . toBe ( true )
408416 } )
409417
@@ -413,7 +421,9 @@ describe('server', () => {
413421 )
414422 const imageSrc = $ ( 'img' ) . first ( ) . attr ( 'src' )
415423 expect (
416- imageSrc . startsWith ( localImageBasePath ) || imageSrc . startsWith ( legacyImageBasePath )
424+ localImageCacheBustBasePathRegex . test ( imageSrc ) ||
425+ imageSrc . startsWith ( localImageBasePath ) ||
426+ imageSrc . startsWith ( legacyImageBasePath )
417427 ) . toBe ( true )
418428 } )
419429
@@ -428,14 +438,20 @@ describe('server', () => {
428438 const $ = await getDOM (
429439 '/en/enterprise-cloud@latest/billing/managing-billing-for-your-github-account/viewing-the-subscription-and-usage-for-your-enterprise-account'
430440 )
431- expect ( $ ( 'img' ) . first ( ) . attr ( 'src' ) . startsWith ( localImageBasePath ) ) . toBe ( true )
441+ const imageSrc = $ ( 'img' ) . first ( ) . attr ( 'src' )
442+ expect (
443+ localImageCacheBustBasePathRegex . test ( imageSrc ) || imageSrc . startsWith ( localImageBasePath )
444+ ) . toBe ( true )
432445 } )
433446
434447 test ( 'admin articles on GHEC have images that point to local assets dir' , async ( ) => {
435448 const $ = await getDOM (
436449 '/en/enterprise-cloud@latest/admin/configuration/configuring-your-enterprise/verifying-or-approving-a-domain-for-your-enterprise'
437450 )
438- expect ( $ ( 'img' ) . first ( ) . attr ( 'src' ) . startsWith ( localImageBasePath ) ) . toBe ( true )
451+ const imageSrc = $ ( 'img' ) . first ( ) . attr ( 'src' )
452+ expect (
453+ localImageCacheBustBasePathRegex . test ( imageSrc ) || imageSrc . startsWith ( localImageBasePath )
454+ ) . toBe ( true )
439455 } )
440456
441457 test ( 'github articles on GHAE have images that point to local assets dir' , async ( ) => {
@@ -444,13 +460,18 @@ describe('server', () => {
444460 )
445461 const imageSrc = $ ( 'img' ) . first ( ) . attr ( 'src' )
446462 expect (
447- imageSrc . startsWith ( localImageBasePath ) || imageSrc . startsWith ( legacyImageBasePath )
463+ localImageCacheBustBasePathRegex . test ( imageSrc ) ||
464+ imageSrc . startsWith ( localImageBasePath ) ||
465+ imageSrc . startsWith ( legacyImageBasePath )
448466 ) . toBe ( true )
449467 } )
450468
451469 test ( 'admin articles on GHAE have images that point to local assets dir' , async ( ) => {
452470 const $ = await getDOM ( '/en/github-ae@latest/admin/user-management/managing-dormant-users' )
453- expect ( $ ( 'img' ) . first ( ) . attr ( 'src' ) . startsWith ( localImageBasePath ) ) . toBe ( true )
471+ const imageSrc = $ ( 'img' ) . first ( ) . attr ( 'src' )
472+ expect (
473+ localImageCacheBustBasePathRegex . test ( imageSrc ) || imageSrc . startsWith ( localImageBasePath )
474+ ) . toBe ( true )
454475 } )
455476 } )
456477
@@ -1003,6 +1024,16 @@ describe('static routes', () => {
10031024 expect ( res . headers [ 'surrogate-key' ] ) . toBeTruthy ( )
10041025 } )
10051026
1027+ it ( 'rewrites /assets requests from a cache-busting prefix' , async ( ) => {
1028+ // The rewrite-asset-urls.js Markdown plugin will do this to img tags.
1029+ const res = await get ( '/assets/cb-123456/images/site/be-social.gif' )
1030+ expect ( res . statusCode ) . toBe ( 200 )
1031+ expect ( res . headers [ 'set-cookie' ] ) . toBeUndefined ( )
1032+ expect ( res . headers [ 'cache-control' ] ) . toContain ( 'public' )
1033+ expect ( res . headers [ 'cache-control' ] ) . toMatch ( / m a x - a g e = \d + / )
1034+ expect ( res . headers [ 'surrogate-key' ] ) . toBeTruthy ( )
1035+ } )
1036+
10061037 it ( 'serves schema files from the /data/graphql directory at /public' , async ( ) => {
10071038 const res = await get ( '/public/schema.docs.graphql' )
10081039 expect ( res . statusCode ) . toBe ( 200 )
0 commit comments