add "make check" to miniupnpd

This commit is contained in:
Thomas Bernard 2015-09-22 16:02:19 +02:00
parent 146613a493
commit 71a7846479
5 changed files with 65 additions and 6 deletions

View File

@ -39,7 +39,7 @@ script:
- 'MAKEFILE=Makefile && if [ -f Makefile.linux -a "$TRAVIS_OS_NAME" = "linux" ]; then MAKEFILE=Makefile.linux; elif [ -f Makefile.macosx -a "$TRAVIS_OS_NAME" = "osx" ]; then MAKEFILE=Makefile.macosx; fi'
- 'if [ "$MAKEFILE" = "Makefile.macosx" ]; then make -f $MAKEFILE depend; fi'
- 'make -f $MAKEFILE -j3'
- 'if [ "$PROJECT" = "miniupnpc" -o "$PROJECT" = "minissdpd" ]; then make -f $MAKEFILE check; fi'
- 'if [ "$PROJECT" = "miniupnpc" -o "$PROJECT" = "minissdpd" -o "$PROJECT" = "miniupnpd" ]; then make -f $MAKEFILE check; fi'
- 'if [ "$PROJECT" = "miniupnpc" ]; then INSTALLPREFIX="$HOME/_pythonmodule" make -f $MAKEFILE pythonmodule; fi'
after_success:

View File

@ -15,3 +15,4 @@ netfilter/testiptcrdr
netfilter/testiptcrdr_dscp
netfilter/testiptcrdr_peer
testdescs
validateupnppermissions

View File

@ -167,6 +167,7 @@ clean:
$(RM) testgetroute.o testasyncsendto.o
$(RM) testportinuse.o
$(RM) miniupnpdctl.o
$(RM) validateupnppermissions
install: miniupnpd miniupnpd.8 miniupnpd.conf genuuid \
netfilter/iptables_init.sh netfilter/iptables_removeall.sh \
@ -197,6 +198,12 @@ else
sed -i -e "s/^uuid=[-0-9a-f]*/uuid=`($(STAGING_DIR_HOST)/bin/genuuid||$(STAGING_DIR_HOST)/bin/uuidgen||$(STAGING_DIR_HOST)/bin/uuid) 2>/dev/null`/" miniupnpd.conf
endif
check: validateupnppermissions
validateupnppermissions: testupnppermissions testupnppermissions.sh
./testupnppermissions.sh
touch $@
miniupnpd: $(BASEOBJS) $(LNXOBJS) $(NETFILTEROBJS)
testupnpdescgen: $(TESTUPNPDESCGENOBJS)

View File

@ -1,5 +1,5 @@
/* $Id: testupnppermissions.c,v 1.3 2009/09/14 15:24:46 nanard Exp $ */
/* (c) 2007-2009 Thomas Bernard
/* (c) 2007-2015 Thomas Bernard
* MiniUPnP Project
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
*/
@ -35,7 +35,7 @@ print_upnpperm(const struct upnpperm * p)
int main(int argc, char * * argv)
{
int i, r;
int i, r, ret;
struct upnpperm p;
if(argc < 2) {
fprintf(stderr, "Usage: %s \"permission line\" [...]\n", argv[0]);
@ -43,8 +43,7 @@ int main(int argc, char * * argv)
return 1;
}
openlog("testupnppermissions", LOG_PERROR, LOG_USER);
/* for(i=0; i<argc; i++)
printf("%2d '%s'\n", i, argv[i]); */
ret = 0;
for(i=1; i<argc; i++) {
printf("%2d '%s'\n", i, argv[i]);
memset(&p, 0, sizeof(struct upnpperm));
@ -54,9 +53,10 @@ int main(int argc, char * * argv)
print_upnpperm(&p);
} else {
printf("Permission read failed, please check its correctness\n");
ret++;
}
putchar('\n');
}
return 0;
return ret;
}

View File

@ -0,0 +1,51 @@
#!/bin/sh
# $Id: $
RULE[1]="allow 1-20000 11.12.13.14/22 1234"
RULEA[1]="allow 1-20000 0b0c0d0e/fffffc00 1234-1234"
RULEB[1]="allow 1-20000 11.12.13.14/255.255.252.0 1234-1234"
RULE[2]="deny 55 21.22.23.24/17 555-559"
RULEA[2]="deny 55-55 15161718/ffff8000 555-559"
RULEB[2]="deny 55-55 21.22.23.24/255.255.128.0 555-559"
i=1
s=1
./testupnppermissions "${RULE[@]}" | while read l;
do
if [ -z "$l" ]; then i=$(($i+1)); s=1; else
#echo "$i $s"
case $s in
1)
if [ "$i '${RULE[$i]}'" != "$l" ] ; then
exit $s
fi;;
2)
if [ ! \( "perm rule added : ${RULEA[$i]}" = "$l" \) ] ; then
exit $s
fi;;
3)
if [ ! \( "Permission read successfully" = "$l" \) ] ; then
exit $s
fi;;
4)
if [ ! \( "${RULEB[$i]}" = "$l" \) ] ; then
exit $s
fi;;
*)
echo "$i $s : $l"
exit $s
;;
esac
s=$(($s+1))
fi
done
# retrieve return status from subshell
r=$?
if [ $r -eq 0 ] ; then
echo "testupnppermissions tests OK"
else
echo "testupnppermissions tests FAILED"
fi
exit $r