The FreeRADIUS server $Id: a4e7f8c94e8038b7627bcf52356b7ed15955c1d7 $
Loading...
Searching...
No Matches
Macros | Functions | Variables
radius_bio_tests.c File Reference

Tests for the RADIUS bio verify callbacks. More...

#include <freeradius-devel/util/test/acutest_common_init.h>
#include <freeradius-devel/util/test/acutest_helpers.h>
#include <freeradius-devel/bio/bio_priv.h>
#include <freeradius-devel/bio/mem.h>
#include <freeradius-devel/bio/pipe.h>
#include <freeradius-devel/radius/bio.h>
+ Include dependency graph for radius_bio_tests.c:

Go to the source code of this file.

Macros

#define BAD(_name, ...)   { _name, (uint8_t const[]) { __VA_ARGS__ }, sizeof((uint8_t const[]) { __VA_ARGS__ }) }
 
#define MAX_PACKET_SIZE   4096
 
#define MESSAGE_AUTHENTICATOR   80
 

Functions

static int cb_noop (fr_bio_t *bio)
 
static void cb_noop_void (fr_bio_t *bio)
 
static fr_bio_verify_action_t datagram_verify (fr_radius_bio_verify_t *ctx, uint8_t const *buf, size_t in_buffer, size_t *size_out)
 Call the datagram verify callback on a buffer holding in_buffer bytes.
 
static size_t make_packet (uint8_t *out, uint8_t code, uint8_t const *attrs, size_t attrs_len)
 Build a packet with a header, and the given attributes.
 
static size_t make_valid (uint8_t *out, uint8_t code)
 Make a packet whose attributes are a User-Name of "ab".
 
static fr_bio_verify_action_t stream_verify (fr_radius_bio_verify_t *ctx, uint8_t const *buf, size_t in_buffer, size_t *size_out)
 Call the stream verify callback on a buffer holding in_buffer bytes.
 
static fr_radius_bio_verify_t test_ctx (void)
 Make a verify context which allows Access-Request and Access-Accept.
 
static void test_datagram_discard (void)
 A datagram which is not a good packet is discarded, and never closes the socket.
 
static void test_datagram_one_packet (void)
 A datagram holds one packet, and trailing bytes are padding.
 
static fr_bio_t * test_mem_alloc (TALLOC_CTX *ctx, fr_bio_t **source_p, fr_radius_bio_verify_t *vctx)
 A memory bio in front of a pipe, which stands in for the network.
 
static void test_mem_fatal (void)
 A packet which cannot be skipped fails the read.
 
static void test_mem_split_packet (void)
 A packet which arrives in pieces is returned when the packet is complete, and the connection stays open.
 
static void test_mem_two_packets (void)
 Packets which arrive together are returned one at a time.
 
static void test_mem_unknown_code_keeps_next_packet (void)
 A packet which the module does not accept does not take the packets after it.
 
static ssize_t test_source_write (fr_bio_t *source, uint8_t const *data, size_t size)
 Put bytes where the memory bio's reads will find them.
 
static void test_stream_fatal (void)
 Errors which leave the stream without a known start of the next packet close the connection.
 
static void test_stream_not_allowed (void)
 A packet with a code which is known, but not allowed, is skipped.
 
static void test_stream_one_packet (void)
 A complete packet is returned, and only that packet.
 
static void test_stream_partial_packet (void)
 A packet which is not all in the buffer asks for the rest of the packet.
 
static void test_stream_short_buffer (void)
 A buffer which holds less than a header asks for the header.
 
static void test_stream_too_large (void)
 A packet which is larger than the module allows closes the connection, even when only the header has arrived.
 
static void test_stream_too_many_attributes (void)
 A packet with more attributes than the limit is skipped, and the packets after it are kept.
 
static void test_stream_unknown_code (void)
 A packet with a code which the module does not know is skipped, and the packets after it are kept.
 

Variables

static fr_bio_cb_funcs_t test_cb
 
 TEST_LIST
 

Detailed Description

Tests for the RADIUS bio verify callbacks.

The verify callbacks are fr_radius_bio_verify() for stream sockets, and fr_radius_bio_verify_datagram() for datagram sockets. The tests call the callbacks directly, and the stream callback also through a memory bio.

Definition in file radius_bio_tests.c.

Macro Definition Documentation

◆ BAD

#define BAD (   _name,
  ... 
)    { _name, (uint8_t const[]) { __VA_ARGS__ }, sizeof((uint8_t const[]) { __VA_ARGS__ }) }

