Add the first version of authzgroups.php with associated tests
git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@1816 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
391
Tests/authzgroupsTest.php
Normal file
391
Tests/authzgroupsTest.php
Normal file
@@ -0,0 +1,391 @@
|
||||
<?php
|
||||
/** DomFramework - Tests
|
||||
@package domframework
|
||||
@author Dominique Fournier <dominique@fournier38.fr> */
|
||||
|
||||
/** Test the authzgroups.php file */
|
||||
class test_authzgroups extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function test_createTables1 ()
|
||||
{
|
||||
$configuration = new configuration ();
|
||||
$dbconfig = $configuration->get ("database");
|
||||
if (! isset ($dbconfig["tableprefix"]))
|
||||
$dbconfig["tableprefix"] = "";
|
||||
$authz = new authzgroups ();
|
||||
$this->setExpectedException ("Exception");
|
||||
$authz->createTables ();
|
||||
}
|
||||
|
||||
public function test_connect ()
|
||||
{
|
||||
// Must use the model to create the database structure as there is no
|
||||
// creation of tables in controller
|
||||
$configuration = new configuration ();
|
||||
$dbconfig = $configuration->get ("database");
|
||||
if (! isset ($dbconfig["tableprefix"]))
|
||||
$dbconfig["tableprefix"] = "";
|
||||
$authz = new authzgroups ();
|
||||
$res = $authz->connect ($dbconfig["dsn"], $dbconfig["username"],
|
||||
$dbconfig["password"], $dbconfig["driver_options"]);
|
||||
$this->assertSame (true, $res);
|
||||
}
|
||||
|
||||
public function test_createTables2 ()
|
||||
{
|
||||
$configuration = new configuration ();
|
||||
$dbconfig = $configuration->get ("database");
|
||||
if (! isset ($dbconfig["tableprefix"]))
|
||||
$dbconfig["tableprefix"] = "";
|
||||
$authz = new authzgroups ();
|
||||
$authz->connect ($dbconfig["dsn"], $dbconfig["username"],
|
||||
$dbconfig["password"], $dbconfig["driver_options"]);
|
||||
$res = $authz->createTables ();
|
||||
$this->assertSame (true, $res);
|
||||
}
|
||||
|
||||
////////////////
|
||||
// OBJECT //
|
||||
////////////////
|
||||
public function test_objectCreate1 ()
|
||||
{
|
||||
$configuration = new configuration ();
|
||||
$dbconfig = $configuration->get ("database");
|
||||
if (! isset ($dbconfig["tableprefix"]))
|
||||
$dbconfig["tableprefix"] = "";
|
||||
$authz = new authzgroups ();
|
||||
$authz->connect ($dbconfig["dsn"], $dbconfig["username"],
|
||||
$dbconfig["password"], $dbconfig["driver_options"]);
|
||||
$res = $authz->objectAdd ("MODULE", "/object");
|
||||
$this->assertSame ("1", $res);
|
||||
}
|
||||
|
||||
public function test_objectUpdate1 ()
|
||||
{
|
||||
$configuration = new configuration ();
|
||||
$dbconfig = $configuration->get ("database");
|
||||
if (! isset ($dbconfig["tableprefix"]))
|
||||
$dbconfig["tableprefix"] = "";
|
||||
$authz = new authzgroups ();
|
||||
$authz->connect ($dbconfig["dsn"], $dbconfig["username"],
|
||||
$dbconfig["password"], $dbconfig["driver_options"]);
|
||||
$res = $authz->objectUpdate ("MODULE", "/object", "/object2");
|
||||
$this->assertSame (1, $res);
|
||||
}
|
||||
|
||||
public function test_objectDelete1 ()
|
||||
{
|
||||
$configuration = new configuration ();
|
||||
$dbconfig = $configuration->get ("database");
|
||||
if (! isset ($dbconfig["tableprefix"]))
|
||||
$dbconfig["tableprefix"] = "";
|
||||
$authz = new authzgroups ();
|
||||
$authz->connect ($dbconfig["dsn"], $dbconfig["username"],
|
||||
$dbconfig["password"], $dbconfig["driver_options"]);
|
||||
// The object was renamed and is not available
|
||||
$this->setExpectedException ("Exception");
|
||||
$res = $authz->objectDel ("MODULE", "/object");
|
||||
}
|
||||
|
||||
////////////////
|
||||
// GROUPS //
|
||||
////////////////
|
||||
public function test_groupCreate1 ()
|
||||
{
|
||||
$configuration = new configuration ();
|
||||
$dbconfig = $configuration->get ("database");
|
||||
if (! isset ($dbconfig["tableprefix"]))
|
||||
$dbconfig["tableprefix"] = "";
|
||||
$authz = new authzgroups ();
|
||||
$authz->connect ($dbconfig["dsn"], $dbconfig["username"],
|
||||
$dbconfig["password"], $dbconfig["driver_options"]);
|
||||
$res = $authz->groupAdd ("MODULE", "group");
|
||||
$this->assertSame ("1", $res);
|
||||
}
|
||||
|
||||
public function test_groupUpdate1 ()
|
||||
{
|
||||
$configuration = new configuration ();
|
||||
$dbconfig = $configuration->get ("database");
|
||||
if (! isset ($dbconfig["tableprefix"]))
|
||||
$dbconfig["tableprefix"] = "";
|
||||
$authz = new authzgroups ();
|
||||
$authz->connect ($dbconfig["dsn"], $dbconfig["username"],
|
||||
$dbconfig["password"], $dbconfig["driver_options"]);
|
||||
$res = $authz->groupUpdate ("MODULE", "group", "group2");
|
||||
$this->assertSame (1, $res);
|
||||
}
|
||||
|
||||
public function test_groupDelete1 ()
|
||||
{
|
||||
$configuration = new configuration ();
|
||||
$dbconfig = $configuration->get ("database");
|
||||
if (! isset ($dbconfig["tableprefix"]))
|
||||
$dbconfig["tableprefix"] = "";
|
||||
$authz = new authzgroups ();
|
||||
$authz->connect ($dbconfig["dsn"], $dbconfig["username"],
|
||||
$dbconfig["password"], $dbconfig["driver_options"]);
|
||||
// The group doesn't exists
|
||||
$this->setExpectedException ("Exception");
|
||||
$res = $authz->groupDel ("MODULE", "group");
|
||||
}
|
||||
|
||||
/////////////////////
|
||||
// GROUPMEMBER //
|
||||
/////////////////////
|
||||
public function test_groupmemberCreate1 ()
|
||||
{
|
||||
$configuration = new configuration ();
|
||||
$dbconfig = $configuration->get ("database");
|
||||
if (! isset ($dbconfig["tableprefix"]))
|
||||
$dbconfig["tableprefix"] = "";
|
||||
$authz = new authzgroups ();
|
||||
$authz->connect ($dbconfig["dsn"], $dbconfig["username"],
|
||||
$dbconfig["password"], $dbconfig["driver_options"]);
|
||||
// The group doesn't exists
|
||||
$this->setExpectedException ("Exception");
|
||||
$res = $authz->groupmemberAdd ("MODULE", "group", "userKnown");
|
||||
}
|
||||
|
||||
public function test_groupmemberCreate2 ()
|
||||
{
|
||||
$configuration = new configuration ();
|
||||
$dbconfig = $configuration->get ("database");
|
||||
if (! isset ($dbconfig["tableprefix"]))
|
||||
$dbconfig["tableprefix"] = "";
|
||||
$authz = new authzgroups ();
|
||||
$authz->connect ($dbconfig["dsn"], $dbconfig["username"],
|
||||
$dbconfig["password"], $dbconfig["driver_options"]);
|
||||
$res = $authz->groupmemberAdd ("MODULE", "group2", "userKnown");
|
||||
$this->assertSame ("1", $res);
|
||||
}
|
||||
|
||||
public function test_groupmemberDelete1 ()
|
||||
{
|
||||
$configuration = new configuration ();
|
||||
$dbconfig = $configuration->get ("database");
|
||||
if (! isset ($dbconfig["tableprefix"]))
|
||||
$dbconfig["tableprefix"] = "";
|
||||
$authz = new authzgroups ();
|
||||
$authz->connect ($dbconfig["dsn"], $dbconfig["username"],
|
||||
$dbconfig["password"], $dbconfig["driver_options"]);
|
||||
// The group doesn't exists
|
||||
$this->setExpectedException ("Exception");
|
||||
$res = $authz->groupmemberDel ("MODULE", "group","userKnown");
|
||||
}
|
||||
|
||||
public function test_groupmemberReadGroup1 ()
|
||||
{
|
||||
$configuration = new configuration ();
|
||||
$dbconfig = $configuration->get ("database");
|
||||
if (! isset ($dbconfig["tableprefix"]))
|
||||
$dbconfig["tableprefix"] = "";
|
||||
$authz = new authzgroups ();
|
||||
$authz->connect ($dbconfig["dsn"], $dbconfig["username"],
|
||||
$dbconfig["password"], $dbconfig["driver_options"]);
|
||||
// The group doesn't exists
|
||||
$this->setExpectedException ("Exception");
|
||||
$res = $authz->groupmemberReadGroup ("MODULE", "group");
|
||||
}
|
||||
|
||||
public function test_groupmemberReadGroup2 ()
|
||||
{
|
||||
$configuration = new configuration ();
|
||||
$dbconfig = $configuration->get ("database");
|
||||
if (! isset ($dbconfig["tableprefix"]))
|
||||
$dbconfig["tableprefix"] = "";
|
||||
$authz = new authzgroups ();
|
||||
$authz->connect ($dbconfig["dsn"], $dbconfig["username"],
|
||||
$dbconfig["password"], $dbconfig["driver_options"]);
|
||||
$res = $authz->groupmemberReadGroup ("MODULE", "group2");
|
||||
$this->assertSame (array (array ("user"=>"userKnown")), $res);
|
||||
}
|
||||
|
||||
public function test_groupmemberReadUser1 ()
|
||||
{
|
||||
$configuration = new configuration ();
|
||||
$dbconfig = $configuration->get ("database");
|
||||
if (! isset ($dbconfig["tableprefix"]))
|
||||
$dbconfig["tableprefix"] = "";
|
||||
$authz = new authzgroups ();
|
||||
$authz->connect ($dbconfig["dsn"], $dbconfig["username"],
|
||||
$dbconfig["password"], $dbconfig["driver_options"]);
|
||||
$res = $authz->groupmemberReadUser ("MODULE", "userKnown");
|
||||
$this->assertSame (array (1=>"group2"), $res);
|
||||
}
|
||||
|
||||
////////////////
|
||||
// RIGHTS //
|
||||
////////////////
|
||||
public function test_rightCreate1 ()
|
||||
{
|
||||
$configuration = new configuration ();
|
||||
$dbconfig = $configuration->get ("database");
|
||||
if (! isset ($dbconfig["tableprefix"]))
|
||||
$dbconfig["tableprefix"] = "";
|
||||
$authz = new authzgroups ();
|
||||
$authz->connect ($dbconfig["dsn"], $dbconfig["username"],
|
||||
$dbconfig["password"], $dbconfig["driver_options"]);
|
||||
$res = $authz->rightAdd ("MODULE", "group2","/object2", "RW");
|
||||
$this->assertSame ("1", $res);
|
||||
}
|
||||
|
||||
public function test_rightUpdate1 ()
|
||||
{
|
||||
$configuration = new configuration ();
|
||||
$dbconfig = $configuration->get ("database");
|
||||
if (! isset ($dbconfig["tableprefix"]))
|
||||
$dbconfig["tableprefix"] = "";
|
||||
$authz = new authzgroups ();
|
||||
$authz->connect ($dbconfig["dsn"], $dbconfig["username"],
|
||||
$dbconfig["password"], $dbconfig["driver_options"]);
|
||||
$res = $authz->rightUpdate ("MODULE", "group2", "/object2", "RO");
|
||||
$this->assertSame (1, $res);
|
||||
}
|
||||
|
||||
public function test_rightDelete1 ()
|
||||
{
|
||||
$configuration = new configuration ();
|
||||
$dbconfig = $configuration->get ("database");
|
||||
if (! isset ($dbconfig["tableprefix"]))
|
||||
$dbconfig["tableprefix"] = "";
|
||||
$authz = new authzgroups ();
|
||||
$authz->connect ($dbconfig["dsn"], $dbconfig["username"],
|
||||
$dbconfig["password"], $dbconfig["driver_options"]);
|
||||
// The object doesn't exists
|
||||
$this->setExpectedException ("Exception");
|
||||
$res = $authz->rightDel ("MODULE", "group2", "/object");
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////
|
||||
// CLEANING DATABASE : REMOVING ENTRIES //
|
||||
//////////////////////////////////////////////
|
||||
public function test_deleteGroupmember2 ()
|
||||
{
|
||||
$configuration = new configuration ();
|
||||
$dbconfig = $configuration->get ("database");
|
||||
if (! isset ($dbconfig["tableprefix"]))
|
||||
$dbconfig["tableprefix"] = "";
|
||||
$authz = new authzgroups ();
|
||||
$authz->connect ($dbconfig["dsn"], $dbconfig["username"],
|
||||
$dbconfig["password"], $dbconfig["driver_options"]);
|
||||
$res = $authz->groupmemberDel ("MODULE", "group2","userKnown");
|
||||
$this->assertSame (1, $res);
|
||||
}
|
||||
|
||||
public function test_deleteObject2 ()
|
||||
{
|
||||
$configuration = new configuration ();
|
||||
$dbconfig = $configuration->get ("database");
|
||||
if (! isset ($dbconfig["tableprefix"]))
|
||||
$dbconfig["tableprefix"] = "";
|
||||
$authz = new authzgroups ();
|
||||
$authz->connect ($dbconfig["dsn"], $dbconfig["username"],
|
||||
$dbconfig["password"], $dbconfig["driver_options"]);
|
||||
$res = $authz->objectDel ("MODULE", "/object2");
|
||||
$this->assertSame (1, $res);
|
||||
}
|
||||
|
||||
public function test_deleteGroup2 ()
|
||||
{
|
||||
$configuration = new configuration ();
|
||||
$dbconfig = $configuration->get ("database");
|
||||
if (! isset ($dbconfig["tableprefix"]))
|
||||
$dbconfig["tableprefix"] = "";
|
||||
$authz = new authzgroups ();
|
||||
$authz->connect ($dbconfig["dsn"], $dbconfig["username"],
|
||||
$dbconfig["password"], $dbconfig["driver_options"]);
|
||||
$res = $authz->groupDel ("MODULE", "group2");
|
||||
$this->assertSame (1, $res);
|
||||
}
|
||||
|
||||
/////////////////////
|
||||
// USER RIGHTS //
|
||||
/////////////////////
|
||||
public function test_userrightsget1 ()
|
||||
{
|
||||
$configuration = new configuration ();
|
||||
$dbconfig = $configuration->get ("database");
|
||||
if (! isset ($dbconfig["tableprefix"]))
|
||||
$dbconfig["tableprefix"] = "";
|
||||
$authz = new authzgroups ();
|
||||
$authz->connect ($dbconfig["dsn"], $dbconfig["username"],
|
||||
$dbconfig["password"], $dbconfig["driver_options"]);
|
||||
// Create infos to tests the userrightsget method
|
||||
$authz->objectAdd ("MODULE1", "/");
|
||||
$authz->objectAdd ("MODULE1", "/rep1");
|
||||
$authz->objectAdd ("MODULE1", "/rep1/rep2");
|
||||
$authz->objectAdd ("MODULE1", "/rep1/rep2/rep3");
|
||||
$authz->objectAdd ("MODULE2", "/");
|
||||
$authz->objectAdd ("MODULE2", "/rep1");
|
||||
$authz->objectAdd ("MODULE2", "/rep1/rep2");
|
||||
$authz->objectAdd ("MODULE2", "/rep1/rep2/rep3");
|
||||
$authz->groupAdd ("MODULE1", "group1");
|
||||
$authz->groupAdd ("MODULE1", "group2");
|
||||
$authz->groupAdd ("MODULE1", "group3");
|
||||
$authz->groupAdd ("MODULE2", "group3");
|
||||
$authz->groupmemberAdd ("MODULE1", "group2", "userKnown");
|
||||
$authz->groupmemberAdd ("MODULE1", "group3", "userKnown");
|
||||
$authz->groupmemberAdd ("MODULE2", "group3", "userKnown");
|
||||
$authz->rightAdd ("MODULE1", "group2","/rep1/rep2","RW");
|
||||
$authz->rightAdd ("MODULE1", "group3","/rep1/rep2","RO");
|
||||
|
||||
$res = $authz->userrightsget ("MODULE1", "userKnown");
|
||||
$this->assertSame (array ("/rep1/rep2"=>"RW"), $res);
|
||||
}
|
||||
|
||||
public function test_allow1 ()
|
||||
{
|
||||
$configuration = new configuration ();
|
||||
$dbconfig = $configuration->get ("database");
|
||||
if (! isset ($dbconfig["tableprefix"]))
|
||||
$dbconfig["tableprefix"] = "";
|
||||
$authz = new authzgroups ();
|
||||
$authz->connect ($dbconfig["dsn"], $dbconfig["username"],
|
||||
$dbconfig["password"], $dbconfig["driver_options"]);
|
||||
$res = $authz->allow ("MODULE1", "userKnown", "/rep1/rep2");
|
||||
$this->assertSame ("NO", $res);
|
||||
}
|
||||
|
||||
public function test_allow2 ()
|
||||
{
|
||||
$configuration = new configuration ();
|
||||
$dbconfig = $configuration->get ("database");
|
||||
if (! isset ($dbconfig["tableprefix"]))
|
||||
$dbconfig["tableprefix"] = "";
|
||||
$authz = new authzgroups ();
|
||||
$authz->connect ($dbconfig["dsn"], $dbconfig["username"],
|
||||
$dbconfig["password"], $dbconfig["driver_options"]);
|
||||
$authz->rightAdd ("MODULE1", "group2","/","RW");
|
||||
$res = $authz->allow ("MODULE1", "userKnown", "/rep1/rep2");
|
||||
$this->assertSame ("NO", $res);
|
||||
}
|
||||
|
||||
public function test_allow3 ()
|
||||
{
|
||||
$configuration = new configuration ();
|
||||
$dbconfig = $configuration->get ("database");
|
||||
if (! isset ($dbconfig["tableprefix"]))
|
||||
$dbconfig["tableprefix"] = "";
|
||||
$authz = new authzgroups ();
|
||||
$authz->connect ($dbconfig["dsn"], $dbconfig["username"],
|
||||
$dbconfig["password"], $dbconfig["driver_options"]);
|
||||
$authz->rightAdd ("MODULE1", "group2","/rep1","RO");
|
||||
$res = $authz->allow ("MODULE1", "userKnown", "/rep1/rep2");
|
||||
$this->assertSame ("RW", $res);
|
||||
}
|
||||
|
||||
public function test_allow4 ()
|
||||
{
|
||||
$configuration = new configuration ();
|
||||
$dbconfig = $configuration->get ("database");
|
||||
if (! isset ($dbconfig["tableprefix"]))
|
||||
$dbconfig["tableprefix"] = "";
|
||||
$authz = new authzgroups ();
|
||||
$authz->connect ($dbconfig["dsn"], $dbconfig["username"],
|
||||
$dbconfig["password"], $dbconfig["driver_options"]);
|
||||
$res = $authz->allow ("MODULE1", "userKnown", "/rep1/rep2/rep3");
|
||||
$this->assertSame ("NO", $res);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user