aws-crt 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (322) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/VERSION +1 -1
  4. data/aws-crt-ffi/CMakeLists.txt +49 -41
  5. data/aws-crt-ffi/crt/aws-c-auth/CMakeLists.txt +0 -10
  6. data/aws-crt-ffi/crt/aws-c-auth/include/aws/auth/credentials.h +3 -2
  7. data/aws-crt-ffi/crt/aws-c-auth/include/aws/auth/private/credentials_utils.h +4 -4
  8. data/aws-crt-ffi/crt/aws-c-auth/source/auth.c +1 -14
  9. data/aws-crt-ffi/crt/aws-c-auth/source/aws_imds_client.c +206 -68
  10. data/aws-crt-ffi/crt/aws-c-auth/source/aws_signing.c +5 -0
  11. data/aws-crt-ffi/crt/aws-c-auth/source/credentials_provider_cached.c +6 -6
  12. data/aws-crt-ffi/crt/aws-c-auth/source/credentials_provider_default_chain.c +16 -1
  13. data/aws-crt-ffi/crt/aws-c-auth/source/credentials_provider_ecs.c +0 -1
  14. data/aws-crt-ffi/crt/aws-c-auth/source/credentials_provider_process.c +0 -1
  15. data/aws-crt-ffi/crt/aws-c-auth/source/credentials_provider_sts_web_identity.c +0 -1
  16. data/aws-crt-ffi/crt/aws-c-auth/source/credentials_provider_x509.c +10 -7
  17. data/aws-crt-ffi/crt/aws-c-auth/source/credentials_utils.c +35 -26
  18. data/aws-crt-ffi/crt/aws-c-auth/source/signable_chunk.c +3 -2
  19. data/aws-crt-ffi/crt/aws-c-auth/tests/CMakeLists.txt +3 -2
  20. data/aws-crt-ffi/crt/aws-c-auth/tests/aws_imds_client_test.c +1 -0
  21. data/aws-crt-ffi/crt/aws-c-auth/tests/credentials_provider_ecs_tests.c +3 -0
  22. data/aws-crt-ffi/crt/aws-c-auth/tests/credentials_provider_process_tests.c +65 -16
  23. data/aws-crt-ffi/crt/aws-c-auth/tests/credentials_tests.c +125 -0
  24. data/aws-crt-ffi/crt/aws-c-auth/tests/sigv4_signing_tests.c +68 -46
  25. data/aws-crt-ffi/crt/aws-c-cal/CMakeLists.txt +8 -3
  26. data/aws-crt-ffi/crt/aws-c-cal/bin/run_x_platform_fuzz_corpus/main.c +9 -0
  27. data/aws-crt-ffi/crt/aws-c-cal/builder.json +11 -3
  28. data/aws-crt-ffi/crt/aws-c-cal/cmake/aws-c-cal-config.cmake +14 -5
  29. data/aws-crt-ffi/crt/aws-c-cal/source/darwin/securityframework_ecc.c +6 -6
  30. data/aws-crt-ffi/crt/aws-c-cal/source/windows/bcrypt_ecc.c +12 -12
  31. data/aws-crt-ffi/crt/aws-c-cal/tests/test_case_helper.h +14 -14
  32. data/aws-crt-ffi/crt/aws-c-common/CMakeLists.txt +21 -1
  33. data/aws-crt-ffi/crt/aws-c-common/README.md +8 -0
  34. data/aws-crt-ffi/crt/aws-c-common/cmake/AwsCFlags.cmake +20 -5
  35. data/aws-crt-ffi/crt/aws-c-common/cmake/AwsFeatureTests.cmake +7 -1
  36. data/aws-crt-ffi/crt/aws-c-common/format-check.sh +1 -1
  37. data/aws-crt-ffi/crt/aws-c-common/include/aws/common/byte_buf.h +14 -0
  38. data/aws-crt-ffi/crt/aws-c-common/include/aws/common/config.h.in +1 -0
  39. data/aws-crt-ffi/crt/{aws-c-auth/include/aws/auth → aws-c-common/include/aws/common}/external/cJSON.h +82 -74
  40. data/aws-crt-ffi/crt/aws-c-common/include/aws/common/json.h +335 -0
  41. data/aws-crt-ffi/crt/aws-c-common/include/aws/common/logging.h +1 -0
  42. data/aws-crt-ffi/crt/aws-c-common/include/aws/common/math.inl +2 -2
  43. data/aws-crt-ffi/crt/aws-c-common/include/aws/common/private/json_impl.h +22 -0
  44. data/aws-crt-ffi/crt/aws-c-common/include/aws/testing/aws_test_harness.h +2 -0
  45. data/aws-crt-ffi/crt/aws-c-common/source/byte_buf.c +36 -0
  46. data/aws-crt-ffi/crt/aws-c-common/source/common.c +5 -2
  47. data/aws-crt-ffi/crt/aws-c-common/source/external/cJSON.c +3113 -0
  48. data/aws-crt-ffi/crt/aws-c-common/source/file.c +9 -0
  49. data/aws-crt-ffi/crt/aws-c-common/source/json.c +348 -0
  50. data/aws-crt-ffi/crt/aws-c-common/source/logging.c +7 -2
  51. data/aws-crt-ffi/crt/aws-c-common/source/posix/system_info.c +8 -0
  52. data/aws-crt-ffi/crt/aws-c-common/source/ref_count.c +3 -1
  53. data/aws-crt-ffi/crt/aws-c-common/source/windows/file.c +47 -0
  54. data/aws-crt-ffi/crt/aws-c-common/source/windows/system_info.c +2 -1
  55. data/aws-crt-ffi/crt/aws-c-common/tests/CMakeLists.txt +5 -0
  56. data/aws-crt-ffi/crt/aws-c-common/tests/byte_buf_test.c +69 -0
  57. data/aws-crt-ffi/crt/aws-c-common/tests/json_test.c +134 -0
  58. data/aws-crt-ffi/crt/aws-c-common/tests/memtrace_test.c +6 -2
  59. data/aws-crt-ffi/crt/aws-c-event-stream/README.md +18 -35
  60. data/aws-crt-ffi/crt/aws-c-event-stream/include/aws/event-stream/event_stream.h +21 -2
  61. data/aws-crt-ffi/crt/aws-c-event-stream/include/aws/event-stream/event_stream_rpc_client.h +14 -2
  62. data/aws-crt-ffi/crt/aws-c-event-stream/include/aws/event-stream/event_stream_rpc_server.h +13 -0
  63. data/aws-crt-ffi/crt/aws-c-event-stream/include/aws/event-stream/private/event_stream_rpc_priv.h +7 -7
  64. data/aws-crt-ffi/crt/aws-c-event-stream/source/event_stream.c +257 -141
  65. data/aws-crt-ffi/crt/aws-c-event-stream/source/event_stream_channel_handler.c +1 -1
  66. data/aws-crt-ffi/crt/aws-c-event-stream/source/event_stream_rpc_client.c +31 -8
  67. data/aws-crt-ffi/crt/aws-c-event-stream/source/event_stream_rpc_server.c +63 -10
  68. data/aws-crt-ffi/crt/aws-c-event-stream/tests/CMakeLists.txt +2 -0
  69. data/aws-crt-ffi/crt/aws-c-event-stream/tests/event_stream_rpc_client_connection_test.c +157 -106
  70. data/aws-crt-ffi/crt/aws-c-event-stream/tests/event_stream_rpc_server_connection_test.c +168 -1
  71. data/aws-crt-ffi/crt/aws-c-event-stream/tests/message_deserializer_test.c +4 -2
  72. data/aws-crt-ffi/crt/aws-c-http/CMakeLists.txt +1 -0
  73. data/aws-crt-ffi/crt/aws-c-http/README.md +8 -0
  74. data/aws-crt-ffi/crt/aws-c-http/bin/elasticurl/main.c +1 -1
  75. data/aws-crt-ffi/crt/aws-c-http/builder.json +4 -3
  76. data/aws-crt-ffi/crt/aws-c-http/include/aws/http/connection.h +8 -1
  77. data/aws-crt-ffi/crt/aws-c-http/include/aws/http/connection_manager.h +45 -1
  78. data/aws-crt-ffi/crt/aws-c-http/include/aws/http/http2_stream_manager.h +63 -12
  79. data/aws-crt-ffi/crt/aws-c-http/include/aws/http/private/connection_impl.h +2 -1
  80. data/aws-crt-ffi/crt/aws-c-http/include/aws/http/private/h2_connection.h +20 -2
  81. data/aws-crt-ffi/crt/aws-c-http/include/aws/http/private/h2_frames.h +1 -0
  82. data/aws-crt-ffi/crt/aws-c-http/include/aws/http/private/h2_stream.h +42 -13
  83. data/aws-crt-ffi/crt/aws-c-http/include/aws/http/private/http2_stream_manager_impl.h +17 -0
  84. data/aws-crt-ffi/crt/aws-c-http/include/aws/http/private/http_impl.h +3 -0
  85. data/aws-crt-ffi/crt/aws-c-http/include/aws/http/private/random_access_set.h +10 -3
  86. data/aws-crt-ffi/crt/aws-c-http/include/aws/http/private/request_response_impl.h +3 -17
  87. data/aws-crt-ffi/crt/aws-c-http/include/aws/http/request_response.h +108 -4
  88. data/aws-crt-ffi/crt/aws-c-http/include/aws/http/statistics.h +22 -0
  89. data/aws-crt-ffi/crt/aws-c-http/source/connection.c +8 -3
  90. data/aws-crt-ffi/crt/aws-c-http/source/connection_manager.c +22 -3
  91. data/aws-crt-ffi/crt/aws-c-http/source/connection_monitor.c +32 -14
  92. data/aws-crt-ffi/crt/aws-c-http/source/h1_connection.c +14 -0
  93. data/aws-crt-ffi/crt/aws-c-http/source/h1_encoder.c +7 -4
  94. data/aws-crt-ffi/crt/aws-c-http/source/h2_connection.c +161 -45
  95. data/aws-crt-ffi/crt/aws-c-http/source/h2_decoder.c +37 -8
  96. data/aws-crt-ffi/crt/aws-c-http/source/h2_frames.c +13 -1
  97. data/aws-crt-ffi/crt/aws-c-http/source/h2_stream.c +345 -87
  98. data/aws-crt-ffi/crt/aws-c-http/source/hpack.c +3 -0
  99. data/aws-crt-ffi/crt/aws-c-http/source/http.c +3 -0
  100. data/aws-crt-ffi/crt/aws-c-http/source/http2_stream_manager.c +266 -39
  101. data/aws-crt-ffi/crt/aws-c-http/source/random_access_set.c +9 -3
  102. data/aws-crt-ffi/crt/aws-c-http/source/request_response.c +80 -20
  103. data/aws-crt-ffi/crt/aws-c-http/source/statistics.c +11 -0
  104. data/aws-crt-ffi/crt/aws-c-http/tests/CMakeLists.txt +28 -1
  105. data/aws-crt-ffi/crt/aws-c-http/tests/fuzz/fuzz_h2_decoder_correct.c +5 -3
  106. data/aws-crt-ffi/crt/aws-c-http/tests/h2_test_helper.c +133 -29
  107. data/aws-crt-ffi/crt/aws-c-http/tests/h2_test_helper.h +6 -0
  108. data/aws-crt-ffi/crt/aws-c-http/tests/py_localhost/README.md +40 -0
  109. data/aws-crt-ffi/crt/aws-c-http/tests/py_localhost/non_tls_server.py +56 -0
  110. data/aws-crt-ffi/crt/aws-c-http/tests/py_localhost/server.py +329 -0
  111. data/aws-crt-ffi/crt/aws-c-http/tests/test_connection_manager.c +1 -1
  112. data/aws-crt-ffi/crt/aws-c-http/tests/test_connection_monitor.c +2 -2
  113. data/aws-crt-ffi/crt/aws-c-http/tests/test_h1_client.c +47 -34
  114. data/aws-crt-ffi/crt/aws-c-http/tests/test_h1_encoder.c +4 -4
  115. data/aws-crt-ffi/crt/aws-c-http/tests/test_h1_server.c +15 -12
  116. data/aws-crt-ffi/crt/aws-c-http/tests/test_h2_client.c +582 -25
  117. data/aws-crt-ffi/crt/aws-c-http/tests/test_h2_encoder.c +3 -3
  118. data/aws-crt-ffi/crt/aws-c-http/tests/test_localhost_integ.c +530 -0
  119. data/aws-crt-ffi/crt/aws-c-http/tests/test_stream_manager.c +459 -67
  120. data/aws-crt-ffi/crt/aws-c-io/CMakeLists.txt +4 -0
  121. data/aws-crt-ffi/crt/aws-c-io/builder.json +3 -2
  122. data/aws-crt-ffi/crt/aws-c-io/include/aws/io/channel.h +21 -0
  123. data/aws-crt-ffi/crt/aws-c-io/include/aws/io/io.h +3 -0
  124. data/aws-crt-ffi/crt/aws-c-io/include/aws/io/socket.h +6 -0
  125. data/aws-crt-ffi/crt/aws-c-io/include/aws/io/stream.h +35 -5
  126. data/aws-crt-ffi/crt/aws-c-io/include/aws/io/tls_channel_handler.h +211 -15
  127. data/aws-crt-ffi/crt/aws-c-io/source/channel.c +56 -30
  128. data/aws-crt-ffi/crt/aws-c-io/source/darwin/secure_transport_tls_channel_handler.c +0 -24
  129. data/aws-crt-ffi/crt/aws-c-io/source/io.c +9 -0
  130. data/aws-crt-ffi/crt/aws-c-io/source/{pkcs11.c → pkcs11_lib.c} +162 -22
  131. data/aws-crt-ffi/crt/aws-c-io/source/pkcs11_private.h +18 -20
  132. data/aws-crt-ffi/crt/aws-c-io/source/pkcs11_tls_op_handler.c +221 -0
  133. data/aws-crt-ffi/crt/aws-c-io/source/posix/socket.c +135 -81
  134. data/aws-crt-ffi/crt/aws-c-io/source/retry_strategy.c +12 -8
  135. data/aws-crt-ffi/crt/aws-c-io/source/s2n/s2n_tls_channel_handler.c +252 -215
  136. data/aws-crt-ffi/crt/aws-c-io/source/stream.c +65 -82
  137. data/aws-crt-ffi/crt/aws-c-io/source/tls_channel_handler.c +188 -57
  138. data/aws-crt-ffi/crt/aws-c-io/source/windows/iocp/socket.c +271 -256
  139. data/aws-crt-ffi/crt/aws-c-io/tests/CMakeLists.txt +21 -12
  140. data/aws-crt-ffi/crt/aws-c-io/tests/channel_test.c +32 -4
  141. data/aws-crt-ffi/crt/aws-c-io/tests/io_lib_test.c +37 -0
  142. data/aws-crt-ffi/crt/aws-c-io/tests/pkcs11_test.c +412 -93
  143. data/aws-crt-ffi/crt/aws-c-io/tests/resources/ec_unittests.crt +15 -0
  144. data/aws-crt-ffi/crt/aws-c-io/tests/resources/ec_unittests.key +5 -0
  145. data/aws-crt-ffi/crt/aws-c-io/tests/resources/ec_unittests.p12 +0 -0
  146. data/aws-crt-ffi/crt/aws-c-io/tests/resources/ec_unittests.p8 +5 -0
  147. data/aws-crt-ffi/crt/aws-c-io/tests/resources/generateCerts.sh +24 -15
  148. data/aws-crt-ffi/crt/aws-c-io/tests/socket_test.c +72 -1
  149. data/aws-crt-ffi/crt/s2n/CMakeLists.txt +6 -1
  150. data/aws-crt-ffi/crt/s2n/bindings/rust/Cargo.toml +1 -0
  151. data/aws-crt-ffi/crt/s2n/bindings/rust/generate/src/main.rs +105 -82
  152. data/aws-crt-ffi/crt/s2n/bindings/rust/generate.sh +1 -0
  153. data/aws-crt-ffi/crt/s2n/bindings/rust/s2n-tls/Cargo.toml +2 -2
  154. data/aws-crt-ffi/crt/s2n/bindings/rust/s2n-tls/src/raw/config.rs +1 -1
  155. data/aws-crt-ffi/crt/s2n/bindings/rust/s2n-tls-sys/Cargo.toml +1 -1
  156. data/aws-crt-ffi/crt/s2n/bindings/rust/s2n-tls-sys/build.rs +84 -30
  157. data/aws-crt-ffi/crt/s2n/bindings/rust/s2n-tls-sys/src/lib.rs +4 -0
  158. data/aws-crt-ffi/crt/s2n/bindings/rust/s2n-tls-tokio/Cargo.toml +21 -0
  159. data/aws-crt-ffi/crt/s2n/bindings/rust/s2n-tls-tokio/examples/certs/cert.pem +14 -0
  160. data/aws-crt-ffi/crt/s2n/bindings/rust/s2n-tls-tokio/examples/certs/key.pem +8 -0
  161. data/aws-crt-ffi/crt/s2n/bindings/rust/s2n-tls-tokio/examples/client.rs +45 -0
  162. data/aws-crt-ffi/crt/s2n/bindings/rust/s2n-tls-tokio/examples/server.rs +60 -0
  163. data/aws-crt-ffi/crt/s2n/bindings/rust/s2n-tls-tokio/src/lib.rs +150 -0
  164. data/aws-crt-ffi/crt/s2n/bindings/rust/s2n-tls-tokio/tests/handshake.rs +51 -0
  165. data/aws-crt-ffi/crt/s2n/crypto/s2n_drbg.c +98 -77
  166. data/aws-crt-ffi/crt/s2n/crypto/s2n_drbg.h +10 -7
  167. data/aws-crt-ffi/crt/s2n/crypto/s2n_openssl.h +2 -0
  168. data/aws-crt-ffi/crt/s2n/error/s2n_errno.c +1 -1
  169. data/aws-crt-ffi/crt/s2n/error/s2n_errno.h +1 -0
  170. data/aws-crt-ffi/crt/s2n/s2n.mk +7 -0
  171. data/aws-crt-ffi/crt/s2n/tests/cbmc/templates/scripts/repository.py +233 -0
  172. data/aws-crt-ffi/crt/s2n/tests/cbmc/templates/scripts/setup-proof.py +8 -7
  173. data/aws-crt-ffi/crt/s2n/tests/cbmc/templates/scripts/setup.py +17 -18
  174. data/aws-crt-ffi/crt/s2n/tests/cbmc/templates/scripts/util.py +41 -23
  175. data/aws-crt-ffi/crt/s2n/tests/fuzz/LD_PRELOAD/global_overrides.c +3 -3
  176. data/aws-crt-ffi/crt/s2n/tests/integration/s2n_client_endpoint_handshake_test.py +2 -2
  177. data/aws-crt-ffi/crt/s2n/tests/integrationv2/Makefile +13 -42
  178. data/aws-crt-ffi/crt/s2n/tests/integrationv2/README.md +6 -1
  179. data/aws-crt-ffi/crt/s2n/tests/integrationv2/common.py +118 -53
  180. data/aws-crt-ffi/crt/s2n/tests/integrationv2/configuration.py +108 -88
  181. data/aws-crt-ffi/crt/s2n/tests/integrationv2/conftest.py +6 -3
  182. data/aws-crt-ffi/crt/s2n/tests/integrationv2/constants.py +6 -4
  183. data/aws-crt-ffi/crt/s2n/tests/integrationv2/fixtures.py +21 -12
  184. data/aws-crt-ffi/crt/s2n/tests/integrationv2/global_flags.py +1 -0
  185. data/aws-crt-ffi/crt/s2n/tests/integrationv2/processes.py +62 -19
  186. data/aws-crt-ffi/crt/s2n/tests/integrationv2/providers.py +304 -48
  187. data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_client_authentication.py +20 -11
  188. data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_cross_compatibility.py +41 -17
  189. data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_dynamic_record_sizes.py +6 -3
  190. data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_early_data.py +105 -48
  191. data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_external_psk.py +160 -76
  192. data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_fragmentation.py +59 -26
  193. data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_happy_path.py +42 -28
  194. data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_hello_retry_requests.py +33 -13
  195. data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_key_update.py +29 -11
  196. data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_ocsp.py +138 -0
  197. data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_pq_handshake.py +103 -36
  198. data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_session_resumption.py +52 -25
  199. data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_signature_algorithms.py +47 -21
  200. data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_sni_match.py +13 -9
  201. data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_sslyze.py +88 -17
  202. data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_version_negotiation.py +71 -22
  203. data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_well_known_endpoints.py +4 -3
  204. data/aws-crt-ffi/crt/s2n/tests/integrationv2/tox.ini +1 -0
  205. data/aws-crt-ffi/crt/s2n/tests/integrationv2/utils.py +50 -15
  206. data/aws-crt-ffi/crt/s2n/tests/litani/CHANGELOG +131 -0
  207. data/aws-crt-ffi/crt/s2n/tests/litani/CONTRIBUTING.md +16 -0
  208. data/aws-crt-ffi/crt/s2n/tests/litani/README.md +36 -14
  209. data/aws-crt-ffi/crt/s2n/tests/litani/THIRD-PARTY +205 -41
  210. data/aws-crt-ffi/crt/s2n/tests/litani/doc/bin/build-html-doc +7 -7
  211. data/aws-crt-ffi/crt/s2n/tests/litani/doc/configure +27 -23
  212. data/aws-crt-ffi/crt/s2n/tests/litani/doc/src/man/litani-add-job.scdoc +7 -0
  213. data/aws-crt-ffi/crt/s2n/tests/litani/doc/src/man/litani-dump-run.scdoc +7 -5
  214. data/aws-crt-ffi/crt/s2n/tests/litani/doc/src/man/litani-transform-jobs.scdoc +248 -0
  215. data/aws-crt-ffi/crt/s2n/tests/litani/doc/src/man/litani.scdoc +2 -2
  216. data/aws-crt-ffi/crt/s2n/tests/litani/doc/templates/index.jinja.html +4 -0
  217. data/aws-crt-ffi/crt/s2n/tests/litani/examples/add-root-node/README +12 -0
  218. data/aws-crt-ffi/crt/s2n/tests/litani/examples/add-root-node/original-run.sh +52 -0
  219. data/aws-crt-ffi/crt/s2n/tests/litani/examples/add-root-node/run-all.py +71 -0
  220. data/aws-crt-ffi/crt/s2n/tests/litani/examples/no-standalone-transform/README +13 -0
  221. data/aws-crt-ffi/crt/s2n/tests/litani/examples/no-standalone-transform/run-1.sh +34 -0
  222. data/aws-crt-ffi/crt/s2n/tests/litani/examples/no-standalone-transform/run-2.sh +35 -0
  223. data/aws-crt-ffi/crt/s2n/tests/litani/examples/no-standalone-transform/run-3.sh +34 -0
  224. data/aws-crt-ffi/crt/s2n/tests/litani/examples/no-standalone-transform/run-all.py +60 -0
  225. data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/README.md +10 -0
  226. data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/assumptions.html +42 -0
  227. data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/file.dat +7 -0
  228. data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/histogram.dat +7 -0
  229. data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/run-1.sh +41 -0
  230. data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/run-2.sh +47 -0
  231. data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/run-3.sh +41 -0
  232. data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/run-all.py +34 -0
  233. data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/scripts/fib-table.py +40 -0
  234. data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/scripts/fib.plt +5 -0
  235. data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/scripts/fib.py +32 -0
  236. data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/scripts/sin-output.py +40 -0
  237. data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/scripts/sin.plt +5 -0
  238. data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/scripts/sin.py +30 -0
  239. data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/templates/fib-table.jinja.html +45 -0
  240. data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/templates/sin-output.jinja.html +30 -0
  241. data/aws-crt-ffi/crt/s2n/tests/litani/lib/add_job.py +55 -0
  242. data/aws-crt-ffi/crt/s2n/tests/litani/lib/graph.py +2 -2
  243. data/aws-crt-ffi/crt/s2n/tests/litani/lib/litani.py +6 -1
  244. data/aws-crt-ffi/crt/s2n/tests/litani/lib/litani_report.py +18 -21
  245. data/aws-crt-ffi/crt/s2n/tests/litani/lib/ninja.py +2 -0
  246. data/aws-crt-ffi/crt/s2n/tests/litani/lib/run_printer.py +26 -7
  247. data/aws-crt-ffi/crt/s2n/tests/litani/lib/transform_jobs.py +84 -0
  248. data/aws-crt-ffi/crt/s2n/tests/litani/litani +28 -33
  249. data/aws-crt-ffi/crt/s2n/tests/litani/script/release +220 -0
  250. data/aws-crt-ffi/crt/s2n/tests/litani/templates/dashboard.jinja.html +78 -15
  251. data/aws-crt-ffi/crt/s2n/tests/litani/templates/pipeline.jinja.html +21 -5
  252. data/aws-crt-ffi/crt/s2n/tests/litani/test/README +15 -0
  253. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/run +56 -33
  254. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/custom_stages.py +1 -0
  255. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/cwd.py +1 -0
  256. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/dump_run.py +1 -0
  257. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/graph_line_break.py +1 -0
  258. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/html_node.py +1 -0
  259. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/job_id_env.py +1 -0
  260. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/multiproc_dump_run.py +1 -0
  261. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/no_pool_serialize.py +1 -0
  262. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/no_pool_serialize_graph.py +1 -0
  263. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/no_timed_out.py +1 -0
  264. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/no_timed_out_timeout_ignored.py +1 -0
  265. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/no_timed_out_timeout_ok.py +1 -0
  266. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/pipeline_order.py +53 -0
  267. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/pool_serialize.py +1 -0
  268. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/pool_serialize_graph.py +1 -0
  269. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/single_pool.py +1 -0
  270. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/timed_out.py +1 -0
  271. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/timed_out_subprocess.py +1 -0
  272. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/timed_out_subprocess_multi_shell.py +1 -0
  273. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/timed_out_subprocess_shell.py +1 -0
  274. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/timed_out_timeout_ignored.py +1 -0
  275. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/timed_out_timeout_ok.py +1 -0
  276. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/transform_delete_job.py +54 -0
  277. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/transform_modify_job.py +46 -0
  278. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/transform_no_change_job.py +44 -0
  279. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/zero_pool.py +1 -0
  280. data/aws-crt-ffi/crt/s2n/tests/litani/test/run +82 -12
  281. data/aws-crt-ffi/crt/s2n/tests/s2n_test.h +58 -33
  282. data/aws-crt-ffi/crt/s2n/tests/testlib/s2n_key_schedule_testlib.c +18 -6
  283. data/aws-crt-ffi/crt/s2n/tests/testlib/s2n_pq_kat_test_utils.c +4 -4
  284. data/aws-crt-ffi/crt/s2n/tests/testlib/s2n_testlib.h +2 -0
  285. data/aws-crt-ffi/crt/s2n/tests/unit/s2n_client_hello_retry_test.c +66 -2
  286. data/aws-crt-ffi/crt/s2n/tests/unit/s2n_connection_test.c +1 -1
  287. data/aws-crt-ffi/crt/s2n/tests/unit/s2n_drbg_test.c +34 -14
  288. data/aws-crt-ffi/crt/s2n/tests/unit/s2n_fork_generation_number_test.c +28 -5
  289. data/aws-crt-ffi/crt/s2n/tests/unit/s2n_mem_usage_test.c +6 -0
  290. data/aws-crt-ffi/crt/s2n/tests/unit/s2n_override_openssl_random_test.c +1 -1
  291. data/aws-crt-ffi/crt/s2n/tests/unit/s2n_random_test.c +60 -41
  292. data/aws-crt-ffi/crt/s2n/tests/unit/s2n_self_talk_broken_pipe_test.c +2 -2
  293. data/aws-crt-ffi/crt/s2n/tests/unit/s2n_tls13_handshake_early_data_test.c +3 -1
  294. data/aws-crt-ffi/crt/s2n/tests/unit/s2n_tls13_hybrid_shared_secret_test.c +9 -1
  295. data/aws-crt-ffi/crt/s2n/tests/unit/s2n_tls13_key_schedule_rfc8448_test.c +31 -130
  296. data/aws-crt-ffi/crt/s2n/tests/unit/s2n_tls13_key_schedule_test.c +2 -4
  297. data/aws-crt-ffi/crt/s2n/tests/unit/s2n_tls13_pq_handshake_test.c +11 -6
  298. data/aws-crt-ffi/crt/s2n/tests/unit/s2n_tls13_secrets_rfc8448_test.c +19 -21
  299. data/aws-crt-ffi/crt/s2n/tests/unit/s2n_tls13_secrets_test.c +109 -60
  300. data/aws-crt-ffi/crt/s2n/tls/s2n_config.c +1 -0
  301. data/aws-crt-ffi/crt/s2n/tls/s2n_config.h +1 -1
  302. data/aws-crt-ffi/crt/s2n/tls/s2n_connection.c +29 -24
  303. data/aws-crt-ffi/crt/s2n/tls/s2n_connection.h +5 -5
  304. data/aws-crt-ffi/crt/s2n/tls/s2n_handshake_hashes.h +1 -7
  305. data/aws-crt-ffi/crt/s2n/tls/s2n_handshake_io.c +2 -0
  306. data/aws-crt-ffi/crt/s2n/tls/s2n_handshake_transcript.c +0 -44
  307. data/aws-crt-ffi/crt/s2n/tls/s2n_internal.h +0 -1
  308. data/aws-crt-ffi/crt/s2n/tls/s2n_quic_support.h +1 -1
  309. data/aws-crt-ffi/crt/s2n/tls/s2n_tls13_key_schedule.c +1 -2
  310. data/aws-crt-ffi/crt/s2n/tls/s2n_tls13_secrets.c +84 -44
  311. data/aws-crt-ffi/crt/s2n/tls/s2n_tls13_secrets.h +3 -9
  312. data/aws-crt-ffi/crt/s2n/utils/s2n_blob.h +15 -8
  313. data/aws-crt-ffi/crt/s2n/utils/s2n_fork_detection.c +2 -6
  314. data/aws-crt-ffi/crt/s2n/utils/s2n_random.c +9 -9
  315. data/aws-crt-ffi/src/input_stream.c +32 -15
  316. data/ext/compile.rb +13 -5
  317. data/lib/aws-crt/platforms.rb +14 -5
  318. data/lib/aws-crt/string_blob.rb +3 -3
  319. metadata +61 -7
  320. data/aws-crt-ffi/crt/aws-c-auth/source/external/cJSON.c +0 -2987
  321. data/aws-crt-ffi/crt/aws-c-auth/tests/external/cJSON.c +0 -2986
  322. data/aws-crt-ffi/crt/aws-c-io/tests/error_test.c +0 -20
