[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[myserver-commit] [2863] Now `SecurityToken' is a class.
From: |
Giuseppe Scrivano |
Subject: |
[myserver-commit] [2863] Now `SecurityToken' is a class. |
Date: |
Sat, 04 Oct 2008 12:46:48 +0000 |
Revision: 2863
http://svn.sv.gnu.org/viewvc/?view=rev&root=myserver&revision=2863
Author: gscrivano
Date: 2008-10-04 12:46:47 +0000 (Sat, 04 Oct 2008)
Log Message:
-----------
Now `SecurityToken' is a class. Previously it was a struct.
Modified Paths:
--------------
branches/myserver_sec_new/include/conf/security/security_token.h
branches/myserver_sec_new/src/conf/security/auth_domain.cpp
branches/myserver_sec_new/src/conf/security/security_manager.cpp
branches/myserver_sec_new/src/conf/security/validator.cpp
branches/myserver_sec_new/src/conf/security/xml_validator.cpp
branches/myserver_sec_new/tests/Makefile.am
Added Paths:
-----------
branches/myserver_sec_new/tests/test_security_token.cpp
Modified: branches/myserver_sec_new/include/conf/security/security_token.h
===================================================================
--- branches/myserver_sec_new/include/conf/security/security_token.h
2008-10-03 22:08:55 UTC (rev 2862)
+++ branches/myserver_sec_new/include/conf/security/security_token.h
2008-10-04 12:46:47 UTC (rev 2863)
@@ -41,13 +41,141 @@
MYSERVER_SERVER_CONF = (1<<2),
};
-struct SecurityToken
+class SecurityToken
{
+public:
SecurityToken();
void reset();
- const char* getHashedData(const char* name, int domains);
+ const char* getHashedData (const char* name, int domains);
+ string& getUser ()
+ {
+ return user;
+ }
+
+ string& getPassword ()
+ {
+ return password;
+ }
+
+ HashMap<string,string*>* getValues ()
+ {
+ return &values;
+ }
+
+ string *getDirectory ()
+ {
+ return directory;
+ }
+
+ string *getSysDirectory ()
+ {
+ return sysdirectory;
+ }
+
+ string *getResource ()
+ {
+ return resource;
+ }
+
+ int getMask ()
+ {
+ return mask;
+ }
+
+ int getProvidedMask ()
+ {
+ return providedMask;
+ }
+
+ string& getNeededPassword ()
+ {
+ return neededPassword;
+ }
+
+ bool isDone ()
+ {
+ return done;
+ }
+
+ bool isAuthenticated ()
+ {
+ return authenticated;
+ }
+
+
+ Server* getServer ()
+ {
+ return server;
+ }
+
+ Vhost* getVhost ()
+ {
+ return vhost;
+ }
+
+ void setUser (string& u)
+ {
+ user.assign (u);
+ }
+
+ void setPassword (string& pw)
+ {
+ password.assign (pw);
+ }
+
+ void setDirectory (string * d)
+ {
+ directory = d;
+ }
+
+ void setSysDirectory (string * sd)
+ {
+ sysdirectory = sd;
+ }
+
+ void setResource (string *r)
+ {
+ resource = r;
+ }
+
+ int setMask (int m)
+ {
+ mask = m;
+ }
+
+ void setProvidedMask (int p)
+ {
+ providedMask = p;
+ }
+
+ void setNeededPassword (string& pw)
+ {
+ neededPassword.assign (pw);
+ }
+
+ bool setDone (bool d)
+ {
+ done = d;
+ }
+
+ bool setAuthenticated (bool a)
+ {
+ authenticated = a;
+ }
+
+ void setServer (Server* s)
+ {
+ server = s;
+ }
+
+ void setVhost (Vhost* v)
+ {
+ vhost = v;
+ }
+
+private:
/*! User to check for. */
string user;
@@ -93,6 +221,8 @@
///////OLD NOT USED////////////
+ friend class Http;
+ friend class Ftp;
char* requiredPassword;
const char* filename;
struct HttpThreadContext* td;
Modified: branches/myserver_sec_new/src/conf/security/auth_domain.cpp
===================================================================
--- branches/myserver_sec_new/src/conf/security/auth_domain.cpp 2008-10-03
22:08:55 UTC (rev 2862)
+++ branches/myserver_sec_new/src/conf/security/auth_domain.cpp 2008-10-04
12:46:47 UTC (rev 2863)
@@ -37,16 +37,16 @@
string *AuthDomain::getValue (string &name)
{
if (!name.compare ("user"))
- return &(securityToken->user);
+ return &(securityToken->getUser ());
if (!name.compare ("password"))
- return &(securityToken->password);
+ return &(securityToken->getPassword ());
if (!name.compare ("directory"))
- return securityToken->directory;
+ return securityToken->getDirectory ();
if (!name.compare ("sysdirectory"))
- return securityToken->sysdirectory;
+ return securityToken->getSysDirectory ();
return NULL;
}
Modified: branches/myserver_sec_new/src/conf/security/security_manager.cpp
===================================================================
--- branches/myserver_sec_new/src/conf/security/security_manager.cpp
2008-10-03 22:08:55 UTC (rev 2862)
+++ branches/myserver_sec_new/src/conf/security/security_manager.cpp
2008-10-04 12:46:47 UTC (rev 2863)
@@ -21,6 +21,7 @@
#include <include/conf/security/validator_factory.h>
#include <include/conf/security/auth_method.h>
#include <include/conf/security/auth_method_factory.h>
+#include <include/conf/security/security_token.h>
#include <string>
#include <sstream>
Modified: branches/myserver_sec_new/src/conf/security/validator.cpp
===================================================================
--- branches/myserver_sec_new/src/conf/security/validator.cpp 2008-10-03
22:08:55 UTC (rev 2862)
+++ branches/myserver_sec_new/src/conf/security/validator.cpp 2008-10-04
12:46:47 UTC (rev 2863)
@@ -40,8 +40,8 @@
{
HashMap<string, SecurityDomain*> hashedDomains;
- if (st->done)
- return st->mask;
+ if (st->isDone ())
+ return st->getMask ();
if (domains)
{
@@ -65,8 +65,8 @@
{
HashMap<string, SecurityDomain*> hashedDomains;
- if (st->done)
- return st->mask;
+ if (st->isDone ())
+ return st->getMask ();
if (domains)
{
@@ -97,7 +97,7 @@
if (!getPermissionMaskImpl (st, hashedDomains, authMethod))
ret = 0;
- st->done = true;
+ st->setDone (true);
return ret;
}
Modified: branches/myserver_sec_new/src/conf/security/xml_validator.cpp
===================================================================
--- branches/myserver_sec_new/src/conf/security/xml_validator.cpp
2008-10-03 22:08:55 UTC (rev 2862)
+++ branches/myserver_sec_new/src/conf/security/xml_validator.cpp
2008-10-04 12:46:47 UTC (rev 2863)
@@ -60,20 +60,20 @@
{
const char *secName;
- SecurityCache *cache = getCache (st->server);
+ SecurityCache *cache = getCache (st->getServer ());
if (!cache)
return NULL;
- secName = st->vhost ? st->vhost->getHashedData ("SECURITY_FILE_NAME") : NULL;
+ secName = st->getVhost () ? st->getVhost ()->getHashedData
("SECURITY_FILE_NAME") : NULL;
if (!secName)
- secName = st->server ? st->server->getHashedData ("SECURITY_FILE_NAME") :
NULL;
+ secName = st->getServer () ? st->getServer ()->getHashedData
("SECURITY_FILE_NAME") : NULL;
if (!secName)
secName = ".security.xml";
- return cache->getParser (*st->resource, *st->sysdirectory, false, secName);
+ return cache->getParser (*(st->getResource ()), *(st->getSysDirectory ()),
false, secName);
}
/*!
@@ -111,23 +111,23 @@
int permissions = getPermissions (attrs, &name, &password);
if (!name || !password ||
- xmlStrcmp (name, (const xmlChar *)st->user.c_str ()))
+ xmlStrcmp (name, (const xmlChar *)st->getUser ().c_str ()))
continue;
- st->providedMask = permissions;
+ st->setProvidedMask (permissions);
- if (xmlStrcmp (password, (const xmlChar *)st->password.c_str ()))
+ if (xmlStrcmp (password, (const xmlChar *)st->getPassword ().c_str ()))
{
- st->authenticated = false;
- st->mask = 0;
+ st->setAuthenticated (false);
+ st->setMask (0);
}
else
{
- st->authenticated = true;
- st->mask = permissions;
+ st->setAuthenticated (true);
+ st->setMask (permissions);
}
- return st->mask;
+ return st->getMask ();
}
return 0;
@@ -295,10 +295,10 @@
const xmlChar *value = (const xmlChar*)"";
xmlAttr *attrs = node->properties;
- st->providedMask = getPermissions (attrs);
+ st->setProvidedMask (getPermissions (attrs));
- if (st->authenticated)
- st->mask = st->providedMask;
+ if (st->isAuthenticated ())
+ st->setMask (st->getProvidedMask ());
}
@@ -329,7 +329,7 @@
string *valStr = new string ((const char *)value);
- string *old = st->values.put (name, valStr);
+ string *old = st->getValues ()->put (name, valStr);
if (old)
delete old;
Modified: branches/myserver_sec_new/tests/Makefile.am
===================================================================
--- branches/myserver_sec_new/tests/Makefile.am 2008-10-03 22:08:55 UTC (rev
2862)
+++ branches/myserver_sec_new/tests/Makefile.am 2008-10-04 12:46:47 UTC (rev
2863)
@@ -2,5 +2,5 @@
#
bin_PROGRAMS = tests_suite
-tests_suite_SOURCES = main.cpp test_connection.cpp test_ftp.cpp
test_log_manager.cpp test_mutex.cpp test_security_domain.cpp test_validator.cpp
test_auth_domain.cpp test_connections_scheduler.cpp test_gzip.cpp
test_log_stream_factory.cpp test_pipe.cpp test_security_manager.cpp
test_validator_factory.cpp test_base64.cpp test_file_stream.cpp
test_hashmap.cpp test_md5.cpp test_recursive_mutex.cpp test_semaphore.cpp
test_xml.cpp test_cached_file_buffer.cpp test_file_stream_creator.cpp
test_homedir.cpp test_mem_buff.cpp test_regex.cpp
test_socket_stream_creator.cpp test_cached_file.cpp test_files_utility.cpp
test_http_request.cpp test_http_req_security_domain.cpp test_mem_stream.cpp
test_safetime.cpp test_thread.cpp test_cached_file_factory.cpp
test_filter_chain.cpp test_http_response.cpp test_multicast.cpp
test_security_cache.cpp test_utility.cpp test_xml_validator.cpp
+tests_suite_SOURCES = main.cpp test_connection.cpp test_ftp.cpp
test_log_manager.cpp test_mutex.cpp test_security_domain.cpp test_validator.cpp
test_auth_domain.cpp test_connections_scheduler.cpp test_gzip.cpp
test_log_stream_factory.cpp test_pipe.cpp test_security_manager.cpp
test_validator_factory.cpp test_base64.cpp test_file_stream.cpp
test_hashmap.cpp test_md5.cpp test_recursive_mutex.cpp test_semaphore.cpp
test_xml.cpp test_cached_file_buffer.cpp test_file_stream_creator.cpp
test_homedir.cpp test_mem_buff.cpp test_regex.cpp
test_socket_stream_creator.cpp test_cached_file.cpp test_files_utility.cpp
test_http_request.cpp test_http_req_security_domain.cpp test_mem_stream.cpp
test_safetime.cpp test_thread.cpp test_cached_file_factory.cpp
test_filter_chain.cpp test_http_response.cpp test_multicast.cpp
test_security_cache.cpp test_security_token.cpp test_utility.cpp
test_xml_validator.cpp
tests_suite_LDADD = ../src/libmyserver.a $(CPPUNIT_LDFLAGS) $(PTHREAD_LIB)
$(IDN_LIB) $(XNET_LIB) $(EVENT_LIB) $(DL_LIB) $(OPENSSL_LIB) $(ZLIB_LIB)
$(XML_LIBS) $(LDFLAGS)
Added: branches/myserver_sec_new/tests/test_security_token.cpp
===================================================================
--- branches/myserver_sec_new/tests/test_security_token.cpp
(rev 0)
+++ branches/myserver_sec_new/tests/test_security_token.cpp 2008-10-04
12:46:47 UTC (rev 2863)
@@ -0,0 +1,163 @@
+/*
+ MyServer
+ Copyright (C) 2008 Free Software Foundation, Inc.
+ This program 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 3 of the License, or
+ (at your option) any later version.
+
+ This program 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#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/security_token.h>
+#include <include/conf/vhost/vhost.h>
+#include <include/server/server.h>
+
+#include <string.h>
+
+#include <iostream>
+using namespace std;
+
+
+class TestSecurityToken : public CppUnit::TestFixture
+{
+ CPPUNIT_TEST_SUITE( TestSecurityToken );
+ CPPUNIT_TEST ( testUser);
+ CPPUNIT_TEST ( testPassword);
+ CPPUNIT_TEST ( testValues );
+ CPPUNIT_TEST ( testDirectory );
+ CPPUNIT_TEST ( testSysDirectory );
+ CPPUNIT_TEST ( testResource );
+ CPPUNIT_TEST ( testMask );
+ CPPUNIT_TEST ( testProvidedMask );
+ CPPUNIT_TEST ( testNeededPassword );
+ CPPUNIT_TEST ( testDone );
+ CPPUNIT_TEST ( testAuthenticated );
+ CPPUNIT_TEST ( testServer );
+ CPPUNIT_TEST ( testVhost );
+ CPPUNIT_TEST_SUITE_END();
+
+ SecurityToken* securityToken;
+public:
+ void setUp()
+ {
+ securityToken = new SecurityToken();
+ }
+
+ void tearDown()
+ {
+ delete securityToken;
+ }
+
+
+ void testUser()
+ {
+ string user ("foo");
+ securityToken->setUser (user);
+ CPPUNIT_ASSERT_EQUAL (securityToken->getUser ().compare (user), 0);
+ }
+
+ void testPassword()
+ {
+ string password ("foo");
+ securityToken->setPassword (password);
+ CPPUNIT_ASSERT_EQUAL (securityToken->getPassword ().compare (password), 0);
+ }
+
+ void testValues ()
+ {
+ CPPUNIT_ASSERT (securityToken->getValues ());
+ }
+
+ void testDirectory ()
+ {
+ string dir ("foo");
+ securityToken->setDirectory (&dir);
+ CPPUNIT_ASSERT_EQUAL (securityToken->getDirectory (), &dir);
+ }
+
+ void testSysDirectory ()
+ {
+ string sysDir ("foo");
+ securityToken->setSysDirectory (&sysDir);
+ CPPUNIT_ASSERT_EQUAL (securityToken->getSysDirectory (), &sysDir);
+ }
+
+ void testResource ()
+ {
+ string resource ("foo");
+ securityToken->setResource (&resource);
+ CPPUNIT_ASSERT_EQUAL (securityToken->getResource (), &resource);
+ }
+
+ void testMask ()
+ {
+ int mask = MYSERVER_PERMISSION_READ;
+ securityToken->setMask (mask);
+ CPPUNIT_ASSERT_EQUAL (securityToken->getMask (), mask);
+ }
+
+ void testProvidedMask ()
+ {
+ int mask = MYSERVER_PERMISSION_READ;
+ securityToken->setProvidedMask (mask);
+ CPPUNIT_ASSERT_EQUAL (securityToken->getProvidedMask (), mask);
+ }
+
+ void testNeededPassword ()
+ {
+ string password ("foo");
+ securityToken->setNeededPassword (password);
+ CPPUNIT_ASSERT_EQUAL (securityToken->getNeededPassword ().compare
(password), 0);
+ }
+
+ void testDone ()
+ {
+ securityToken->setDone (true);
+ CPPUNIT_ASSERT_EQUAL (securityToken->isDone (), true);
+
+ securityToken->setDone (false);
+ CPPUNIT_ASSERT_EQUAL (securityToken->isDone (), false);
+ }
+
+ void testAuthenticated ()
+ {
+ securityToken->setAuthenticated (true);
+ CPPUNIT_ASSERT_EQUAL (securityToken->isAuthenticated (), true);
+
+ securityToken->setAuthenticated (false);
+ CPPUNIT_ASSERT_EQUAL (securityToken->isAuthenticated (), false);
+ }
+
+ void testServer ()
+ {
+ Server *s = (Server*)0x10; //XXX: Dirty but it avoids to use the Singleton
instance.
+ securityToken->setServer (s);
+ CPPUNIT_ASSERT_EQUAL (securityToken->getServer (), s);
+ }
+
+ void testVhost ()
+ {
+ Vhost *v = (Vhost*)0x100; //XXX: Dirty.
+ securityToken->setVhost (v);
+ CPPUNIT_ASSERT_EQUAL (securityToken->getVhost (), v);
+ }
+
+};
+
+
+CPPUNIT_TEST_SUITE_REGISTRATION( TestSecurityToken );
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [myserver-commit] [2863] Now `SecurityToken' is a class.,
Giuseppe Scrivano <=