G
G
gto61202017-02-06 13:11:12
Yii
gto6120, 2017-02-06 13:11:12

Are automated functional tests necessary for access control?

I use RBAC, there are 3 roles and many, many permissions, as well as a couple of rules, you need to keep track of this whole thing so that it does not break during the changes. I want to understand whether automatic tests are used for such tasks? In theory, unit tests are definitely not suitable here, functional ones seem to be similar in purpose.
How can you implement an access check?
1. I created data (ActiveFixture dataFile) for 3 users (by the number of roles)
2. I created a console RbacController in which I do all the necessary RBAC operations (creation, assignment, etc.).
3. I create a functional (unit?) test.
Here is the question: a unit test can drive data into the database, it has haveFixtures for this, but checking the route is a task for a functional test, I don’t understand what type my situation is?
Another question: how to pull the action of the console controller from the test? Well, that is, an analogue of the php yii rbac / init command
Another question: How to do
$I->amOnPage('...');
from users of certain roles? Well, that is, you need to check for certain routes from each role in turn. By the way, what routes to do, for all or just selectively?
Am I in the right direction at all? Is it done like this? Maybe someone has better ideas?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Entelis, 2017-09-14
@sensus

Without pretensions to the beauty of the code.
It is assumed that the original array is sorted by key, there are no gaps.

$arr = [
    11 => true, 
    12 => true, 
    15 => false, 
    16 => true, 
    17 => false,
    18 => false
];

reset($arr);
$key_from = key($arr);
$key_to = key($arr);
$last_value = array_values($arr)[0]; 

$result = [];
foreach ($arr as $key => $value) {
    if ($last_value == $value) {
        $key_to = $key;
    } else {
        $result[] = $key_from . ' - ' . $key_to . ' ' . (($last_value) ? 'true' : 'false');
        $key_from = $key;
        $key_to = $key;
        $last_value = $value;
    }
}
$result[] = $key_from . ' - ' . $key_to . ' ' . (($last_value) ? 'true' : 'false');


print_r($result);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question