23#include <freeradius-devel/util/test/acutest_common_init.h>
24#include <freeradius-devel/util/test/acutest_helpers.h>
26#include <freeradius-devel/ldap/base.h>
33#define TEST_CHECK_BOX_BYTES(_vb, _exp) \
35 fr_value_box_t const *_our_vb = (_vb); \
36 TEST_CHECK_LEN(_our_vb->vb_length, sizeof(_exp) - 1); \
37 TEST_CHECK(memcmp(_our_vb->vb_strvalue, _exp, sizeof(_exp) - 1) == 0); \
38 TEST_MSG("Expected : \"%s\"", _exp); \
39 TEST_MSG("Got : \"%s\"", _our_vb->vb_strvalue); \
44#define BOX_FROM_LITERAL(_str) box_from_bytes(_str, sizeof(_str) - 1)
61 TEST_CASE(
"Filter value with no special characters is unchanged");
72 TEST_CASE(
"RFC 4515 special characters are hex escaped");
83 TEST_CASE(
"Embedded NUL is escaped rather than truncating the value");
98 TEST_CASE(
"Specials before an embedded NUL are escaped when lengths collide");
109 TEST_CASE(
"Empty filter value stays empty");
120 TEST_CASE(
"DN value with no special characters is unchanged");
131 TEST_CASE(
"RFC 4514 special characters are hex escaped");
154 TEST_CASE(
"Interior '#' is not escaped");
169 TEST_CASE(
"Specials before an embedded NUL are escaped when lengths collide");
182 TEST_CASE(
"Escaping consumes the whole input, NUL included");
196 TEST_CASE(
"Escaping into a buffer that is too small fails and advances neither sbuff");
208 TEST_CASE(
"Leading '#' and interior ',' are escaped");
220 TEST_CASE(
"Empty DN value writes nothing");
227 char const *
const dn_list[] = {
"cn=a*b,dc=example",
"cn=c(d),dc=example", NULL };
230 TEST_CASE(
"DN list filter escapes each DN and ANDs the extra filter");
233 "(&(objectClass=groupOfNames)(|(entryDN=cn=a\\2ab,dc=example)(entryDN=cn=c\\28d\\29,dc=example)))");
236 TEST_CASE(
"DN list filter without an extra filter");
238 TEST_CHECK_STRCMP(filter,
"(|(entryDN=cn=a\\2ab,dc=example)(entryDN=cn=c\\28d\\29,dc=example))");
#define TEST_ASSERT(cond)
#define TEST_CHECK_SLEN(_got, _exp)
#define TEST_CHECK_LEN(_got, _exp)
#define TEST_CHECK_RET(_got, _exp)
#define TEST_CHECK_STRCMP(_got, _exp)
int fr_ldap_filter_box_escape(fr_value_box_t *vb, UNUSED void *uctx)
Escape a value box for use as an RFC 4515 filter assertion value.
fr_slen_t fr_ldap_dn_escape(fr_sbuff_t *out, fr_sbuff_t *in)
Escape a value for use as an RFC 4514 DN attribute value.
fr_slen_t fr_ldap_filter_escape(fr_sbuff_t *out, fr_sbuff_t *in)
Escape a value for use as an RFC 4515 filter assertion value.
int fr_ldap_dn_box_escape(fr_value_box_t *vb, UNUSED void *uctx)
Escape a value box for use as an RFC 4514 DN attribute value.
char * fr_ldap_filter_afrom_dn_list(TALLOC_CTX *ctx, char const *dn_attr, char const *filter, char const *const *dn_list)
Build a filter matching a set of objects by DN.
static void test_filter_afrom_dn_list(void)
static void test_filter_escape_sbuff_no_space(void)
static void test_filter_box_escape_specials(void)
static void test_dn_escape_sbuff_empty(void)
static void test_dn_box_escape_plain(void)
static fr_value_box_t * box_from_bytes(char const *bytes, size_t len)
static void test_dn_box_escape_nul_length_collision(void)
#define TEST_CHECK_BOX_BYTES(_vb, _exp)
Check a value box holds exactly the expected bytes, NUL bytes included.
static void test_filter_box_escape_plain(void)
static void test_filter_box_escape_nul_length_collision(void)
#define BOX_FROM_LITERAL(_str)
Allocate a tainted string box from a literal, NUL bytes included.
static void test_filter_escape_sbuff(void)
static void test_filter_box_escape_nul_truncation(void)
static void test_filter_box_escape_empty(void)
static void test_dn_box_escape_specials(void)
static void test_dn_box_escape_leading(void)
static void test_dn_escape_sbuff(void)
@ FR_TYPE_STRING
String of printable characters.
#define FR_SBUFF_IN(_start, _len_or_end)
#define FR_SBUFF_IN_STR(_start)
#define fr_sbuff_remaining(_sbuff_or_marker)
#define FR_SBUFF_OUT(_start, _len_or_end)
#define fr_sbuff_used(_sbuff_or_marker)
static char buff[sizeof("18446744073709551615")+3]
int fr_value_box_bstrndup(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_dict_attr_t const *enumv, char const *src, size_t len, bool tainted)
Copy a string to to a fr_value_box_t.
#define fr_value_box_alloc(_ctx, _type, _enumv)
Allocate a value box of a specific type.
static size_t char ** out