diff options
author | Nick Mathewson <nickm@torproject.org> | 2011-06-29 17:44:29 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2011-06-29 17:45:27 -0400 |
commit | 05c424f4b830e98595b33397b58504462dbda8db (patch) | |
tree | f2d36e4b49a885ba4d45c74a2e7e71a9596311a6 /src/test/test.c | |
parent | 5d43a1572094868e598541f9ce686546c910f071 (diff) | |
download | tor-05c424f4b830e98595b33397b58504462dbda8db.tar.gz tor-05c424f4b830e98595b33397b58504462dbda8db.zip |
Refactor fetch_from_buf_socks() to be greedy
Previously, fetch_from_buf_socks() might return 0 if there was still
data on the buffer and a subsequent call to fetch_from_buf_socks()
would return 1. This was making some of the socks5 unit tests
harder to write, and could potentially have caused misbehavior with
some overly verbose SOCKS implementations. Now,
fetch_from_buf_socks() does as much processing as it can, and
returns 0 only if it really needs more data. This brings it into
line with the evbuffer socks implementation.
Diffstat (limited to 'src/test/test.c')
-rw-r--r-- | src/test/test.c | 23 |
1 files changed, 8 insertions, 15 deletions
diff --git a/src/test/test.c b/src/test/test.c index 64916eab21..01fb30cd0c 100644 --- a/src/test/test.c +++ b/src/test/test.c @@ -382,8 +382,6 @@ test_socks_5_supported_commands(void *ptr) ADD_DATA(buf, "\x05\x01\x00"); ADD_DATA(buf, "\x05\x01\x00\x03\x0Etorproject.org\x11\x11"); test_eq(fetch_from_buf_socks(buf, socks, get_options()->TestSocks, - get_options()->SafeSocks), 0); - test_eq(fetch_from_buf_socks(buf, socks, get_options()->TestSocks, get_options()->SafeSocks), 1); test_eq(5, socks->socks_version); @@ -400,8 +398,6 @@ test_socks_5_supported_commands(void *ptr) ADD_DATA(buf, "\x05\x01\x00"); ADD_DATA(buf, "\x05\xF0\x00\x03\x0Etorproject.org\x01\x02"); test_assert(fetch_from_buf_socks(buf, socks, get_options()->TestSocks, - get_options()->SafeSocks) == 0); - test_assert(fetch_from_buf_socks(buf, socks, get_options()->TestSocks, get_options()->SafeSocks) == 1); test_eq(5, socks->socks_version); test_eq(2, socks->replylen); @@ -416,8 +412,6 @@ test_socks_5_supported_commands(void *ptr) ADD_DATA(buf, "\x05\x01\x00"); ADD_DATA(buf, "\x05\xF1\x00\x01\x02\x02\x02\x05\x01\x03"); test_assert(fetch_from_buf_socks(buf, socks, get_options()->TestSocks, - get_options()->SafeSocks) == 0); - test_assert(fetch_from_buf_socks(buf, socks, get_options()->TestSocks, get_options()->SafeSocks) == 1); test_eq(5, socks->socks_version); test_eq(2, socks->replylen); @@ -528,24 +522,23 @@ test_socks_5_authenticate_with_data(void *ptr) /* SOCKS 5 Send username/password */ /* SOCKS 5 Send CONNECT [01] to IP address 2.2.2.2:4369 */ - ADD_DATA(buf, "\x01\x02me\x02me\x05\x01\x00\x01\x02\x02\x02\x02\x11\x11"); - test_assert(!fetch_from_buf_socks(buf, socks, + ADD_DATA(buf, "\x01\x02me\x03you\x05\x01\x00\x01\x02\x02\x02\x02\x11\x11"); + test_assert(fetch_from_buf_socks(buf, socks, get_options()->TestSocks, - get_options()->SafeSocks)); - test_eq(5, socks->socks_version); - test_eq(2, socks->replylen); - test_eq(5, socks->reply[0]); - test_eq(0, socks->reply[1]); - - test_assert(fetch_from_buf_socks(buf, socks, get_options()->TestSocks, get_options()->SafeSocks) == 1); test_eq(5, socks->socks_version); test_eq(2, socks->replylen); test_eq(5, socks->reply[0]); test_eq(0, socks->reply[1]); + test_streq("2.2.2.2", socks->address); test_eq(4369, socks->port); + test_eq(2, socks->usernamelen); + test_eq(3, socks->passwordlen); + test_memeq("me", socks->username, 2); + test_memeq("you", socks->password, 3); + done: ; } |