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:
parent
6f05367ae6
commit
10a3123305
@ -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)
|
||||||
|
@ -8,39 +8,80 @@ 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': {
|
||||||
'read': True,
|
'user': {
|
||||||
'write': False,
|
'read': True,
|
||||||
'execute': False,
|
'write': False,
|
||||||
|
'execute': False,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'group': {
|
||||||
|
None: {
|
||||||
|
'read': True,
|
||||||
|
'write': False,
|
||||||
|
'execute': False,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'mask': {
|
||||||
|
None: {
|
||||||
|
'read': True,
|
||||||
|
'write': False,
|
||||||
|
'execute': False,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'other': {
|
||||||
|
None: {
|
||||||
|
'read': True,
|
||||||
|
'write': False,
|
||||||
|
'execute': False,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
'group': {
|
),
|
||||||
None: {
|
(
|
||||||
'read': True,
|
'user:user:-w-',
|
||||||
'write': False,
|
{
|
||||||
'execute': False,
|
'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,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
'mask': {
|
),
|
||||||
None: {
|
]
|
||||||
'read': True,
|
|
||||||
'write': False,
|
@mark.parametrize('aclin, aclout', testdata)
|
||||||
'execute': False,
|
def test_parse_acl(sample_file, aclin, aclout):
|
||||||
},
|
|
||||||
},
|
|
||||||
'other': {
|
|
||||||
None: {
|
|
||||||
'read': True,
|
|
||||||
'write': False,
|
|
||||||
'execute': False,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
have = acl.parsefromfile(sample_file)
|
have = acl.parsefromfile(sample_file)
|
||||||
assert want == have
|
assert aclout == have
|
||||||
|
Loading…
Reference in New Issue
Block a user