test_relaycell.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  1. /* Copyright (c) 2014-2017, The Tor Project, Inc. */
  2. /* See LICENSE for licensing information */
  3. /* Unit tests for handling different kinds of relay cell */
  4. #define RELAY_PRIVATE
  5. #define CIRCUITLIST_PRIVATE
  6. #include "or.h"
  7. #include "main.h"
  8. #include "config.h"
  9. #include "connection.h"
  10. #include "crypto.h"
  11. #include "circuitbuild.h"
  12. #include "circuitlist.h"
  13. #include "connection_edge.h"
  14. #include "relay.h"
  15. #include "test.h"
  16. #include "crypt_path_st.h"
  17. #include "entry_connection_st.h"
  18. #include "origin_circuit_st.h"
  19. #include "socks_request_st.h"
  20. static int srm_ncalls;
  21. static entry_connection_t *srm_conn;
  22. static int srm_atype;
  23. static size_t srm_alen;
  24. static int srm_answer_is_set;
  25. static uint8_t srm_answer[512];
  26. static int srm_ttl;
  27. static time_t srm_expires;
  28. void connection_free_minimal(connection_t*);
  29. int connected_cell_format_payload(uint8_t *payload_out,
  30. const tor_addr_t *addr,
  31. uint32_t ttl);
  32. /* Mock replacement for connection_ap_hannshake_socks_resolved() */
  33. static void
  34. socks_resolved_mock(entry_connection_t *conn,
  35. int answer_type,
  36. size_t answer_len,
  37. const uint8_t *answer,
  38. int ttl,
  39. time_t expires)
  40. {
  41. srm_ncalls++;
  42. srm_conn = conn;
  43. srm_atype = answer_type;
  44. srm_alen = answer_len;
  45. if (answer) {
  46. memset(srm_answer, 0, sizeof(srm_answer));
  47. memcpy(srm_answer, answer, answer_len < 512 ? answer_len : 512);
  48. srm_answer_is_set = 1;
  49. } else {
  50. srm_answer_is_set = 0;
  51. }
  52. srm_ttl = ttl;
  53. srm_expires = expires;
  54. }
  55. static int mum_ncalls;
  56. static entry_connection_t *mum_conn;
  57. static int mum_endreason;
  58. /* Mock replacement for connection_mark_unattached_ap_() */
  59. static void
  60. mark_unattached_mock(entry_connection_t *conn, int endreason,
  61. int line, const char *file)
  62. {
  63. ++mum_ncalls;
  64. mum_conn = conn;
  65. mum_endreason = endreason;
  66. (void) line;
  67. (void) file;
  68. }
  69. /* Helper: Return a newly allocated and initialized origin circuit with
  70. * purpose and flags. A default HS identifier is set to an ed25519
  71. * authentication key for introduction point. */
  72. static origin_circuit_t *
  73. helper_create_origin_circuit(int purpose, int flags)
  74. {
  75. origin_circuit_t *circ = NULL;
  76. circ = origin_circuit_init(purpose, flags);
  77. tor_assert(circ);
  78. circ->cpath = tor_malloc_zero(sizeof(crypt_path_t));
  79. circ->cpath->magic = CRYPT_PATH_MAGIC;
  80. circ->cpath->state = CPATH_STATE_OPEN;
  81. circ->cpath->package_window = circuit_initial_package_window();
  82. circ->cpath->deliver_window = CIRCWINDOW_START;
  83. circ->cpath->prev = circ->cpath;
  84. /* Create a default HS identifier. */
  85. circ->hs_ident = tor_malloc_zero(sizeof(hs_ident_circuit_t));
  86. return circ;
  87. }
  88. static void
  89. mock_connection_mark_unattached_ap_(entry_connection_t *conn, int endreason,
  90. int line, const char *file)
  91. {
  92. (void) line;
  93. (void) file;
  94. conn->edge_.end_reason = endreason;
  95. }
  96. static void
  97. mock_mark_for_close(connection_t *conn,
  98. int line, const char *file)
  99. {
  100. (void)line;
  101. (void)file;
  102. conn->marked_for_close = 1;
  103. return;
  104. }
  105. static void
  106. mock_start_reading(connection_t *conn)
  107. {
  108. (void)conn;
  109. return;
  110. }
  111. static void
  112. test_circbw_relay(void *arg)
  113. {
  114. cell_t cell;
  115. relay_header_t rh;
  116. tor_addr_t addr;
  117. edge_connection_t *edgeconn;
  118. entry_connection_t *entryconn;
  119. origin_circuit_t *circ;
  120. int delivered = 0;
  121. int overhead = 0;
  122. (void)arg;
  123. #define PACK_CELL(id, cmd, body_s) do { \
  124. memset(&cell, 0, sizeof(cell)); \
  125. memset(&rh, 0, sizeof(rh)); \
  126. memcpy(cell.payload+RELAY_HEADER_SIZE, (body_s), sizeof((body_s))-1); \
  127. rh.length = sizeof((body_s))-1; \
  128. rh.command = (cmd); \
  129. rh.stream_id = (id); \
  130. relay_header_pack((uint8_t*)&cell.payload, &rh); \
  131. } while (0)
  132. #define ASSERT_COUNTED_BW() do { \
  133. tt_int_op(circ->n_delivered_read_circ_bw, OP_EQ, delivered+rh.length); \
  134. tt_int_op(circ->n_overhead_read_circ_bw, OP_EQ, \
  135. overhead+RELAY_PAYLOAD_SIZE-rh.length); \
  136. delivered = circ->n_delivered_read_circ_bw; \
  137. overhead = circ->n_overhead_read_circ_bw; \
  138. } while (0)
  139. #define ASSERT_UNCOUNTED_BW() do { \
  140. tt_int_op(circ->n_delivered_read_circ_bw, OP_EQ, delivered); \
  141. tt_int_op(circ->n_overhead_read_circ_bw, OP_EQ, overhead); \
  142. } while (0)
  143. MOCK(connection_mark_unattached_ap_, mock_connection_mark_unattached_ap_);
  144. MOCK(connection_start_reading, mock_start_reading);
  145. MOCK(connection_mark_for_close_internal_, mock_mark_for_close);
  146. entryconn = entry_connection_new(CONN_TYPE_AP, AF_INET);
  147. edgeconn = ENTRY_TO_EDGE_CONN(entryconn);
  148. edgeconn->base_.state = AP_CONN_STATE_CONNECT_WAIT;
  149. edgeconn->deliver_window = 1000;
  150. circ = helper_create_origin_circuit(CIRCUIT_PURPOSE_C_GENERAL, 0);
  151. edgeconn->cpath_layer = circ->cpath;
  152. circ->cpath->state = CPATH_STATE_AWAITING_KEYS;
  153. circ->cpath->deliver_window = 1000;
  154. /* Stream id 0: Not counted */
  155. PACK_CELL(0, RELAY_COMMAND_END, "Data1234");
  156. connection_edge_process_relay_cell(&cell, TO_CIRCUIT(circ), edgeconn,
  157. circ->cpath);
  158. ASSERT_UNCOUNTED_BW();
  159. /* Stream id 1: Counted */
  160. PACK_CELL(1, RELAY_COMMAND_END, "Data1234");
  161. connection_edge_process_relay_cell(&cell, TO_CIRCUIT(circ), edgeconn,
  162. circ->cpath);
  163. ASSERT_COUNTED_BW();
  164. /* Properly formatted connect cell: counted */
  165. PACK_CELL(1, RELAY_COMMAND_CONNECTED, "Data1234");
  166. tor_addr_parse(&addr, "30.40.50.60");
  167. rh.length = connected_cell_format_payload(cell.payload+RELAY_HEADER_SIZE,
  168. &addr, 1024);
  169. relay_header_pack((uint8_t*)&cell.payload, &rh); \
  170. connection_edge_process_relay_cell(&cell, TO_CIRCUIT(circ), edgeconn,
  171. circ->cpath);
  172. ASSERT_COUNTED_BW();
  173. /* Properly formatted resolved cell in correct state: counted */
  174. edgeconn->base_.state = AP_CONN_STATE_RESOLVE_WAIT;
  175. entryconn->socks_request->command = SOCKS_COMMAND_RESOLVE;
  176. edgeconn->on_circuit = TO_CIRCUIT(circ);
  177. PACK_CELL(1, RELAY_COMMAND_RESOLVED,
  178. "\x04\x04\x12\x00\x00\x01\x00\x00\x02\x00");
  179. connection_edge_process_relay_cell(&cell, TO_CIRCUIT(circ), edgeconn,
  180. circ->cpath);
  181. ASSERT_COUNTED_BW();
  182. edgeconn->base_.state = AP_CONN_STATE_OPEN;
  183. entryconn->socks_request->has_finished = 1;
  184. /* Connected cell after open: not counted */
  185. PACK_CELL(1, RELAY_COMMAND_CONNECTED, "Data1234");
  186. connection_edge_process_relay_cell(&cell, TO_CIRCUIT(circ), edgeconn,
  187. circ->cpath);
  188. ASSERT_UNCOUNTED_BW();
  189. /* Resolved cell after open: not counted */
  190. PACK_CELL(1, RELAY_COMMAND_RESOLVED, "Data1234");
  191. connection_edge_process_relay_cell(&cell, TO_CIRCUIT(circ), edgeconn,
  192. circ->cpath);
  193. ASSERT_UNCOUNTED_BW();
  194. /* Drop cell: not counted */
  195. PACK_CELL(1, RELAY_COMMAND_DROP, "Data1234");
  196. connection_edge_process_relay_cell(&cell, TO_CIRCUIT(circ), edgeconn,
  197. circ->cpath);
  198. ASSERT_UNCOUNTED_BW();
  199. /* Data cell on stream 0: not counted */
  200. PACK_CELL(1, RELAY_COMMAND_DATA, "Data1234");
  201. connection_edge_process_relay_cell(&cell, TO_CIRCUIT(circ), edgeconn,
  202. circ->cpath);
  203. ASSERT_UNCOUNTED_BW();
  204. /* Data cell on open connection: counted */
  205. ENTRY_TO_CONN(entryconn)->marked_for_close = 0;
  206. PACK_CELL(1, RELAY_COMMAND_DATA, "Data1234");
  207. connection_edge_process_relay_cell(&cell, TO_CIRCUIT(circ), edgeconn,
  208. circ->cpath);
  209. ASSERT_COUNTED_BW();
  210. /* Empty Data cell on open connection: not counted */
  211. ENTRY_TO_CONN(entryconn)->marked_for_close = 0;
  212. PACK_CELL(1, RELAY_COMMAND_DATA, "");
  213. connection_edge_process_relay_cell(&cell, TO_CIRCUIT(circ), edgeconn,
  214. circ->cpath);
  215. ASSERT_UNCOUNTED_BW();
  216. /* Sendme on stream: not counted */
  217. ENTRY_TO_CONN(entryconn)->outbuf_flushlen = 0;
  218. PACK_CELL(1, RELAY_COMMAND_SENDME, "Data1234");
  219. connection_edge_process_relay_cell(&cell, TO_CIRCUIT(circ), edgeconn,
  220. circ->cpath);
  221. ASSERT_UNCOUNTED_BW();
  222. /* Sendme on circuit with full window: not counted */
  223. PACK_CELL(0, RELAY_COMMAND_SENDME, "Data1234");
  224. connection_edge_process_relay_cell(&cell, TO_CIRCUIT(circ), edgeconn,
  225. circ->cpath);
  226. ASSERT_UNCOUNTED_BW();
  227. /* Sendme on circuit with non-full window: counted */
  228. PACK_CELL(0, RELAY_COMMAND_SENDME, "Data1234");
  229. circ->cpath->package_window = 900;
  230. connection_edge_process_relay_cell(&cell, TO_CIRCUIT(circ), edgeconn,
  231. circ->cpath);
  232. ASSERT_COUNTED_BW();
  233. /* End cell on non-closed connection: counted */
  234. PACK_CELL(1, RELAY_COMMAND_END, "Data1234");
  235. connection_edge_process_relay_cell(&cell, TO_CIRCUIT(circ), edgeconn,
  236. circ->cpath);
  237. ASSERT_COUNTED_BW();
  238. /* End cell on connection that already got one: not counted */
  239. PACK_CELL(1, RELAY_COMMAND_END, "Data1234");
  240. connection_edge_process_relay_cell(&cell, TO_CIRCUIT(circ), NULL,
  241. circ->cpath);
  242. ASSERT_UNCOUNTED_BW();
  243. /* Invalid extended cell: not counted */
  244. PACK_CELL(1, RELAY_COMMAND_EXTENDED2, "Data1234");
  245. connection_edge_process_relay_cell(&cell, TO_CIRCUIT(circ), NULL,
  246. circ->cpath);
  247. ASSERT_UNCOUNTED_BW();
  248. /* Invalid extended cell: not counted */
  249. PACK_CELL(1, RELAY_COMMAND_EXTENDED, "Data1234");
  250. connection_edge_process_relay_cell(&cell, TO_CIRCUIT(circ), NULL,
  251. circ->cpath);
  252. ASSERT_UNCOUNTED_BW();
  253. /* Invalid HS cell: not counted */
  254. PACK_CELL(1, RELAY_COMMAND_ESTABLISH_INTRO, "Data1234");
  255. connection_edge_process_relay_cell(&cell, TO_CIRCUIT(circ), NULL,
  256. circ->cpath);
  257. ASSERT_UNCOUNTED_BW();
  258. /* "Valid" HS cell in expected state: counted */
  259. TO_CIRCUIT(circ)->purpose = CIRCUIT_PURPOSE_C_ESTABLISH_REND;
  260. PACK_CELL(1, RELAY_COMMAND_RENDEZVOUS_ESTABLISHED, "Data1234");
  261. connection_edge_process_relay_cell(&cell, TO_CIRCUIT(circ), NULL,
  262. circ->cpath);
  263. ASSERT_COUNTED_BW();
  264. done:
  265. UNMOCK(connection_start_reading);
  266. UNMOCK(connection_mark_unattached_ap_);
  267. UNMOCK(connection_mark_for_close_internal_);
  268. circuit_free_(TO_CIRCUIT(circ));
  269. connection_free_minimal(ENTRY_TO_CONN(entryconn));
  270. }
  271. /* Tests for connection_edge_process_resolved_cell().
  272. The point of ..process_resolved_cell() is to handle an incoming cell
  273. on an entry connection, and call connection_mark_unattached_ap() and/or
  274. connection_ap_handshake_socks_resolved().
  275. */
  276. static void
  277. test_relaycell_resolved(void *arg)
  278. {
  279. entry_connection_t *entryconn;
  280. edge_connection_t *edgeconn;
  281. cell_t cell;
  282. relay_header_t rh;
  283. int r;
  284. or_options_t *options = get_options_mutable();
  285. #define SET_CELL(s) do { \
  286. memset(&cell, 0, sizeof(cell)); \
  287. memset(&rh, 0, sizeof(rh)); \
  288. memcpy(cell.payload + RELAY_HEADER_SIZE, (s), sizeof((s))-1); \
  289. rh.length = sizeof((s))-1; \
  290. rh.command = RELAY_COMMAND_RESOLVED; \
  291. } while (0)
  292. #define MOCK_RESET() do { \
  293. srm_ncalls = mum_ncalls = 0; \
  294. } while (0)
  295. #define ASSERT_MARK_CALLED(reason) do { \
  296. tt_int_op(mum_ncalls, OP_EQ, 1); \
  297. tt_ptr_op(mum_conn, OP_EQ, entryconn); \
  298. tt_int_op(mum_endreason, OP_EQ, (reason)); \
  299. } while (0)
  300. #define ASSERT_RESOLVED_CALLED(atype, answer, ttl, expires) do { \
  301. tt_int_op(srm_ncalls, OP_EQ, 1); \
  302. tt_ptr_op(srm_conn, OP_EQ, entryconn); \
  303. tt_int_op(srm_atype, OP_EQ, (atype)); \
  304. if ((answer) != NULL) { \
  305. tt_int_op(srm_alen, OP_EQ, sizeof(answer)-1); \
  306. tt_int_op(srm_alen, OP_LT, 512); \
  307. tt_int_op(srm_answer_is_set, OP_EQ, 1); \
  308. tt_mem_op(srm_answer, OP_EQ, answer, sizeof(answer)-1); \
  309. } else { \
  310. tt_int_op(srm_answer_is_set, OP_EQ, 0); \
  311. } \
  312. tt_int_op(srm_ttl, OP_EQ, ttl); \
  313. tt_i64_op(srm_expires, OP_EQ, expires); \
  314. } while (0)
  315. (void)arg;
  316. MOCK(connection_mark_unattached_ap_, mark_unattached_mock);
  317. MOCK(connection_ap_handshake_socks_resolved, socks_resolved_mock);
  318. options->ClientDNSRejectInternalAddresses = 0;
  319. SET_CELL(/* IPv4: 127.0.1.2, ttl 256 */
  320. "\x04\x04\x7f\x00\x01\x02\x00\x00\x01\x00"
  321. /* IPv4: 18.0.0.1, ttl 512 */
  322. "\x04\x04\x12\x00\x00\x01\x00\x00\x02\x00"
  323. /* IPv6: 2003::3, ttl 1024 */
  324. "\x06\x10"
  325. "\x20\x02\x00\x00\x00\x00\x00\x00"
  326. "\x00\x00\x00\x00\x00\x00\x00\x03"
  327. "\x00\x00\x04\x00");
  328. entryconn = entry_connection_new(CONN_TYPE_AP, AF_INET);
  329. edgeconn = ENTRY_TO_EDGE_CONN(entryconn);
  330. /* Try with connection in non-RESOLVE_WAIT state: cell gets ignored */
  331. MOCK_RESET();
  332. r = connection_edge_process_resolved_cell(edgeconn, &cell, &rh);
  333. tt_int_op(r, OP_EQ, 0);
  334. tt_int_op(srm_ncalls, OP_EQ, 0);
  335. tt_int_op(mum_ncalls, OP_EQ, 0);
  336. /* Now put it in the right state. */
  337. ENTRY_TO_CONN(entryconn)->state = AP_CONN_STATE_RESOLVE_WAIT;
  338. entryconn->socks_request->command = SOCKS_COMMAND_RESOLVE;
  339. entryconn->entry_cfg.ipv4_traffic = 1;
  340. entryconn->entry_cfg.ipv6_traffic = 1;
  341. entryconn->entry_cfg.prefer_ipv6 = 0;
  342. /* We prefer ipv4, so we should get the first ipv4 answer */
  343. MOCK_RESET();
  344. r = connection_edge_process_resolved_cell(edgeconn, &cell, &rh);
  345. tt_int_op(r, OP_EQ, 0);
  346. ASSERT_MARK_CALLED(END_STREAM_REASON_DONE|
  347. END_STREAM_REASON_FLAG_ALREADY_SOCKS_REPLIED);
  348. ASSERT_RESOLVED_CALLED(RESOLVED_TYPE_IPV4, "\x7f\x00\x01\x02", 256, -1);
  349. /* But we may be discarding private answers. */
  350. MOCK_RESET();
  351. options->ClientDNSRejectInternalAddresses = 1;
  352. r = connection_edge_process_resolved_cell(edgeconn, &cell, &rh);
  353. tt_int_op(r, OP_EQ, 0);
  354. ASSERT_MARK_CALLED(END_STREAM_REASON_DONE|
  355. END_STREAM_REASON_FLAG_ALREADY_SOCKS_REPLIED);
  356. ASSERT_RESOLVED_CALLED(RESOLVED_TYPE_IPV4, "\x12\x00\x00\x01", 512, -1);
  357. /* now prefer ipv6, and get the first ipv6 answer */
  358. entryconn->entry_cfg.prefer_ipv6 = 1;
  359. MOCK_RESET();
  360. r = connection_edge_process_resolved_cell(edgeconn, &cell, &rh);
  361. tt_int_op(r, OP_EQ, 0);
  362. ASSERT_MARK_CALLED(END_STREAM_REASON_DONE|
  363. END_STREAM_REASON_FLAG_ALREADY_SOCKS_REPLIED);
  364. ASSERT_RESOLVED_CALLED(RESOLVED_TYPE_IPV6,
  365. "\x20\x02\x00\x00\x00\x00\x00\x00"
  366. "\x00\x00\x00\x00\x00\x00\x00\x03",
  367. 1024, -1);
  368. /* With a cell that only has IPv4, we report IPv4 even if we prefer IPv6 */
  369. MOCK_RESET();
  370. SET_CELL("\x04\x04\x12\x00\x00\x01\x00\x00\x02\x00");
  371. r = connection_edge_process_resolved_cell(edgeconn, &cell, &rh);
  372. tt_int_op(r, OP_EQ, 0);
  373. ASSERT_MARK_CALLED(END_STREAM_REASON_DONE|
  374. END_STREAM_REASON_FLAG_ALREADY_SOCKS_REPLIED);
  375. ASSERT_RESOLVED_CALLED(RESOLVED_TYPE_IPV4, "\x12\x00\x00\x01", 512, -1);
  376. /* But if we don't allow IPv4, we report nothing if the cell contains only
  377. * ipv4 */
  378. MOCK_RESET();
  379. entryconn->entry_cfg.ipv4_traffic = 0;
  380. r = connection_edge_process_resolved_cell(edgeconn, &cell, &rh);
  381. tt_int_op(r, OP_EQ, 0);
  382. ASSERT_MARK_CALLED(END_STREAM_REASON_DONE|
  383. END_STREAM_REASON_FLAG_ALREADY_SOCKS_REPLIED);
  384. ASSERT_RESOLVED_CALLED(RESOLVED_TYPE_ERROR, NULL, -1, -1);
  385. /* If we wanted hostnames, we report nothing, since we only had IPs. */
  386. MOCK_RESET();
  387. entryconn->entry_cfg.ipv4_traffic = 1;
  388. entryconn->socks_request->command = SOCKS_COMMAND_RESOLVE_PTR;
  389. r = connection_edge_process_resolved_cell(edgeconn, &cell, &rh);
  390. tt_int_op(r, OP_EQ, 0);
  391. ASSERT_MARK_CALLED(END_STREAM_REASON_DONE|
  392. END_STREAM_REASON_FLAG_ALREADY_SOCKS_REPLIED);
  393. ASSERT_RESOLVED_CALLED(RESOLVED_TYPE_ERROR, NULL, -1, -1);
  394. /* A hostname cell is fine though. */
  395. MOCK_RESET();
  396. SET_CELL("\x00\x0fwww.example.com\x00\x01\x00\x00");
  397. r = connection_edge_process_resolved_cell(edgeconn, &cell, &rh);
  398. tt_int_op(r, OP_EQ, 0);
  399. ASSERT_MARK_CALLED(END_STREAM_REASON_DONE|
  400. END_STREAM_REASON_FLAG_ALREADY_SOCKS_REPLIED);
  401. ASSERT_RESOLVED_CALLED(RESOLVED_TYPE_HOSTNAME, "www.example.com", 65536, -1);
  402. /* error on malformed cell */
  403. MOCK_RESET();
  404. entryconn->socks_request->command = SOCKS_COMMAND_RESOLVE;
  405. SET_CELL("\x04\x04\x01\x02\x03\x04"); /* no ttl */
  406. r = connection_edge_process_resolved_cell(edgeconn, &cell, &rh);
  407. tt_int_op(r, OP_EQ, 0);
  408. ASSERT_MARK_CALLED(END_STREAM_REASON_TORPROTOCOL);
  409. tt_int_op(srm_ncalls, OP_EQ, 0);
  410. /* error on all addresses private */
  411. MOCK_RESET();
  412. SET_CELL(/* IPv4: 127.0.1.2, ttl 256 */
  413. "\x04\x04\x7f\x00\x01\x02\x00\x00\x01\x00"
  414. /* IPv4: 192.168.1.1, ttl 256 */
  415. "\x04\x04\xc0\xa8\x01\x01\x00\x00\x01\x00");
  416. r = connection_edge_process_resolved_cell(edgeconn, &cell, &rh);
  417. tt_int_op(r, OP_EQ, 0);
  418. ASSERT_MARK_CALLED(END_STREAM_REASON_TORPROTOCOL);
  419. ASSERT_RESOLVED_CALLED(RESOLVED_TYPE_ERROR_TRANSIENT, NULL, 0, TIME_MAX);
  420. /* Legit error code */
  421. MOCK_RESET();
  422. SET_CELL("\xf0\x15" "quiet and meaningless" "\x00\x00\x0f\xff");
  423. r = connection_edge_process_resolved_cell(edgeconn, &cell, &rh);
  424. tt_int_op(r, OP_EQ, 0);
  425. ASSERT_MARK_CALLED(END_STREAM_REASON_DONE|
  426. END_STREAM_REASON_FLAG_ALREADY_SOCKS_REPLIED);
  427. ASSERT_RESOLVED_CALLED(RESOLVED_TYPE_ERROR_TRANSIENT, NULL, -1, -1);
  428. done:
  429. UNMOCK(connection_mark_unattached_ap_);
  430. UNMOCK(connection_ap_handshake_socks_resolved);
  431. }
  432. struct testcase_t relaycell_tests[] = {
  433. { "resolved", test_relaycell_resolved, TT_FORK, NULL, NULL },
  434. { "circbw", test_circbw_relay, TT_FORK, NULL, NULL },
  435. END_OF_TESTCASES
  436. };