◆ MAX_PACKET_SIZE

#define MAX_PACKET_SIZE   4096

Definition at line 37 of file radius_bio_tests.c.

◆ MESSAGE_AUTHENTICATOR

#define MESSAGE_AUTHENTICATOR   80

Definition at line 35 of file radius_bio_tests.c.

Function Documentation

◆ cb_noop()

static int cb_noop ( fr_bio_t *  bio)
static

Definition at line 39 of file radius_bio_tests.c.

◆ cb_noop_void()

static void cb_noop_void ( fr_bio_t *  bio)
static

Definition at line 40 of file radius_bio_tests.c.

◆ datagram_verify()

static fr_bio_verify_action_t datagram_verify ( fr_radius_bio_verify_t *  ctx,
uint8_t const *  buf,
size_t  in_buffer,
size_t *  size_out 
)
static

Call the datagram verify callback on a buffer holding in_buffer bytes.

Definition at line 113 of file radius_bio_tests.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ make_packet()

static size_t make_packet ( uint8_t *  out,
uint8_t  code,
uint8_t const *  attrs,
size_t  attrs_len 
)
static

Build a packet with a header, and the given attributes.

Parameters
[out]outwhere to write the packet.
[in]codeof the packet.
[in]attrsto copy after the header, which may be NULL.
[in]attrs_lenlength of the attributes.
Returns
the length of the packet.

Definition at line 72 of file radius_bio_tests.c.

+ Here is the caller graph for this function:

◆ make_valid()

static size_t make_valid ( uint8_t *  out,
uint8_t  code 
)
static

Make a packet whose attributes are a User-Name of "ab".

Definition at line 89 of file radius_bio_tests.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ stream_verify()

static fr_bio_verify_action_t stream_verify ( fr_radius_bio_verify_t *  ctx,
uint8_t const *  buf,
size_t  in_buffer,
size_t *  size_out 
)
static

Call the stream verify callback on a buffer holding in_buffer bytes.

Definition at line 98 of file radius_bio_tests.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ test_ctx()

static fr_radius_bio_verify_t test_ctx ( void  )
static

Make a verify context which allows Access-Request and Access-Accept.

Definition at line 52 of file radius_bio_tests.c.

+ Here is the caller graph for this function:

◆ test_datagram_discard()

static void test_datagram_discard ( void  )
static

A datagram which is not a good packet is discarded, and never closes the socket.

Definition at line 374 of file radius_bio_tests.c.

+ Here is the call graph for this function:

◆ test_datagram_one_packet()

static void test_datagram_one_packet ( void  )
static

A datagram holds one packet, and trailing bytes are padding.

Definition at line 354 of file radius_bio_tests.c.

+ Here is the call graph for this function:

◆ test_mem_alloc()

static fr_bio_t * test_mem_alloc ( TALLOC_CTX *  ctx,
fr_bio_t **  source_p,
fr_radius_bio_verify_t *  vctx 
)
static

A memory bio in front of a pipe, which stands in for the network.

Definition at line 437 of file radius_bio_tests.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ test_mem_fatal()

static void test_mem_fatal ( void  )
static

A packet which cannot be skipped fails the read.

Definition at line 563 of file radius_bio_tests.c.

+ Here is the call graph for this function:

◆ test_mem_split_packet()

static void test_mem_split_packet ( void  )
static

A packet which arrives in pieces is returned when the packet is complete, and the connection stays open.

Definition at line 494 of file radius_bio_tests.c.

+ Here is the call graph for this function:

◆ test_mem_two_packets()

static void test_mem_two_packets ( void  )
static

Packets which arrive together are returned one at a time.

Definition at line 533 of file radius_bio_tests.c.

+ Here is the call graph for this function:

◆ test_mem_unknown_code_keeps_next_packet()

static void test_mem_unknown_code_keeps_next_packet ( void  )
static

A packet which the module does not accept does not take the packets after it.

Definition at line 462 of file radius_bio_tests.c.

+ Here is the call graph for this function:

◆ test_source_write()

static ssize_t test_source_write ( fr_bio_t *  source,
uint8_t const *  data,
size_t  size 
)
static

Put bytes where the memory bio's reads will find them.

Definition at line 455 of file radius_bio_tests.c.

+ Here is the caller graph for this function:

◆ test_stream_fatal()

static void test_stream_fatal ( void  )
static

Errors which leave the stream without a known start of the next packet close the connection.

Definition at line 264 of file radius_bio_tests.c.

+ Here is the call graph for this function:

