Fix ACL binary comparison

This commit is contained in:
Romain Neutron
2013-12-09 18:39:51 +01:00
parent ef55bd29cc
commit 0804d01b4f
2 changed files with 33 additions and 5 deletions

View File

@@ -223,7 +223,7 @@ class ACL implements cache_cacheableInterface
public function has_status_access_to_record(record_adapter $record)
{
return (Boolean) ('Ob' . $record->get_status() ^ $this->get_mask_xor($record->get_base_id()) & $this->get_mask_and($record->get_base_id()));
return 0 === ((bindec($record->get_status()) ^ $this->get_mask_xor($record->get_base_id())) & $this->get_mask_and($record->get_base_id()));
}
public function has_access_to_subdef(record_Interface $record, $subdef_name)
@@ -1050,9 +1050,9 @@ class ACL implements cache_cacheableInterface
$this->_rights_bas[$row['base_id']]['canreport']
= $row['canreport'] == '1';
$this->_rights_bas[$row['base_id']]['mask_and']
= $row['mask_and'];
= (int) $row['mask_and'];
$this->_rights_bas[$row['base_id']]['mask_xor']
= $row['mask_xor'];
= (int) $row['mask_xor'];
$this->_rights_bas[$row['base_id']]['modify_struct']
= $row['modify_struct'] == '1';
$this->_rights_bas[$row['base_id']]['manage']
@@ -1551,6 +1551,8 @@ class ACL implements cache_cacheableInterface
unset($stmt);
$this->delete_data_from_cache(self::CACHE_RIGHTS_BAS);
return $this;
}

View File

@@ -48,14 +48,40 @@ class ACLTest extends PhraseanetPHPUnitAuthenticatedAbstract
$this->assertTrue(self::$object->has_status_access_to_record(self::$DI['record_1']));
}
public function testHasAccesToRecordStatus()
{
self::$DI['record_1']->set_binary_status(str_repeat('0', 32));
self::$object->set_masks_on_base(self::$DI['record_1']->get_base_id(), '10000', '10000', '0', '0');
self::$DI['record_1']->set_binary_status('10000');
$this->assertFalse(self::$object->has_status_access_to_record(self::$DI['record_1']));
self::$DI['record_1']->set_binary_status('00000');
$this->assertTrue(self::$object->has_status_access_to_record(self::$DI['record_1']));
self::$object->set_masks_on_base(self::$DI['record_1']->get_base_id(), '10000', '10000', '10000', '10000');
$this->assertFalse(self::$object->has_status_access_to_record(self::$DI['record_1']));
self::$DI['record_1']->set_binary_status('10000');
$this->assertTrue(self::$object->has_status_access_to_record(self::$DI['record_1']));
self::$object->set_masks_on_base(self::$DI['record_1']->get_base_id(), '0', '0', '0', '0');
$this->assertTrue(self::$object->has_status_access_to_record(self::$DI['record_1']));
self::$DI['record_1']->set_binary_status(str_repeat('0', 32));
$this->assertTrue(self::$object->has_status_access_to_record(self::$DI['record_1']));
}
public function testHasAccesToRecordFailsOnBase()
{
$this->assertFalse(self::$object->has_status_access_to_record(self::$DI['record_no_access']));
$this->assertFalse(self::$object->has_access_to_record(self::$DI['record_no_access']));
}
public function testHasAccesToRecordFailsOnStatus()
{
$this->assertFalse(self::$object->has_status_access_to_record(self::$DI['record_no_access_by_status']));
$this->assertFalse(self::$object->has_access_to_record(self::$DI['record_no_access_by_status']));
}
public function testApply_model()