mirror of
https://github.com/HeyPuter/puter
synced 2024-11-14 14:03:42 +00:00
test: add more test scenarios for sharing
This commit is contained in:
parent
1429d6f57c
commit
a0f4292072
@ -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 = {
|
||||
|
@ -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',
|
||||
}
|
||||
},
|
||||
]
|
||||
},
|
||||
];
|
||||
|
Loading…
Reference in New Issue
Block a user