Add unit tests for filtering rules

for both the parser and the translator

TODO: Add reject tests
pull/48/head
Soner Tari 3 years ago
parent e4d27bee99
commit 17630340d2

@ -1644,7 +1644,7 @@ out:
}
#endif /* !WITHOUT_USERAUTH */
static char *
char *
filter_str(filter_t *filter)
{
char *fs = NULL;
@ -2759,7 +2759,7 @@ opts_find_macro(macro_t *macro, char *name)
return NULL;
}
static int WUNRES
int
opts_set_macro(opts_t *opts, char *value, int line_num)
{
#define MAX_MACRO_TOKENS 50
@ -3348,7 +3348,7 @@ filter_rule_parse(opts_t *opts, const char *name, int argc, char **argv, int lin
return filter_rule_translate(opts, name, argc, argv, line_num);
}
static int WUNRES
int
opts_set_filter_rule(opts_t *opts, const char *name, char *value, int line_num)
{
char *argv[sizeof(char *) * MAX_FILTER_RULE_TOKENS];

@ -394,6 +394,7 @@ opts_t *opts_new(void) MALLOC WUNRES;
void opts_free(opts_t *) NONNULL(1);
void opts_free_filter_rules(opts_t *) NONNULL(1);
char *filter_rule_str(filter_rule_t *);
char *filter_str(filter_t *filter);
char *opts_proto_dbg_dump(opts_t *) NONNULL(1);
int opts_set_cacrt(opts_t *, const char *, const char *, tmp_global_opts_t *) NONNULL(1,2,3) WUNRES;
int opts_set_cakey(opts_t *, const char *, const char *, tmp_global_opts_t *) NONNULL(1,2,3) WUNRES;
@ -416,11 +417,13 @@ int opts_set_ciphers(opts_t *, const char *, const char *) NONNULL(1,2,3) WUNRES
int opts_set_ciphersuites(opts_t *, const char *, const char *) NONNULL(1,2,3) WUNRES;
int opts_set_passsite(opts_t *, char *, int) WUNRES;
int opts_set_macro(opts_t *, char *, int) WUNRES;
filter_ip_t *opts_find_ip(filter_ip_t *, char *) NONNULL(2);
#ifndef WITHOUT_USERAUTH
filter_keyword_t *opts_find_keyword(filter_keyword_t *, char *) NONNULL(2);
filter_user_t *opts_find_user(filter_user_t *, char *) NONNULL(2);
#endif /* !WITHOUT_USERAUTH */
int opts_set_filter_rule(opts_t *, const char *, char *, int) WUNRES;
filter_t *opts_set_filter(filter_rule_t *);
#define OPTS_DEBUG(global) unlikely((global)->debug)

File diff suppressed because it is too large Load Diff

@ -66,6 +66,7 @@ main_suite(void)
}
Suite * opts_suite(void);
Suite * filter_suite(void);
Suite * dynbuf_suite(void);
Suite * logbuf_suite(void);
Suite * cert_suite(void);
@ -92,6 +93,7 @@ main(UNUSED int argc, UNUSED char *argv[])
sr = srunner_create(blank_suite());
srunner_add_suite(sr, main_suite());
srunner_add_suite(sr, opts_suite());
srunner_add_suite(sr, filter_suite());
srunner_add_suite(sr, dynbuf_suite());
srunner_add_suite(sr, logbuf_suite());
srunner_add_suite(sr, cert_suite());

@ -3,6 +3,7 @@
* https://www.roe.ch/SSLsplit
*
* Copyright (c) 2009-2019, Daniel Roethlisberger <daniel@roe.ch>.
* Copyright (c) 2017-2021, Soner Tari <sonertari@gmail.com>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -862,6 +863,8 @@ START_TEST(opts_get_name_value_01)
fail_unless(retval == 0, "failed parsing name value");
free(name);
close(2);
// Leading white space must be handled by the caller
// We cannot modify the name pointer, so we return -1
// So we don't actually need a test for " Name Value", or similar

Loading…
Cancel
Save