myserver-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[myserver-commit] [2851] Added `XmlValidator' class test.


From: Giuseppe Scrivano
Subject: [myserver-commit] [2851] Added `XmlValidator' class test.
Date: Sun, 28 Sep 2008 14:44:47 +0000

Revision: 2851
          http://svn.sv.gnu.org/viewvc/?view=rev&root=myserver&revision=2851
Author:   gscrivano
Date:     2008-09-28 14:44:47 +0000 (Sun, 28 Sep 2008)

Log Message:
-----------
Added `XmlValidator' class test.

Modified Paths:
--------------
    branches/myserver_sec_new/include/conf/security/xml_validator.h
    branches/myserver_sec_new/src/conf/security/xml_validator.cpp

Added Paths:
-----------
    branches/myserver_sec_new/tests/test_xml_validator.cpp

Modified: branches/myserver_sec_new/include/conf/security/xml_validator.h
===================================================================
--- branches/myserver_sec_new/include/conf/security/xml_validator.h     
2008-09-28 12:49:53 UTC (rev 2850)
+++ branches/myserver_sec_new/include/conf/security/xml_validator.h     
2008-09-28 14:44:47 UTC (rev 2851)
@@ -38,7 +38,7 @@
 
   virtual int getPermissionMaskImpl (SecurityToken *st);
 private:
-  int computeXmlNode (xmlNodePtr node, SecurityToken *st);
+  int computeXmlNode (xmlNodePtr node, SecurityToken *st, int *cmd);
   SecurityCache* getCache(Server*);
   SecurityCache *secCache;
   Mutex cacheMutex;

Modified: branches/myserver_sec_new/src/conf/security/xml_validator.cpp
===================================================================
--- branches/myserver_sec_new/src/conf/security/xml_validator.cpp       
2008-09-28 12:49:53 UTC (rev 2850)
+++ branches/myserver_sec_new/src/conf/security/xml_validator.cpp       
2008-09-28 14:44:47 UTC (rev 2851)
@@ -78,14 +78,58 @@
   if (xmlFile == NULL)
     return 0;
 
+  for (xmlNodePtr cur = xmlFile->getDoc ()->children; cur; cur = cur->next)
+    if (cur->type == XML_ELEMENT_NODE)
+    {
+      int cmd;
 
-  return computeXmlNode (xmlFile->getDoc ()->children, st);
+      computeXmlNode (cur, st, &cmd);
+
+      return cmd;
+    }
+
+  return 0;
 }
 
 /*!
  *Compute the current XML node.
  */
-int XmlValidator::computeXmlNode (xmlNodePtr node, SecurityToken *st)
+int XmlValidator::computeXmlNode (xmlNodePtr node, SecurityToken *st, int *cmd)
 {
+  printf ("%s\n", node->name);
+
+  if (node == NULL)
+    return 0;
+
+  for (xmlNodePtr cur = node->children; cur; cur = cur->next)
+    if (cur->type == XML_ELEMENT_NODE)
+    {
+      if (!xmlStrcmp (cur->name, (const xmlChar *) "CONDITION"))
+      {
+        string name;
+        const xmlChar *value = "";
+        xmlAttr *attrs = cur->properties;
+
+        while (attrs)
+        {
+          if(!xmlStrcmp (attrs->name, (const xmlChar *)"name") &&
+             attrs->children && attrs->children->content)
+            name.assign ((const char*)attrs->children->content);
+          
+          if(!xmlStrcmp (attrs->name, (const xmlChar *)"value") &&
+             attrs->children && attrs->children->content)
+            value = attrs->children->content;
+          
+          attrs = attrs->next;
+        }
+
+        string *storedValue = getValue (name);
+
+        if (storedValue && storedValue->compare ((const char*)value) == 0)
+          computeXmlNode (cur, st, cmd);
+
+      }
+    }
+
   return 0;
 }

Added: branches/myserver_sec_new/tests/test_xml_validator.cpp
===================================================================
--- branches/myserver_sec_new/tests/test_xml_validator.cpp                      
        (rev 0)
+++ branches/myserver_sec_new/tests/test_xml_validator.cpp      2008-09-28 
14:44:47 UTC (rev 2851)
@@ -0,0 +1,61 @@
+#include <ctype.h>
+
+#include <cppunit/CompilerOutputter.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+#include <cppunit/ui/text/TestRunner.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <include/conf/security/security_manager.h>
+#include <include/conf/security/xml_validator.h>
+
+#include <string.h>
+
+#include <iostream>
+using namespace std;
+
+class TestXmlValidator : public CppUnit::TestFixture
+{
+  CPPUNIT_TEST_SUITE( TestXmlValidator );
+  CPPUNIT_TEST( testGetPermissionMask );
+  CPPUNIT_TEST( testGetPermissionMaskImpl );
+  CPPUNIT_TEST( testGetValue );
+  CPPUNIT_TEST_SUITE_END();
+  
+  XmlValidator* xmlValidator;
+public:
+  void setUp()
+  {
+    xmlValidator = new XmlValidator();
+  }
+
+  void tearDown()
+  {
+    delete xmlValidator;
+  }
+
+  void testGetValue()
+  {
+    string val("value");
+    CPPUNIT_ASSERT_EQUAL(xmlValidator->getValue(val), (string*)NULL);
+ 
+  }
+ 
+  void testGetPermissionMaskImpl()
+  {
+    string val("value");
+    SecurityToken secToken;
+    CPPUNIT_ASSERT_EQUAL(xmlValidator->getPermissionMaskImpl(&secToken), 0);
+ 
+  }
+
+  void testGetPermissionMask()
+  {
+    string val("value");
+    SecurityToken secToken;
+    CPPUNIT_ASSERT_EQUAL(xmlValidator->getPermissionMask(&secToken, NULL), 0);
+ 
+  }
+};
+
+
+CPPUNIT_TEST_SUITE_REGISTRATION( TestXmlValidator );






reply via email to

[Prev in Thread] Current Thread [Next in Thread]