11import { strict as assert } from "node:assert" ;
2+ import { createHash } from "node:crypto" ;
23import test from "node:test" ;
34import { App } from "@tinyhttp/app" ;
45import { CommunityMeshRoutes } from "../src/routes/communityMeshes.js" ;
@@ -30,6 +31,11 @@ test("registry uses ETags for cache revalidation", async () => {
3031 const first = await fetch ( `${ origin } /v1/community-meshes` ) ;
3132 const etag = first . headers . get ( "etag" ) ;
3233 assert . ok ( etag ) ;
34+ const body = await first . text ( ) ;
35+ const expectedEtag = `"${ createHash ( "sha256" )
36+ . update ( body )
37+ . digest ( "base64url" ) } "`;
38+ assert . equal ( etag , expectedEtag ) ;
3339
3440 const second = await fetch ( `${ origin } /v1/community-meshes` , {
3541 headers : { "If-None-Match" : etag } ,
@@ -39,6 +45,25 @@ test("registry uses ETags for cache revalidation", async () => {
3945 } ) ;
4046} ) ;
4147
48+ test ( "registry accepts standard If-None-Match validator forms" , async ( ) => {
49+ const app = new App ( ) ;
50+ CommunityMeshRoutes ( app ) ;
51+
52+ await withServer ( app , async ( origin ) => {
53+ const first = await fetch ( `${ origin } /v1/community-meshes` ) ;
54+ const etag = first . headers . get ( "etag" ) ;
55+ assert . ok ( etag ) ;
56+
57+ const validators = [ `W/${ etag } ` , `"unrelated", W/${ etag } ` , "*" ] ;
58+ for ( const validator of validators ) {
59+ const response = await fetch ( `${ origin } /v1/community-meshes` , {
60+ headers : { "If-None-Match" : validator } ,
61+ } ) ;
62+ assert . equal ( response . status , 304 , validator ) ;
63+ }
64+ } ) ;
65+ } ) ;
66+
4267test ( "serves the schema and returns 404 for an unknown community" , async ( ) => {
4368 const app = new App ( ) ;
4469 CommunityMeshRoutes ( app ) ;
0 commit comments