2
0
Эх сурвалжийг харах

- various cleanups and checks added
- move mysql command definition to own include file
- cleanups some configurations
- add command to check for a mysql DB access with the default auth data
- fix some carrierroute related mysql warnings


git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@4482 689a6050-402a-0410-94f2-e92a70836424

Henning Westerholt 17 жил өмнө
parent
commit
8028d6c965

+ 2 - 1
test/unit/11.sh

@@ -20,10 +20,11 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 source include/require
+source include/database
 
 CFG=11.cfg
 
-if ! (check_netcat && check_openser && check_module "db_mysql"); then
+if ! (check_netcat && check_openser && check_module "db_mysql" && check_mysql); then
 	exit 0
 fi ;
 

+ 5 - 6
test/unit/13.sh

@@ -20,6 +20,7 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 source include/require
+source include/database
 
 CFG=13.cfg
 
@@ -34,8 +35,6 @@ echo "loadmodule \"db_mysql/db_mysql.so\"" >> $CFG
 echo "modparam(\"carrierroute\", \"config_source\", \"db\")" >> $CFG
 
 # setup database
-MYSQL="mysql openser -u openser --password=openserrw -e"
-
 $MYSQL "insert into route_tree (id, carrier) values ('1', 'carrier1');"
 $MYSQL "insert into route_tree (id, carrier) values ('2', 'default');"
 $MYSQL "insert into route_tree (id, carrier) values ('3', 'carrier2');"
@@ -53,13 +52,13 @@ $MYSQL "insert into carrierroute (id, carrier, domain, scan_prefix, prob, strip,
 $MYSQL "insert into carrierroute (id, carrier, domain, scan_prefix, prob, strip, rewrite_host) values ('11','3','0','','1','0','host1.local');"
 
 $MYSQL "insert into carrierfailureroute(id, carrier, domain, scan_prefix, host_name, reply_code, flags,
-mask, next_domain) values ('1', '1', '1', '49', 'host1.local', '404', '', '', '2');"
+mask, next_domain) values ('1', '1', '1', '49', 'host1.local', '404', '0', '0', '2');"
 $MYSQL "insert into carrierfailureroute(id, carrier, domain, scan_prefix, host_name, reply_code, flags,
-mask, next_domain) values ('2', '1', '1', '49', 'host1.local', '4..', '', '', '3');"
+mask, next_domain) values ('2', '1', '1', '49', 'host1.local', '4..', '0', '0', '3');"
 $MYSQL "insert into carrierfailureroute(id, carrier, domain, scan_prefix, host_name, reply_code, flags,
-mask, next_domain) values ('3', '2', '1', '49', 'host1.local', '503', '', '', '2');"
+mask, next_domain) values ('3', '2', '1', '49', 'host1.local', '503', '0', '0', '2');"
 $MYSQL "insert into carrierfailureroute(id, carrier, domain, scan_prefix, host_name, reply_code, flags,
-mask, next_domain) values ('4', '2', '2', '49', 'host1.local', '5..', '', '', '3');"
+mask, next_domain) values ('4', '2', '2', '49', 'host1.local', '5..', '0', '0', '3');"
 
 ../openser -w . -f $CFG > /dev/null
 

+ 7 - 20
test/unit/19.cfg

