unwrap: perform consistency check in SessionIterator

C# servers with SessionEnabled=false will return iterator IDs and no session
IDs which can be reported as an error immediately because the iterator can't
be traversed.
This commit is contained in:
Roman Khimov 2022-08-17 15:08:24 +03:00
parent 37619743ad
commit 689331b960
2 changed files with 7 additions and 1 deletions

View file

@ -155,6 +155,9 @@ func SessionIterator(r *result.Invoke, err error) (uuid.UUID, result.Iterator, e
if !ok {
return uuid.UUID{}, result.Iterator{}, errors.New("the item is InteropInterface, but not an Iterator")
}
if (r.Session == uuid.UUID{}) && iter.ID != nil {
return uuid.UUID{}, result.Iterator{}, errors.New("server returned iterator ID, but no session ID")
}
return r.Session, iter, nil
}

View file

@ -197,8 +197,11 @@ func TestSessionIterator(t *testing.T) {
require.Error(t, err)
iid := uuid.New()
sid := uuid.New()
iter := result.Iterator{ID: &iid}
_, _, err = SessionIterator(&result.Invoke{State: "HALT", Stack: []stackitem.Item{stackitem.NewInterop(iter)}}, nil)
require.Error(t, err)
sid := uuid.New()
rs, ri, err := SessionIterator(&result.Invoke{Session: sid, State: "HALT", Stack: []stackitem.Item{stackitem.NewInterop(iter)}}, nil)
require.NoError(t, err)
require.Equal(t, sid, rs)