test: add more test scenarios for sharing

This commit is contained in:
KernelDeimos 2024-06-30 15:09:49 -04:00
parent 1429d6f57c
commit a0f4292072
2 changed files with 94 additions and 1 deletions

View File

@ -185,6 +185,47 @@ class ShareTestService extends use.Service {
return { message: 'expected error, got none' };
}
}
async ['__scenario:grant'] (
{ actor, user },
{ to, permission },
) {
const svc_permission = this.services.get('permission');
await svc_permission.grant_user_user_permission(
actor, to, permission, {}, {},
);
}
async ['__scenario:assert-access'] (
{ actor, user },
{ path, level }
) {
const svc_fs = this.services.get('filesystem');
const svc_acl = this.services.get('acl');
const node = await svc_fs.node(new NodePathSelector(path));
const has_read = await svc_acl.check(actor, node, 'read');
const has_write = await svc_acl.check(actor, node, 'write');
if ( level !== 'write' && level !== 'read' ) {
return {
message: 'unexpected value for "level" parameter'
};
}
if ( level === 'read' && has_write ) {
return {
message: 'expected read-only but actor can write'
};
}
if ( level === 'read' && !has_read ) {
return {
message: 'expected read access but no read access'
};
}
if ( level === 'write' && (!has_write || !has_read) ) {
return {
message: 'expected write access but no write access'
};
}
}
}
module.exports = {

View File

@ -19,5 +19,57 @@ module.exports = [
}
},
]
}
},
{
sequence: [
{
title: 'Stan creates a file',
call: 'create-example-file',
as: 'testuser_stan',
with: {
name: 'example.txt',
contents: 'secret file',
}
},
{
title: 'Stan grants permission to Eric',
call: 'grant',
as: 'testuser_stan',
with: {
to: 'testuser_eric',
permission: 'fs:/testuser_stan/Desktop/example.txt:read'
}
},
{
title: 'Eric tries to access it',
call: 'assert-access',
as: 'testuser_eric',
with: {
path: '/testuser_stan/Desktop/example.txt',
level: 'read'
}
},
]
},
{
sequence: [
{
title: 'Stan grants Kyle\'s file to Eric',
call: 'grant',
as: 'testuser_stan',
with: {
to: 'testuser_eric',
permission: 'fs:/testuser_kyle/Desktop/example.txt:read'
}
},
{
title: 'Eric tries to access it',
call: 'assert-no-access',
as: 'testuser_eric',
with: {
path: '/testuser_kyle/Desktop/example.txt',
}
},
]
},
];