[Cs-webapplibs-commits] SF.net SVN: cs-webapplibs:[205] trunk/0.4
Status: Beta
Brought to you by:
crazedsanity
From: <cra...@us...> - 2011-02-01 03:51:44
|
Revision: 205 http://cs-webapplibs.svn.sourceforge.net/cs-webapplibs/?rev=205&view=rev Author: crazedsanity Date: 2011-02-01 03:51:37 +0000 (Tue, 01 Feb 2011) Log Message: ----------- Updated tests & schema. /setup/genericPermissions.pgsql.sql: * cswal_group_table: -- group_admin: changed to NOT NULL * cswal_object_table: -- object_id: changed to serial (instead of integer) * cswal_permission_table: -- object_path: removed UNIQUE constraint * MAIN... -- remove arbitrary INSERT statements -- add a constraint to the cswal_permission_table /tests/testOfCSGenericPermissions.php: * setUp(): -- supplement all the arbitrary insertsfrom the setup file with code before each run... * get_valid_users(): -- set some internal vars for later testing. * test_userGroups(): -- more tests... * test_object_paths() [NEW]: -- testing creation & manipulation of ID and object paths * test_permissions(): -- build a larger list of permissions for testing * _gpTester{}: -- create testDbTableHandler object for SQL stuff. Modified Paths: -------------- trunk/0.4/setup/genericPermissions.pgsql.sql trunk/0.4/tests/testOfCSGenericPermissions.php Modified: trunk/0.4/setup/genericPermissions.pgsql.sql =================================================================== --- trunk/0.4/setup/genericPermissions.pgsql.sql 2011-02-01 03:29:22 UTC (rev 204) +++ trunk/0.4/setup/genericPermissions.pgsql.sql 2011-02-01 03:51:37 UTC (rev 205) @@ -6,7 +6,7 @@ CREATE TABLE cswal_group_table ( group_id serial NOT NULL PRIMARY KEY, group_name text NOT NULL UNIQUE, - group_admin integer REFERENCES cs_authentication_table(uid), + group_admin integer NOT NULL REFERENCES cs_authentication_table(uid), created TIMESTAMPTZ NOT NULL DEFAULT NOW() ); @@ -43,7 +43,7 @@ -- with ID's, such as "member"=1, "blog"=2, "edit"=3; the object path would then be ":1::2::3:". -- CREATE TABLE cswal_object_table ( - object_id integer NOT NULL PRIMARY KEY, + object_id serial NOT NULL PRIMARY KEY, object_name text NOT NULL UNIQUE, created TIMESTAMPTZ NOT NULL DEFAULT NOW() ); @@ -60,7 +60,7 @@ CREATE TABLE cswal_permission_table ( permission_id serial NOT NULL PRIMARY KEY, system_name integer NOT NULL DEFAULT 0 REFERENCES cswal_system_table(system_id), - object_path text NOT NULL UNIQUE, + object_path text NOT NULL, user_id integer NOT NULL REFERENCES cs_authentication_table(uid), group_id integer NOT NULL REFERENCES cswal_group_table(group_id), inherit boolean NOT NULL DEFAULT FALSE, @@ -78,20 +78,6 @@ INSERT INTO cswal_system_table (system_id, system_name) VALUES (0, 'DEFAULT'); -INSERT INTO cswal_group_table (group_name) VALUES ('www'); -INSERT INTO cswal_group_table (group_name) VALUES ('blogs'); -INSERT INTO cswal_group_table (group_name) VALUES ('admin'); +ALTER TABLE ONLY cswal_permission_table + ADD CONSTRAINT cswal_permission_table_system_path_key UNIQUE (system_name, object_path); -INSERT INTO cswal_object_table (object_id, object_name) VALUES (0, '{APPURL}'); -INSERT INTO cswal_object_table (object_id, object_name) VALUES (1, 'member'); - -INSERT INTO cswal_permission_table - (object_path,user_id, group_id) - VALUES - (':0:', 101, 1); - -INSERT INTO cswal_permission_table - (object_path, user_id, group_id, g_r, g_w) - VALUES - (':0::1:', 101, 2, true, true); - Modified: trunk/0.4/tests/testOfCSGenericPermissions.php =================================================================== --- trunk/0.4/tests/testOfCSGenericPermissions.php 2011-02-01 03:29:22 UTC (rev 204) +++ trunk/0.4/tests/testOfCSGenericPermissions.php 2011-02-01 03:51:37 UTC (rev 205) @@ -29,6 +29,39 @@ $this->permObj = new _gpTester($this->db); $this->permObj->do_schema(); $this->get_valid_users(); + + $this->defaultGroupId = null; + + //create some groups. + { + $myGroupList = array('www', 'blogs', 'admin', __METHOD__); + #$newGroupId = $this->permObj->create_group(__METHOD__); + $userKeys = array_keys($this->validUsers); + foreach($myGroupList as $tName) { + $newGroupId = $this->permObj->create_group($tName, $this->chosenOneUid); + if(is_null($this->defaultGroupId)) { + $this->defaultGroupId = $newGroupId; + } + $this->assertTrue(is_numeric($newGroupId)); + } + + $groupList = $this->permObj->get_all_groups(); + + foreach($groupList as $groupId=>$groupData) { + $this->assertEqual($this->permObj->get_group_by_id($groupId), $groupData, "failed to get group (". $groupData['group_name'] .") by ID (". $groupId .")"); + $this->assertEqual($this->permObj->get_group($groupData['group_name']), $groupData, "failed to get group (". $groupData['group_name'] .") by name"); + } + } + + //create some objects... + { + $requiredItems = array('{APPURL}', 'member'); + foreach($requiredItems as $name) { + $newId = $this->permObj->create_object($name); + $this->assertTrue(is_numeric($newId)); + } + } + }//end setUp() //-------------------------------------------------------------------------- @@ -55,6 +88,11 @@ $sql = "SELECT uid,username FROM cs_authentication_table ORDER BY uid"; try { $this->validUsers = $this->db->run_query($sql); + + $userKeys = array_keys($this->validUsers); + $myUser = $this->validUsers[$userKeys[0]]; + $this->chosenOneUid = $myUser['uid']; + $this->defaultUid = $this->chosenOneUid; } catch(Exception $e) { cs_debug_backtrace(1); @@ -82,25 +120,12 @@ $this->assertTrue(isset($groupList[$myKey]['group_id'])); } - //create some groups. - { - $newGroupId = $this->permObj->create_group(__METHOD__); - $this->assertTrue(is_numeric($newGroupId)); - - $groupList = $this->permObj->get_all_groups(); - - foreach($groupList as $groupId=>$groupData) { - $this->assertEqual($this->permObj->get_group_by_id($groupId), $groupData, "failed to get group (". $groupData['group_name'] .") by ID (". $groupId .")"); - $this->assertEqual($this->permObj->get_group($groupData['group_name']), $groupData, "failed to get group (". $groupData['group_name'] .") by name"); - } - } - //create & test user_group relationships. { - $newId = $this->permObj->create_user_group($this->validUsers[$myKey]['uid'],$newGroupId); + $newId = $this->permObj->create_user_group($this->validUsers[$myKey]['uid'],$this->defaultGroupId); $this->assertTrue(is_numeric($newId)); - $this->assertTrue($this->permObj->is_group_member($this->validUsers[$myKey]['uid'],$newGroupId), "user (". - $this->validUsers[$myKey]['uid'] .") isn't member of group (". $newGroupId .") after being added to it... "); + $this->assertTrue($this->permObj->is_group_member($this->validUsers[$myKey]['uid'],$this->defaultGroupId), "user (". + $this->validUsers[$myKey]['uid'] .") isn't member of group (". $this->defaultGroupId .") after being added to it... "); $ugList = $this->permObj->get_user_groups($this->validUsers[$myKey]['uid']); $this->assertTrue(is_array($ugList)); @@ -113,7 +138,73 @@ //-------------------------------------------------------------------------- + public function test_object_paths() { + //basic functionality test for ID Path creation. + { + $expectThis = ':5::30::2::18::5:'; + + //make the expected string into something that be broken into an array of numbers. + $chunktify = preg_replace('/^:(.*):$/', '$1', $expectThis); + $chunktify = preg_replace('/:{2,}/', ':', $chunktify); + $bits = explode(':', $chunktify); + + $this->assertEqual($bits, $this->permObj->explode_id_path($expectThis)); + + $this->assertEqual(count($bits), 5, 'could not break string into id bits'); + + $derivedIdPath = ""; + foreach($bits as $id) { + $derivedIdPath .= $this->permObj->create_id_path_part($id); + } + $this->assertEqual($derivedIdPath, $expectThis, 'Invalid idPath, expected=('. $expectThis .'), actual=('. $derivedIdPath .')'); + + $idPathList = array(':9:', ':9::5:', ':0::0::0:', ':-1:', ':-1::-1:', ':-400::1::3:', ':51041::600000::8109223::999999999999999999999999999999999:'); + foreach($idPathList as $tPath) { + $this->assertTrue($this->permObj->is_id_path($tPath), "valid path (". $tPath .") not recognized as such"); + } + + $invalidIdPathList = array('', ':--1:', '1::3::4:', ':1::3::4', ':1:3:4:'); + foreach($invalidIdPathList as $tPath) { + $this->assertFalse($this->permObj->is_id_path($tPath), "invalid path (". $tPath .") evaluated as valid"); + } + } + + //Search for existing items (should have been created from setUp()) + { + $requiredItems = array('{APPURL}', 'member'); + $existingItems = $this->permObj->get_object_ids($requiredItems, false); + $this->assertEqual(count($existingItems), 2, 'Required items not present... '. $this->gfObj->debug_print($existingItems,0,1)); + + //in the event the required items aren't there, create them. + $testExistingItems = $this->permObj->get_object_ids($requiredItems, true); + $this->assertEqual(count($requiredItems), count($testExistingItems), 'failed to create some existing items'); + $this->assertEqual(count($testExistingItems), count($existingItems), 'WARNING: some required items were not found'); + } + + //Build new ID paths... + { + $newObjects = array('admin', 'logs', 'view'); + $idPath = $this->permObj->create_id_path('/admin/logs/view'); + $this->assertTrue(preg_match('/^:[0-9]{1,}::[0-9]{1,}::[0-9]{1,}:/', $idPath), 'path appears syntactically incorrect ('. $idPath .')'); + + //make sure the manually-created ID Path matches what was actually created. + $idList = $this->permObj->get_object_ids($newObjects, false); + $this->assertEqual(count($idList), count($newObjects), "there must be missing objects, counts don't match"); + + $expectedIdPath = ""; + foreach($idList as $id=>$n) { + $expectedIdPath .= $this->permObj->create_id_path_part($id); + } + $this->assertEqual($expectedIdPath, $idPath, "Manually created path (". $expectedIdPath .") does not match idPath (". $idPath .")"); + } + }//end test_object_paths() + //-------------------------------------------------------------------------- + + + + //-------------------------------------------------------------------------- public function test_permissions() { + #$GLOBALS['keepDb'] = true; //Test permission string parsing. { @@ -169,7 +260,9 @@ $usePermName = __METHOD__ .'/test1'; $this->assertFalse($this->permObj->permission_exists($usePermName)); $permId = $this->permObj->create_permission($usePermName, $myUid, 1, $usePermString); - $this->assertTrue($this->permObj->permission_exists($usePermName)); + if(!$this->assertTrue($this->permObj->permission_exists($usePermName), "Permission ('". $usePermName ."', id=". $permId .") does not exist")) { + $this->gfObj->debug_print($this->permObj->testDbTableHandler->get_records()); + } $this->assertTrue(is_numeric($permId)); //the method 'build_permissions_string()' should disregard extra indices in the array & build the string. @@ -199,14 +292,57 @@ $this->assertEqual($this->permObj->has_write_permission(0,$usePermName), $this->permObj->has_write_permission($thirdUser,$usePermName)); $this->assertEqual($this->permObj->has_execute_permission(0,$usePermName), $this->permObj->has_execute_permission($thirdUser,$usePermName)); } + + //create a huge list of permissions to test different scenarios. + { + $testPaths = array( + '/member', + '/member/ttorp', + '/member/ttorp/character', + '/member/ttorp/character/sheet', + '/member/ttorp/character/sheet/44', + '/admin/x', + '/admin/logs', + '/test/scripts/1/2/3/magicMarker', + '/api/system/test/212312300231223.21231/get/333', + '/content/dev/corner/cs/project', + '/content/dev/corner/cs/web/app/libs', + '/content/dev', + '/content/dev/corner', + '/content/dev/coner/cs', + + //The following items fail for no apparent reason (that I can find)... + '/admin', + '/cntenx', + '/content/dev/corner/cs/content', //fails due to duplicate objects in path ("content" is in there twice). + ); + $testPerms = array( + 'rwxrwxrwx', + 'rwxrwx---', + 'rwx---rwx', + '---rwxrwx', + 'rwx------', + '---------', + 'r--r--r--', + '-w--w--w-', + '--x--x--x' + ); + foreach($testPaths as $tPath) { + $tPermString = 'rwxrwx---'; + $newPermId = $this->permObj->create_permission($tPath, $this->chosenOneUid, $this->defaultGroupId, $tPermString); + $this->assertTrue(is_numeric($newPermId)); + } + }///*/ }//end test_permissions //-------------------------------------------------------------------------- } class _gpTester extends cs_genericPermission { + public $testDbTableHandler; public function __construct($db) { parent::__construct($db); + $this->testDbTableHandler = $this->dbTableHandler; } public function do_schema() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |