@@ -665,6 +665,52 @@ public function testQueryCacheReliesOnPurgeForDocumentSecurityCollections(): voi
665665 $ this ->assertSame ([], $ fresh );
666666 }
667667
668+ public function testQueryCacheFiltersDocumentSecurityPayloadsOnHit (): void
669+ {
670+ $ cache = new HashMemoryCache ();
671+ $ database = $ this ->createDatabase ($ cache );
672+ $ database ->getAuthorization ()->skip (function () use ($ database ): void {
673+ $ database ->createCollection ('secureRules ' , permissions: [
674+ Permission::create (Role::any ()),
675+ ], documentSecurity: true );
676+ });
677+
678+ $ database ->getAuthorization ()->addRole (Role::user ('user-1 ' )->toString ());
679+
680+ $ collection = $ database ->getCollection ('secureRules ' );
681+ $ key = $ database ->getQueryCacheKey ($ collection ->getId (), '_39 ' );
682+ $ hash = $ database ->getQueryCacheField ($ collection );
683+ $ database ->getCache ()->save ($ key , [
684+ 'collection ' => $ collection ->getId (),
685+ 'type ' => 'documents ' ,
686+ 'value ' => [
687+ [
688+ '$id ' => 'rule-a ' ,
689+ '$permissions ' => [
690+ Permission::read (Role::user ('user-2 ' )),
691+ ],
692+ ],
693+ ],
694+ ], $ hash );
695+
696+ $ callbackCalls = 0 ;
697+ $ documents = $ database ->withCache (
698+ key: $ key ,
699+ callback: function () use (&$ callbackCalls ): array {
700+ $ callbackCalls ++;
701+ return [
702+ new Document ([
703+ '$id ' => 'fresh ' ,
704+ ]),
705+ ];
706+ },
707+ hash: $ hash ,
708+ );
709+
710+ $ this ->assertSame ([], $ documents );
711+ $ this ->assertSame (0 , $ callbackCalls );
712+ }
713+
668714 public function testQueryCacheRehydratesNestedDocumentPayloads (): void
669715 {
670716 $ cache = new HashMemoryCache ();
0 commit comments