@@ -333,15 +333,45 @@ func TestBzzFeed(t *testing.T) {
333333 }
334334 urlQuery = testUrl .Query ()
335335 body = updateRequest .AppendValues (urlQuery ) // this adds all query parameters
336+ goodQueryParameters := urlQuery .Encode () // save the query parameters for a second attempt
337+
338+ // create bad query parameters in which the signature is missing
339+ urlQuery .Del ("signature" )
336340 testUrl .RawQuery = urlQuery .Encode ()
337341
342+ // 1st attempt with bad query parameters in which the signature is missing
338343 resp , err = http .Post (testUrl .String (), "application/octet-stream" , bytes .NewReader (body ))
339344 if err != nil {
340345 t .Fatal (err )
341346 }
342347 defer resp .Body .Close ()
343- if resp .StatusCode != http .StatusOK {
344- t .Fatalf ("Update returned %s" , resp .Status )
348+ expectedCode := http .StatusBadRequest
349+ if resp .StatusCode != expectedCode {
350+ t .Fatalf ("Update returned %s. Expected %d" , resp .Status , expectedCode )
351+ }
352+
353+ // 2nd attempt with bad query parameters in which the signature is of incorrect length
354+ urlQuery .Set ("signature" , "0xabcd" ) // should be 130 hex chars
355+ resp , err = http .Post (testUrl .String (), "application/octet-stream" , bytes .NewReader (body ))
356+ if err != nil {
357+ t .Fatal (err )
358+ }
359+ defer resp .Body .Close ()
360+ expectedCode = http .StatusBadRequest
361+ if resp .StatusCode != expectedCode {
362+ t .Fatalf ("Update returned %s. Expected %d" , resp .Status , expectedCode )
363+ }
364+
365+ // 3rd attempt, with good query parameters:
366+ testUrl .RawQuery = goodQueryParameters
367+ resp , err = http .Post (testUrl .String (), "application/octet-stream" , bytes .NewReader (body ))
368+ if err != nil {
369+ t .Fatal (err )
370+ }
371+ defer resp .Body .Close ()
372+ expectedCode = http .StatusOK
373+ if resp .StatusCode != expectedCode {
374+ t .Fatalf ("Update returned %s. Expected %d" , resp .Status , expectedCode )
345375 }
346376
347377 // get latest update through bzz-feed directly
0 commit comments