@@ -28,30 +28,17 @@ modparam("usrloc", "db_url", "mysql://openser:openserrw@localhost/openser")
 
 #-----------------------Routing configuration---------------------------------#
 route{
-if (!mf_process_maxfwd_header("10")) {
-	sl_send_reply("483","Too Many Hops");
-	exit();
-}
-
-if(!lookup ("location")){
-	sl_send_reply("404", "Not Found");
-}
-
-if(method==INVITE){
-	if (!t_relay()) {
-		sl_reply_error();
+	if (!mf_process_maxfwd_header("10")) {
+		sl_send_reply("483","Too Many Hops");
+		exit();
 	}
-}
-if (method== ACK) {
-	if (!t_relay()) {
-		sl_reply_error();
+
+	if(!lookup ("location")){
+		sl_send_reply("404", "Not Found");
 	}
-}
-if (method==BYE){
+
 	if (!t_relay()) {
 		sl_reply_error();
 	}
 }
-exit();
-}
 

+ 3 - 2
test/unit/19.sh

@@ -20,6 +20,7 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 source include/require
+source include/database
 
 if ! (check_sipp && check_openser); then
 	exit 0
@@ -32,7 +33,7 @@ UAC=5080
 
 
 # add an registrar entry to the db;
-mysql --show-warnings -B -u openser --password=openserrw -D openser -e "INSERT INTO location (username,contact,socket,user_agent,cseq,q) VALUES (\"foo\",\"sip:foo@localhost:$UAS\",\"udp:127.0.0.1:$UAS\",\"ser_test\",1,-1);"
+$MYSQL "INSERT INTO location (username,contact,socket,user_agent,cseq,q) VALUES (\"foo\",\"sip:foo@localhost:$UAS\",\"udp:127.0.0.1:$UAS\",\"ser_test\",1,-1);"
 
 ../openser -w . -f $CFG &> /dev/null
 sipp -sn uas -bg -i localhost -m 10 -f 2 -p $UAS &> /dev/null
@@ -44,5 +45,5 @@ ret=$?
 killall -9 sipp > /dev/null 2>&1
 killall -9 openser > /dev/null 2>&1
 
-mysql  --show-warnings -B -u openser --password=openserrw -D openser -e "DELETE FROM location WHERE ((contact = \"sip:foo@localhost:$UAS\") and (user_agent = \"ser_test\"));"
+$MYSQL "DELETE FROM location WHERE ((contact = \"sip:foo@localhost:$UAS\") and (user_agent = \"ser_test\"));"
 exit $ret;

+ 3 - 1
test/unit/2.sh

@@ -22,9 +22,11 @@
 # Needs a default openser database setup for mysql
 
 source include/require
+source include/database
+
 CFG=2.cfg
 
-if ! (check_openser && check_module "db_mysql" ); then
+if ! (check_openser && check_module "db_mysql" && check_mysql); then
 	exit 0
 fi ;
 

+ 10 - 22
test/unit/20.cfg

@@ -34,32 +34,20 @@ modparam("db_mysql", "timeout_interval", 2)
 #-----------------------Routing configuration---------------------------------#
 
 route{
-if (!mf_process_maxfwd_header("10")) {
-	sl_send_reply("483","Too Many Hops");
-	exit();
-}
-
-if(!lookup ("location")){
-	sl_send_reply("404", "Not Found");
-}
+	if (!mf_process_maxfwd_header("10")) {
+		sl_send_reply("483","Too Many Hops");
+		exit();
+	}
 
-if(method=="INVITE"){
-	setflag(1);
-	if (!t_relay()) {
-		sl_reply_error();
+	if(!lookup ("location")){
+		sl_send_reply("404", "Not Found");
 	}
-}
 
-if (method=="ACK") {
-	if (!t_relay()) {
-		sl_reply_error();
+	if(method=="INVITE"){
+		setflag(1);
 	}
-}
-if (method=="BYE") {
+
 	if (!t_relay()) {
-		sl_reply_error();
+			sl_reply_error();
 	}
 }
-exit();
-
-}

+ 3 - 2
test/unit/20.sh

@@ -20,6 +20,7 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 source include/require
+source include/database
 
 if ! (check_sipp && check_openser); then
 	exit 0
@@ -29,7 +30,7 @@ CFG="20.cfg"
 TMPFILE=`mktemp -t openser-test.XXXXXXXXXX`
 
 # add an registrar entry to the db;
-mysql --show-warnings -B -u openser --password=openserrw -D openser -e "INSERT INTO location (username,contact,socket,user_agent,cseq,q) VALUES (\"foo\",\"sip:foo@localhost\",\"udp:127.0.0.1:5060\",\"ser_test\",1,-1);"
+$MYSQL "INSERT INTO location (username,contact,socket,user_agent,cseq,q) VALUES (\"foo\",\"sip:foo@localhost\",\"udp:127.0.0.1:5060\",\"ser_test\",1,-1);"
 
 sipp -sn uas -bg -i localhost -m 1 -f 10 -p 5060 &> /dev/null
 
@@ -45,6 +46,6 @@ killall -9 sipp &> /dev/null
 killall -9 openser &> /dev/null
 rm $TMPFILE
 
-mysql  --show-warnings -B -u openser --password=openserrw -D openser -e "DELETE FROM location WHERE ((contact = \"sip:foo@localhost\") and (user_agent = \"ser_test\"));"
+$MYSQL "DELETE FROM location WHERE ((contact = \"sip:foo@localhost\") and (user_agent = \"ser_test\"));"
 
 exit $ret;

+ 1 - 2
test/unit/21.sh

@@ -20,6 +20,7 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 source include/require
+source include/database
 
 if ! (check_sipp && check_openser); then
 	exit 0
@@ -28,8 +29,6 @@ fi ;
 
 CFG=21.cfg
 
-MYSQL="mysql openser -u openser --password=openserrw -e"
-
 # add an registrar entry to the db;
 $MYSQL "INSERT INTO subscriber (username, domain, password, email_address) VALUES (\"alice\",\"localhost\",\"alice\",\"alice@localhost\");"
 

+ 1 - 3
test/unit/25.sh

@@ -20,6 +20,7 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 source include/require
+source include/database
 
 if ! (check_sipp && check_openser); then
 	exit 0
@@ -27,9 +28,6 @@ fi ;
 
 CFG=25.cfg
 
-MYSQL="mysql openser -u openser --password=openserrw -e"
-
-
 # add an registrar entry to the db;
 $MYSQL "insert into location (username,contact,socket,user_agent,cseq,q) values (\"49721123456789\",\"sip:123456789@localhost\",\"udp:127.0.0.1:5060\",\"ser_test\",1,-1);"
 

+ 7 - 8
test/unit/26.sh

@@ -20,8 +20,9 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 source include/require
+source include/database
 
-if ! (check_openser && check_module "carrierroute" ); then
+if ! (check_openser && check_module "carrierroute"); then
 	exit 0
 fi ;
 
@@ -34,8 +35,6 @@ echo "loadmodule \"db_mysql/db_mysql.so\"" >> $CFG
 echo "modparam(\"carrierroute\", \"config_source\", \"db\")" >> $CFG
 
 # setup database
-MYSQL="mysql openser -u openser --password=openserrw -e"
-
 $MYSQL "insert into route_tree (id, carrier) values ('1', 'default');"
 $MYSQL "insert into route_tree (id, carrier) values ('2', 'carrier1');"
 $MYSQL "insert into route_tree (id, carrier) values ('3', 'carrier2');"
@@ -58,11 +57,11 @@ $MYSQL "insert into carrierroute (id, carrier, domain, scan_prefix, flags, prob,
 values ('8','3','2','49','0','1','0','127.0.0.1:10000');"
 
 $MYSQL "insert into carrierfailureroute(id, carrier, domain, scan_prefix, host_name, reply_code,
-flags, mask, next_domain) values ('1', '3', '0', '49', '127.0.0.1:10000', '5..', '', '', 'fallback');"
+flags, mask, next_domain) values ('1', '3', '0', '49', '127.0.0.1:10000', '5..', '0', '0', 'fallback');"
 $MYSQL "insert into carrierfailureroute(id, carrier, domain, scan_prefix, host_name, reply_code,
-flags, mask, next_domain) values ('2', '3', 'fallback', '49', '127.0.0.1:10000', '483', '', '', '2');"
+flags, mask, next_domain) values ('2', '3', 'fallback', '49', '127.0.0.1:10000', '483', '0', '0', '2');"
 $MYSQL "insert into carrierfailureroute(id, carrier, domain, scan_prefix, host_name, reply_code,
