Skip to content

Commit 4f0d978

Browse files
jpeletierzelig
authored andcommitted
cmd/swarm: update should error on manifest mismatch (#18047)
* cmd/swarm: fix ethersphere/swarm#979: update should error on manifest mistmatch * cmd/swarm: fixed comments and remove sprintf from log.Info * cmd/swarm: remove unnecessary comment
1 parent 1cd007e commit 4f0d978

File tree

2 files changed

+41
-6
lines changed

2 files changed

+41
-6
lines changed

cmd/swarm/feeds.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ func feedUpdate(ctx *cli.Context) {
169169
query = new(feed.Query)
170170
query.User = signer.Address()
171171
query.Topic = getTopic(ctx)
172-
173172
}
174173

175174
// Retrieve a feed update request
@@ -178,6 +177,11 @@ func feedUpdate(ctx *cli.Context) {
178177
utils.Fatalf("Error retrieving feed status: %s", err.Error())
179178
}
180179

180+
// Check that the provided signer matches the request to sign
181+
if updateRequest.User != signer.Address() {
182+
utils.Fatalf("Signer address does not match the update request")
183+
}
184+
181185
// set the new data
182186
updateRequest.SetData(data)
183187

cmd/swarm/feeds_test.go

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package main
1919
import (
2020
"bytes"
2121
"encoding/json"
22-
"fmt"
2322
"io/ioutil"
2423
"os"
2524
"testing"
@@ -69,7 +68,7 @@ func TestCLIFeedUpdate(t *testing.T) {
6968
hexData}
7069

7170
// create an update and expect an exit without errors
72-
log.Info(fmt.Sprintf("updating a feed with 'swarm feed update'"))
71+
log.Info("updating a feed with 'swarm feed update'")
7372
cmd := runSwarm(t, flags...)
7473
cmd.ExpectExit()
7574

@@ -116,7 +115,7 @@ func TestCLIFeedUpdate(t *testing.T) {
116115
"--user", address.Hex(),
117116
}
118117

119-
log.Info(fmt.Sprintf("getting feed info with 'swarm feed info'"))
118+
log.Info("getting feed info with 'swarm feed info'")
120119
cmd = runSwarm(t, flags...)
121120
_, matches := cmd.ExpectRegexp(`.*`) // regex hack to extract stdout
122121
cmd.ExpectExit()
@@ -141,9 +140,9 @@ func TestCLIFeedUpdate(t *testing.T) {
141140
"--topic", topic.Hex(),
142141
}
143142

144-
log.Info(fmt.Sprintf("Publishing manifest with 'swarm feed create'"))
143+
log.Info("Publishing manifest with 'swarm feed create'")
145144
cmd = runSwarm(t, flags...)
146-
_, matches = cmd.ExpectRegexp(`[a-f\d]{64}`) // regex hack to extract stdout
145+
_, matches = cmd.ExpectRegexp(`[a-f\d]{64}`)
147146
cmd.ExpectExit()
148147

149148
manifestAddress := matches[0] // read the received feed manifest
@@ -162,4 +161,36 @@ func TestCLIFeedUpdate(t *testing.T) {
162161
if !bytes.Equal(data, retrieved) {
163162
t.Fatalf("Received %s, expected %s", retrieved, data)
164163
}
164+
165+
// test publishing a manifest for a different user
166+
flags = []string{
167+
"--bzzapi", srv.URL,
168+
"feed", "create",
169+
"--topic", topic.Hex(),
170+
"--user", "0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", // different user
171+
}
172+
173+
log.Info("Publishing manifest with 'swarm feed create' for a different user")
174+
cmd = runSwarm(t, flags...)
175+
_, matches = cmd.ExpectRegexp(`[a-f\d]{64}`)
176+
cmd.ExpectExit()
177+
178+
manifestAddress = matches[0] // read the received feed manifest
179+
180+
// now let's try to update that user's manifest which we don't have the private key for
181+
flags = []string{
182+
"--bzzapi", srv.URL,
183+
"--bzzaccount", pkFileName,
184+
"feed", "update",
185+
"--manifest", manifestAddress,
186+
hexData}
187+
188+
// create an update and expect an error given there is a user mismatch
189+
log.Info("updating a feed with 'swarm feed update'")
190+
cmd = runSwarm(t, flags...)
191+
cmd.ExpectRegexp("Fatal:.*") // best way so far to detect a failure.
192+
cmd.ExpectExit()
193+
if cmd.ExitStatus() == 0 {
194+
t.Fatal("Expected nonzero exit code when updating a manifest with the wrong user. Got 0.")
195+
}
165196
}

0 commit comments

Comments
 (0)