@@ -76,6 +76,8 @@ static struct tester {
76
76
  struct testing_channel testing_channel;
77
77
  struct h2_fake_peer peer;
78
78
  struct connection_user_data user_data;
79
+
80
+ bool no_conn_manual_win_management;
79
81
  } s_tester;
80
82
 
81
83
  static int s_tester_init(struct aws_allocator *alloc, void *ctx) {
@@ -99,6 +101,7 @@ static int s_tester_init(struct aws_allocator *alloc, void *ctx) {
99
101
  .max_closed_streams = AWS_HTTP2_DEFAULT_MAX_CLOSED_STREAMS,
100
102
  .on_goaway_received = s_on_goaway_received,
101
103
  .on_remote_settings_change = s_on_remote_settings_change,
104
+ .conn_manual_window_management = !s_tester.no_conn_manual_win_management,
102
105
  };
103
106
 
104
107
  s_tester.connection =
@@ -315,7 +318,7 @@ TEST_CASE(h2_client_auto_ping_ack_higher_priority) {
315
318
  /* clean up */
316
319
  aws_http_message_release(request);
317
320
  client_stream_tester_clean_up(&stream_tester);
318
- aws_input_stream_destroy(request_body);
321
+ aws_input_stream_release(request_body);
319
322
  return s_tester_clean_up();
320
323
  }
321
324
 
@@ -561,6 +564,7 @@ TEST_CASE(h2_client_stream_with_h1_request_message) {
561
564
  DEFINE_HEADER("Accept", "*/*"),
562
565
  DEFINE_HEADER("Host", "example.com"),
563
566
  DEFINE_HEADER("Content-Length", "5"),
567
+ DEFINE_HEADER("Upgrade", "HTTP/2.0"), /* Connection-specific header should be skiped */
564
568
  };
565
569
  aws_http_message_add_header_array(request, request_headers_src, AWS_ARRAY_SIZE(request_headers_src));
566
570
  /* body */
@@ -580,6 +584,7 @@ TEST_CASE(h2_client_stream_with_h1_request_message) {
580
584
  struct aws_http_header expected_headers_src[] = {
581
585
  DEFINE_HEADER(":method", "POST"),
582
586
  DEFINE_HEADER(":scheme", "https"),
587
+ DEFINE_HEADER(":authority", "example.com"),
583
588
  DEFINE_HEADER(":path", "/"),
584
589
  DEFINE_HEADER("accept", "*/*"),
585
590
  DEFINE_HEADER("host", "example.com"),
@@ -632,6 +637,7 @@ TEST_CASE(h2_client_stream_with_cookies_headers) {
632
637
  struct aws_http_header expected_headers_src[] = {
633
638
  DEFINE_HEADER(":method", "GET"),
634
639
  DEFINE_HEADER(":scheme", "https"),
640
+ DEFINE_HEADER(":authority", "example.com"),
635
641
  DEFINE_HEADER(":path", "/"),
636
642
  DEFINE_HEADER("accept", "*/*"),
637
643
  DEFINE_HEADER("host", "example.com"),
@@ -787,7 +793,7 @@ TEST_CASE(h2_client_stream_err_state_forbids_frame) {
787
793
  aws_http_headers_release(response_headers);
788
794
  aws_http_message_release(request);
789
795
  client_stream_tester_clean_up(&stream_tester);
790
- aws_input_stream_destroy(request_body);
796
+ aws_input_stream_release(request_body);
791
797
  return s_tester_clean_up();
792
798
  }
793
799
 
@@ -1452,6 +1458,70 @@ TEST_CASE(h2_client_stream_err_receive_data_before_headers) {
1452
1458
  return s_tester_clean_up();
1453
1459
  }
1454
1460
 
1461
+ /* A message is malformed if DATA is received not match the content_length received */
1462
+ TEST_CASE(h2_client_stream_err_receive_data_not_match_content_length) {
1463
+ ASSERT_SUCCESS(s_tester_init(allocator, ctx));
1464
+
1465
+ /* fake peer sends connection preface */
1466
+ ASSERT_SUCCESS(h2_fake_peer_send_connection_preface_default_settings(&s_tester.peer));
1467
+ testing_channel_drain_queued_tasks(&s_tester.testing_channel);
1468
+
1469
+ /* send request */
1470
+ struct aws_http_message *request = aws_http2_message_new_request(allocator);
1471
+ ASSERT_NOT_NULL(request);
1472
+
1473
+ struct aws_http_header request_headers_src[] = {
1474
+ DEFINE_HEADER(":method", "GET"),
1475
+ DEFINE_HEADER(":scheme", "https"),
1476
+ DEFINE_HEADER(":path", "/"),
1477
+ };
1478
+ aws_http_message_add_header_array(request, request_headers_src, AWS_ARRAY_SIZE(request_headers_src));
1479
+
1480
+ struct client_stream_tester stream_tester;
1481
+ ASSERT_SUCCESS(s_stream_tester_init(&stream_tester, request));
1482
+ testing_channel_drain_queued_tasks(&s_tester.testing_channel);
1483
+
1484
+ uint32_t stream_id = aws_http_stream_get_id(stream_tester.stream);
1485
+
1486
+ /* fake peer sends response headers */
1487
+ struct aws_http_header response_headers_src[] = {
1488
+ DEFINE_HEADER(":status", "200"),
1489
+ DEFINE_HEADER("content-length", "200"),
1490
+ };
1491
+
1492
+ struct aws_http_headers *response_headers = aws_http_headers_new(allocator);
1493
+ aws_http_headers_add_array(response_headers, response_headers_src, AWS_ARRAY_SIZE(response_headers_src));
1494
+
1495
+ struct aws_h2_frame *response_frame =
1496
+ aws_h2_frame_new_headers(allocator, stream_id, response_headers, false /*end_stream*/, 0, NULL);
1497
+ ASSERT_SUCCESS(h2_fake_peer_send_frame(&s_tester.peer, response_frame));
1498
+
1499
+ /* fake peer sends response body */
1500
+ const char *body_src = "hello";
1501
+ ASSERT_SUCCESS(h2_fake_peer_send_data_frame_str(&s_tester.peer, stream_id, body_src, true /*end_stream*/));
1502
+
1503
+ /* validate that stream completed with error */
1504
+ testing_channel_drain_queued_tasks(&s_tester.testing_channel);
1505
+ ASSERT_TRUE(stream_tester.complete);
1506
+ ASSERT_INT_EQUALS(AWS_ERROR_HTTP_PROTOCOL_ERROR, stream_tester.on_complete_error_code);
1507
+
1508
+ /* a stream error should not affect the connection */
1509
+ ASSERT_TRUE(aws_http_connection_is_open(s_tester.connection));
1510
+
1511
+ /* validate that stream sent RST_STREAM */
1512
+ ASSERT_SUCCESS(h2_fake_peer_decode_messages_from_testing_channel(&s_tester.peer));
1513
+ struct h2_decoded_frame *rst_stream_frame =
1514
+ h2_decode_tester_find_stream_frame(&s_tester.peer.decode, AWS_H2_FRAME_T_RST_STREAM, stream_id, 0, NULL);
1515
+ ASSERT_INT_EQUALS(AWS_H2_FRAME_T_RST_STREAM, rst_stream_frame->type);
1516
+ ASSERT_UINT_EQUALS(AWS_HTTP2_ERR_PROTOCOL_ERROR, rst_stream_frame->error_code);
1517
+
1518
+ /* clean up */
1519
+ aws_http_headers_release(response_headers);
1520
+ aws_http_message_release(request);
1521
+ client_stream_tester_clean_up(&stream_tester);
1522
+ return s_tester_clean_up();
1523
+ }
1524
+
1455
1525
  /* Test sending a request with DATA frames */
1456
1526
  TEST_CASE(h2_client_stream_send_data) {
1457
1527
  ASSERT_SUCCESS(s_tester_init(allocator, ctx));
@@ -1521,7 +1591,7 @@ TEST_CASE(h2_client_stream_send_data) {
1521
1591
  aws_http_headers_release(response_headers);
1522
1592
  aws_http_message_release(request);
1523
1593
  client_stream_tester_clean_up(&stream_tester);
1524
- aws_input_stream_destroy(request_body);
1594
+ aws_input_stream_release(request_body);
1525
1595
  return s_tester_clean_up();
1526
1596
  }
1527
1597
 
@@ -1669,7 +1739,7 @@ TEST_CASE(h2_client_stream_send_lots_of_data) {
1669
1739
  for (size_t i = 0; i < NUM_STREAMS; ++i) {
1670
1740
  client_stream_tester_clean_up(&stream_testers[i]);
1671
1741
  aws_http_message_release(requests[i]);
1672
- aws_input_stream_destroy(request_bodies[i]);
1742
+ aws_input_stream_release(request_bodies[i]);
1673
1743
  aws_byte_buf_clean_up(&request_body_bufs[i]);
1674
1744
  }
1675
1745
  return s_tester_clean_up();
@@ -1743,7 +1813,7 @@ TEST_CASE(h2_client_stream_send_stalled_data) {
1743
1813
  /* clean up */
1744
1814
  aws_http_message_release(request);
1745
1815
  client_stream_tester_clean_up(&stream_tester);
1746
- aws_input_stream_destroy(request_body);
1816
+ aws_input_stream_release(request_body);
1747
1817
  return s_tester_clean_up();
1748
1818
  }
1749
1819
 
@@ -1855,7 +1925,7 @@ TEST_CASE(h2_client_stream_send_data_controlled_by_stream_window_size) {
1855
1925
  aws_http_headers_release(response_headers);
1856
1926
  aws_http_message_release(request);
1857
1927
  client_stream_tester_clean_up(&stream_tester);
1858
- aws_input_stream_destroy(request_body);
1928
+ aws_input_stream_release(request_body);
1859
1929
  return s_tester_clean_up();
1860
1930
  }
1861
1931
 
@@ -1965,7 +2035,7 @@ TEST_CASE(h2_client_stream_send_data_controlled_by_negative_stream_window_size)
1965
2035
  aws_http_headers_release(response_headers);
1966
2036
  aws_http_message_release(request);
1967
2037
  client_stream_tester_clean_up(&stream_tester);
1968
- aws_input_stream_destroy(request_body);
2038
+ aws_input_stream_release(request_body);
1969
2039
  return s_tester_clean_up();
1970
2040
  }
1971
2041
 
@@ -2089,7 +2159,7 @@ TEST_CASE(h2_client_stream_send_data_controlled_by_connection_window_size) {
2089
2159
  for (size_t i = 0; i < NUM_STREAMS; ++i) {
2090
2160
  client_stream_tester_clean_up(&stream_testers[i]);
2091
2161
  aws_http_message_release(requests[i]);
2092
- aws_input_stream_destroy(request_bodies[i]);
2162
+ aws_input_stream_release(request_bodies[i]);
2093
2163
  aws_byte_buf_clean_up(&request_body_bufs[i]);
2094
2164
  }
2095
2165
  return s_tester_clean_up();
@@ -2292,7 +2362,7 @@ TEST_CASE(h2_client_stream_send_data_controlled_by_connection_and_stream_window_
2292
2362
  for (size_t i = 0; i < NUM_STREAMS; ++i) {
2293
2363
  client_stream_tester_clean_up(&stream_testers[i]);
2294
2364
  aws_http_message_release(requests[i]);
2295
- aws_input_stream_destroy(request_bodies[i]);
2365
+ aws_input_stream_release(request_bodies[i]);
2296
2366
  aws_byte_buf_clean_up(&request_body_bufs[i]);
2297
2367
  }
2298
2368
  return s_tester_clean_up();
@@ -2300,11 +2370,22 @@ TEST_CASE(h2_client_stream_send_data_controlled_by_connection_and_stream_window_
2300
2370
 
2301
2371
  /* Test receiving a response with DATA frames, the window update frame will be sent */
2302
2372
  TEST_CASE(h2_client_stream_send_window_update) {
2373
+ /* Enable automatic window manager management */
2374
+ s_tester.no_conn_manual_win_management = true;
2303
2375
  ASSERT_SUCCESS(s_tester_init(allocator, ctx));
2304
2376
 
2305
2377
  /* fake peer sends connection preface */
2306
2378
  ASSERT_SUCCESS(h2_fake_peer_send_connection_preface_default_settings(&s_tester.peer));
2307
2379
  testing_channel_drain_queued_tasks(&s_tester.testing_channel);
2380
+ ASSERT_SUCCESS(h2_fake_peer_decode_messages_from_testing_channel(&s_tester.peer));
2381
+ /* Check the inital window update frame has been sent to maximize the connection window */
2382
+ size_t initial_window_update_index = 0;
2383
+ struct h2_decoded_frame *initial_connection_window_update_frame = h2_decode_tester_find_stream_frame(
2384
+ &s_tester.peer.decode, AWS_H2_FRAME_T_WINDOW_UPDATE, 0 /*stream_id*/, 0 /*idx*/, &initial_window_update_index);
2385
+ ASSERT_NOT_NULL(initial_connection_window_update_frame);
2386
+ ASSERT_UINT_EQUALS(
2387
+ AWS_H2_WINDOW_UPDATE_MAX - AWS_H2_INIT_WINDOW_SIZE,
2388
+ initial_connection_window_update_frame->window_size_increment);
2308
2389
 
2309
2390
  /* send request */
2310
2391
  struct aws_http_message *request = aws_http2_message_new_request(allocator);
@@ -2349,7 +2430,11 @@ TEST_CASE(h2_client_stream_send_window_update) {
2349
2430
  ASSERT_UINT_EQUALS(5, stream_window_update_frame->window_size_increment);
2350
2431
 
2351
2432
  struct h2_decoded_frame *connection_window_update_frame = h2_decode_tester_find_stream_frame(
2352
- &s_tester.peer.decode, AWS_H2_FRAME_T_WINDOW_UPDATE, 0 /*stream_id*/, 0 /*idx*/, NULL);
2433
+ &s_tester.peer.decode,
2434
+ AWS_H2_FRAME_T_WINDOW_UPDATE,
2435
+ 0 /*stream_id*/,
2436
+ initial_window_update_index + 1 /*idx*/,
2437
+ NULL);
2353
2438
  ASSERT_NOT_NULL(connection_window_update_frame);
2354
2439
  ASSERT_UINT_EQUALS(5, connection_window_update_frame->window_size_increment);
2355
2440
 
@@ -2814,7 +2899,7 @@ TEST_CASE(h2_client_stream_receive_end_stream_before_done_sending) {
2814
2899
  aws_http_headers_release(response_headers);
2815
2900
  client_stream_tester_clean_up(&stream_tester);
2816
2901
  aws_http_message_release(request);
2817
- aws_input_stream_destroy(request_body);
2902
+ aws_input_stream_release(request_body);
2818
2903
  return s_tester_clean_up();
2819
2904
  }
2820
2905
 
@@ -2886,7 +2971,7 @@ TEST_CASE(h2_client_stream_receive_end_stream_and_rst_before_done_sending) {
2886
2971
  aws_http_headers_release(response_headers);
2887
2972
  client_stream_tester_clean_up(&stream_tester);
2888
2973
  aws_http_message_release(request);
2889
- aws_input_stream_destroy(request_body);
2974
+ aws_input_stream_release(request_body);
2890
2975
  return s_tester_clean_up();
2891
2976
  }
2892
2977
 
@@ -2931,7 +3016,7 @@ TEST_CASE(h2_client_stream_err_input_stream_failure) {
2931
3016
  /* clean up */
2932
3017
  client_stream_tester_clean_up(&stream_tester);
2933
3018
  aws_http_message_release(request);
2934
- aws_input_stream_destroy(request_body);
3019
+ aws_input_stream_release(request_body);
2935
3020
  return s_tester_clean_up();
2936
3021
  }
2937
3022
 
@@ -4621,8 +4706,8 @@ TEST_CASE(h2_client_send_multiple_goaway) {
4621
4706
  struct aws_byte_cursor debug_info = aws_byte_cursor_from_buf(&info_buf);
4622
4707
 
4623
4708
  /* First graceful shutdown warning */
4624
- ASSERT_SUCCESS(aws_http2_connection_send_goaway(
4625
- s_tester.connection, AWS_HTTP2_ERR_NO_ERROR, true /*allow_more_streams*/, &debug_info /*debug_data*/));
4709
+ aws_http2_connection_send_goaway(
4710
+ s_tester.connection, AWS_HTTP2_ERR_NO_ERROR, true /*allow_more_streams*/, &debug_info /*debug_data*/);
4626
4711
  testing_channel_drain_queued_tasks(&s_tester.testing_channel);
4627
4712
  /* Check the goaway frame received */
4628
4713
  ASSERT_SUCCESS(h2_fake_peer_decode_messages_from_testing_channel(&s_tester.peer));
@@ -4632,8 +4717,8 @@ TEST_CASE(h2_client_send_multiple_goaway) {
4632
4717
  ASSERT_TRUE(aws_byte_buf_eq_c_str(&latest_frame->data, "this is a debug info"));
4633
4718
 
4634
4719
  /* Real GOAWAY */
4635
- ASSERT_SUCCESS(aws_http2_connection_send_goaway(
4636
- s_tester.connection, AWS_HTTP2_ERR_PROTOCOL_ERROR, false /*allow_more_streams*/, &debug_info));
4720
+ aws_http2_connection_send_goaway(
4721
+ s_tester.connection, AWS_HTTP2_ERR_PROTOCOL_ERROR, false /*allow_more_streams*/, &debug_info);
4637
4722
  /* It is fine to free the buffer right after the call, since we keep it in the connection's memory */
4638
4723
  aws_byte_buf_clean_up(&info_buf);
4639
4724
  testing_channel_drain_queued_tasks(&s_tester.testing_channel);
@@ -4646,8 +4731,8 @@ TEST_CASE(h2_client_send_multiple_goaway) {
4646
4731
  size_t frames_count = h2_decode_tester_frame_count(&s_tester.peer.decode);
4647
4732
 
4648
4733
  /* Graceful shutdown warning after real GOAWAY will be ignored */
4649
- ASSERT_SUCCESS(aws_http2_connection_send_goaway(
4650
- s_tester.connection, AWS_HTTP2_ERR_NO_ERROR, true /*allow_more_streams*/, NULL /*debug_data*/));
4734
+ aws_http2_connection_send_goaway(
4735
+ s_tester.connection, AWS_HTTP2_ERR_NO_ERROR, true /*allow_more_streams*/, NULL /*debug_data*/);
4651
4736
  testing_channel_drain_queued_tasks(&s_tester.testing_channel);
4652
4737
  /* Check the goaway frame received */
4653
4738
  ASSERT_SUCCESS(h2_fake_peer_decode_messages_from_testing_channel(&s_tester.peer));
@@ -4669,8 +4754,8 @@ TEST_CASE(h2_client_get_sent_goaway) {
4669
4754
  ASSERT_FAILS(aws_http2_connection_get_sent_goaway(s_tester.connection, &http2_error, &last_stream_id));
4670
4755
 
4671
4756
  /* First graceful shutdown warning */
4672
- ASSERT_SUCCESS(aws_http2_connection_send_goaway(
4673
- s_tester.connection, AWS_HTTP2_ERR_NO_ERROR, true /*allow_more_streams*/, NULL /*debug_data*/));
4757
+ aws_http2_connection_send_goaway(
4758
+ s_tester.connection, AWS_HTTP2_ERR_NO_ERROR, true /*allow_more_streams*/, NULL /*debug_data*/);
4674
4759
  /* User send goaway asynchronously, you are not able to get the sent goaway right after the call */
4675
4760
  ASSERT_FAILS(aws_http2_connection_get_sent_goaway(s_tester.connection, &http2_error, &last_stream_id));
4676
4761
 
@@ -4680,8 +4765,8 @@ TEST_CASE(h2_client_get_sent_goaway) {
4680
4765
  ASSERT_UINT_EQUALS(AWS_HTTP2_ERR_NO_ERROR, http2_error);
4681
4766
 
4682
4767
  /* Second graceful shutdown warning, with non-zero error. Well it's not against the law, just do what user wants */
4683
- ASSERT_SUCCESS(aws_http2_connection_send_goaway(
4684
- s_tester.connection, AWS_HTTP2_ERR_ENHANCE_YOUR_CALM, true /*allow_more_streams*/, NULL /*debug_data*/));
4768
+ aws_http2_connection_send_goaway(
4769
+ s_tester.connection, AWS_HTTP2_ERR_ENHANCE_YOUR_CALM, true /*allow_more_streams*/, NULL /*debug_data*/);
4685
4770
  testing_channel_drain_queued_tasks(&s_tester.testing_channel);
4686
4771
  ASSERT_SUCCESS(aws_http2_connection_get_sent_goaway(s_tester.connection, &http2_error, &last_stream_id));
4687
4772
  ASSERT_UINT_EQUALS(AWS_H2_STREAM_ID_MAX, last_stream_id);
@@ -4846,8 +4931,8 @@ TEST_CASE(h2_client_request_apis_failed_after_connection_begin_shutdown) {
4846
4931
  aws_http_connection_close(s_tester.connection);
4847
4932
 
4848
4933
  /* Send goaway will silently do nothing as the connection already closed */
4849
- ASSERT_SUCCESS(aws_http2_connection_send_goaway(
4850
- s_tester.connection, AWS_HTTP2_ERR_NO_ERROR, false /*allow_more_streams*/, NULL /*debug_data*/));
4934
+ aws_http2_connection_send_goaway(
4935
+ s_tester.connection, AWS_HTTP2_ERR_NO_ERROR, false /*allow_more_streams*/, NULL /*debug_data*/);
4851
4936
  /* validate all those user apis to add stuff into synced data will fail */
4852
4937
  ASSERT_FAILS(aws_http_stream_activate(stream));
4853
4938
  ASSERT_FAILS(aws_http2_connection_change_settings(
@@ -4859,3 +4944,475 @@ TEST_CASE(h2_client_request_apis_failed_after_connection_begin_shutdown) {
4859
4944
  aws_http_stream_release(stream);
4860
4945
  return s_tester_clean_up();
4861
4946
  }
4947
+
4948
+ enum request_callback {
4949
+ REQUEST_CALLBACK_OUTGOING_BODY,
4950
+ REQUEST_CALLBACK_INCOMING_HEADERS,
4951
+ REQUEST_CALLBACK_INCOMING_HEADERS_DONE,
4952
+ REQUEST_CALLBACK_INCOMING_BODY,
4953
+ REQUEST_CALLBACK_COMPLETE,
4954
+ REQUEST_CALLBACK_COUNT,
4955
+ };
4956
+
4957
+ struct error_from_callback_tester {
4958
+ struct aws_input_stream base;
4959
+ enum request_callback error_at;
4960
+ int callback_counts[REQUEST_CALLBACK_COUNT];
4961
+ bool has_errored;
4962
+ struct aws_stream_status status;
4963
+ int on_complete_error_code;
4964
+ };
4965
+
4966
+ static const int ERROR_FROM_CALLBACK_ERROR_CODE = (int)0xBEEFCAFE;
4967
+
4968
+ static int s_error_from_callback_common(
4969
+ struct error_from_callback_tester *error_tester,
4970
+ enum request_callback current_callback) {
4971
+
4972
+ error_tester->callback_counts[current_callback]++;
4973
+
4974
+ /* After error code returned, no more callbacks should fire (except for on_complete) */
4975
+ AWS_FATAL_ASSERT(!error_tester->has_errored);
4976
+ AWS_FATAL_ASSERT(current_callback <= error_tester->error_at);
4977
+ if (current_callback == error_tester->error_at) {
4978
+ error_tester->has_errored = true;
4979
+ return aws_raise_error(ERROR_FROM_CALLBACK_ERROR_CODE);
4980
+ }
4981
+
4982
+ return AWS_OP_SUCCESS;
4983
+ }
4984
+
4985
+ static int s_error_from_outgoing_body_read(struct aws_input_stream *body, struct aws_byte_buf *dest) {
4986
+
4987
+ (void)dest;
4988
+
4989
+ struct error_from_callback_tester *error_tester = AWS_CONTAINER_OF(body, struct error_from_callback_tester, base);
4990
+ if (s_error_from_callback_common(error_tester, REQUEST_CALLBACK_OUTGOING_BODY)) {
4991
+ return AWS_OP_ERR;
4992
+ }
4993
+
4994
+ /* If the common fn was successful, write out some data and end the stream */
4995
+ ASSERT_TRUE(aws_byte_buf_write(dest, (const uint8_t *)"abcd", 4));
4996
+ error_tester->status.is_end_of_stream = true;
4997
+ return AWS_OP_SUCCESS;
4998
+ }
4999
+
5000
+ static int s_error_from_outgoing_body_get_status(struct aws_input_stream *body, struct aws_stream_status *status) {
5001
+ struct error_from_callback_tester *error_tester = AWS_CONTAINER_OF(body, struct error_from_callback_tester, base);
5002
+ *status = error_tester->status;
5003
+ return AWS_OP_SUCCESS;
5004
+ }
5005
+
5006
+ static void s_error_from_outgoing_body_destroy(void *stream) {
5007
+ /* allocated from stack, nothing to do */
5008
+ (void)stream;
5009
+ }
5010
+ static struct aws_input_stream_vtable s_error_from_outgoing_body_vtable = {
5011
+ .seek = NULL,
5012
+ .read = s_error_from_outgoing_body_read,
5013
+ .get_status = s_error_from_outgoing_body_get_status,
5014
+ .get_length = NULL,
5015
+ };
5016
+
5017
+ static int s_error_from_incoming_headers(
5018
+ struct aws_http_stream *stream,
5019
+ enum aws_http_header_block header_block,
5020
+ const struct aws_http_header *header_array,
5021
+ size_t num_headers,
5022
+ void *user_data) {
5023
+
5024
+ (void)stream;
5025
+ (void)header_block;
5026
+ (void)header_array;
5027
+ (void)num_headers;
5028
+ return s_error_from_callback_common(user_data, REQUEST_CALLBACK_INCOMING_HEADERS);
5029
+ }
5030
+
5031
+ static int s_error_from_incoming_headers_done(
5032
+ struct aws_http_stream *stream,
5033
+ enum aws_http_header_block header_block,
5034
+ void *user_data) {
5035
+ (void)stream;
5036
+ (void)header_block;
5037
+ return s_error_from_callback_common(user_data, REQUEST_CALLBACK_INCOMING_HEADERS_DONE);
5038
+ }
5039
+
5040
+ static int s_error_from_incoming_body(
5041
+ struct aws_http_stream *stream,
5042
+ const struct aws_byte_cursor *data,
5043
+ void *user_data) {
5044
+
5045
+ (void)stream;
5046
+ (void)data;
5047
+ return s_error_from_callback_common(user_data, REQUEST_CALLBACK_INCOMING_BODY);
5048
+ }
5049
+
5050
+ static void s_error_tester_on_stream_complete(struct aws_http_stream *stream, int error_code, void *user_data) {
5051
+ (void)stream;
5052
+ struct error_from_callback_tester *error_tester = user_data;
5053
+ error_tester->callback_counts[REQUEST_CALLBACK_COMPLETE]++;
5054
+ error_tester->on_complete_error_code = error_code;
5055
+ }
5056
+
5057
+ static int s_test_error_from_callback(struct aws_allocator *allocator, void *ctx, enum request_callback error_at) {
5058
+
5059
+ ASSERT_SUCCESS(s_tester_init(allocator, ctx));
5060
+ /* get connection preface and acks out of the way */
5061
+ ASSERT_SUCCESS(h2_fake_peer_send_connection_preface_default_settings(&s_tester.peer));
5062
+ ASSERT_SUCCESS(h2_fake_peer_decode_messages_from_testing_channel(&s_tester.peer));
5063
+ /* send request */
5064
+ struct aws_http_message *request = aws_http2_message_new_request(allocator);
5065
+ ASSERT_NOT_NULL(request);
5066
+
5067
+ struct aws_http_header request_headers_src[] = {
5068
+ DEFINE_HEADER(":method", "GET"),
5069
+ DEFINE_HEADER(":scheme", "https"),
5070
+ DEFINE_HEADER(":path", "/"),
5071
+ };
5072
+ aws_http_message_add_header_array(request, request_headers_src, AWS_ARRAY_SIZE(request_headers_src));
5073
+
5074
+ struct error_from_callback_tester error_tester = {
5075
+ .error_at = error_at,
5076
+ .status =
5077
+ {
5078
+ .is_valid = true,
5079
+ .is_end_of_stream = false,
5080
+ },
5081
+ };
5082
+ error_tester.base.vtable = &s_error_from_outgoing_body_vtable;
5083
+ aws_ref_count_init(&error_tester.base.ref_count, &error_tester, s_error_from_outgoing_body_destroy);
5084
+
5085
+ aws_http_message_set_body_stream(request, &error_tester.base);
5086
+
5087
+ struct aws_http_make_request_options opt = {
5088
+ .self_size = sizeof(opt),
5089
+ .request = request,
5090
+ .on_response_headers = s_error_from_incoming_headers,
5091
+ .on_response_header_block_done = s_error_from_incoming_headers_done,
5092
+ .on_response_body = s_error_from_incoming_body,
5093
+ .on_complete = s_error_tester_on_stream_complete,
5094
+ .user_data = &error_tester,
5095
+ };
5096
+ testing_channel_drain_queued_tasks(&s_tester.testing_channel);
5097
+
5098
+ struct aws_http_stream *stream = aws_http_connection_make_request(s_tester.connection, &opt);
5099
+ ASSERT_NOT_NULL(stream);
5100
+ ASSERT_SUCCESS(aws_http_stream_activate(stream));
5101
+
5102
+ testing_channel_drain_queued_tasks(&s_tester.testing_channel);
5103
+
5104
+ /* Ensure the request can be destroyed after request is sent */
5105
+ aws_http_message_release(opt.request);
5106
+
5107
+ /* fake peer sends response headers */
5108
+ struct aws_http_header response_headers_src[] = {
5109
+ DEFINE_HEADER(":status", "200"),
5110
+ DEFINE_HEADER("date", "Fri, 01 Mar 2019 17:18:55 GMT"),
5111
+ };
5112
+
5113
+ struct aws_http_headers *response_headers = aws_http_headers_new(allocator);
5114
+ aws_http_headers_add_array(response_headers, response_headers_src, AWS_ARRAY_SIZE(response_headers_src));
5115
+ uint32_t stream_id = aws_http_stream_get_id(stream);
5116
+ struct aws_h2_frame *response_frame =
5117
+ aws_h2_frame_new_headers(allocator, stream_id, response_headers, false /*end_stream*/, 0, NULL);
5118
+ ASSERT_SUCCESS(h2_fake_peer_send_frame(&s_tester.peer, response_frame));
5119
+
5120
+ struct aws_byte_buf response_body_bufs;
5121
+ size_t body_length = 5;
5122
+
5123
+ /* fake peer sends a DATA frame larger than the window size we have */
5124
+ ASSERT_SUCCESS(aws_byte_buf_init(&response_body_bufs, allocator, body_length));
5125
+ ASSERT_TRUE(aws_byte_buf_write_u8_n(&response_body_bufs, (uint8_t)'a', body_length));
5126
+ struct aws_byte_cursor body_cursor = aws_byte_cursor_from_buf(&response_body_bufs);
5127
+ ASSERT_SUCCESS(h2_fake_peer_send_data_frame(&s_tester.peer, stream_id, body_cursor, true /*end_stream*/));
5128
+
5129
+ /* validate that stream completed with error */
5130
+ testing_channel_drain_queued_tasks(&s_tester.testing_channel);
5131
+
5132
+ /* check that callbacks were invoked before error_at, but not after */
5133
+ for (int i = 0; i < REQUEST_CALLBACK_COMPLETE; ++i) {
5134
+ if (i <= error_at) {
5135
+ ASSERT_TRUE(error_tester.callback_counts[i] > 0);
5136
+ } else {
5137
+ ASSERT_INT_EQUALS(0, error_tester.callback_counts[i]);
5138
+ }
5139
+ }
5140
+
5141
+ /* validate the RST_STREAM sent and connection is still open */
5142
+ ASSERT_SUCCESS(h2_fake_peer_decode_messages_from_testing_channel(&s_tester.peer));
5143
+ struct h2_decoded_frame *rst_stream_frame =
5144
+ h2_decode_tester_find_frame(&s_tester.peer.decode, AWS_H2_FRAME_T_RST_STREAM, 0, NULL);
5145
+ ASSERT_NOT_NULL(rst_stream_frame);
5146
+ ASSERT_UINT_EQUALS(AWS_HTTP2_ERR_INTERNAL_ERROR, rst_stream_frame->error_code);
5147
+ ASSERT_TRUE(aws_http_connection_is_open(s_tester.connection));
5148
+
5149
+ /* the on_complete callback should always fire though, and should receive the proper error_code */
5150
+ ASSERT_INT_EQUALS(1, error_tester.callback_counts[REQUEST_CALLBACK_COMPLETE]);
5151
+ ASSERT_INT_EQUALS(ERROR_FROM_CALLBACK_ERROR_CODE, error_tester.on_complete_error_code);
5152
+
5153
+ aws_http_headers_release(response_headers);
5154
+ aws_byte_buf_clean_up(&response_body_bufs);
5155
+ aws_http_stream_release(stream);
5156
+ return s_tester_clean_up();
5157
+ }
5158
+
5159
+ TEST_CASE(h2_client_error_from_outgoing_body_callback_reset_stream) {
5160
+ (void)ctx;
5161
+ ASSERT_SUCCESS(s_test_error_from_callback(allocator, ctx, REQUEST_CALLBACK_OUTGOING_BODY));
5162
+ return AWS_OP_SUCCESS;
5163
+ }
5164
+
5165
+ TEST_CASE(h2_client_error_from_incoming_headers_callback_reset_stream) {
5166
+ (void)ctx;
5167
+ ASSERT_SUCCESS(s_test_error_from_callback(allocator, ctx, REQUEST_CALLBACK_INCOMING_HEADERS));
5168
+ return AWS_OP_SUCCESS;
5169
+ }
5170
+
5171
+ TEST_CASE(h2_client_error_from_incoming_headers_done_callback_reset_stream) {
5172
+ (void)ctx;
5173
+ ASSERT_SUCCESS(s_test_error_from_callback(allocator, ctx, REQUEST_CALLBACK_INCOMING_HEADERS_DONE));
5174
+ return AWS_OP_SUCCESS;
5175
+ }
5176
+
5177
+ TEST_CASE(h2_client_error_from_incoming_body_callback_reset_stream) {
5178
+ (void)ctx;
5179
+ ASSERT_SUCCESS(s_test_error_from_callback(allocator, ctx, REQUEST_CALLBACK_INCOMING_BODY));
5180
+ return AWS_OP_SUCCESS;
5181
+ }
5182
+
5183
+ struct h2_client_manual_data_write_ctx {
5184
+ struct aws_allocator *allocator;
5185
+ struct aws_byte_buf data;
5186
+ int complete_error_code;
5187
+ };
5188
+
5189
+ static struct aws_input_stream *s_h2_client_manual_data_write_generate_data(
5190
+ struct h2_client_manual_data_write_ctx *ctx) {
5191
+ struct aws_byte_cursor data = aws_byte_cursor_from_buf(&ctx->data);
5192
+ data.len = aws_max_size(rand() % ctx->data.capacity, 1);
5193
+ return aws_input_stream_new_from_cursor(ctx->allocator, &data);
5194
+ }
5195
+
5196
+ TEST_CASE(h2_client_manual_data_write) {
5197
+
5198
+ ASSERT_SUCCESS(s_tester_init(allocator, ctx));
5199
+ /* get connection preface and acks out of the way */
5200
+ ASSERT_SUCCESS(h2_fake_peer_send_connection_preface_default_settings(&s_tester.peer));
5201
+ ASSERT_SUCCESS(h2_fake_peer_decode_messages_from_testing_channel(&s_tester.peer));
5202
+ size_t frame_count = h2_decode_tester_frame_count(&s_tester.peer.decode);
5203
+
5204
+ struct aws_http_message *request = aws_http2_message_new_request(allocator);
5205
+ ASSERT_NOT_NULL(request);
5206
+
5207
+ struct aws_http_header request_headers_src[] = {
5208
+ DEFINE_HEADER(":method", "GET"),
5209
+ DEFINE_HEADER(":scheme", "https"),
5210
+ DEFINE_HEADER(":path", "/"),
5211
+ };
5212
+ aws_http_message_add_header_array(request, request_headers_src, AWS_ARRAY_SIZE(request_headers_src));
5213
+ struct aws_http_make_request_options request_options = {
5214
+ .self_size = sizeof(request_options),
5215
+ .request = request,
5216
+ .http2_use_manual_data_writes = true,
5217
+ };
5218
+ struct aws_http_stream *stream = aws_http_connection_make_request(s_tester.connection, &request_options);
5219
+ ASSERT_NOT_NULL(stream);
5220
+
5221
+ aws_http_stream_activate(stream);
5222
+ testing_channel_drain_queued_tasks(&s_tester.testing_channel);
5223
+ uint32_t stream_id = aws_http_stream_get_id(stream);
5224
+
5225
+ struct aws_byte_buf payload;
5226
+ aws_byte_buf_init(&payload, allocator, 1024);
5227
+
5228
+ struct h2_client_manual_data_write_ctx test_ctx = {
5229
+ .allocator = allocator,
5230
+ .data = payload,
5231
+ };
5232
+ size_t total_length = 0;
5233
+
5234
+ /* Simulate writes coming in over time */
5235
+ for (int idx = 0; idx < 1000; ++idx) {
5236
+ struct aws_input_stream *data_stream = s_h2_client_manual_data_write_generate_data(&test_ctx);
5237
+ int64_t stream_length = 0;
5238
+ ASSERT_SUCCESS(aws_input_stream_get_length(data_stream, &stream_length));
5239
+ total_length += (size_t)stream_length;
5240
+ struct aws_http2_stream_write_data_options write = {
5241
+ .data = data_stream,
5242
+ .on_complete = NULL,
5243
+ .user_data = NULL,
5244
+ };
5245
+ ASSERT_SUCCESS(aws_http2_stream_write_data(stream, &write));
5246
+ /* fake peer sends WINDOW_UPDATE */
5247
+ struct aws_h2_frame *peer_frame = aws_h2_frame_new_window_update(allocator, stream_id, (uint32_t)stream_length);
5248
+ ASSERT_SUCCESS(h2_fake_peer_send_frame(&s_tester.peer, peer_frame));
5249
+ /* Connection level window update */
5250
+ peer_frame = aws_h2_frame_new_window_update(allocator, 0, (uint32_t)stream_length);
5251
+ ASSERT_SUCCESS(h2_fake_peer_send_frame(&s_tester.peer, peer_frame));
5252
+ if (idx % 10 == 0) {
5253
+ testing_channel_drain_queued_tasks(&s_tester.testing_channel);
5254
+ ASSERT_SUCCESS(h2_fake_peer_decode_messages_from_testing_channel(&s_tester.peer));
5255
+ }
5256
+ aws_input_stream_release(data_stream);
5257
+ }
5258
+ struct aws_http2_stream_write_data_options last_write = {.end_stream = true};
5259
+
5260
+ ASSERT_SUCCESS(aws_http2_stream_write_data(stream, &last_write));
5261
+
5262
+ testing_channel_drain_queued_tasks(&s_tester.testing_channel);
5263
+ ASSERT_SUCCESS(h2_fake_peer_decode_messages_from_testing_channel(&s_tester.peer));
5264
+ size_t frame_count2 = h2_decode_tester_frame_count(&s_tester.peer.decode);
5265
+ /* Peer should received header frame without end_stream and mutiple data frames and combined payload length should
5266
+ * be the same as total length sent. */
5267
+ struct h2_decoded_frame *header_frame = h2_decode_tester_get_frame(&s_tester.peer.decode, frame_count);
5268
+ ASSERT_UINT_EQUALS(AWS_H2_FRAME_T_HEADERS, header_frame->type);
5269
+ ASSERT_FALSE(header_frame->end_stream);
5270
+ size_t received_length = 0;
5271
+ for (size_t i = frame_count + 1; i < frame_count2; i++) {
5272
+ struct h2_decoded_frame *data_frame = h2_decode_tester_get_frame(&s_tester.peer.decode, i);
5273
+ ASSERT_UINT_EQUALS(AWS_H2_FRAME_T_DATA, data_frame->type);
5274
+ received_length += data_frame->data_payload_len;
5275
+ if (i == frame_count2 - 1) {
5276
+ ASSERT_TRUE(data_frame->end_stream);
5277
+ } else {
5278
+ ASSERT_FALSE(data_frame->end_stream);
5279
+ }
5280
+ }
5281
+ ASSERT_UINT_EQUALS(received_length, total_length);
5282
+
5283
+ aws_http_message_release(request);
5284
+ aws_http_stream_release(stream);
5285
+
5286
+ /* close the connection */
5287
+ aws_http_connection_close(s_tester.connection);
5288
+
5289
+ aws_byte_buf_clean_up(&test_ctx.data);
5290
+
5291
+ /* clean up */
5292
+ return s_tester_clean_up();
5293
+ }
5294
+
5295
+ TEST_CASE(h2_client_manual_data_write_no_data) {
5296
+
5297
+ ASSERT_SUCCESS(s_tester_init(allocator, ctx));
5298
+ /* get connection preface and acks out of the way */
5299
+ ASSERT_SUCCESS(h2_fake_peer_send_connection_preface_default_settings(&s_tester.peer));
5300
+ ASSERT_SUCCESS(h2_fake_peer_decode_messages_from_testing_channel(&s_tester.peer));
5301
+ size_t frame_count = h2_decode_tester_frame_count(&s_tester.peer.decode);
5302
+
5303
+ struct aws_http_message *request = aws_http2_message_new_request(allocator);
5304
+ ASSERT_NOT_NULL(request);
5305
+
5306
+ struct aws_http_header request_headers_src[] = {
5307
+ DEFINE_HEADER(":method", "GET"),
5308
+ DEFINE_HEADER(":scheme", "https"),
5309
+ DEFINE_HEADER(":path", "/"),
5310
+ };
5311
+ aws_http_message_add_header_array(request, request_headers_src, AWS_ARRAY_SIZE(request_headers_src));
5312
+ struct aws_http_make_request_options request_options = {
5313
+ .self_size = sizeof(request_options),
5314
+ .request = request,
5315
+ .http2_use_manual_data_writes = true,
5316
+ };
5317
+ struct aws_http_stream *stream = aws_http_connection_make_request(s_tester.connection, &request_options);
5318
+ ASSERT_NOT_NULL(stream);
5319
+
5320
+ aws_http_stream_activate(stream);
5321
+
5322
+ struct aws_http2_stream_write_data_options last_write = {.end_stream = true};
5323
+ ASSERT_SUCCESS(aws_http2_stream_write_data(stream, &last_write));
5324
+
5325
+ testing_channel_drain_queued_tasks(&s_tester.testing_channel);
5326
+ ASSERT_SUCCESS(h2_fake_peer_decode_messages_from_testing_channel(&s_tester.peer));
5327
+ size_t frame_count_2 = h2_decode_tester_frame_count(&s_tester.peer.decode);
5328
+ /* Peer should received header frame without end_stream and empty data frame with end_stream */
5329
+ ASSERT_UINT_EQUALS(frame_count + 2, frame_count_2);
5330
+ struct h2_decoded_frame *header_frame = h2_decode_tester_get_frame(&s_tester.peer.decode, frame_count);
5331
+ ASSERT_UINT_EQUALS(AWS_H2_FRAME_T_HEADERS, header_frame->type);
5332
+ ASSERT_FALSE(header_frame->end_stream);
5333
+ struct h2_decoded_frame *empty_data_frame = h2_decode_tester_get_frame(&s_tester.peer.decode, frame_count + 1);
5334
+ ASSERT_UINT_EQUALS(AWS_H2_FRAME_T_DATA, empty_data_frame->type);
5335
+ ASSERT_UINT_EQUALS(0, empty_data_frame->data_payload_len);
5336
+ ASSERT_TRUE(empty_data_frame->end_stream);
5337
+ aws_http_message_release(request);
5338
+ aws_http_stream_release(stream);
5339
+
5340
+ /* close the connection */
5341
+ aws_http_connection_close(s_tester.connection);
5342
+
5343
+ /* clean up */
5344
+ return s_tester_clean_up();
5345
+ }
5346
+
5347
+ static void s_on_manual_data_stream_complete(struct aws_http_stream *stream, int error_code, void *user_data) {
5348
+ (void)stream;
5349
+ struct h2_client_manual_data_write_ctx *test_ctx = (struct h2_client_manual_data_write_ctx *)user_data;
5350
+ test_ctx->complete_error_code = error_code;
5351
+ }
5352
+
5353
+ /* Close the connection before finishes writing data */
5354
+ TEST_CASE(h2_client_manual_data_write_connection_close) {
5355
+
5356
+ ASSERT_SUCCESS(s_tester_init(allocator, ctx));
5357
+ /* get connection preface and acks out of the way */
5358
+ ASSERT_SUCCESS(h2_fake_peer_send_connection_preface_default_settings(&s_tester.peer));
5359
+ ASSERT_SUCCESS(h2_fake_peer_decode_messages_from_testing_channel(&s_tester.peer));
5360
+
5361
+ struct aws_http_message *request = aws_http2_message_new_request(allocator);
5362
+ ASSERT_NOT_NULL(request);
5363
+
5364
+ struct aws_http_header request_headers_src[] = {
5365
+ DEFINE_HEADER(":method", "GET"),
5366
+ DEFINE_HEADER(":scheme", "https"),
5367
+ DEFINE_HEADER(":path", "/"),
5368
+ };
5369
+ aws_http_message_add_header_array(request, request_headers_src, AWS_ARRAY_SIZE(request_headers_src));
5370
+
5371
+ struct aws_byte_buf payload;
5372
+ aws_byte_buf_init(&payload, allocator, 1024);
5373
+
5374
+ struct h2_client_manual_data_write_ctx test_ctx = {
5375
+ .allocator = allocator,
5376
+ .data = payload,
5377
+ };
5378
+
5379
+ struct aws_http_make_request_options request_options = {
5380
+ .self_size = sizeof(request_options),
5381
+ .request = request,
5382
+ .http2_use_manual_data_writes = true,
5383
+ .on_complete = s_on_manual_data_stream_complete,
5384
+ .user_data = &test_ctx,
5385
+ };
5386
+ struct aws_http_stream *stream = aws_http_connection_make_request(s_tester.connection, &request_options);
5387
+ ASSERT_NOT_NULL(stream);
5388
+
5389
+ struct aws_input_stream *data_stream = s_h2_client_manual_data_write_generate_data(&test_ctx);
5390
+ struct aws_http2_stream_write_data_options write = {
5391
+ .data = data_stream,
5392
+ .on_complete = NULL,
5393
+ .user_data = NULL,
5394
+ };
5395
+ /* Cannot write before activate the stream */
5396
+ ASSERT_FAILS(aws_http2_stream_write_data(stream, &write));
5397
+ aws_http_stream_activate(stream);
5398
+ ASSERT_SUCCESS(aws_http2_stream_write_data(stream, &write));
5399
+
5400
+ /* close connection */
5401
+ aws_http_connection_close(s_tester.connection);
5402
+
5403
+ ASSERT_SUCCESS(aws_http2_stream_write_data(stream, &write));
5404
+
5405
+ testing_channel_drain_queued_tasks(&s_tester.testing_channel);
5406
+ /* Cannot write after stream closed */
5407
+ ASSERT_FAILS(aws_http2_stream_write_data(stream, &write));
5408
+
5409
+ ASSERT_INT_EQUALS(AWS_ERROR_HTTP_CONNECTION_CLOSED, test_ctx.complete_error_code);
5410
+
5411
+ aws_http_message_release(request);
5412
+ aws_http_stream_release(stream);
5413
+
5414
+ /* clean up */
5415
+ aws_byte_buf_clean_up(&test_ctx.data);
5416
+ aws_input_stream_release(data_stream);
5417
+ return s_tester_clean_up();
5418
+ }