Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
36ca85fa
Commit
36ca85fa
authored
6 years ago
by
Javier Peletier
Committed by
Anton Evangelatov
6 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
swarm/api: Fix #18007, missing signature should return HTTP 400 (#18008)
parent
b3516555
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
6 deletions
+38
-6
server.go
swarm/api/http/server.go
+6
-4
server_test.go
swarm/api/http/server_test.go
+32
-2
No files found.
swarm/api/http/server.go
View file @
36ca85fa
...
...
@@ -484,7 +484,8 @@ func (s *Server) HandlePostFeed(w http.ResponseWriter, r *http.Request) {
return
}
if
updateRequest
.
IsUpdate
()
{
switch
{
case
updateRequest
.
IsUpdate
()
:
// Verify that the signature is intact and that the signer is authorized
// to update this feed
// Check this early, to avoid creating a feed and then not being able to set its first update.
...
...
@@ -497,9 +498,8 @@ func (s *Server) HandlePostFeed(w http.ResponseWriter, r *http.Request) {
respondError
(
w
,
r
,
err
.
Error
(),
http
.
StatusInternalServerError
)
return
}
}
if
query
.
Get
(
"manifest"
)
==
"1"
{
fallthrough
case
query
.
Get
(
"manifest"
)
==
"1"
:
// we create a manifest so we can retrieve feed updates with bzz:// later
// this manifest has a special "feed type" manifest, and saves the
// feed identification used to retrieve feed updates later
...
...
@@ -519,6 +519,8 @@ func (s *Server) HandlePostFeed(w http.ResponseWriter, r *http.Request) {
fmt
.
Fprint
(
w
,
string
(
outdata
))
w
.
Header
()
.
Add
(
"Content-type"
,
"application/json"
)
default
:
respondError
(
w
,
r
,
"Missing signature in feed update request"
,
http
.
StatusBadRequest
)
}
}
...
...
This diff is collapsed.
Click to expand it.
swarm/api/http/server_test.go
View file @
36ca85fa
...
...
@@ -333,15 +333,45 @@ func TestBzzFeed(t *testing.T) {
}
urlQuery
=
testUrl
.
Query
()
body
=
updateRequest
.
AppendValues
(
urlQuery
)
// this adds all query parameters
goodQueryParameters
:=
urlQuery
.
Encode
()
// save the query parameters for a second attempt
// create bad query parameters in which the signature is missing
urlQuery
.
Del
(
"signature"
)
testUrl
.
RawQuery
=
urlQuery
.
Encode
()
// 1st attempt with bad query parameters in which the signature is missing
resp
,
err
=
http
.
Post
(
testUrl
.
String
(),
"application/octet-stream"
,
bytes
.
NewReader
(
body
))
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
defer
resp
.
Body
.
Close
()
if
resp
.
StatusCode
!=
http
.
StatusOK
{
t
.
Fatalf
(
"Update returned %s"
,
resp
.
Status
)
expectedCode
:=
http
.
StatusBadRequest
if
resp
.
StatusCode
!=
expectedCode
{
t
.
Fatalf
(
"Update returned %s. Expected %d"
,
resp
.
Status
,
expectedCode
)
}
// 2nd attempt with bad query parameters in which the signature is of incorrect length
urlQuery
.
Set
(
"signature"
,
"0xabcd"
)
// should be 130 hex chars
resp
,
err
=
http
.
Post
(
testUrl
.
String
(),
"application/octet-stream"
,
bytes
.
NewReader
(
body
))
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
defer
resp
.
Body
.
Close
()
expectedCode
=
http
.
StatusBadRequest
if
resp
.
StatusCode
!=
expectedCode
{
t
.
Fatalf
(
"Update returned %s. Expected %d"
,
resp
.
Status
,
expectedCode
)
}
// 3rd attempt, with good query parameters:
testUrl
.
RawQuery
=
goodQueryParameters
resp
,
err
=
http
.
Post
(
testUrl
.
String
(),
"application/octet-stream"
,
bytes
.
NewReader
(
body
))
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
defer
resp
.
Body
.
Close
()
expectedCode
=
http
.
StatusOK
if
resp
.
StatusCode
!=
expectedCode
{
t
.
Fatalf
(
"Update returned %s. Expected %d"
,
resp
.
Status
,
expectedCode
)
}
// get latest update through bzz-feed directly
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment