[tor-commits] [obfsproxy/master] ...then revive the obfs2 unit tests as well.
nickm at torproject.org
nickm at torproject.org
Fri Sep 9 17:08:58 UTC 2011
commit 297439cd51903fa8010f83ffaec74b4eed755c24
Author: George Kadianakis <desnacked at gmail.com>
Date: Sat Aug 20 03:26:31 2011 +0200
...then revive the obfs2 unit tests as well.
---
src/test/unittest.c | 4 +-
src/test/unittest_obfs2.c | 108 ++++++++++++++++++++++----------------------
2 files changed, 56 insertions(+), 56 deletions(-)
diff --git a/src/test/unittest.c b/src/test/unittest.c
index 13557bf..5f2613c 100644
--- a/src/test/unittest.c
+++ b/src/test/unittest.c
@@ -9,14 +9,14 @@ extern struct testcase_t container_tests[];
extern struct testcase_t crypt_tests[];
extern struct testcase_t socks_tests[];
extern struct testcase_t dummy_tests[];
-/*extern struct testcase_t obfs2_tests[];*/
+extern struct testcase_t obfs2_tests[];
struct testgroup_t groups[] = {
{ "container/", container_tests },
{ "crypt/", crypt_tests },
{ "socks/", socks_tests },
{ "dummy/", dummy_tests },
- /*{ "obfs2/", obfs2_tests },*/
+ { "obfs2/", obfs2_tests },
END_OF_GROUPS
};
diff --git a/src/test/unittest_obfs2.c b/src/test/unittest_obfs2.c
index e5addcc..211f6af 100644
--- a/src/test/unittest_obfs2.c
+++ b/src/test/unittest_obfs2.c
@@ -14,17 +14,17 @@
#define ALEN(x) (sizeof x/sizeof x[0])
-static inline obfs2_protocol_t *
-downcast(protocol_t *proto)
+static inline obfs2_conn_t *
+downcast(conn_t *proto)
{
- return DOWNCAST(obfs2_protocol_t, super, proto);
+ return DOWNCAST(obfs2_conn_t, super, proto);
}
static void
test_obfs2_option_parsing(void *unused)
{
struct option_parsing_case {
- protocol_params_t *result;
+ config_t *result;
short should_succeed;
short n_opts;
const char *const opts[6];
@@ -58,7 +58,7 @@ test_obfs2_option_parsing(void *unused)
struct option_parsing_case *c;
for (c = cases; c->n_opts; c++) {
- c->result = proto_params_init(c->n_opts, c->opts);
+ c->result = config_create(c->n_opts, c->opts);
if (c->should_succeed)
tt_ptr_op(c->result, !=, NULL);
else
@@ -68,7 +68,7 @@ test_obfs2_option_parsing(void *unused)
end:
for (c = cases; c->n_opts; c++)
if (c->result)
- proto_params_free(c->result);
+ config_free(c->result);
/* Unsuspend logging */
log_set_method(LOG_METHOD_STDERR, NULL);
@@ -77,10 +77,10 @@ test_obfs2_option_parsing(void *unused)
/* All the tests below use this test environment: */
struct test_obfs2_state
{
- protocol_params_t *proto_params_client;
- protocol_params_t *proto_params_server;
- protocol_t *client_proto;
- protocol_t *server_proto;
+ config_t *cfg_client;
+ config_t *cfg_server;
+ conn_t *conn_client;
+ conn_t *conn_server;
struct evbuffer *output_buffer;
struct evbuffer *dummy_buffer;
};
@@ -90,15 +90,15 @@ cleanup_obfs2_state(const struct testcase_t *unused, void *state)
{
struct test_obfs2_state *s = (struct test_obfs2_state *)state;
- if (s->client_proto)
- proto_destroy(s->client_proto);
- if (s->server_proto)
- proto_destroy(s->server_proto);
+ if (s->conn_client)
+ proto_conn_free(s->conn_client);
+ if (s->conn_server)
+ proto_conn_free(s->conn_server);
- if (s->proto_params_client)
- proto_params_free(s->proto_params_client);
- if (s->proto_params_server)
- proto_params_free(s->proto_params_server);
+ if (s->cfg_client)
+ config_free(s->cfg_client);
+ if (s->cfg_server)
+ config_free(s->cfg_server);
if (s->output_buffer)
evbuffer_free(s->output_buffer);
@@ -121,19 +121,19 @@ setup_obfs2_state(const struct testcase_t *unused)
{
struct test_obfs2_state *s = xzalloc(sizeof(struct test_obfs2_state));
- s->proto_params_client =
- proto_params_init(ALEN(options_client), options_client);
- tt_assert(s->proto_params_client);
+ s->cfg_client =
+ config_create(ALEN(options_client), options_client);
+ tt_assert(s->cfg_client);
- s->proto_params_server =
- proto_params_init(ALEN(options_server), options_server);
- tt_assert(s->proto_params_server);
+ s->cfg_server =
+ config_create(ALEN(options_server), options_server);
+ tt_assert(s->cfg_server);
- s->client_proto = proto_create(s->proto_params_client);
- tt_assert(s->client_proto);
+ s->conn_client = proto_conn_create(s->cfg_client);
+ tt_assert(s->conn_client);
- s->server_proto = proto_create(s->proto_params_server);
- tt_assert(s->server_proto);
+ s->conn_server = proto_conn_create(s->cfg_server);
+ tt_assert(s->conn_server);
s->output_buffer = evbuffer_new();
tt_assert(s->output_buffer);
@@ -155,22 +155,22 @@ static void
test_obfs2_handshake(void *state)
{
struct test_obfs2_state *s = (struct test_obfs2_state *)state;
- obfs2_protocol_t *client_state = downcast(s->client_proto);
- obfs2_protocol_t *server_state = downcast(s->server_proto);
+ obfs2_state_t *client_state = downcast(s->conn_client)->state;
+ obfs2_state_t *server_state = downcast(s->conn_server)->state;
/* We create a client handshake message and pass it to output_buffer */
- tt_int_op(0, <=, proto_handshake(s->client_proto, s->output_buffer));
+ tt_int_op(0, <=, proto_handshake(s->conn_client, s->output_buffer));
/* We simulate the server receiving and processing the client's
handshake message, by using proto_recv() on the output_buffer */
- tt_assert(RECV_GOOD == proto_recv(s->server_proto, s->output_buffer,
+ tt_assert(RECV_GOOD == proto_recv(s->conn_server, s->output_buffer,
s->dummy_buffer));
/* Now, we create the server's handshake and pass it to output_buffer */
- tt_int_op(0, <=, proto_handshake(s->server_proto, s->output_buffer));
+ tt_int_op(0, <=, proto_handshake(s->conn_server, s->output_buffer));
/* We simulate the client receiving and processing the server's handshake */
- tt_assert(RECV_GOOD == proto_recv(s->client_proto, s->output_buffer,
+ tt_assert(RECV_GOOD == proto_recv(s->conn_client, s->output_buffer,
s->dummy_buffer));
/* The handshake is now complete. We should have:
@@ -193,11 +193,11 @@ test_obfs2_transfer(void *state)
struct evbuffer_iovec v[2];
/* Handshake */
- tt_int_op(0, <=, proto_handshake(s->client_proto, s->output_buffer));
- tt_assert(RECV_GOOD == proto_recv(s->server_proto, s->output_buffer,
+ tt_int_op(0, <=, proto_handshake(s->conn_client, s->output_buffer));
+ tt_assert(RECV_GOOD == proto_recv(s->conn_server, s->output_buffer,
s->dummy_buffer));
- tt_int_op(0, <=, proto_handshake(s->server_proto, s->output_buffer));
- tt_assert(RECV_GOOD == proto_recv(s->client_proto, s->output_buffer,
+ tt_int_op(0, <=, proto_handshake(s->conn_server, s->output_buffer));
+ tt_assert(RECV_GOOD == proto_recv(s->conn_client, s->output_buffer,
s->dummy_buffer));
/* End of Handshake */
@@ -207,9 +207,9 @@ test_obfs2_transfer(void *state)
/* client -> server */
evbuffer_add(s->dummy_buffer, msg1, 54);
- proto_send(s->client_proto, s->dummy_buffer, s->output_buffer);
+ proto_send(s->conn_client, s->dummy_buffer, s->output_buffer);
- tt_assert(RECV_GOOD == proto_recv(s->server_proto, s->output_buffer,
+ tt_assert(RECV_GOOD == proto_recv(s->conn_server, s->output_buffer,
s->dummy_buffer));
n = evbuffer_peek(s->dummy_buffer, -1, NULL, &v[0], 2);
@@ -222,10 +222,10 @@ test_obfs2_transfer(void *state)
/* client <- server */
evbuffer_add(s->dummy_buffer, msg2, 55);
- tt_int_op(0, <=, proto_send(s->server_proto, s->dummy_buffer,
+ tt_int_op(0, <=, proto_send(s->conn_server, s->dummy_buffer,
s->output_buffer));
- tt_assert(RECV_GOOD == proto_recv(s->client_proto, s->output_buffer,
+ tt_assert(RECV_GOOD == proto_recv(s->conn_client, s->output_buffer,
s->dummy_buffer));
n = evbuffer_peek(s->dummy_buffer, -1, NULL, &v[1], 2);
@@ -249,8 +249,8 @@ static void
test_obfs2_split_handshake(void *state)
{
struct test_obfs2_state *s = (struct test_obfs2_state *)state;
- obfs2_protocol_t *client_state = downcast(s->client_proto);
- obfs2_protocol_t *server_state = downcast(s->server_proto);
+ obfs2_state_t *client_state = downcast(s->conn_client)->state;
+ obfs2_state_t *server_state = downcast(s->conn_server)->state;
uint32_t magic = htonl(OBFUSCATE_MAGIC_VALUE);
uint32_t plength1, plength1_msg1, plength1_msg2, send_plength1;
@@ -285,7 +285,7 @@ test_obfs2_split_handshake(void *state)
OBFUSCATE_SEED_LENGTH+8+plength1_msg1);
/* Server receives handshake part 1 */
- tt_assert(RECV_INCOMPLETE == proto_recv(s->server_proto, s->output_buffer,
+ tt_assert(RECV_INCOMPLETE == proto_recv(s->conn_server, s->output_buffer,
s->dummy_buffer));
tt_assert(server_state->state == ST_WAIT_FOR_PADDING);
@@ -298,7 +298,7 @@ test_obfs2_split_handshake(void *state)
evbuffer_add(s->output_buffer, msgclient_2, plength1_msg2);
/* Server receives handshake part 2 */
- tt_assert(RECV_GOOD == proto_recv(s->server_proto, s->output_buffer,
+ tt_assert(RECV_GOOD == proto_recv(s->conn_server, s->output_buffer,
s->dummy_buffer));
tt_assert(server_state->state == ST_OPEN);
@@ -329,7 +329,7 @@ test_obfs2_split_handshake(void *state)
evbuffer_add(s->output_buffer, msgserver_1, OBFUSCATE_SEED_LENGTH+8);
/* Client receives handshake part 1 */
- tt_assert(RECV_INCOMPLETE == proto_recv(s->client_proto, s->output_buffer,
+ tt_assert(RECV_INCOMPLETE == proto_recv(s->conn_client, s->output_buffer,
s->dummy_buffer));
tt_assert(client_state->state == ST_WAIT_FOR_PADDING);
@@ -342,7 +342,7 @@ test_obfs2_split_handshake(void *state)
evbuffer_add(s->output_buffer, msgserver_2, plength2);
/* Client receives handshake part 2 */
- tt_assert(RECV_GOOD == proto_recv(s->client_proto, s->output_buffer,
+ tt_assert(RECV_GOOD == proto_recv(s->conn_client, s->output_buffer,
s->dummy_buffer));
tt_assert(client_state->state == ST_OPEN);
@@ -367,8 +367,8 @@ static void
test_obfs2_wrong_handshake_magic(void *state)
{
struct test_obfs2_state *s = (struct test_obfs2_state *)state;
- obfs2_protocol_t *client_state = downcast(s->client_proto);
- obfs2_protocol_t *server_state = downcast(s->server_proto);
+ obfs2_state_t *client_state = downcast(s->conn_client)->state;
+ obfs2_state_t *server_state = downcast(s->conn_server)->state;
uint32_t wrong_magic = 0xD15EA5E;
@@ -391,7 +391,7 @@ test_obfs2_wrong_handshake_magic(void *state)
evbuffer_add(s->output_buffer, msg, OBFUSCATE_SEED_LENGTH+8+plength);
- tt_assert(RECV_BAD == proto_recv(s->server_proto, s->output_buffer,
+ tt_assert(RECV_BAD == proto_recv(s->conn_server, s->output_buffer,
s->dummy_buffer));
tt_assert(server_state->state == ST_WAIT_FOR_KEY);
@@ -406,8 +406,8 @@ static void
test_obfs2_wrong_handshake_plength(void *state)
{
struct test_obfs2_state *s = (struct test_obfs2_state *)state;
- obfs2_protocol_t *client_state = downcast(s->client_proto);
- obfs2_protocol_t *server_state = downcast(s->server_proto);
+ obfs2_state_t *client_state = downcast(s->conn_client)->state;
+ obfs2_state_t *server_state = downcast(s->conn_server)->state;
uchar msg[OBFUSCATE_MAX_PADDING + OBFUSCATE_SEED_LENGTH + 8 + 1];
uint32_t magic = htonl(OBFUSCATE_MAGIC_VALUE);
@@ -429,7 +429,7 @@ test_obfs2_wrong_handshake_plength(void *state)
evbuffer_add(s->output_buffer, msg, OBFUSCATE_SEED_LENGTH+8+plength);
- tt_assert(RECV_BAD == proto_recv(s->server_proto, s->output_buffer,
+ tt_assert(RECV_BAD == proto_recv(s->conn_server, s->output_buffer,
s->dummy_buffer));
tt_assert(server_state->state == ST_WAIT_FOR_KEY);
More information about the tor-commits
mailing list