test_relaycell.c 18 KB

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