-
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added tests for Python Bindings (#133)
* feat: Added CI for python bindings Signed-off-by: Yash Pandey (YP) <yash.btech.cs19@iiitranchi.ac.in> * fix: Pybind CI Signed-off-by: Yash Pandey (YP) <yash.btech.cs19@iiitranchi.ac.in>
- Loading branch information
1 parent
6d8baae
commit 3332324
Showing
10 changed files
with
254 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Copyright 2021 The casbin Authors. All Rights Reserved. | ||
|
||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
|
||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
name: Python Bindings Test | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
benchmark: | ||
name: Python Bindings Test | ||
runs-on: macos-latest | ||
steps: | ||
- name: Checkout | ||
id: checkout | ||
uses: actions/checkout@v2 | ||
- name: Configuring CMake files | ||
id: building-files | ||
run: | | ||
mkdir build && cd build && cmake .. -DCMAKE_BUILD_TYPE:STRING=Release | ||
- name: Building library | ||
id: building-lib | ||
run: | | ||
cd build && cmake --build . --config Release --target all -j 10 -- | ||
- name: Installing pycasbin | ||
id: installing-pycasbin | ||
run: | | ||
cd build && sudo cmake --build . --config Release --target install -j 10 -- | ||
- name: Run Tests | ||
id: run-tests | ||
run: | | ||
cd tests/python && python3 pycasbin_test_suite.py | ||
- name: Cleanup | ||
id: clean-up | ||
run: | | ||
rm -r build | ||
rm tests/python/pycasbin.so |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -355,6 +355,7 @@ MigrationBackup/ | |
*.iml | ||
.vscode | ||
.DS_Store | ||
*.so | ||
|
||
# CMake work directory | ||
cmake-build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Copyright 2021 The casbin Authors. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
relative_path = '../../' | ||
basic_model_path = relative_path + 'examples/basic_model.conf' | ||
basic_policy_path = relative_path + 'examples/basic_policy.csv' | ||
rbac_model_path = relative_path + 'examples/rbac_model.conf' | ||
rbac_policy_path = relative_path + 'examples/rbac_policy.csv' | ||
rbac_with_resource_roles_model_path = relative_path + 'examples/rbac_with_resource_roles_model.conf' | ||
rbac_with_resource_roles_policy_path = relative_path + 'examples/rbac_with_resource_roles_policy.csv' | ||
rbac_with_domains_model_path = relative_path + 'examples/rbac_with_domains_model.conf' | ||
rbac_with_domains_policy_path = relative_path + 'examples/rbac_with_domains_policy.csv' | ||
keymatch_model_path = relative_path + 'examples/keymatch_model.conf' | ||
keymatch_policy_path = relative_path + 'examples/keymatch_policy.csv' | ||
rbac_with_deny_model_path = relative_path + 'examples/rbac_with_deny_model.conf' | ||
rbac_with_deny_policy_path = relative_path + 'examples/rbac_with_deny_policy.csv' | ||
priority_model_path = relative_path + 'examples/priority_model.conf' | ||
priority_policy_path = relative_path + 'examples/priority_policy.csv' | ||
basic_model_without_spaces_path = relative_path + 'examples/basic_model_without_spaces.conf' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Copyright 2021 The casbin Authors. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import unittest | ||
import sys | ||
import os | ||
import pycasbin | ||
import test_enforcer | ||
|
||
def suite(): | ||
|
||
# top level directory cached on loader instance | ||
suite = unittest.TestSuite() | ||
loader = unittest.TestLoader() | ||
|
||
suite.addTest(loader.loadTestsFromModule(test_enforcer)) | ||
return suite | ||
|
||
|
||
if __name__ == '__main__': | ||
runner = unittest.TextTestRunner(verbosity=2) | ||
test_suite = suite() | ||
result = runner.run(test_suite) | ||
if result.wasSuccessful() == False: | ||
sys.exit(1) | ||
sys.exit(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Copyright 2021 The casbin Authors. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import pycasbin as casbin | ||
from config_path import * | ||
import unittest | ||
|
||
class TestEnforcer(unittest.TestCase): | ||
def setUp(self): | ||
self.initEnforcer(rbac_with_domains_model_path, rbac_with_domains_policy_path) | ||
|
||
def initEnforcer(self, model, policy): | ||
self.current_model = model | ||
self.current_policy = policy | ||
self.e = casbin.Enforcer(self.current_model, self.current_policy) | ||
|
||
def tearDown(self): | ||
self.e = None | ||
|
||
def test_FourParams(self): | ||
self.initEnforcer(rbac_with_domains_model_path, rbac_with_domains_policy_path) | ||
|
||
self.assertEqual(self.e.Enforce(['alice', 'domain1', 'data1', 'read']), True) | ||
self.assertEqual(self.e.Enforce(['alice', 'domain1', 'data1', 'write']), True) | ||
self.assertEqual(self.e.Enforce(['alice', 'domain1', 'data2', 'read']), False) | ||
self.assertEqual(self.e.Enforce(['alice', 'domain1', 'data2', 'write']), False) | ||
self.assertEqual(self.e.Enforce(['bob', 'domain2', 'data1', 'read']), False) | ||
self.assertEqual(self.e.Enforce(['bob', 'domain2', 'data1', 'write']), False) | ||
self.assertEqual(self.e.Enforce(['bob', 'domain2', 'data2', 'read']), True) | ||
self.assertEqual(self.e.Enforce(['bob', 'domain2', 'data2', 'write']), True) | ||
|
||
def test_ThreeParams(self): | ||
self.initEnforcer(basic_model_without_spaces_path, basic_policy_path) | ||
|
||
self.assertEqual(self.e.Enforce([ 'alice', 'data1', 'read' ]), True) | ||
self.assertEqual(self.e.Enforce([ 'alice', 'data1', 'write' ]), False) | ||
self.assertEqual(self.e.Enforce([ 'alice', 'data2', 'read' ]), False) | ||
self.assertEqual(self.e.Enforce([ 'alice', 'data2', 'write' ]), False) | ||
self.assertEqual(self.e.Enforce([ 'bob', 'data1', 'read' ]), False) | ||
self.assertEqual(self.e.Enforce([ 'bob', 'data1', 'write' ]), False) | ||
self.assertEqual(self.e.Enforce([ 'bob', 'data2', 'read' ]), False) | ||
self.assertEqual(self.e.Enforce([ 'bob', 'data2', 'write' ]), True) | ||
|
||
def test_VectorParams(self): | ||
self.initEnforcer(basic_model_without_spaces_path, basic_policy_path) | ||
|
||
self.assertEqual(self.e.Enforce([ 'alice', 'data1', 'read' ]), True) | ||
self.assertEqual(self.e.Enforce([ 'alice', 'data1', 'write' ]), False) | ||
self.assertEqual(self.e.Enforce([ 'alice', 'data2', 'read' ]), False) | ||
self.assertEqual(self.e.Enforce([ 'alice', 'data2', 'write' ]), False) | ||
self.assertEqual(self.e.Enforce([ 'bob', 'data1', 'read' ]), False) | ||
self.assertEqual(self.e.Enforce([ 'bob', 'data1', 'write' ]), False) | ||
self.assertEqual(self.e.Enforce([ 'bob', 'data2', 'read' ]), False) | ||
self.assertEqual(self.e.Enforce([ 'bob', 'data2', 'write' ]), True) |