1
0
forked from Georg/pyacl

Enhance test suite

Map input ACLs for setfacl with expected pyacl output to allow for
an easily expandable test matrix.

Signed-off-by: Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>
This commit is contained in:
Georg Pfuetzenreuter 2024-09-16 18:43:10 +02:00
parent 6f05367ae6
commit 10a3123305
Signed by untrusted user: Georg
GPG Key ID: 1ED2F138E7E6FF57
2 changed files with 76 additions and 32 deletions

View File

@ -14,14 +14,17 @@ from subprocess import run
import pytest import pytest
@pytest.fixture(scope='session') #@pytest.fixture(scope='session')
def sample_file(tmp_path_factory): @pytest.fixture
def sample_file(tmp_path_factory, aclin):
directory = tmp_path_factory.mktemp('sample_files') directory = tmp_path_factory.mktemp('sample_files')
file = directory / 'file_with_user_read_acl' file = directory / 'file_with_user_read_acl'
file.touch() file.touch()
assert not file.read_text() # file should exist assert not file.read_text() # file should exist
run(['setfacl', '-m', 'u:user:r', file], check=True) requested_acl = aclin
print(requested_acl)
run(['setfacl', '-m', requested_acl, file], check=True)
out = run(['getfacl', '-c', file], check=True, capture_output=True) out = run(['getfacl', '-c', file], check=True, capture_output=True)
assert 'user:user:r--' in out.stdout.decode() # file should have the ACL set assert requested_acl in out.stdout.decode() # file should have the ACL set
yield file yield file
rmtree(directory) rmtree(directory)

View File

@ -8,11 +8,14 @@ An English copy of the Licence is shipped in a file called LICENSE along with th
You may obtain copies of the Licence in any of the official languages at https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12. You may obtain copies of the Licence in any of the official languages at https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12.
""" """
from pytest import mark
from pyacl import acl from pyacl import acl
testdata = [
def test_parse_acl(sample_file): (
want = { 'user:user:r',
{
'user': { 'user': {
'user': { 'user': {
'read': True, 'read': True,
@ -41,6 +44,44 @@ def test_parse_acl(sample_file):
'execute': False, 'execute': False,
}, },
}, },
} },
),
(
'user:user:-w-',
{
'user': {
'user': {
'read': False,
'write': True,
'execute': False,
},
},
'group': {
None: {
'read': True,
'write': False,
'execute': False,
},
},
'mask': {
None: {
'read': True,
'write': True,
'execute': False,
},
},
'other': {
None: {
'read': True,
'write': False,
'execute': False,
},
},
},
),
]
@mark.parametrize('aclin, aclout', testdata)
def test_parse_acl(sample_file, aclin, aclout):
have = acl.parsefromfile(sample_file) have = acl.parsefromfile(sample_file)
assert want == have assert aclout == have