test_relaycell.c 18 KB

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