From 09148cfceae217d5fc2f3606894568ed0c42ae21 Mon Sep 17 00:00:00 2001
From: Ruben S. Montero <rubensm@dacya.ucm.es>
Date: Thu, 19 May 2011 10:48:29 +0200
Subject: [PATCH] Bug: Fixes AuthRequests time_outs in AuthManager. Tests for
 the timeout feature are now included and fix

---
 src/authm/AuthManager.cc          |   10 ++++++++--
 src/authm/test/AuthManagerTest.cc |    4 ++--
 src/authm/test/dummy              |   10 +++++++---
 3 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/src/authm/AuthManager.cc b/src/authm/AuthManager.cc
index c162abc..d661f76 100644
--- a/src/authm/AuthManager.cc
+++ b/src/authm/AuthManager.cc
@@ -360,12 +360,14 @@ void AuthManager::timer_action()
 
     lock();
 
-    for (it=auth_requests.begin();it!=auth_requests.end();it++)
+    it = auth_requests.begin();
+
+    while ( it !=auth_requests.end())
     {
         if (the_time > it->second->time_out)
         {
             AuthRequest * ar = it->second;
-            auth_requests.erase(it);
+            auth_requests.erase(it++);
 
             ar->result  = false;
             ar->timeout = true;
@@ -373,6 +375,10 @@ void AuthManager::timer_action()
 
             ar->notify();
         }
+        else
+        {
+            ++it;
+        }
     }
 
     unlock();
diff --git a/src/authm/test/AuthManagerTest.cc b/src/authm/test/AuthManagerTest.cc
index 32984b3..fc67877 100644
--- a/src/authm/test/AuthManagerTest.cc
+++ b/src/authm/test/AuthManagerTest.cc
@@ -39,7 +39,7 @@ class AuthManagerTest : public OneUnitTest
     CPPUNIT_TEST_SUITE (AuthManagerTest);
 
     CPPUNIT_TEST (load);
-    //CPPUNIT_TEST (timeout);
+    CPPUNIT_TEST (timeout);
     CPPUNIT_TEST (authenticate);
     CPPUNIT_TEST (authorize);
     CPPUNIT_TEST (self_authorize);
@@ -118,7 +118,7 @@ public:
 
         am->load_mads(0);
 
-        ar.add_authenticate("the_user","the_pass","the_secret");
+        ar.add_authenticate("timeout","the_pass","the_secret");
 
         am->trigger(AuthManager::AUTHENTICATE,&ar);
 
diff --git a/src/authm/test/dummy b/src/authm/test/dummy
index 5bb3712..2217040 100755
--- a/src/authm/test/dummy
+++ b/src/authm/test/dummy
@@ -19,9 +19,9 @@
 echo "MAD started" >> mad.log
 
 
-while read COMMAND ARG1 ARG2 ARG3
+while read COMMAND ARG1 ARG2 ARG3 ARG4
 do
-    echo "$COMMAND $ARG1 $ARG2 $ARG3" >> mad.log
+    echo "$COMMAND $ARG1 $ARG2 $ARG3 $ARG4" >> mad.log
     case $COMMAND in
         "INIT")
             echo "INIT SUCCESS"
@@ -31,9 +31,13 @@ do
             exit 0
             ;;
         "AUTHORIZE")
-            echo "AUTHORIZE FAILURE $ARG1 $ARG3"
+            echo "AUTHORIZE FAILURE $ARG1 $ARG3 $ARG4"
             ;;
         "AUTHENTICATE")
+            if [ "$ARG3" = "timeout" ] ; then
+                sleep 4
+            fi
+
             echo "AUTHENTICATE SUCCESS $ARG1"
             ;;
         *)
-- 
1.7.5.1