-flags, mask, next_domain) values ('3', '3', 'fallback', '49', '127.0.0.1:9000', '4..', '', '', '2');"
+flags, mask, next_domain) values ('3', '3', 'fallback', '49', '127.0.0.1:9000', '4..', '0', '0', '2');"
 
 $MYSQL "alter table subscriber add cr_preferred_carrier int(10) default NULL;"
 
@@ -104,9 +103,9 @@ if [ "$ret" -eq 0 ] ; then
 fi;
 
 $MYSQL "insert into carrierfailureroute(id, carrier, domain, scan_prefix, host_name, reply_code,
-flags, mask, next_domain) values ('4', '3', 'fallback', '49', '127.0.0.1:10000', '4..', '', '', '4');"
+flags, mask, next_domain) values ('4', '3', 'fallback', '49', '127.0.0.1:10000', '4..', '0', '0', '4');"
 $MYSQL "insert into carrierfailureroute(id, carrier, domain, scan_prefix, host_name, reply_code,
-flags, mask, next_domain) values ('5', '3', 'fallback', '49', '127.0.0.1:10000', '486', '', '', '2');"
+flags, mask, next_domain) values ('5', '3', 'fallback', '49', '127.0.0.1:10000', '486', '0', '0', '2');"
 
 if [ ! "$ret" -eq 0 ] ; then
 	../scripts/openserctl fifo cr_reload_routes

