Skip to content

Commit

Permalink
fix: Amend some variables of savePolicy method
Browse files Browse the repository at this point in the history
  • Loading branch information
basakest committed Aug 25, 2021
1 parent 9590645 commit d5f1e47
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
12 changes: 6 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ public function loadPolicy($model): void

public function savePolicy($model): void
{
foreach ($model->model['p'] as $ptype => $ast) {
foreach ($model['p'] as $ptype => $ast) {
foreach ($ast->policy as $rule) {
$this->savePolicyLine($ptype, $rule);
}
}

foreach ($model->model['g'] as $ptype => $ast) {
foreach ($model['g'] as $ptype => $ast) {
foreach ($ast->policy as $rule) {
$this->savePolicyLine($ptype, $rule);
}
Expand Down
14 changes: 14 additions & 0 deletions tests/DatabaseAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,20 @@ public function testAddPolicies()
$this->assertEquals($policies, $e->getPolicy());
}

public function testSavePolicy()
{
$e = $this->getEnforcer();
$this->assertFalse($e->enforce('alice', 'data4', 'read'));

$model = $e->getModel();
$model->clearPolicy();
$model->addPolicy('p', 'p', ['alice', 'data4', 'read']);

$adapter = $e->getAdapter();
$adapter->savePolicy($model);
$this->assertTrue($e->enforce('alice', 'data4', 'read'));
}

public function testRemovePolicy()
{
$e = $this->getEnforcer();
Expand Down
3 changes: 3 additions & 0 deletions tests/casbin-model.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ r = sub, obj, act
[policy_definition]
p = sub, obj, act

[role_definition]
g = _, _

[policy_effect]
e = some(where (p.eft == allow))

Expand Down

0 comments on commit d5f1e47

Please sign in to comment.