549 lines
18 KiB
PHP
549 lines
18 KiB
PHP
<?php
|
|
|
|
/** DomFramework - Tests
|
|
* @package domframework
|
|
* @author Dominique Fournier <dominique@fournier38.fr>
|
|
* @license BSD
|
|
*/
|
|
|
|
namespace Domframework\Tests;
|
|
|
|
use Domframework\Dblayerauthzgroups;
|
|
use Domframework\Authzgroups;
|
|
|
|
class DblayerauthzgroupsTest extends \PHPUnit_Framework_TestCase
|
|
{
|
|
public $confs = array (
|
|
"sqlite" => array (
|
|
"dsn" => "sqlite:/tmp/databaseAuthz.db",
|
|
"username" => null,
|
|
"password" => null,
|
|
"driver_options" => null,
|
|
"tableprefix" => "",
|
|
));
|
|
|
|
public function test_delDB()
|
|
{
|
|
if (file_exists("/tmp/databaseAuthz.db")) {
|
|
unlink("/tmp/databaseAuthz.db");
|
|
}
|
|
}
|
|
|
|
public function test_createTablesAuthzgroups()
|
|
{
|
|
$dbconfig = $this->confs["sqlite"];
|
|
$a = new Authzgroups();
|
|
$a->connect(
|
|
$dbconfig["dsn"],
|
|
$dbconfig["username"],
|
|
$dbconfig["password"],
|
|
$dbconfig["driver_options"]
|
|
);
|
|
$a->createTables();
|
|
$a->groupAdd("modTest", "group");
|
|
$a->groupmemberAdd("modTest", "group", "user");
|
|
$a->objectAdd("modTest", "/");
|
|
$a->objectAdd("modTest", "/article");
|
|
$a->objectAdd("modTest", "/article/base");
|
|
$a->objectAdd("modTest", "/article/base/poub");
|
|
$a->rightAdd("modTest", "group", "/", "RO");
|
|
$a->rightAdd("modTest", "group", "/article", "RO");
|
|
$a->rightAdd("modTest", "group", "/article/base", "RO");
|
|
$res = $a->rightAdd("modTest", "group", "/article/base/poub", "RW");
|
|
// Should not be verified : it is not a test for authzgroups !
|
|
$this->assertSame("4", $res);
|
|
}
|
|
|
|
public function test_createTable()
|
|
{
|
|
$dbconfig = $this->confs["sqlite"];
|
|
$n = new Dblayerauthzgroups(
|
|
$dbconfig["dsn"],
|
|
$dbconfig["username"],
|
|
$dbconfig["password"],
|
|
$dbconfig["driver_options"]
|
|
);
|
|
$n->disconnect();
|
|
$n = new Dblayerauthzgroups(
|
|
$dbconfig["dsn"],
|
|
$dbconfig["username"],
|
|
$dbconfig["password"],
|
|
$dbconfig["driver_options"]
|
|
);
|
|
$n->tableSet("dns zones")
|
|
->fieldsSet(array (
|
|
"id" => array ("integer", "not null", "autoincrement"),
|
|
"zo ne" => array ("varchar", "255", "not null"),
|
|
"vie wname" => array ("varchar", "255"),
|
|
"view clients" => array ("varchar", "255"),
|
|
"comme nt" => array ("varchar", "1024"),
|
|
"opendate" => array ("datetime", "not null"),
|
|
"closedate" => array ("datetime")))
|
|
->primarySet("id")
|
|
->uniqueSet(array ("id", array ("zo ne", "vie wname")));
|
|
$res = $n->createTable();
|
|
$this->assertSame(0, $res);
|
|
}
|
|
|
|
public function test_insert1()
|
|
{
|
|
$dbconfig = $this->confs["sqlite"];
|
|
$a = new Authzgroups();
|
|
$a->connect(
|
|
$dbconfig["dsn"],
|
|
$dbconfig["username"],
|
|
$dbconfig["password"],
|
|
$dbconfig["driver_options"]
|
|
);
|
|
$n = new Dblayerauthzgroups(
|
|
$dbconfig["dsn"],
|
|
$dbconfig["username"],
|
|
$dbconfig["password"],
|
|
$dbconfig["driver_options"]
|
|
);
|
|
$n->tableSet("dns zones")
|
|
->fieldsSet(array (
|
|
"id" => array ("integer", "not null", "autoincrement"),
|
|
"zo ne" => array ("varchar", "255", "not null"),
|
|
"vie wname" => array ("varchar", "255"),
|
|
"view clients" => array ("varchar", "255"),
|
|
"comme nt" => array ("varchar", "1024"),
|
|
"opendate" => array ("datetime", "not null"),
|
|
"closedate" => array ("datetime")))
|
|
->primarySet("id")
|
|
->uniqueSet(array ("id", array ("zo ne", "vie wname")))
|
|
->authzgroupsSet($a)
|
|
->moduleSet("modTest")
|
|
->userSet("user")
|
|
->createGroupSet("group")
|
|
->pathSet("/article/base/poub");
|
|
$res = $n->insert(array ("zo ne" => "zone1",
|
|
"opendate" => "2015-05-04 00:11:22"));
|
|
$n->disconnect();
|
|
$this->assertSame("1", $res);
|
|
}
|
|
|
|
// Check if the update of the authzgroups database is OK
|
|
public function test_addAuthzgroups()
|
|
{
|
|
$dbconfig = $this->confs["sqlite"];
|
|
$a = new Authzgroups();
|
|
$a->connect(
|
|
$dbconfig["dsn"],
|
|
$dbconfig["username"],
|
|
$dbconfig["password"],
|
|
$dbconfig["driver_options"]
|
|
);
|
|
$res = $a->allow("modTest", "user", "/article/base/poub/1");
|
|
$this->assertSame("RW", $res);
|
|
}
|
|
|
|
public function test_insert2()
|
|
{
|
|
$dbconfig = $this->confs["sqlite"];
|
|
$a = new Authzgroups();
|
|
$a->connect(
|
|
$dbconfig["dsn"],
|
|
$dbconfig["username"],
|
|
$dbconfig["password"],
|
|
$dbconfig["driver_options"]
|
|
);
|
|
$n = new Dblayerauthzgroups(
|
|
$dbconfig["dsn"],
|
|
$dbconfig["username"],
|
|
$dbconfig["password"],
|
|
$dbconfig["driver_options"]
|
|
);
|
|
$n->tableSet("dns zones")
|
|
->fieldsSet(array (
|
|
"id" => array ("integer", "not null", "autoincrement"),
|
|
"zo ne" => array ("varchar", "255", "not null"),
|
|
"vie wname" => array ("varchar", "255"),
|
|
"view clients" => array ("varchar", "255"),
|
|
"comme nt" => array ("varchar", "1024"),
|
|
"opendate" => array ("datetime", "not null"),
|
|
"closedate" => array ("datetime")))
|
|
->primarySet("id")
|
|
->uniqueSet(array ("id", array ("zo ne", "vie wname")))
|
|
->authzgroupsSet($a)
|
|
->moduleSet("modTest")
|
|
->userSet("user")
|
|
->createGroupSet("group")
|
|
->pathSet("/article/base/poub");
|
|
$n->insert(array ("zo ne" => "zone2", "opendate" => "2015-05-04 00:11:22"));
|
|
$n->insert(array ("zo ne" => "zone3", "opendate" => "2015-05-04 00:11:22"));
|
|
$n->insert(array ("zo ne" => "zone4", "opendate" => "2015-05-04 00:11:22"));
|
|
$res = $n->insert(array ("zo ne" => "zone5",
|
|
"opendate" => "2015-05-04 00:11:22"));
|
|
$n->disconnect();
|
|
$this->assertSame("5", $res);
|
|
}
|
|
|
|
// Access to all the tuples
|
|
public function test_read1()
|
|
{
|
|
$dbconfig = $this->confs["sqlite"];
|
|
$a = new Authzgroups();
|
|
$a->connect(
|
|
$dbconfig["dsn"],
|
|
$dbconfig["username"],
|
|
$dbconfig["password"],
|
|
$dbconfig["driver_options"]
|
|
);
|
|
$n = new Dblayerauthzgroups(
|
|
$dbconfig["dsn"],
|
|
$dbconfig["username"],
|
|
$dbconfig["password"],
|
|
$dbconfig["driver_options"]
|
|
);
|
|
$n->tableSet("dns zones")
|
|
->fieldsSet(array (
|
|
"id" => array ("integer", "not null", "autoincrement"),
|
|
"zo ne" => array ("varchar", "255", "not null"),
|
|
"vie wname" => array ("varchar", "255"),
|
|
"view clients" => array ("varchar", "255"),
|
|
"comme nt" => array ("varchar", "1024"),
|
|
"opendate" => array ("datetime", "not null"),
|
|
"closedate" => array ("datetime")))
|
|
->primarySet("id")
|
|
->uniqueSet(array ("id", array ("zo ne", "vie wname")))
|
|
->authzgroupsSet($a)
|
|
->moduleSet("modTest")
|
|
->userSet("user")
|
|
->createGroupSet("group")
|
|
->pathSet("/article/base/poub");
|
|
$res = count($n->read());
|
|
$n->disconnect();
|
|
$this->assertSame(5, $res);
|
|
}
|
|
|
|
// Remove the right access to 2 and 4
|
|
public function test_rightDel()
|
|
{
|
|
$dbconfig = $this->confs["sqlite"];
|
|
$a = new Authzgroups();
|
|
$a->connect(
|
|
$dbconfig["dsn"],
|
|
$dbconfig["username"],
|
|
$dbconfig["password"],
|
|
$dbconfig["driver_options"]
|
|
);
|
|
$a->rightDel("modTest", "group", "/article/base/poub/2");
|
|
$res = $a->rightDel("modTest", "group", "/article/base/poub/4");
|
|
// Should not be verified : it is not a test for authzgroups !
|
|
$this->assertSame(1, $res);
|
|
}
|
|
|
|
// Access to 3 of the tuples (2 are blacklisted for the user)
|
|
public function test_read2()
|
|
{
|
|
$dbconfig = $this->confs["sqlite"];
|
|
$a = new Authzgroups();
|
|
$a->connect(
|
|
$dbconfig["dsn"],
|
|
$dbconfig["username"],
|
|
$dbconfig["password"],
|
|
$dbconfig["driver_options"]
|
|
);
|
|
$n = new Dblayerauthzgroups(
|
|
$dbconfig["dsn"],
|
|
$dbconfig["username"],
|
|
$dbconfig["password"],
|
|
$dbconfig["driver_options"]
|
|
);
|
|
$n->tableSet("dns zones")
|
|
->fieldsSet(array (
|
|
"id" => array ("integer", "not null", "autoincrement"),
|
|
"zo ne" => array ("varchar", "255", "not null"),
|
|
"vie wname" => array ("varchar", "255"),
|
|
"view clients" => array ("varchar", "255"),
|
|
"comme nt" => array ("varchar", "1024"),
|
|
"opendate" => array ("datetime", "not null"),
|
|
"closedate" => array ("datetime")))
|
|
->primarySet("id")
|
|
->uniqueSet(array ("id", array ("zo ne", "vie wname")))
|
|
->authzgroupsSet($a)
|
|
->moduleSet("modTest")
|
|
->userSet("user")
|
|
->createGroupSet("group")
|
|
->pathSet("/article/base/poub");
|
|
$res = count($n->read());
|
|
$n->disconnect();
|
|
$this->assertSame(3, $res);
|
|
}
|
|
|
|
// Del an entry without right -> exception
|
|
public function test_delEntry1()
|
|
{
|
|
$dbconfig = $this->confs["sqlite"];
|
|
$a = new Authzgroups();
|
|
$a->connect(
|
|
$dbconfig["dsn"],
|
|
$dbconfig["username"],
|
|
$dbconfig["password"],
|
|
$dbconfig["driver_options"]
|
|
);
|
|
$n = new Dblayerauthzgroups(
|
|
$dbconfig["dsn"],
|
|
$dbconfig["username"],
|
|
$dbconfig["password"],
|
|
$dbconfig["driver_options"]
|
|
);
|
|
$n->tableSet("dns zones")
|
|
->fieldsSet(array (
|
|
"id" => array ("integer", "not null", "autoincrement"),
|
|
"zo ne" => array ("varchar", "255", "not null"),
|
|
"vie wname" => array ("varchar", "255"),
|
|
"view clients" => array ("varchar", "255"),
|
|
"comme nt" => array ("varchar", "1024"),
|
|
"opendate" => array ("datetime", "not null"),
|
|
"closedate" => array ("datetime")))
|
|
->primarySet("id")
|
|
->uniqueSet(array ("id", array ("zo ne", "vie wname")))
|
|
->authzgroupsSet($a)
|
|
->moduleSet("modTest")
|
|
->userSet("user")
|
|
->createGroupSet("group")
|
|
->pathSet("/article/base/poub");
|
|
$this->setExpectedException("Exception");
|
|
$res = $n->delete(2);
|
|
}
|
|
|
|
// Update a right to RO
|
|
public function test_rightRO()
|
|
{
|
|
$dbconfig = $this->confs["sqlite"];
|
|
$a = new Authzgroups();
|
|
$a->connect(
|
|
$dbconfig["dsn"],
|
|
$dbconfig["username"],
|
|
$dbconfig["password"],
|
|
$dbconfig["driver_options"]
|
|
);
|
|
$res = $a->rightUpdate("modTest", "group", "/article/base/poub/1", "RO");
|
|
// Not necessary to test : authzgroups
|
|
$this->assertSame(1, $res);
|
|
}
|
|
|
|
// Update an entry with RO right -> exception
|
|
public function test_updateEntry2()
|
|
{
|
|
$dbconfig = $this->confs["sqlite"];
|
|
$a = new Authzgroups();
|
|
$a->connect(
|
|
$dbconfig["dsn"],
|
|
$dbconfig["username"],
|
|
$dbconfig["password"],
|
|
$dbconfig["driver_options"]
|
|
);
|
|
$n = new Dblayerauthzgroups(
|
|
$dbconfig["dsn"],
|
|
$dbconfig["username"],
|
|
$dbconfig["password"],
|
|
$dbconfig["driver_options"]
|
|
);
|
|
$n->tableSet("dns zones")
|
|
->fieldsSet(array (
|
|
"id" => array ("integer", "not null", "autoincrement"),
|
|
"zo ne" => array ("varchar", "255", "not null"),
|
|
"vie wname" => array ("varchar", "255"),
|
|
"view clients" => array ("varchar", "255"),
|
|
"comme nt" => array ("varchar", "1024"),
|
|
"opendate" => array ("datetime", "not null"),
|
|
"closedate" => array ("datetime")))
|
|
->primarySet("id")
|
|
->uniqueSet(array ("id", array ("zo ne", "vie wname")))
|
|
->authzgroupsSet($a)
|
|
->moduleSet("modTest")
|
|
->userSet("user")
|
|
->createGroupSet("group")
|
|
->pathSet("/article/base/poub");
|
|
$this->setExpectedException("Exception");
|
|
$res = $n->update(1, array ("zo ne" => "NOT ALLOWED"));
|
|
}
|
|
|
|
// Del an entry with the RO right -> exception
|
|
public function test_delEntry2()
|
|
{
|
|
$dbconfig = $this->confs["sqlite"];
|
|
$a = new Authzgroups();
|
|
$a->connect(
|
|
$dbconfig["dsn"],
|
|
$dbconfig["username"],
|
|
$dbconfig["password"],
|
|
$dbconfig["driver_options"]
|
|
);
|
|
$n = new Dblayerauthzgroups(
|
|
$dbconfig["dsn"],
|
|
$dbconfig["username"],
|
|
$dbconfig["password"],
|
|
$dbconfig["driver_options"]
|
|
);
|
|
$n->tableSet("dns zones")
|
|
->fieldsSet(array (
|
|
"id" => array ("integer", "not null", "autoincrement"),
|
|
"zo ne" => array ("varchar", "255", "not null"),
|
|
"vie wname" => array ("varchar", "255"),
|
|
"view clients" => array ("varchar", "255"),
|
|
"comme nt" => array ("varchar", "1024"),
|
|
"opendate" => array ("datetime", "not null"),
|
|
"closedate" => array ("datetime")))
|
|
->primarySet("id")
|
|
->uniqueSet(array ("id", array ("zo ne", "vie wname")))
|
|
->authzgroupsSet($a)
|
|
->moduleSet("modTest")
|
|
->userSet("user")
|
|
->createGroupSet("group")
|
|
->pathSet("/article/base/poub");
|
|
$this->setExpectedException("Exception");
|
|
$res = $n->delete(1);
|
|
}
|
|
|
|
// Update a right to RW
|
|
public function test_rightRW()
|
|
{
|
|
$dbconfig = $this->confs["sqlite"];
|
|
$a = new Authzgroups();
|
|
$a->connect(
|
|
$dbconfig["dsn"],
|
|
$dbconfig["username"],
|
|
$dbconfig["password"],
|
|
$dbconfig["driver_options"]
|
|
);
|
|
$res = $a->rightUpdate("modTest", "group", "/article/base/poub/1", "RW");
|
|
// Not necessary to test : authzgroups
|
|
$this->assertSame(1, $res);
|
|
}
|
|
|
|
// Update an entry with RW right
|
|
public function test_updateEntry3()
|
|
{
|
|
$dbconfig = $this->confs["sqlite"];
|
|
$a = new Authzgroups();
|
|
$a->connect(
|
|
$dbconfig["dsn"],
|
|
$dbconfig["username"],
|
|
$dbconfig["password"],
|
|
$dbconfig["driver_options"]
|
|
);
|
|
$n = new Dblayerauthzgroups(
|
|
$dbconfig["dsn"],
|
|
$dbconfig["username"],
|
|
$dbconfig["password"],
|
|
$dbconfig["driver_options"]
|
|
);
|
|
$n->tableSet("dns zones")
|
|
->fieldsSet(array (
|
|
"id" => array ("integer", "not null", "autoincrement"),
|
|
"zo ne" => array ("varchar", "255", "not null"),
|
|
"vie wname" => array ("varchar", "255"),
|
|
"view clients" => array ("varchar", "255"),
|
|
"comme nt" => array ("varchar", "1024"),
|
|
"opendate" => array ("datetime", "not null"),
|
|
"closedate" => array ("datetime")))
|
|
->primarySet("id")
|
|
->uniqueSet(array ("id", array ("zo ne", "vie wname")))
|
|
->authzgroupsSet($a)
|
|
->moduleSet("modTest")
|
|
->userSet("user")
|
|
->createGroupSet("group")
|
|
->pathSet("/article/base/poub");
|
|
$res = $n->update(1, array ("zo ne" => "ALLOWED"));
|
|
$this->assertSame(1, $res);
|
|
}
|
|
|
|
// Del an entry with the RW right
|
|
public function test_delEntry3()
|
|
{
|
|
$dbconfig = $this->confs["sqlite"];
|
|
$a = new Authzgroups();
|
|
$a->connect(
|
|
$dbconfig["dsn"],
|
|
$dbconfig["username"],
|
|
$dbconfig["password"],
|
|
$dbconfig["driver_options"]
|
|
);
|
|
$n = new Dblayerauthzgroups(
|
|
$dbconfig["dsn"],
|
|
$dbconfig["username"],
|
|
$dbconfig["password"],
|
|
$dbconfig["driver_options"]
|
|
);
|
|
$n->tableSet("dns zones")
|
|
->fieldsSet(array (
|
|
"id" => array ("integer", "not null", "autoincrement"),
|
|
"zo ne" => array ("varchar", "255", "not null"),
|
|
"vie wname" => array ("varchar", "255"),
|
|
"view clients" => array ("varchar", "255"),
|
|
"comme nt" => array ("varchar", "1024"),
|
|
"opendate" => array ("datetime", "not null"),
|
|
"closedate" => array ("datetime")))
|
|
->primarySet("id")
|
|
->uniqueSet(array ("id", array ("zo ne", "vie wname")))
|
|
->authzgroupsSet($a)
|
|
->moduleSet("modTest")
|
|
->userSet("user")
|
|
->createGroupSet("group")
|
|
->pathSet("/article/base/poub");
|
|
$res = $n->delete(1);
|
|
$this->assertSame(1, $res);
|
|
}
|
|
|
|
// Check if the update of the authzgroups database is OK after deletion
|
|
public function test_delAuthzgroups()
|
|
{
|
|
$dbconfig = $this->confs["sqlite"];
|
|
$a = new Authzgroups();
|
|
$a->connect(
|
|
$dbconfig["dsn"],
|
|
$dbconfig["username"],
|
|
$dbconfig["password"],
|
|
$dbconfig["driver_options"]
|
|
);
|
|
$res = $a->objectRead("modTest", "/article/base/poub/1");
|
|
$this->assertSame(array (), $res);
|
|
}
|
|
|
|
|
|
// Read the zone without id
|
|
public function test_read3()
|
|
{
|
|
$dbconfig = $this->confs["sqlite"];
|
|
$a = new Authzgroups();
|
|
$a->connect(
|
|
$dbconfig["dsn"],
|
|
$dbconfig["username"],
|
|
$dbconfig["password"],
|
|
$dbconfig["driver_options"]
|
|
);
|
|
$n = new Dblayerauthzgroups(
|
|
$dbconfig["dsn"],
|
|
$dbconfig["username"],
|
|
$dbconfig["password"],
|
|
$dbconfig["driver_options"]
|
|
);
|
|
$n->tableSet("dns zones")
|
|
->fieldsSet(array (
|
|
"id" => array ("integer", "not null", "autoincrement"),
|
|
"zo ne" => array ("varchar", "255", "not null"),
|
|
"vie wname" => array ("varchar", "255"),
|
|
"view clients" => array ("varchar", "255"),
|
|
"comme nt" => array ("varchar", "1024"),
|
|
"opendate" => array ("datetime", "not null"),
|
|
"closedate" => array ("datetime")))
|
|
->primarySet("id")
|
|
->uniqueSet(array ("id", array ("zo ne", "vie wname")))
|
|
->authzgroupsSet($a)
|
|
->moduleSet("modTest")
|
|
->userSet("user")
|
|
->createGroupSet("group")
|
|
->pathSet("/article/base/poub");
|
|
$res = $n->read(null, array ("zo ne", "vie wname"));
|
|
$this->assertSame(
|
|
array (1 => array ("zo ne" => "zone3", "vie wname" => null),
|
|
3 => array ("zo ne" => "zone5", "vie wname" => null)),
|
|
$res
|
|
);
|
|
}
|
|
}
|