+ 4 - 1
test/unit/27.sh

@@ -20,8 +20,11 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 source include/require
+source include/database
 
-if ! (check_sipp && check_openser && check_module "db_mysql" && check_module "presence" && check_module "presence_xml"); then
+if ! (check_sipp && check_openser && check_module "db_mysql" \
+	&& check_module "presence" && check_module "presence_xml" \
+	&& check_mysql); then
 	exit 0
 fi ;
 

+ 2 - 1
test/unit/28.sh

@@ -20,8 +20,9 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 source include/require
+source include/database
 
-if ! (check_sipp && check_openser && check_module "db_mysql" && check_module "cpl-c"); then
+if ! (check_sipp && check_openser && check_module "db_mysql" && check_module "cpl-c" && check_mysql); then
 	exit 0
 fi ;
 

+ 2 - 2
test/unit/31.sh

@@ -20,15 +20,15 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 source include/require
+source include/database
 
-if ! (check_openser && check_module "db_mysql"); then
+if ! (check_openser && check_module "db_mysql" && check_mysql); then
 	exit 0
 fi ;
 
 CFG=11.cfg
 
 DOMAIN="local"
-MYSQL="mysql openser -u openser --password=openserrw -e"
 
 cp $CFG $CFG.bak
 

+ 3 - 1
test/unit/34.sh

@@ -22,6 +22,8 @@
 # Needs a default openser database setup for mysql
 
 source include/require
+source include/database
+
 CFG=34.cfg
 
 if ! (check_openser && check_module "db_mysql" && check_module "presence" \
@@ -29,7 +31,7 @@ if ! (check_openser && check_module "db_mysql" && check_module "presence" \
 		&& check_module "xcap_client" && check_module "rls" \
 		&& check_module "presence_mwi" && check_module "pua_bla" \
 		&& check_module "pua_mi" && check_module "pua_usrloc" \
-		&& check_module "pua_xmpp" && check_module "xmpp"); then
+		&& check_module "pua_xmpp" && check_module "xmpp" && check_mysql); then
 	exit 0
 fi ;
 

+ 9 - 8
test/unit/35.sh

@@ -20,6 +20,7 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 source include/require
+source include/database
 
 if ! (check_sipp && check_openser); then
 	exit 0
@@ -33,22 +34,22 @@ IP="127.0.0.31"
 MASK=27
 
 # add an registrar entry to the db;
-mysql --show-warnings -B -u openser --password=openserrw -D openser -e "INSERT INTO location (username,contact,socket,user_agent,cseq,q) VALUES (\"foo\",\"sip:foo@localhost:$UAS\",\"udp:127.0.0.1:$UAS\",\"ser_test\",1,-1);"
-mysql --show-warnings -B -u openser --password=openserrw -D openser -e "INSERT INTO trusted (src_ip, proto) VALUES (\"127.0.0.1\",\"any\");"
+$MYSQL "INSERT INTO location (username,contact,socket,user_agent,cseq,q) VALUES (\"foo\",\"sip:foo@localhost:$UAS\",\"udp:127.0.0.1:$UAS\",\"ser_test\",1,-1);"
+$MYSQL "INSERT INTO trusted (src_ip, proto) VALUES (\"127.0.0.1\",\"any\");"
 
