412 lines
12 KiB
PHP
412 lines
12 KiB
PHP
<?php
|
|
|
|
/**
|
|
* DomFramework - Tests
|
|
* @package domframework
|
|
* @author Dominique Fournier <dominique@fournier38.fr>
|
|
* @license BSD
|
|
*/
|
|
|
|
namespace Domframework\Tests;
|
|
|
|
use Domframework\Authzgroupsoo;
|
|
|
|
/**
|
|
* Test the Authzgroupsoo.php file
|
|
*/
|
|
class AuthzgroupsooTest extends \PHPUnit_Framework_TestCase
|
|
{
|
|
private $dbconfig = [
|
|
"dsn" => "sqlite:/tmp/databaseAuthzGroupsoo.db",
|
|
"username" => null,
|
|
"password" => null,
|
|
"driver_options" => null,
|
|
"tableprefix" => "",
|
|
];
|
|
public function testInitialization()
|
|
{
|
|
if (file_exists("/tmp/databaseAuthzGroupsoo.db")) {
|
|
unlink("/tmp/databaseAuthzGroupsoo.db");
|
|
}
|
|
}
|
|
|
|
public function testCreateTables1()
|
|
{
|
|
$authz = new Authzgroupsoo();
|
|
$this->setExpectedException("Exception");
|
|
$authz->createTables();
|
|
}
|
|
|
|
public function testConnect()
|
|
{
|
|
// Must use the model to create the database structure as there is no
|
|
// creation of tables in controller
|
|
$authz = new Authzgroupsoo();
|
|
$res = $authz->connect(
|
|
$this->dbconfig["dsn"],
|
|
$this->dbconfig["username"],
|
|
$this->dbconfig["password"],
|
|
$this->dbconfig["driver_options"]
|
|
);
|
|
$this->assertSame(true, $res);
|
|
}
|
|
|
|
public function testCreateTables2()
|
|
{
|
|
$authz = new Authzgroupsoo();
|
|
$authz->connect(
|
|
$this->dbconfig["dsn"],
|
|
$this->dbconfig["username"],
|
|
$this->dbconfig["password"],
|
|
$this->dbconfig["driver_options"]
|
|
);
|
|
$res = $authz->createTables();
|
|
$this->assertSame(true, $res);
|
|
}
|
|
|
|
////////////////
|
|
// OBJECT //
|
|
////////////////
|
|
public function testObjectCreate1()
|
|
{
|
|
$authz = new Authzgroupsoo();
|
|
$authz->connect(
|
|
$this->dbconfig["dsn"],
|
|
$this->dbconfig["username"],
|
|
$this->dbconfig["password"],
|
|
$this->dbconfig["driver_options"]
|
|
);
|
|
$res = $authz->objectAdd("MODULE", "/object");
|
|
$this->assertSame("1", $res);
|
|
}
|
|
|
|
public function testObjectUpdate1()
|
|
{
|
|
$authz = new Authzgroupsoo();
|
|
$authz->connect(
|
|
$this->dbconfig["dsn"],
|
|
$this->dbconfig["username"],
|
|
$this->dbconfig["password"],
|
|
$this->dbconfig["driver_options"]
|
|
);
|
|
$res = $authz->objectUpdate("MODULE", "/object", "/object2");
|
|
$this->assertSame(1, $res);
|
|
}
|
|
|
|
public function testObjectDelete1()
|
|
{
|
|
$authz = new Authzgroupsoo();
|
|
$authz->connect(
|
|
$this->dbconfig["dsn"],
|
|
$this->dbconfig["username"],
|
|
$this->dbconfig["password"],
|
|
$this->dbconfig["driver_options"]
|
|
);
|
|
// The object was renamed and is not available
|
|
$this->setExpectedException("Exception");
|
|
$res = $authz->objectDel("MODULE", "/object");
|
|
}
|
|
|
|
////////////////
|
|
// GROUPS //
|
|
////////////////
|
|
public function testGroupCreate1()
|
|
{
|
|
$authz = new Authzgroupsoo();
|
|
$authz->connect(
|
|
$this->dbconfig["dsn"],
|
|
$this->dbconfig["username"],
|
|
$this->dbconfig["password"],
|
|
$this->dbconfig["driver_options"]
|
|
);
|
|
$res = $authz->groupAdd("MODULE", "group");
|
|
$this->assertSame("1", $res);
|
|
}
|
|
|
|
public function testGroupUpdate1()
|
|
{
|
|
$authz = new Authzgroupsoo();
|
|
$authz->connect(
|
|
$this->dbconfig["dsn"],
|
|
$this->dbconfig["username"],
|
|
$this->dbconfig["password"],
|
|
$this->dbconfig["driver_options"]
|
|
);
|
|
$res = $authz->groupUpdate("MODULE", "group", "group2");
|
|
$this->assertSame(1, $res);
|
|
}
|
|
|
|
public function testGroupDelete1()
|
|
{
|
|
$authz = new Authzgroupsoo();
|
|
$authz->connect(
|
|
$this->dbconfig["dsn"],
|
|
$this->dbconfig["username"],
|
|
$this->dbconfig["password"],
|
|
$this->dbconfig["driver_options"]
|
|
);
|
|
// The group doesn't exists
|
|
$this->setExpectedException("Exception");
|
|
$res = $authz->groupDel("MODULE", "group");
|
|
}
|
|
|
|
/////////////////////
|
|
// GROUPMEMBER //
|
|
/////////////////////
|
|
public function testGroupmemberCreate1()
|
|
{
|
|
$authz = new Authzgroupsoo();
|
|
$authz->connect(
|
|
$this->dbconfig["dsn"],
|
|
$this->dbconfig["username"],
|
|
$this->dbconfig["password"],
|
|
$this->dbconfig["driver_options"]
|
|
);
|
|
// The group doesn't exists
|
|
$this->setExpectedException("Exception");
|
|
$res = $authz->groupmemberAdd("MODULE", "group", "userKnown");
|
|
}
|
|
|
|
public function testGroupmemberCreate2()
|
|
{
|
|
$authz = new Authzgroupsoo();
|
|
$authz->connect(
|
|
$this->dbconfig["dsn"],
|
|
$this->dbconfig["username"],
|
|
$this->dbconfig["password"],
|
|
$this->dbconfig["driver_options"]
|
|
);
|
|
$res = $authz->groupmemberAdd("MODULE", "group2", "userKnown");
|
|
$this->assertSame("1", $res);
|
|
}
|
|
|
|
public function testGroupmemberDelete1()
|
|
{
|
|
$authz = new Authzgroupsoo();
|
|
$authz->connect(
|
|
$this->dbconfig["dsn"],
|
|
$this->dbconfig["username"],
|
|
$this->dbconfig["password"],
|
|
$this->dbconfig["driver_options"]
|
|
);
|
|
// The group doesn't exists
|
|
$this->setExpectedException("Exception");
|
|
$res = $authz->groupmemberDel("MODULE", "group", "userKnown");
|
|
}
|
|
|
|
public function testGroupmemberReadGroup1()
|
|
{
|
|
$authz = new Authzgroupsoo();
|
|
$authz->connect(
|
|
$this->dbconfig["dsn"],
|
|
$this->dbconfig["username"],
|
|
$this->dbconfig["password"],
|
|
$this->dbconfig["driver_options"]
|
|
);
|
|
// The group doesn't exists
|
|
$this->setExpectedException("Exception");
|
|
$res = $authz->groupmemberReadGroup("MODULE", "group");
|
|
}
|
|
|
|
public function testGroupmemberReadGroup2()
|
|
{
|
|
$authz = new Authzgroupsoo();
|
|
$authz->connect(
|
|
$this->dbconfig["dsn"],
|
|
$this->dbconfig["username"],
|
|
$this->dbconfig["password"],
|
|
$this->dbconfig["driver_options"]
|
|
);
|
|
$res = $authz->groupmemberReadGroup("MODULE", "group2");
|
|
$this->assertSame([["user" => "userKnown"]], $res);
|
|
}
|
|
|
|
public function testGroupmemberReadUser1()
|
|
{
|
|
$authz = new Authzgroupsoo();
|
|
$authz->connect(
|
|
$this->dbconfig["dsn"],
|
|
$this->dbconfig["username"],
|
|
$this->dbconfig["password"],
|
|
$this->dbconfig["driver_options"]
|
|
);
|
|
$res = $authz->groupmemberReadUser("MODULE", "userKnown");
|
|
$this->assertSame([1 => "group2"], $res);
|
|
}
|
|
|
|
////////////////
|
|
// RIGHTS //
|
|
////////////////
|
|
public function testRightCreate1()
|
|
{
|
|
$authz = new Authzgroupsoo();
|
|
$authz->connect(
|
|
$this->dbconfig["dsn"],
|
|
$this->dbconfig["username"],
|
|
$this->dbconfig["password"],
|
|
$this->dbconfig["driver_options"]
|
|
);
|
|
$res = $authz->rightAdd("MODULE", "group2", "/object2", "RW");
|
|
$this->assertSame("1", $res);
|
|
}
|
|
|
|
public function testRightUpdate1()
|
|
{
|
|
$authz = new Authzgroupsoo();
|
|
$authz->connect(
|
|
$this->dbconfig["dsn"],
|
|
$this->dbconfig["username"],
|
|
$this->dbconfig["password"],
|
|
$this->dbconfig["driver_options"]
|
|
);
|
|
$res = $authz->rightUpdate("MODULE", "group2", "/object2", "RO");
|
|
$this->assertSame(1, $res);
|
|
}
|
|
|
|
public function testRightDelete1()
|
|
{
|
|
$authz = new Authzgroupsoo();
|
|
$authz->connect(
|
|
$this->dbconfig["dsn"],
|
|
$this->dbconfig["username"],
|
|
$this->dbconfig["password"],
|
|
$this->dbconfig["driver_options"]
|
|
);
|
|
// The object doesn't exists
|
|
$this->setExpectedException("Exception");
|
|
$res = $authz->rightDel("MODULE", "group2", "/object");
|
|
}
|
|
|
|
|
|
//////////////////////////////////////////////
|
|
// CLEANING DATABASE : REMOVING ENTRIES //
|
|
//////////////////////////////////////////////
|
|
public function testDeleteGroupmember2()
|
|
{
|
|
$authz = new Authzgroupsoo();
|
|
$authz->connect(
|
|
$this->dbconfig["dsn"],
|
|
$this->dbconfig["username"],
|
|
$this->dbconfig["password"],
|
|
$this->dbconfig["driver_options"]
|
|
);
|
|
$res = $authz->groupmemberDel("MODULE", "group2", "userKnown");
|
|
$this->assertSame(1, $res);
|
|
}
|
|
|
|
public function testDeleteObject2()
|
|
{
|
|
$authz = new Authzgroupsoo();
|
|
$authz->connect(
|
|
$this->dbconfig["dsn"],
|
|
$this->dbconfig["username"],
|
|
$this->dbconfig["password"],
|
|
$this->dbconfig["driver_options"]
|
|
);
|
|
$res = $authz->objectDel("MODULE", "/object2");
|
|
$this->assertSame(1, $res);
|
|
}
|
|
|
|
public function testDeleteGroup2()
|
|
{
|
|
$authz = new Authzgroupsoo();
|
|
$authz->connect(
|
|
$this->dbconfig["dsn"],
|
|
$this->dbconfig["username"],
|
|
$this->dbconfig["password"],
|
|
$this->dbconfig["driver_options"]
|
|
);
|
|
$res = $authz->groupDel("MODULE", "group2");
|
|
$this->assertSame(1, $res);
|
|
}
|
|
|
|
/////////////////////
|
|
// USER RIGHTS //
|
|
/////////////////////
|
|
public function testUserrightsget1()
|
|
{
|
|
$authz = new Authzgroupsoo();
|
|
$authz->connect(
|
|
$this->dbconfig["dsn"],
|
|
$this->dbconfig["username"],
|
|
$this->dbconfig["password"],
|
|
$this->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(["/rep1/rep2" => "RW"], $res);
|
|
}
|
|
|
|
public function testAllow1()
|
|
{
|
|
$authz = new Authzgroupsoo();
|
|
$authz->connect(
|
|
$this->dbconfig["dsn"],
|
|
$this->dbconfig["username"],
|
|
$this->dbconfig["password"],
|
|
$this->dbconfig["driver_options"]
|
|
);
|
|
$res = $authz->allow("MODULE1", "userKnown", "/rep1/rep2");
|
|
$this->assertSame("RW", $res);
|
|
}
|
|
|
|
public function testAllow2()
|
|
{
|
|
$authz = new Authzgroupsoo();
|
|
$authz->connect(
|
|
$this->dbconfig["dsn"],
|
|
$this->dbconfig["username"],
|
|
$this->dbconfig["password"],
|
|
$this->dbconfig["driver_options"]
|
|
);
|
|
$authz->rightAdd("MODULE1", "group2", "/", "RW");
|
|
$res = $authz->allow("MODULE1", "userKnown", "/rep1/rep2");
|
|
$this->assertSame("RW", $res);
|
|
}
|
|
|
|
public function testAllow3()
|
|
{
|
|
$authz = new Authzgroupsoo();
|
|
$authz->connect(
|
|
$this->dbconfig["dsn"],
|
|
$this->dbconfig["username"],
|
|
$this->dbconfig["password"],
|
|
$this->dbconfig["driver_options"]
|
|
);
|
|
$authz->rightAdd("MODULE1", "group2", "/rep1", "RO");
|
|
$res = $authz->allow("MODULE1", "userKnown", "/rep1/rep2");
|
|
$this->assertSame("RW", $res);
|
|
}
|
|
|
|
public function testAllow4()
|
|
{
|
|
$authz = new Authzgroupsoo();
|
|
$authz->connect(
|
|
$this->dbconfig["dsn"],
|
|
$this->dbconfig["username"],
|
|
$this->dbconfig["password"],
|
|
$this->dbconfig["driver_options"]
|
|
);
|
|
$res = $authz->allow("MODULE1", "userKnown", "/rep1/rep2/rep3");
|
|
$this->assertSame("NO", $res);
|
|
}
|
|
}
|