@@ -174,6 +174,71 @@ var _ = Describe("DriveItemPermissionsService", func() {
174174 Expect (permission .GrantedToV2 .Group .GetId ()).To (Equal ("2" ))
175175 })
176176
177+ It ("applies a default 30-day expiration to a user share created without one" , func () {
178+ var capturedReq * collaboration.CreateShareRequest
179+ gatewayClient .On ("GetUser" , mock .Anything , mock .Anything ).Return (getUserResponse , nil )
180+ gatewayClient .On ("CreateShare" , mock .Anything , mock .Anything ).
181+ Run (func (args mock.Arguments ) {
182+ capturedReq = args .Get (1 ).(* collaboration.CreateShareRequest )
183+ }).Return (createShareResponse , nil )
184+ driveItemInvite .Recipients = []libregraph.DriveRecipient {
185+ {ObjectId : libregraph .PtrString ("1" ), LibreGraphRecipientType : libregraph .PtrString ("user" )},
186+ }
187+ driveItemInvite .ExpirationDateTime = nil
188+ createShareResponse .Share = & collaboration.Share {
189+ Id : & collaboration.ShareId {OpaqueId : "123" },
190+ }
191+
192+ expectedDefault := time .Now ().UTC ().AddDate (0 , 0 , 30 )
193+ _ , err := driveItemPermissionsService .Invite (context .Background (), driveItemId , driveItemInvite )
194+ Expect (err ).ToNot (HaveOccurred ())
195+ Expect (capturedReq .GetGrant ().GetExpiration ()).ToNot (BeNil ())
196+ Expect (utils .TSToTime (capturedReq .GetGrant ().GetExpiration ())).To (BeTemporally ("~" , expectedDefault , time .Minute ))
197+ })
198+
199+ It ("applies a default 30-day expiration to a group share created without one" , func () {
200+ var capturedReq * collaboration.CreateShareRequest
201+ gatewayClient .On ("GetGroup" , mock .Anything , mock .Anything ).Return (getGroupResponse , nil )
202+ gatewayClient .On ("CreateShare" , mock .Anything , mock .Anything ).
203+ Run (func (args mock.Arguments ) {
204+ capturedReq = args .Get (1 ).(* collaboration.CreateShareRequest )
205+ }).Return (createShareResponse , nil )
206+ driveItemInvite .Recipients = []libregraph.DriveRecipient {
207+ {ObjectId : libregraph .PtrString ("2" ), LibreGraphRecipientType : libregraph .PtrString ("group" )},
208+ }
209+ driveItemInvite .ExpirationDateTime = nil
210+ createShareResponse .Share = & collaboration.Share {
211+ Id : & collaboration.ShareId {OpaqueId : "123" },
212+ }
213+
214+ expectedDefault := time .Now ().UTC ().AddDate (0 , 0 , 30 )
215+ _ , err := driveItemPermissionsService .Invite (context .Background (), driveItemId , driveItemInvite )
216+ Expect (err ).ToNot (HaveOccurred ())
217+ Expect (capturedReq .GetGrant ().GetExpiration ()).ToNot (BeNil ())
218+ Expect (utils .TSToTime (capturedReq .GetGrant ().GetExpiration ())).To (BeTemporally ("~" , expectedDefault , time .Minute ))
219+ })
220+
221+ It ("keeps a client-provided expiration instead of the default" , func () {
222+ var capturedReq * collaboration.CreateShareRequest
223+ gatewayClient .On ("GetUser" , mock .Anything , mock .Anything ).Return (getUserResponse , nil )
224+ gatewayClient .On ("CreateShare" , mock .Anything , mock .Anything ).
225+ Run (func (args mock.Arguments ) {
226+ capturedReq = args .Get (1 ).(* collaboration.CreateShareRequest )
227+ }).Return (createShareResponse , nil )
228+ driveItemInvite .Recipients = []libregraph.DriveRecipient {
229+ {ObjectId : libregraph .PtrString ("1" ), LibreGraphRecipientType : libregraph .PtrString ("user" )},
230+ }
231+ explicit := time .Now ().Add (time .Hour )
232+ driveItemInvite .ExpirationDateTime = libregraph .PtrTime (explicit )
233+ createShareResponse .Share = & collaboration.Share {
234+ Id : & collaboration.ShareId {OpaqueId : "123" },
235+ }
236+
237+ _ , err := driveItemPermissionsService .Invite (context .Background (), driveItemId , driveItemInvite )
238+ Expect (err ).ToNot (HaveOccurred ())
239+ Expect (utils .TSToTime (capturedReq .GetGrant ().GetExpiration ())).To (BeTemporally ("~" , explicit , time .Second ))
240+ })
241+
177242 It ("succeeds with file roles (happy path)" , func () {
178243 gatewayClient .On ("GetUser" , mock .Anything , mock .Anything ).Return (getUserResponse , nil )
179244 gatewayClient .On ("CreateShare" , mock .Anything , mock .Anything ).Return (createShareResponse , nil )
@@ -349,6 +414,37 @@ var _ = Describe("DriveItemPermissionsService", func() {
349414 Expect (permission .GrantedToV2 .User .GetDisplayName ()).To (Equal (getUserResponse .User .DisplayName ))
350415 Expect (permission .GrantedToV2 .User .GetId ()).To (Equal ("1" ))
351416 })
417+ It ("does not apply a default expiration to a space membership created without one" , func () {
418+ root := & provider.ResourceId {
419+ StorageId : "1" ,
420+ SpaceId : "2" ,
421+ OpaqueId : "2" , // space root: OpaqueId == SpaceId
422+ }
423+ listSpacesResponse .StorageSpaces [0 ].SpaceType = "project"
424+ listSpacesResponse .StorageSpaces [0 ].Root = root
425+ statResponse .Info .Id = root
426+ statResponse .Info .Space = & provider.StorageSpace {Root : root }
427+
428+ var capturedReq * collaboration.CreateShareRequest
429+ gatewayClient .On ("ListStorageSpaces" , mock .Anything , mock .Anything ).Return (listSpacesResponse , nil )
430+ gatewayClient .On ("GetUser" , mock .Anything , mock .Anything ).Return (getUserResponse , nil )
431+ gatewayClient .On ("Stat" , mock .Anything , mock .Anything ).Return (statResponse , nil )
432+ gatewayClient .On ("CreateShare" , mock .Anything , mock .Anything ).
433+ Run (func (args mock.Arguments ) {
434+ capturedReq = args .Get (1 ).(* collaboration.CreateShareRequest )
435+ }).Return (createShareResponse , nil )
436+ driveItemInvite .Recipients = []libregraph.DriveRecipient {
437+ {ObjectId : libregraph .PtrString ("1" ), LibreGraphRecipientType : libregraph .PtrString ("user" )},
438+ }
439+ driveItemInvite .ExpirationDateTime = nil
440+ createShareResponse .Share = & collaboration.Share {
441+ Id : & collaboration.ShareId {OpaqueId : "123" },
442+ }
443+
444+ _ , err := driveItemPermissionsService .SpaceRootInvite (context .Background (), driveId , driveItemInvite )
445+ Expect (err ).ToNot (HaveOccurred ())
446+ Expect (capturedReq .GetGrant ().GetExpiration ()).To (BeNil ())
447+ })
352448 It ("rejects to add a user to a personal space" , func () {
353449 gatewayClient .On ("ListStorageSpaces" , mock .Anything , mock .Anything ).Return (listSpacesResponse , nil )
354450 driveItemInvite .Recipients = []libregraph.DriveRecipient {
0 commit comments