Sfoglia il codice sorgente

- more tests
- user lookup for proxy functionality
- authentification with auth and auth_db
- basic accounting functionality
- openser command line arguments
- Credits go to Frederick Bullik, Frederick dot Bullik at 1und1 dot de


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

Henning Westerholt 17 anni fa
parent
commit
7a5b447b92
8 ha cambiato i file con 383 aggiunte e 0 eliminazioni
  1. 25 0
      test/unit/18.sh
  2. 57 0
      test/unit/19.cfg
  3. 29 0
      test/unit/19.sh
  4. 60 0
      test/unit/20.cfg
  5. 41 0
      test/unit/20.sh
  6. 93 0
      test/unit/21.cfg
  7. 38 0
      test/unit/21.sh
  8. 40 0
      test/unit/auth_test.xml

+ 25 - 0
test/unit/18.sh

@@ -0,0 +1,25 @@
+#!/bin/bash
+# runs ../openser with all command line arguments.
+# ommited options are -h -v -C -c -D
+
+# the config file
+CFG=18.cfg
+
+# setup config
+echo -e "debug=3" > $CFG
+
+# start:
+../openser -f ./$CFG -l 127.0.0.1 -n 0 -rR -v  -E -d -T -N 0 -b 23 -m 42 -w ./  -u $(id -u)  -g $(id -g) -P ./pid.out -G ./pgid.out  > /dev/null 2>&1
+
+ret=$?
+
+sleep 1
+
+# clean up:
+killall -9 openser
+
+rm $CFG
+rm pgid.out
+rm pid.out
+
+exit $ret

+ 57 - 0
test/unit/19.cfg

@@ -0,0 +1,57 @@
+# OpenSER config for lookup / registrar testing
+
+#------------------------Global configuration----------------------------------
+debug=3
+fork=yes
+log_stderror=yes
+listen=127.0.0.1
+port=5059
+dns=no
+rev_dns=no
+
+#-----------------------Loading Modiules-------------------------------------
+mpath="../modules/"
+loadmodule "mysql/mysql.so"
+loadmodule "usrloc/usrloc.so"
+loadmodule "registrar/registrar.so"
+loadmodule "sl/sl.so"
+loadmodule "tm/tm.so"
+loadmodule "maxfwd/maxfwd.so"
+#for debugging purposes only
+loadmodule "mi_fifo/mi_fifo.so"
+
+
+#-----------------------Module parameters-------------------------------------
+modparam("mi_fifo", "fifo_name", "/tmp/openser_fifo")
+modparam("usrloc", "db_mode", 3)
+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 (method== ACK) {
+	if (!t_relay()) {
+		sl_reply_error();
+	}
+}
+if (method==BYE){
+	if (!t_relay()) {
+		sl_reply_error();
+	}
+}
+exit();
+}
+

+ 29 - 0
test/unit/19.sh

@@ -0,0 +1,29 @@
+#!/bin/bash
+# check user lockup for proxy functionality with usrloc and registrar
+
+CFG=19.cfg
+
+# needs the sipp utility to run
+which sipp > /dev/null
+ret=$?
+
+if [ ! $? -eq 0 ] ; then
+	echo "sipp not found, not run"
+	exit 0
+fi ;
+
+# 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);"
+
+../openser -f $CFG &> /dev/null
+sipp -sn uas -bg -i localhost -m 10 -f 2 -p 5060 -nr &> /dev/null
+sipp -sn uac -s foo 127.0.0.1:5059 -i 127.0.0.1 -m 10 -f 2 -p 5061 -nr &> /dev/null
+
+ret=$?
+
+# cleanup:
+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\") and (user_agent = \"ser_test\"));"
+exit $ret;

+ 60 - 0
test/unit/20.cfg

