validate query range on requestMessages API (#1060)
This commit is contained in:
parent
b003400b4b
commit
1bc63df5f2
|
@ -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)
|
||||
|
|
|
@ -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{
|
||||
|
|
Loading…
Reference in New Issue