Skip to content

Commit

Permalink
internal links shouldn't have a password (#8668)
Browse files Browse the repository at this point in the history
* internal links shouldn't have a password

* commented out incorrect cases
  • Loading branch information
2403905 committed Mar 18, 2024
1 parent 7795ef1 commit 246f7bf
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 7 deletions.
6 changes: 6 additions & 0 deletions changelog/unreleased/fix-graph-internal-link.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Bugfix: Internal links shouldn't have a password

Internal links shouldn't have a password when create/update

https://github.com/owncloud/ocis/pull/8668
https://github.com/owncloud/ocis/issues/8619
69 changes: 69 additions & 0 deletions services/graph/pkg/service/v0/driveitems_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
10 changes: 10 additions & 0 deletions services/graph/pkg/service/v0/links.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions tests/acceptance/features/apiSharingNg/linkShare.feature
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Feature: Create a share link for a resource
| permissionsRole |
| view |
| edit |
| internal |
# | internal |
| upload |
| createOnly |
| blocksDownload |
Expand Down Expand Up @@ -143,7 +143,7 @@ Feature: Create a share link for a resource
| permissionsRole |
| view |
| edit |
| internal |
# | internal |
| blocksDownload |

@issue-7879
Expand Down Expand Up @@ -219,7 +219,7 @@ Feature: Create a share link for a resource
| permissionsRole |
| view |
| edit |
| internal |
# | internal |
| upload |
| createOnly |
| blocksDownload |
Expand Down Expand Up @@ -297,7 +297,7 @@ Feature: Create a share link for a resource
| permissionsRole |
| view |
| edit |
| internal |
# | internal |
| blocksDownload |

@env-config @issue-7879
Expand Down Expand Up @@ -440,14 +440,14 @@ Feature: Create a share link for a resource
Examples:
| previousPermissionsRole | newPermissionsRole |
| view | edit |
| view | internal |
# | view | internal |
| view | blocksDownload |
| edit | view |
| edit | blocksDownload |
| view | internal |
# | view | internal |
| blocksDownload | edit |
| blocksDownload | blocksDownload |
| view | internal |
# | view | internal |


Scenario: update expiration date of a file's link share
Expand Down

0 comments on commit 246f7bf

Please sign in to comment.