@@ -0,0 +1,60 @@
+# OpenSER config for lookup / registrar testing
+
+#------------------------Global configuration----------------------------------
+debug=3
+fork=yes
+log_stderror=yes
+listen=127.0.0.1
+port=5059
+dns=no
+rev_dns=no
+
+#-----------------------Loading Modiules-------------------------------------
+mpath="../modules/"
+loadmodule "mysql/mysql.so"
+loadmodule "usrloc/usrloc.so"
+loadmodule "registrar/registrar.so"
+loadmodule "sl/sl.so"
+loadmodule "tm/tm.so"
+loadmodule "maxfwd/maxfwd.so"
+loadmodule "acc/acc.so"
+#for debugging purposes only
+loadmodule "mi_fifo/mi_fifo.so"
+
+
+#-----------------------Module parameters-------------------------------------
+modparam("mi_fifo", "fifo_name", "/tmp/openser_fifo")
+modparam("usrloc", "db_mode", 3)
+modparam("usrloc", "db_url", "mysql://openser:openserrw@localhost/openser")
+modparam("acc", "log_level", 3)
+modparam("acc", "log_flag", 1)
+#-----------------------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){
+	setflag(1);
+	if (!t_relay()) {
+		sl_reply_error();
+	}
+}
+if (method== ACK) {
+	if (!t_relay()) {
+		sl_reply_error();
+	}
+}
+if (method==BYE){
+	if (!t_relay()) {
+		sl_reply_error();
+	}
+}
+exit();
+}
+

+ 41 - 0
test/unit/20.sh

@@ -0,0 +1,41 @@
+#! /bin/bash
+# test basic accounting functionality
+
+# needs the sipp utility to run
+which sipp > /dev/null
+ret=$?
+
+if [ ! $? -eq 0 ] ; then
+	echo "sipp not found, not run"
+	exit 0
+fi ;
+                
+CFG="20.cfg"
+TMPFILE=`mktemp -t openser-test.XXXXXXXXXX`
+
+# insert a test user into log db
+if [ ! -e $SIPP ] ; then 
+	echo "404 - sipp not found"
+	exit 0
+fi;
+
+# 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);"
+
+sipp -sn uas -bg -i localhost -m 1 -f 10 -p 5060 -nr &> /dev/null
+
+../openser -f $CFG &> $TMPFILE
+
+sipp -sn uac -s foo 127.0.0.1:5059 -i 127.0.0.1 -m 1 -f 10 -p 5061 -nr &> /dev/null
+
+egrep '^ACC:[[:space:]]+transaction[[:space:]]+answered:[[:print:]]*code=200;reason=OK$' $TMPFILE > /dev/null
+ret=$?
+
+# cleanup:
+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\"));"
+
+exit $ret;

+ 93 - 0
test/unit/21.cfg

@@ -0,0 +1,93 @@
+#
+# $Id: openser.cfg 2825 2007-09-27 09:05:52Z henningw $
+#
+# simple quick-start config script
+# Please refer to the Core CookBook at http://www.openser.org/dokuwiki/doku.php
+# for a explanation of possible statements, functions and parameters.
+#
+
+# ----------- global configuration parameters ------------------------
+
+debug=3      # debug level (cmd line: -dddddddddd)
+fork=yes
+log_stderror=yes    # (cmd line: -E)
+children=4
+
+listen=127.0.0.1 
+port=5059
+
+dns=no
+rev_dns=no
+
+# ------------------ module loading ----------------------------------
+
+#set module path
+mpath="../modules/"
+
+# Uncomment this if you want to use SQL database
+loadmodule "mysql/mysql.so"
+
+loadmodule "sl/sl.so"
+loadmodule "tm/tm.so"
+loadmodule "rr/rr.so"
+loadmodule "maxfwd/maxfwd.so"
+loadmodule "usrloc/usrloc.so"
+loadmodule "registrar/registrar.so"
+loadmodule "textops/textops.so"
+loadmodule "auth/auth.so"
+loadmodule "auth_db/auth_db.so"
+
+# ----------------- setting module-specific parameters ---------------
+# -- usrloc params --
+
+# Uncomment this if you want to use SQL database 
+# for persistent storage and comment the previous line
+modparam("usrloc", "db_mode", 3)
+modparam("usrloc", "db_url", "mysql://openser:openserrw@localhost/openser")
+
+# -- auth params --
+# Uncomment if you are using auth module
+#
+modparam("auth_db", "calculate_ha1", 1)
+
+# If you set "calculate_ha1" parameter to 1 (which true in this config), 
+# uncomment also the following parameter)
+#
+modparam("auth_db", "password_column", "password")
+
+# -- rr params --
+# add value to ;lr param to make some broken UAs happy
+modparam("rr", "enable_full_lr", 1)
+
+
+# -------------------------  request routing logic -------------------
+
+# main routing logic
+
+route{
+
+#--------Main sainity checks----------------
+
+#look if msg bounces
+if (!mf_process_maxfwd_header("10")) {
+sl_send_reply("483", "Too Many Hops");
+exit;
+};
+
+#-----------------------------------------
+
+if (uri == myself) {
+	
+	if(method==REGISTER){
+		if (!proxy_authorize("localhost", "subscriber")) {
+			proxy_challenge("localhost", "0");
+		}
+		else{
+			sl_send_reply("200","OK");
+		}
+	}
+
+exit();
+}
+}
+

