28#include <freeradius-devel/util/test/acutest_common_init.h>
29#include <freeradius-devel/util/test/acutest_helpers.h>
31#include <freeradius-devel/tls/bio.h>
41 static bool done =
false;
55 return fr_tls_bio_dbuff_alloc(
out, NULL, NULL, 1024, 0,
true);
66 if (!bio)
return NULL;
77 fr_tls_bio_dbuff_t *bd = NULL;
91 TEST_CHECK(fr_tls_bio_dbuff_datagram_len(bd) == 0);
100 fr_tls_bio_dbuff_t *bd = NULL;
106 TEST_CHECK(fr_tls_bio_dbuff_datagram_len(bd) == 0);
109 TEST_CHECK(fr_tls_bio_dbuff_datagram_len(bd) == 5);
111 fr_tls_bio_dbuff_datagram_sent(bd);
112 TEST_CHECK(fr_tls_bio_dbuff_datagram_len(bd) == 0);
125 fr_tls_bio_dbuff_t *bd = NULL;
127 static size_t const len[] = { 71, 1103, 314, 308, 12 };
134 memset(buf, 0xa5,
sizeof(buf));
137 TEST_CHECK(BIO_write(bio, (
char const *) buf, (
int)
len[i]) == (
int)
len[i]);
142 fr_tls_bio_dbuff_datagram_sent(bd);
145 TEST_CHECK(fr_tls_bio_dbuff_datagram_len(bd) == 0);
158 fr_tls_bio_dbuff_t *bd = NULL;
166 memset(buf, 0,
sizeof(buf));
168 for (i = 0; i < 16; i++) {
176 for (flight = 0; flight < 2; flight++) {
177 size_t len = (i * 2) + flight + 1;
182 for (flight = 0; flight < 2; flight++) {
183 TEST_CHECK_LEN(fr_tls_bio_dbuff_datagram_len(bd), (i * 2) + flight + 1);
184 fr_tls_bio_dbuff_datagram_sent(bd);
187 TEST_CHECK(fr_tls_bio_dbuff_datagram_len(bd) == 0);
197 fr_tls_bio_dbuff_t *bd = NULL;
204 memset(buf, 0,
sizeof(buf));
206 TEST_CHECK(BIO_write(bio, (
char const *) buf, 10) == 10);
207 TEST_CHECK(BIO_write(bio, (
char const *) buf, 20) == 20);
210 fr_tls_bio_dbuff_datagram_sent(bd);
216 TEST_CHECK(BIO_write(bio, (
char const *) buf, 30) == 30);
219 fr_tls_bio_dbuff_datagram_sent(bd);
221 fr_tls_bio_dbuff_datagram_sent(bd);
222 TEST_CHECK(fr_tls_bio_dbuff_datagram_len(bd) == 0);
231 fr_tls_bio_dbuff_t *bd = NULL;
237 fr_tls_bio_dbuff_datagram_sent(bd);
238 TEST_CHECK(fr_tls_bio_dbuff_datagram_len(bd) == 0);
241 fr_tls_bio_dbuff_datagram_sent(bd);
242 fr_tls_bio_dbuff_datagram_sent(bd);
243 TEST_CHECK(fr_tls_bio_dbuff_datagram_len(bd) == 0);
268 fr_tls_bio_dbuff_t *bd = NULL;
276 memset(buf, 0,
sizeof(buf));
278 for (i = 0; i < FR_TLS_MAX_DATAGRAMS; i++) {
286 TEST_CHECK(BIO_write(bio, (
char const *) buf, 1) <= 0);
292 for (i = 0; i < 3; i++) {
294 fr_tls_bio_dbuff_datagram_sent(bd);
297 for (i = 0; i < 3; i++) {
298 TEST_CHECK(BIO_write(bio, (
char const *) buf, 7 + (
int) i) == 7 + (
int) i);
305 for (i = 3; i < FR_TLS_MAX_DATAGRAMS; i++) {
307 fr_tls_bio_dbuff_datagram_sent(bd);
310 for (i = 0; i < 3; i++) {
312 fr_tls_bio_dbuff_datagram_sent(bd);
315 TEST_CHECK(fr_tls_bio_dbuff_datagram_len(bd) == 0);
328 fr_tls_bio_dbuff_t *bd = NULL;
337 bio = fr_tls_bio_dbuff_alloc(&bd, NULL, NULL, 64, 64,
true);
341 TEST_CHECK(fr_tls_bio_dbuff_datagram_init(bd) == 0);
343 memset(buf, 0,
sizeof(buf));
345 TEST_CHECK(BIO_write(bio, (
char const *) buf, 40) == 40);
352 TEST_CHECK(BIO_write(bio, (
char const *) buf, 100) <= 0);
359 fr_tls_bio_dbuff_datagram_sent(bd);
360 TEST_CHECK(fr_tls_bio_dbuff_datagram_len(bd) == 0);
369 fr_tls_bio_dbuff_t *bd = NULL;
378 fr_tls_bio_dbuff_clear(bd);
381 TEST_CHECK(fr_tls_bio_dbuff_datagram_len(bd) == 0);
390 fr_tls_bio_dbuff_t *bd = NULL;
397 TEST_CHECK(fr_tls_bio_dbuff_datagram_init(bd) == 0);
#define TEST_CHECK_LEN(_got, _exp)
#define fr_dbuff_remaining(_dbuff_or_marker)
Return the number of bytes remaining between the dbuff or marker and the end of the buffer.
static void test_partial_drain(void)
Draining part of a flight leaves the rest in order.
static BIO * datagram_bio_alloc(fr_tls_bio_dbuff_t **out)
Allocate a bio with datagram boundaries turned on.
static void test_queue_cap(void)
The queue is capped, a write past the cap fails, and draining makes room.
static void test_clear_discards_boundaries(void)
Clearing the buffer discards the boundaries with the data.
static void tls_bio_test_init(void)
Build the BIO_METHOD which fr_tls_bio_dbuff_alloc() clones.
static void test_one_write_one_datagram(void)
One write is one datagram.
static BIO * stream_bio_alloc(fr_tls_bio_dbuff_t **out)
Allocate a bio, without datagram boundaries.
static void test_flight_keeps_its_boundaries(void)
Writes of different lengths come back in the order they were written.
static size_t cap_test_len(size_t i)
Vary the datagram length, so that a mis-ordered queue is visible.
static void test_enable_is_idempotent(void)
Enabling datagram mode twice is not an error.
static void test_stream_has_no_boundaries(void)
Without datagram mode the bio reports no boundaries at all.
static void test_flight_after_flight(void)
A flight which is fully drained is followed by another.
static void test_over_send(void)
Sending more datagrams than were written is harmless.
static void test_partial_write_records_nothing(void)
A datagram which does not fit records no boundary at all.
static fr_sbuff_err_t char ** out
static fr_sbuff_err_t char size_t * len