@@ -576,4 +576,111 @@ URI: https://docs.fileverse.io
576576
577577 expect ( controller . getAccountPolicies ( EOA_ACC . addr ) ) . toEqual ( [ ] )
578578 } )
579+ it ( 'revokeAllPoliciesForDomain works' , async ( ) => {
580+ const POLICY_1 : AutoLoginPolicy = {
581+ domain : 'docs.fileverse.io' ,
582+ uriPrefix : 'https://docs.fileverse.io/login' ,
583+ allowedChains : [ 1 ] ,
584+ allowedResources : [ 'https://privy.io' ] ,
585+ supportsEIP6492 : false ,
586+ expiresAt : Date . now ( ) + 60000 ,
587+ lastAuthenticated : Date . now ( )
588+ }
589+
590+ const POLICY_2 : AutoLoginPolicy = {
591+ domain : 'docs.fileverse.io' ,
592+ uriPrefix : 'https://docs.fileverse.io/admin' ,
593+ allowedChains : [ 1 , 137 ] ,
594+ allowedResources : [ 'https://privy.io' ] ,
595+ supportsEIP6492 : false ,
596+ expiresAt : Date . now ( ) + 60000 ,
597+ lastAuthenticated : Date . now ( )
598+ }
599+
600+ const OTHER_DOMAIN_POLICY : AutoLoginPolicy = {
601+ domain : 'other-site.com' ,
602+ uriPrefix : 'https://other-site.com/login' ,
603+ allowedChains : [ 1 ] ,
604+ allowedResources : [ ] ,
605+ supportsEIP6492 : false ,
606+ expiresAt : Date . now ( ) + 60000 ,
607+ lastAuthenticated : Date . now ( )
608+ }
609+
610+ const { controller } = await prepareTest ( ( s ) => {
611+ return s . set ( 'autoLoginPolicies' , {
612+ [ EOA_ACC . addr ] : [ POLICY_1 , POLICY_2 , OTHER_DOMAIN_POLICY ]
613+ } )
614+ } )
615+
616+ expect ( controller . getAccountPolicies ( EOA_ACC . addr ) ) . toEqual ( [
617+ POLICY_1 ,
618+ POLICY_2 ,
619+ OTHER_DOMAIN_POLICY
620+ ] )
621+
622+ await controller . revokeAllPoliciesForDomain (
623+ 'docs.fileverse.io' ,
624+ 'https://docs.fileverse.io/login'
625+ )
626+ await controller . revokeAllPoliciesForDomain (
627+ 'docs.fileverse.io' ,
628+ 'https://docs.fileverse.io/admin'
629+ )
630+
631+ expect ( controller . getAccountPolicies ( EOA_ACC . addr ) ) . toEqual ( [ OTHER_DOMAIN_POLICY ] )
632+ } )
633+
634+ it ( 'revokeAllPoliciesForDomain removes policies across multiple accounts' , async ( ) => {
635+ const SHARED_POLICY : AutoLoginPolicy = {
636+ domain : 'docs.fileverse.io' ,
637+ uriPrefix : 'https://docs.fileverse.io/login' ,
638+ allowedChains : [ 1 ] ,
639+ allowedResources : [ 'https://privy.io' ] ,
640+ supportsEIP6492 : false ,
641+ expiresAt : Date . now ( ) + 60000 ,
642+ lastAuthenticated : Date . now ( )
643+ }
644+
645+ const EOA_POLICY : AutoLoginPolicy = {
646+ domain : 'eoa-only.com' ,
647+ uriPrefix : 'https://eoa-only.com/login' ,
648+ allowedChains : [ 1 ] ,
649+ allowedResources : [ ] ,
650+ supportsEIP6492 : false ,
651+ expiresAt : Date . now ( ) + 60000 ,
652+ lastAuthenticated : Date . now ( )
653+ }
654+
655+ const HW_POLICY : AutoLoginPolicy = {
656+ domain : 'hw-only.com' ,
657+ uriPrefix : 'https://hw-only.com/login' ,
658+ allowedChains : [ 137 ] ,
659+ allowedResources : [ ] ,
660+ supportsEIP6492 : false ,
661+ expiresAt : Date . now ( ) + 60000 ,
662+ lastAuthenticated : Date . now ( )
663+ }
664+
665+ const { controller } = await prepareTest ( ( s ) => {
666+ return s . set ( 'autoLoginPolicies' , {
667+ [ EOA_ACC . addr ] : [ SHARED_POLICY , EOA_POLICY ] ,
668+ [ HW_ACC . addr ] : [ SHARED_POLICY , HW_POLICY ]
669+ } )
670+ } )
671+
672+ // Verify initial state
673+ expect ( controller . getAccountPolicies ( EOA_ACC . addr ) ) . toEqual ( [ SHARED_POLICY , EOA_POLICY ] )
674+ expect ( controller . getAccountPolicies ( HW_ACC . addr ) ) . toEqual ( [ SHARED_POLICY , HW_POLICY ] )
675+
676+ // Remove the shared policy from all accounts
677+ await controller . revokeAllPoliciesForDomain (
678+ 'docs.fileverse.io' ,
679+ 'https://docs.fileverse.io/login'
680+ )
681+
682+ // Verify the shared policy is removed from both accounts, but other policies remain
683+ expect ( controller . getAccountPolicies ( EOA_ACC . addr ) ) . toEqual ( [ EOA_POLICY ] )
684+ expect ( controller . getAccountPolicies ( HW_ACC . addr ) ) . toEqual ( [ HW_POLICY ] )
685+ } )
579686} )
0 commit comments