+ 38 - 0
test/unit/21.sh

@@ -0,0 +1,38 @@
+#!/bin/bash
+# tests the authentification via auth_db
+
+# needs the sipp utility to run
+which sipp > /dev/null
+ret=$?
+
+if [ ! $? -eq 0 ] ; then
+	echo "sipp not found, not run"
+	exit 0
+fi ;
+
+CFG=21.cfg
+
+#insert a test user into log db
+if [ ! -e $SIPP ] ; then 
+	echo "404 - sipp not found"
+	exit 0
+fi;
+
+# add an registrar entry to the db;
+
+#username domain password email-adreess
+mysql --show-warnings -B -u openser --password=openserrw -D openser -e "INSERT INTO subscriber (username, domain, password, email_address) VALUES (\"alice\",\"localhost\",\"alice\",\"alice@localhost\");"
+
+../openser -f $CFG &> /dev/null;
+##sleep 5;
+sipp -s alice 127.0.0.1:5059 -i 127.0.0.1 -m 1 -f 1 -auth_uri alice@localhost -p 5061 -sf auth_test.xml -ap alice &> /dev/null;
+
+ret=$?
+
+#cleanup:
+killall -9 openser &> /dev/null;
+
+mysql  --show-warnings -B -u openser --password=openserrw -D openser -e "DELETE FROM subscriber WHERE((username = \"alice\") and (domain = \"localhost\"));"
+
+
+exit $ret;

+ 40 - 0
test/unit/auth_test.xml

@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+<scenario name="register_client">
+  <send retrans="500">
+      <![CDATA[
+
+      REGISTER sip:localhost:5059 SIP/2.0
+      Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
+      From: <sip:alice@localhost>;tag=[call_number]
+      To: <sip:alice@localhost>
+      Call-ID: [call_id]
+      CSeq: 1 REGISTER
+      Contact: sip:alice@[local_ip]:[local_port]
+      Max-Forwards: 5
+      Expires: 1800
+      User-Agent: SIPp/Linux
+      Content-Length: 0
+      ]]>
+   </send>
+   <recv response="407" auth="true">
+   </recv>
+   
+   <send retrans="500">
+      <![CDATA[
+      REGISTER sip:localhost:5059 SIP/2.0
+      Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
+      From: <sip:alice@localhost>;tag=[call_number]
+      To: <sip:alice@localhost>
+      Call-ID: [call_id]
+      CSeq: 2 REGISTER
+      Contact: sip:alice@[local_ip]:[local_port]
+      [authentication username=alice password=alice realm=localhost];
+      Max-Forwards: 5
+      Expires: 1800
+      User-Agent: SIPp/Linux
+      Content-Length: 0
+    ]]>
+   </send>
+   <recv response="200">
+  </recv>
+   </scenario>