@@ -597,6 +597,92 @@ func TestCreateShareInteractSetUsesCanonicalDoc(t *testing.T) {
597597 require .Equal (t , ShareInteractPermissionID (sharingID ), all [0 ].ID ())
598598}
599599
600+ func TestCreateShareInteractSetReactivatesExpiredCanonicalDoc (t * testing.T ) {
601+ if testing .Short () {
602+ t .Skip ("an instance is required for this test: test skipped due to the use of --short flag" )
603+ }
604+
605+ config .UseTestFile (t )
606+ db := testPrefix (t )
607+ require .NoError (t , couchdb .ResetDB (db , consts .Permissions ))
608+
609+ const sharingID = "sharing-expired-canonical-interact-permissions"
610+ rules := Set {{
611+ Title : "Shared drive" ,
612+ Type : consts .Files ,
613+ Values : []string {"shared-drive-root" },
614+ Verbs : ALL ,
615+ }}
616+ expiredAt := time .Now ().Add (- time .Hour ).Format (time .RFC3339 )
617+
618+ err := couchdb .CreateNamedDoc (db , & Permission {
619+ PID : ShareInteractPermissionID (sharingID ),
620+ Type : TypeShareInteract ,
621+ Permissions : rules ,
622+ Codes : map [string ]string {
623+ "alice@example.test" : "alice-token" ,
624+ },
625+ ExpiresAt : expiredAt ,
626+ SourceID : consts .Sharings + "/" + sharingID ,
627+ })
628+ require .NoError (t , err )
629+
630+ updated , err := CreateShareInteractSet (db , sharingID , map [string ]string {
631+ "bob@example.test" : "bob-token" ,
632+ }, Permission {Permissions : rules })
633+ require .NoError (t , err )
634+ require .Nil (t , updated .ExpiresAt )
635+ require .Equal (t , map [string ]string {
636+ "alice@example.test" : "alice-token" ,
637+ "bob@example.test" : "bob-token" ,
638+ }, updated .Codes )
639+
640+ stored , err := GetForShareInteract (db , sharingID )
641+ require .NoError (t , err )
642+ require .Nil (t , stored .ExpiresAt )
643+ }
644+
645+ func TestCreateShareInteractSetDoesNotRepairLegacyDuplicates (t * testing.T ) {
646+ if testing .Short () {
647+ t .Skip ("an instance is required for this test: test skipped due to the use of --short flag" )
648+ }
649+
650+ config .UseTestFile (t )
651+ db := testPrefix (t )
652+ require .NoError (t , couchdb .ResetDB (db , consts .Permissions ))
653+
654+ const sharingID = "sharing-create-with-legacy-duplicate"
655+ rules := Set {{
656+ Title : "Shared drive" ,
657+ Type : consts .Files ,
658+ Values : []string {"shared-drive-root" },
659+ Verbs : ALL ,
660+ }}
661+
662+ err := couchdb .CreateDoc (db , & Permission {
663+ Type : TypeShareInteract ,
664+ Permissions : rules ,
665+ Codes : map [string ]string {
666+ "alice@example.test" : "alice-token" ,
667+ },
668+ SourceID : consts .Sharings + "/" + sharingID ,
669+ })
670+ require .NoError (t , err )
671+
672+ created , err := CreateShareInteractSet (db , sharingID , map [string ]string {
673+ "bob@example.test" : "bob-token" ,
674+ }, Permission {Permissions : rules })
675+ require .NoError (t , err )
676+ require .Equal (t , ShareInteractPermissionID (sharingID ), created .ID ())
677+ require .Equal (t , map [string ]string {
678+ "bob@example.test" : "bob-token" ,
679+ }, created .Codes )
680+
681+ all , err := getShareInteractPermissions (db , sharingID )
682+ require .NoError (t , err )
683+ require .Len (t , all , 2 )
684+ }
685+
600686func TestCreateShareSetBlocklist (t * testing.T ) {
601687 s := Set {Rule {Type : "io.cozy.notifications" }}
602688 subdoc := Permission {
0 commit comments