@@ -375,6 +375,7 @@ describe('server', () => {
375
375
} )
376
376
377
377
describe ( 'image asset paths' , ( ) => {
378
+ const localImageCacheBustBasePathRegex = / ^ \/ a s s e t s \/ c b - \d + \/ i m a g e s \/ /
378
379
const localImageBasePath = '/assets/images'
379
380
const legacyImageBasePath = '/assets/enterprise'
380
381
const latestEnterprisePath = `/en/enterprise/${ enterpriseServerReleases . latest } `
@@ -384,7 +385,10 @@ describe('server', () => {
384
385
const $ = await getDOM (
385
386
'/en/github/authenticating-to-github/configuring-two-factor-authentication'
386
387
)
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 )
388
392
} )
389
393
390
394
test ( 'github articles on GHE have images that point to local assets dir' , async ( ) => {
@@ -393,7 +397,9 @@ describe('server', () => {
393
397
)
394
398
const imageSrc = $ ( 'img' ) . first ( ) . attr ( 'src' )
395
399
expect (
396
- imageSrc . startsWith ( localImageBasePath ) || imageSrc . startsWith ( legacyImageBasePath )
400
+ localImageCacheBustBasePathRegex . test ( imageSrc ) ||
401
+ imageSrc . startsWith ( localImageBasePath ) ||
402
+ imageSrc . startsWith ( legacyImageBasePath )
397
403
) . toBe ( true )
398
404
} )
399
405
@@ -403,7 +409,9 @@ describe('server', () => {
403
409
)
404
410
const imageSrc = $ ( 'img' ) . first ( ) . attr ( 'src' )
405
411
expect (
406
- imageSrc . startsWith ( localImageBasePath ) || imageSrc . startsWith ( legacyImageBasePath )
412
+ localImageCacheBustBasePathRegex . test ( imageSrc ) ||
413
+ imageSrc . startsWith ( localImageBasePath ) ||
414
+ imageSrc . startsWith ( legacyImageBasePath )
407
415
) . toBe ( true )
408
416
} )
409
417
@@ -413,7 +421,9 @@ describe('server', () => {
413
421
)
414
422
const imageSrc = $ ( 'img' ) . first ( ) . attr ( 'src' )
415
423
expect (
416
- imageSrc . startsWith ( localImageBasePath ) || imageSrc . startsWith ( legacyImageBasePath )
424
+ localImageCacheBustBasePathRegex . test ( imageSrc ) ||
425
+ imageSrc . startsWith ( localImageBasePath ) ||
426
+ imageSrc . startsWith ( legacyImageBasePath )
417
427
) . toBe ( true )
418
428
} )
419
429
@@ -428,14 +438,20 @@ describe('server', () => {
428
438
const $ = await getDOM (
429
439
'/en/enterprise-cloud@latest/billing/managing-billing-for-your-github-account/viewing-the-subscription-and-usage-for-your-enterprise-account'
430
440
)
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 )
432
445
} )
433
446
434
447
test ( 'admin articles on GHEC have images that point to local assets dir' , async ( ) => {
435
448
const $ = await getDOM (
436
449
'/en/enterprise-cloud@latest/admin/configuration/configuring-your-enterprise/verifying-or-approving-a-domain-for-your-enterprise'
437
450
)
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 )
439
455
} )
440
456
441
457
test ( 'github articles on GHAE have images that point to local assets dir' , async ( ) => {
@@ -444,13 +460,18 @@ describe('server', () => {
444
460
)
445
461
const imageSrc = $ ( 'img' ) . first ( ) . attr ( 'src' )
446
462
expect (
447
- imageSrc . startsWith ( localImageBasePath ) || imageSrc . startsWith ( legacyImageBasePath )
463
+ localImageCacheBustBasePathRegex . test ( imageSrc ) ||
464
+ imageSrc . startsWith ( localImageBasePath ) ||
465
+ imageSrc . startsWith ( legacyImageBasePath )
448
466
) . toBe ( true )
449
467
} )
450
468
451
469
test ( 'admin articles on GHAE have images that point to local assets dir' , async ( ) => {
452
470
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 )
454
475
} )
455
476
} )
456
477
@@ -1003,6 +1024,16 @@ describe('static routes', () => {
1003
1024
expect ( res . headers [ 'surrogate-key' ] ) . toBeTruthy ( )
1004
1025
} )
1005
1026
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
+
1006
1037
it ( 'serves schema files from the /data/graphql directory at /public' , async ( ) => {
1007
1038
const res = await get ( '/public/schema.docs.graphql' )
1008
1039
expect ( res . statusCode ) . toBe ( 200 )
0 commit comments