mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-14 13:56:01 +03:00
Update unit test framework to build with libtool and show test name in debug log.
This commit is contained in:
parent
45e85e4c89
commit
96b3ea6f21
@ -5,11 +5,17 @@ MOD_SECURITY2 = mod_security2 apache2_config apache2_io apache2_util \
|
||||
msc_logging msc_xml msc_multipart modsecurity msc_parsers msc_util msc_pcre \
|
||||
persist_dbm msc_reqbody pdf_protect msc_geo acmp msc_lua
|
||||
|
||||
MSC_TEST = re re_operators re_actions re_tfns re_variables \
|
||||
msc_logging msc_xml msc_multipart modsecurity \
|
||||
msc_parsers msc_util msc_pcre persist_dbm \
|
||||
msc_reqbody msc_geo acmp msc_lua
|
||||
|
||||
MOD_SECURITY2_H = re.h modsecurity.h msc_logging.h msc_multipart.h msc_parsers.h \
|
||||
msc_pcre.h msc_util.h msc_xml.h persist_dbm.h apache2.h pdf_protect.h \
|
||||
msc_geo.h acmp.h utf8tables.h msc_lua.h
|
||||
|
||||
CC = @CC@
|
||||
CC = @APXS_CC@
|
||||
LIBTOOL = @APXS_LIBTOOL@
|
||||
PERL = @PERL@
|
||||
EXTRA_CFLAGS = @EXTRA_CFLAGS@
|
||||
MODSEC_EXTRA_CFLAGS = @MODSEC_EXTRA_CFLAGS@
|
||||
@ -86,18 +92,7 @@ mod_security2.la: $(MOD_SECURITY2_H) *.c
|
||||
done; \
|
||||
$(COMPILE_APACHE_MOD) $(APXS_EXTRA_CFLAGS) $(MODSEC_APXS_EXTRA_CFLAGS) $$src
|
||||
|
||||
### Experimental Test Framework (UNIX only right now)
|
||||
TESTOBJS = re.o re_operators.o re_actions.o re_tfns.o re_variables.o \
|
||||
msc_logging.o msc_xml.o msc_multipart.o modsecurity.o \
|
||||
msc_parsers.o msc_util.o msc_pcre.o persist_dbm.o \
|
||||
msc_reqbody.o msc_geo.o acmp.o msc_lua.o
|
||||
|
||||
msc_test: mod_security2.la msc_test.c
|
||||
@$(CC) $(CPPFLAGS) $(LDFLAGS) $(APXS_INCLUDES) $(EXTRA_CFLAGS) $(MODSEC_EXTRA_CFLAGS) $(APR_CFLAGS) $(APU_CFLAGS) -o msc_test $(TESTOBJS) msc_test.c $(LIBS) $(APR_LIBS) $(APU_LIBS) $(APXS_LIBS) $(APR_LINK_LD) $(APU_LINK_LD)
|
||||
|
||||
test: t/run-tests.pl msc_test
|
||||
@$(PERL) t/run-tests.pl
|
||||
|
||||
### MLogC
|
||||
mlogc:
|
||||
@$(MAKE) -C mlogc-src mlogc \
|
||||
&& cp -p mlogc-src/mlogc ../tools \
|
||||
@ -113,3 +108,19 @@ mlogc-static:
|
||||
&& echo "Successfully built \"mlogc-static\" in ../tools." \
|
||||
&& echo "See: mlogc-src/INSTALL" \
|
||||
&& echo
|
||||
|
||||
### Experimental Test Framework (*NIX only right now)
|
||||
msc_test.lo: msc_test.c
|
||||
$(LIBTOOL) --mode=compile $(CC) $(EXTRA_CFLAGS) $(MODSEC_EXTRA_CFLAGS) $(CPPFLAGS) -c msc_test.c
|
||||
|
||||
msc_test: $(TESTOBJS) msc_test.lo
|
||||
@objs=""; \
|
||||
for f in $(MSC_TEST); do \
|
||||
objs="$$objs $$f.lo"; \
|
||||
done; \
|
||||
$(LIBTOOL) --mode=link $(CC) $$objs -o msc_test msc_test.lo $(LDFLAGS) $(LIBS) $(APR_LINK_LD) $(APU_LINK_LD)
|
||||
|
||||
test: t/run-tests.pl msc_test
|
||||
@rm -f msc-test-debug.log; \
|
||||
$(PERL) t/run-tests.pl
|
||||
|
||||
|
@ -93,6 +93,8 @@ VERSION_OK
|
||||
APXS_CFLAGS="`$APXS -q CFLAGS` `$APXS -q EXTRA_CFLAGS`"
|
||||
APXS_LDFLAGS="`$APXS -q LDFLAGS` `$APXS -q EXTRA_LDFLAGS`"
|
||||
APXS_LIBS="`$APXS -q LIBS` `$APXS -q EXTRA_LIBS`"
|
||||
APXS_LIBTOOL="`$APXS -q LIBTOOL`"
|
||||
APXS_CC="`$APXS -q CC`"
|
||||
else
|
||||
AC_MSG_ERROR(couldn't find APXS)
|
||||
fi
|
||||
@ -231,6 +233,8 @@ AC_SUBST(MODSEC_APXS_EXTRA_CFLAGS)
|
||||
AC_SUBST(APXS_LDFLAGS)
|
||||
AC_SUBST(APXS_LIBS)
|
||||
AC_SUBST(APXS_CFLAGS)
|
||||
AC_SUBST(APXS_LIBTOOL)
|
||||
AC_SUBST(APXS_CC)
|
||||
|
||||
CHECK_PCRE()
|
||||
CHECK_APR()
|
||||
|
@ -25,6 +25,7 @@
|
||||
#define RESULT_WRONGRET -4
|
||||
|
||||
/* Globals */
|
||||
static char *test_name = NULL;
|
||||
static apr_pool_t *g_mp = NULL;
|
||||
static modsec_rec *g_msr = NULL;
|
||||
msc_engine *modsecurity = NULL;
|
||||
@ -66,7 +67,7 @@ void msr_log(modsec_rec *msr, int level, const char *text, ...) {
|
||||
if (msr->txcfg->debuglog_fd != NULL) {
|
||||
apr_size_t nbytes_written = 0;
|
||||
apr_vsnprintf(str1, sizeof(str1), text, ap);
|
||||
apr_snprintf(str2, sizeof(str2), "[%d] %s\n", level, str1);
|
||||
apr_snprintf(str2, sizeof(str2), "[%d] [%s] %s\n", level, test_name, str1);
|
||||
|
||||
apr_file_write_full(msr->txcfg->debuglog_fd, str2, strlen(str2), &nbytes_written);
|
||||
}
|
||||
@ -366,6 +367,8 @@ int main(int argc, const char * const argv[])
|
||||
returnval = argv[4];
|
||||
}
|
||||
|
||||
test_name = apr_psprintf(g_mp, "%s/%s", type, name);
|
||||
|
||||
if (apr_file_open_stdin(&fd, g_mp) != APR_SUCCESS) {
|
||||
fprintf(stderr, "Failed to open stdin\n");
|
||||
exit(1);
|
||||
|
Loading…
x
Reference in New Issue
Block a user