Skip to content

Commit

Permalink
cmd/swarm: fix ethersphere/swarm#979:
Browse files Browse the repository at this point in the history
update should error on manifest mistmatch
  • Loading branch information
jpeletier committed Nov 25, 2018
1 parent 2a113f6 commit 2bd4106
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
6 changes: 5 additions & 1 deletion cmd/swarm/feeds.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ func feedUpdate(ctx *cli.Context) {
query = new(feed.Query)
query.User = signer.Address()
query.Topic = getTopic(ctx)

}

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

// Check that the provided signer matches the request to sign
if updateRequest.User != signer.Address() {
utils.Fatalf("Signer address does not match the update request")
}

// set the new data
updateRequest.SetData(data)

Expand Down
33 changes: 33 additions & 0 deletions cmd/swarm/feeds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,37 @@ func TestCLIFeedUpdate(t *testing.T) {
if !bytes.Equal(data, retrieved) {
t.Fatalf("Received %s, expected %s", retrieved, data)
}

// test publishing a manifest for a different user
flags = []string{
"--bzzapi", srv.URL,
"--bzzaccount", pkFileName,
"feed", "create",
"--topic", topic.Hex(),
"--user", "0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", // different user
}

log.Info(fmt.Sprintf("Publishing manifest with 'swarm feed create' for a different user"))
cmd = runSwarm(t, flags...)
_, matches = cmd.ExpectRegexp(`[a-f\d]{64}`) // regex hack to extract stdout
cmd.ExpectExit()

manifestAddress = matches[0] // read the received feed manifest

// now let's try to update that user's manifest which we don't have the private key for
flags = []string{
"--bzzapi", srv.URL,
"--bzzaccount", pkFileName,
"feed", "update",
"--manifest", manifestAddress,
hexData}

// create an update and expect an exit without errors
log.Info(fmt.Sprintf("updating a feed with 'swarm feed update'"))
cmd = runSwarm(t, flags...)
cmd.ExpectRegexp("Fatal:.*") // best way so far to detect a failure.
cmd.ExpectExit()
if cmd.ExitStatus() == 0 {
t.Fatal("Expected nonzero exit code when updating a manifest with the wrong user. Got 0.")
}
}

0 comments on commit 2bd4106

Please sign in to comment.