-mysql --show-warnings -B -u openser --password=openserrw -D openser -e "INSERT INTO address (ip_addr, mask) VALUES ('$IP', '$MASK');"
+$MYSQL "INSERT INTO address (ip_addr, mask) VALUES ('$IP', '$MASK');"
 
 ../openser -w . -f $CFG &> /dev/null
 sipp -sn uas -bg -i localhost -m 10 -f 2 -p $UAS &> /dev/null
 sipp -sn uac -s foo 127.0.0.1:$SRV -i localhost -m 10 -f 2 -p $UAC &> /dev/null
 ret=$?
-mysql --show-warnings -B -u openser --password=openserrw -D openser -e "DELETE FROM address WHERE (ip_addr='$IP' AND mask='$MASK');"
+$MYSQL "DELETE FROM address WHERE (ip_addr='$IP' AND mask='$MASK');"
 
 if [ "$ret" -eq 0 ] ; then
 	killall sipp
 	IP="127.47.6.254"
 	MASK=10
-	mysql --show-warnings -B -u openser --password=openserrw -D openser -e "INSERT INTO address (ip_addr, mask) VALUES ('$IP', '$MASK');"
+	$MYSQL "INSERT INTO address (ip_addr, mask) VALUES ('$IP', '$MASK');"
 	
 	../scripts/openserctl fifo address_reload
 	#../scripts/openserctl fifo address_dump
@@ -56,7 +57,7 @@ if [ "$ret" -eq 0 ] ; then
 	sipp -sn uas -bg -i localhost -m 10 -f 2 -p $UAS &> /dev/null
 	sipp -sn uac -s foo 127.0.0.1:$SRV -i localhost -m 10 -f 2 -p $UAC &> /dev/null
 	ret=$?
-	mysql --show-warnings -B -u openser --password=openserrw -D openser -e "DELETE FROM address WHERE (ip_addr='$IP' AND mask='$MASK');"
+	$MYSQL "DELETE FROM address WHERE (ip_addr='$IP' AND mask='$MASK');"
 fi;
 
 
@@ -64,7 +65,7 @@ fi;
 killall -9 sipp > /dev/null 2>&1
 killall -9 openser > /dev/null 2>&1
 
-mysql  --show-warnings -B -u openser --password=openserrw -D openser -e "DELETE FROM location WHERE ((contact = \"sip:foo@localhost:$UAS\") and (user_agent = \"ser_test\"));"
-mysql --show-warnings -B -u openser --password=openserrw -D openser -e "DELETE FROM trusted WHERE (src_ip=\"127.0.0.1\");"
+$MYSQL "DELETE FROM location WHERE ((contact = \"sip:foo@localhost:$UAS\") and (user_agent = \"ser_test\"));"
+$MYSQL "DELETE FROM trusted WHERE (src_ip=\"127.0.0.1\");"
 
 exit $ret;

+ 34 - 0
test/unit/include/database

@@ -0,0 +1,34 @@
+# Copyright (C) 2008 1&1 Internet AG
+#
+# This file is part of openser, a free SIP server.
+#
+# openser is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version
+#
+# openser is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+MYSQL="mysql openser --show-warnings --batch --user=openser --password=openserrw -e"
+
+function check_mysql() {
+	$MYSQL "select * from location;"
+	if ! [ "$?" -eq 0 ] ; then
+		echo "can't read from database"
+		return -1
+	fi;
+	$MYSQL "insert into location (user_agent) values ('___test___');"
+	if ! [ "$?" -eq 0 ] ; then
+		echo "can't write to database"
+		return -1
+	fi;
+	$MYSQL "delete from location where user_agent ='___test___';"
+	return 0
+}