@@ -494,6 +494,57 @@ func TestGetForShareInteractRepairsDuplicateDocs(t *testing.T) {
494494 require .Len (t , all , 1 )
495495}
496496
497+ func TestGetForShareInteractRepairsExpiredDuplicateDocs (t * testing.T ) {
498+ if testing .Short () {
499+ t .Skip ("an instance is required for this test: test skipped due to the use of --short flag" )
500+ }
501+
502+ config .UseTestFile (t )
503+ require .NoError (t , couchdb .ResetDB (testPrefix , consts .Permissions ))
504+
505+ const sharingID = "sharing-expired-duplicate-interact-permissions"
506+ rules := Set {{
507+ Title : "Shared drive" ,
508+ Type : consts .Files ,
509+ Values : []string {"shared-drive-root" },
510+ Verbs : ALL ,
511+ }}
512+ expiredAt := time .Now ().Add (- time .Hour ).Format (time .RFC3339 )
513+
514+ err := couchdb .CreateNamedDoc (testPrefix , & Permission {
515+ PID : ShareInteractPermissionID (sharingID ),
516+ Type : TypeShareInteract ,
517+ Permissions : rules ,
518+ Codes : map [string ]string {
519+ "alice@example.test" : "alice-token" ,
520+ },
521+ SourceID : consts .Sharings + "/" + sharingID ,
522+ })
523+ require .NoError (t , err )
524+ err = couchdb .CreateDoc (testPrefix , & Permission {
525+ Type : TypeShareInteract ,
526+ Permissions : rules ,
527+ Codes : map [string ]string {
528+ "expired@example.test" : "expired-token" ,
529+ },
530+ ExpiresAt : expiredAt ,
531+ SourceID : consts .Sharings + "/" + sharingID ,
532+ })
533+ require .NoError (t , err )
534+
535+ repaired , err := GetForShareInteract (testPrefix , sharingID )
536+ require .NoError (t , err )
537+ require .Equal (t , ShareInteractPermissionID (sharingID ), repaired .ID ())
538+ require .Equal (t , map [string ]string {
539+ "alice@example.test" : "alice-token" ,
540+ }, repaired .Codes )
541+
542+ all , err := getShareInteractPermissions (testPrefix , sharingID )
543+ require .NoError (t , err )
544+ require .Len (t , all , 1 )
545+ require .Equal (t , ShareInteractPermissionID (sharingID ), all [0 ].ID ())
546+ }
547+
497548func TestCreateShareInteractSetUsesCanonicalDoc (t * testing.T ) {
498549 if testing .Short () {
499550 t .Skip ("an instance is required for this test: test skipped due to the use of --short flag" )
0 commit comments