internal links shouldn't have a password (#8668)

* internal links shouldn't have a password

* commented out incorrect cases
This commit is contained in:
Roman Perekhod
2024-03-18 15:23:10 +01:00
committed by GitHub
parent 7795ef1ad6
commit 246f7bf538
4 changed files with 92 additions and 7 deletions
@@ -814,6 +814,75 @@ var _ = Describe("Driveitems", func() {
linkType := res.Link.GetType()
Expect(string(linkType)).To(Equal("edit"))
})
It("updates the public share to internal link", func() {
getShareMockResponse.Share = nil
getShareMockResponse.Status = status.NewNotFound(ctx, "not found")
getPublicShareMock := gatewayClient.On("GetPublicShare",
mock.Anything,
mock.MatchedBy(func(req *link.GetPublicShareRequest) bool {
return req.GetRef().GetId().GetOpaqueId() == "permissionid"
}),
)
getPublicShareMockResponse = &link.GetPublicShareResponse{
Status: status.NewOK(ctx),
Share: &link.PublicShare{
Id: &link.PublicShareId{
OpaqueId: "permissionid",
},
ResourceId: &provider.ResourceId{
StorageId: "1",
SpaceId: "2",
OpaqueId: "3",
},
PasswordProtected: true,
Permissions: &link.PublicSharePermissions{
Permissions: linktype.NewFileEditLinkPermissionSet().GetPermissions(),
},
Token: "token",
},
}
getPublicShareMock.Return(getPublicShareMockResponse, nil)
newLink := libregraph.NewSharingLink()
newLinkType, err := libregraph.NewSharingLinkTypeFromValue("internal")
Expect(err).ToNot(HaveOccurred())
newLink.SetType(*newLinkType)
updatePublicShareMock := gatewayClient.On("UpdatePublicShare",
mock.Anything,
mock.MatchedBy(func(req *link.UpdatePublicShareRequest) bool {
return req.GetRef().GetId().GetOpaqueId() == "permissionid"
}),
)
updatePublicShareMockResponse.Share.Permissions = &link.PublicSharePermissions{
Permissions: linktype.NewInternalLinkPermissionSet().Permissions,
}
updatePublicShareMock.Return(updatePublicShareMockResponse, nil)
driveItemPermission.SetLink(*newLink)
body, err := driveItemPermission.MarshalJSON()
Expect(err).To(BeNil())
svc.UpdatePermission(
rr,
httptest.NewRequest(http.MethodPatch, "/", strings.NewReader(string(body))).
WithContext(ctx),
)
Expect(rr.Code).To(Equal(http.StatusOK))
data, err := io.ReadAll(rr.Body)
Expect(err).ToNot(HaveOccurred())
res := libregraph.Permission{}
err = json.Unmarshal(data, &res)
Expect(err).ToNot(HaveOccurred())
linkType := res.Link.GetType()
Expect(string(linkType)).To(Equal("internal"))
pp, hasPP := res.GetHasPasswordOk()
Expect(hasPP).To(Equal(true))
Expect(*pp).To(Equal(false))
})
It("updates the password on a public share", func() {
getShareMockResponse.Share = nil
getShareMockResponse.Status = status.NewNotFound(ctx, "not found")
+10
View File
@@ -133,6 +133,9 @@ func (g Graph) createLink(ctx context.Context, driveItemID *providerv1beta1.Reso
g.logger.Debug().Interface("createLink", createLink).Msg(err.Error())
return nil, errorcode.New(errorcode.InvalidRequest, "invalid link type")
}
if createLink.GetType() == libregraph.INTERNAL && len(createLink.GetPassword()) > 0 {
return nil, errorcode.New(errorcode.InvalidRequest, "password is redundant for the internal link")
}
req := link.CreatePublicShareRequest{
ResourceInfo: statResp.GetInfo(),
Grant: &link.Grant{
@@ -312,6 +315,13 @@ func (g Graph) updatePublicLinkPermission(ctx context.Context, permissionID stri
if err != nil {
return nil, err
}
// reset the password for the internal link
if changedLink == libregraph.INTERNAL {
perm, err = g.updatePublicLinkPassword(ctx, permissionID, "")
if err != nil {
return nil, err
}
}
}
return perm, err