validate query range on requestMessages API (#1060)

This commit is contained in:
Andrea Franz 2018-06-26 10:41:03 +02:00 committed by GitHub
parent b003400b4b
commit 1bc63df5f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 0 deletions

View File

@ -115,6 +115,11 @@ func (api *PublicAPI) RequestMessages(_ context.Context, r MessagesRequest) (hex
shh := api.service.w
now := api.service.w.GetCurrentTime()
r.setDefaults(now)
if r.From > r.To {
return nil, fmt.Errorf("Query range is invalid: from > to (%d > %d)", r.From, r.To)
}
mailServerNode, err := discover.ParseNode(r.MailServerPeer)
if err != nil {
return nil, fmt.Errorf("%v: %v", ErrInvalidMailServerPeer, err)

View File

@ -196,6 +196,14 @@ func (s *ShhExtSuite) TestRequestMessages() {
s.Contains(err.Error(), "Could not find peer with ID")
s.Nil(hash)
// from is greater than to
hash, err = api.RequestMessages(context.TODO(), MessagesRequest{
From: 10,
To: 5,
})
s.Contains(err.Error(), "Query range is invalid: from > to (10 > 5)")
s.Nil(hash)
// with a peer acting as a mailserver
// prepare a node first
mailNode, err := node.New(&node.Config{