◆ test_stream_not_allowed()

static void test_stream_not_allowed ( void  )
static

A packet with a code which is known, but not allowed, is skipped.

Definition at line 225 of file radius_bio_tests.c.

+ Here is the call graph for this function:

◆ test_stream_one_packet()

static void test_stream_one_packet ( void  )
static

A complete packet is returned, and only that packet.

Definition at line 155 of file radius_bio_tests.c.

+ Here is the call graph for this function:

◆ test_stream_partial_packet()

static void test_stream_partial_packet ( void  )
static

A packet which is not all in the buffer asks for the rest of the packet.

Definition at line 179 of file radius_bio_tests.c.

+ Here is the call graph for this function:

◆ test_stream_short_buffer()

static void test_stream_short_buffer ( void  )
static

A buffer which holds less than a header asks for the header.

Definition at line 132 of file radius_bio_tests.c.

+ Here is the call graph for this function:

◆ test_stream_too_large()

static void test_stream_too_large ( void  )
static

A packet which is larger than the module allows closes the connection, even when only the header has arrived.

Definition at line 316 of file radius_bio_tests.c.

+ Here is the call graph for this function:

◆ test_stream_too_many_attributes()

static void test_stream_too_many_attributes ( void  )
static

A packet with more attributes than the limit is skipped, and the packets after it are kept.

Definition at line 240 of file radius_bio_tests.c.

+ Here is the call graph for this function:

◆ test_stream_unknown_code()

static void test_stream_unknown_code ( void  )
static

A packet with a code which the module does not know is skipped, and the packets after it are kept.

Definition at line 198 of file radius_bio_tests.c.

+ Here is the call graph for this function:

Variable Documentation

◆ test_cb

fr_bio_cb_funcs_t test_cb
static
Initial value:
= {
.read_resume = cb_noop,
.write_resume = cb_noop,
.read_blocked = cb_noop,
.write_blocked = cb_noop,
.eof = cb_noop_void,
}
static void cb_noop_void(fr_bio_t *bio)
static int cb_noop(fr_bio_t *bio)

Definition at line 42 of file radius_bio_tests.c.

◆ TEST_LIST

TEST_LIST
Initial value:
= {
{ "stream_short_buffer", test_stream_short_buffer },
{ "stream_one_packet", test_stream_one_packet },
{ "stream_partial_packet", test_stream_partial_packet },
{ "stream_unknown_code", test_stream_unknown_code },
{ "stream_not_allowed", test_stream_not_allowed },
{ "stream_too_many_attributes", test_stream_too_many_attributes },
{ "stream_fatal", test_stream_fatal },
{ "stream_too_large", test_stream_too_large },
{ "datagram_one_packet", test_datagram_one_packet },
{ "datagram_discard", test_datagram_discard },
{ "mem_unknown_code_keeps_next_packet", test_mem_unknown_code_keeps_next_packet },
{ "mem_split_packet", test_mem_split_packet },
{ "mem_two_packets", test_mem_two_packets },
{ "mem_fatal", test_mem_fatal },
{ NULL, NULL }
}
static void test_stream_unknown_code(void)
A packet with a code which the module does not know is skipped, and the packets after it are kept.
static void test_stream_partial_packet(void)
A packet which is not all in the buffer asks for the rest of the packet.
static void test_stream_one_packet(void)
A complete packet is returned, and only that packet.
static void test_stream_not_allowed(void)
A packet with a code which is known, but not allowed, is skipped.
static void test_mem_fatal(void)
A packet which cannot be skipped fails the read.
static void test_mem_two_packets(void)
Packets which arrive together are returned one at a time.
static void test_datagram_discard(void)
A datagram which is not a good packet is discarded, and never closes the socket.
static void test_stream_too_many_attributes(void)
A packet with more attributes than the limit is skipped, and the packets after it are kept.
static void test_datagram_one_packet(void)
A datagram holds one packet, and trailing bytes are padding.
static void test_mem_split_packet(void)
A packet which arrives in pieces is returned when the packet is complete, and the connection stays op...
static void test_stream_fatal(void)
Errors which leave the stream without a known start of the next packet close the connection.
static void test_stream_too_large(void)
A packet which is larger than the module allows closes the connection, even when only the header has ...
static void test_mem_unknown_code_keeps_next_packet(void)
A packet which the module does not accept does not take the packets after it.
static void test_stream_short_buffer(void)
A buffer which holds less than a header asks for the header.

Definition at line 585 of file radius_bio_tests.c.