@@ -19,7 +19,6 @@ package main
1919import (
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