Skip to content

Commit

Permalink
FIX: re-init history so that it can be saved; only add publisher if h…
Browse files Browse the repository at this point in the history
…istroy is zero
  • Loading branch information
bosi95 committed May 7, 2024
1 parent 5ae2d9d commit f7b7560
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pkg/api/dynamicaccess_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ func TestDacGrantees(t *testing.T) {
})

t.Run("get-grantees-unauthorized", func(t *testing.T) {
jsonhttptest.Request(t, client, http.MethodGet, "/grantee/fc4e9fe978991257b897d987bc4ff13058b66ef45a53189a0b4fe84bb3346396", http.StatusUnauthorized,
jsonhttptest.Request(t, client, http.MethodGet, "/grantee/fc4e9fe978991257b897d987bc4ff13058b66ef45a53189a0b4fe84bb3346396", http.StatusNotFound,
jsonhttptest.WithExpectedJSONResponse(jsonhttp.StatusResponse{
Message: "granteelist not found",
Code: http.StatusNotFound,
Expand Down
15 changes: 12 additions & 3 deletions pkg/dynamicaccess/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,11 @@ func (c *controller) HandleGrantees(
var granteesToAdd []*ecdsa.PublicKey
// generate new access key and new act
if len(removeList) != 0 || encryptedglref.IsZero() {
err = c.accessLogic.AddPublisher(ctx, act, publisher)
if err != nil {
return swarm.ZeroAddress, swarm.ZeroAddress, swarm.ZeroAddress, swarm.ZeroAddress, err
if historyref.IsZero() {
err = c.accessLogic.AddPublisher(ctx, act, publisher)
if err != nil {
return swarm.ZeroAddress, swarm.ZeroAddress, swarm.ZeroAddress, swarm.ZeroAddress, err
}
}
granteesToAdd = gl.Get()
} else {
Expand Down Expand Up @@ -229,6 +231,13 @@ func (c *controller) HandleGrantees(
if err != nil {
return swarm.ZeroAddress, swarm.ZeroAddress, swarm.ZeroAddress, swarm.ZeroAddress, err
}
// need to re-initialize history, because Lookup loads the forks causing the manifest save to skip the root node
if !historyref.IsZero() {
h, err = NewHistoryReference(ls, historyref)
if err != nil {
return swarm.ZeroAddress, swarm.ZeroAddress, swarm.ZeroAddress, swarm.ZeroAddress, err
}
}

mtdt := map[string]string{"encryptedglref": eglref.String()}
err = h.Add(ctx, actref, nil, &mtdt)
Expand Down

0 comments on commit f7b7560

Please sign in to comment.