r032: fix share capacity and add native scoped administration
This commit is contained in:
1 parent
50c4ad2ed0
commit
6527281854
19 files changed
+754
-23
No files matched your search
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
require_once __DIR__.'/unraid-admin-helper.php';
|
||||
require_once __DIR__.'/unraid-mcp-status-helper.php';
|
||||
$count=0;
|
||||
function check_admin(string $name,bool $condition): void {global $count;if(!$condition)throw new RuntimeException('FAIL: '.$name);$count++;echo "PASS: $name\n";}
|
||||
function rejects_admin(string $name,callable $f): void {try{$f();}catch(Throwable){check_admin($name,true);return;}check_admin($name,false);}
|
||||
$root=sys_get_temp_dir().'/mua-fixtures-'.bin2hex(random_bytes(8));
|
||||
$GLOBALS['mua_test_root']=$root;
|
||||
foreach(['/var/local/emhttp','/boot/config/shares','/boot/config/plugins/dockerMan/templates-user','/mnt/nvme-test','/mnt/user','/var/lock'] as $dir)mkdir($root.$dir,0700,true);
|
||||
try {
|
||||
file_put_contents($root.'/var/local/emhttp/users.ini',"[root]\nidx=7\npassword=never-output\n[michael]\nidx=3\n[sarah]\nidx=8\n");
|
||||
check_admin('user discovery excludes credentials and root',json_encode(mua_users())==='[{"name":"michael","index":3},{"name":"sarah","index":8}]');
|
||||
rejects_admin('protected targets rejected',fn()=>mua_name('OpenVPN-KIT'));
|
||||
rejects_admin('traversal rejected',fn()=>mua_name('../other'));
|
||||
rejects_admin('unknown SMB user rejected',fn()=>mua_private_spec(['action'=>'create','name'=>'test','pool'=>'nvme-test','access'=>['nobody'=>'read-write']]));
|
||||
$spec=mua_private_spec(['action'=>'create','name'=>'test','pool'=>'nvme-test','access'=>['michael'=>'read-write','sarah'=>'read-only'],'description'=>'Test']);
|
||||
$plan=mua_plan('share',$spec);
|
||||
$queries=[];
|
||||
$GLOBALS['mua_test_run']=function(array $argv)use(&$queries,$root){
|
||||
if(basename($argv[0])==='testparm')return "[test]\nvalid users = michael sarah\nwrite list = michael\nread list = sarah";
|
||||
if(basename($argv[0])!=='emcmd')throw new RuntimeException('Unexpected test command');
|
||||
parse_str($argv[1],$q);$queries[]=$argv[1];
|
||||
if(isset($q['cmdEditShare'])&&$q['cmdEditShare']==='Add Share') {mkdir($root.'/mnt/user/test');file_put_contents(mua_cfg('test'),"shareExport=\"-\"\nshareSecurity=\"public\"\n");}
|
||||
if(isset($q['changeShareSecurity']))file_put_contents(mua_cfg('test'),"shareExport=\"".$q['shareExport']."\"\nshareSecurity=\"private\"\nshareReadList=\"sarah\"\nshareWriteList=\"michael\"\n");
|
||||
return '';
|
||||
};
|
||||
$result=mua_apply_plan($plan);
|
||||
check_admin('share creation verified without real host changes',$result['ok']===true);
|
||||
$joined=implode("\n",$queries);
|
||||
check_admin('current indices used including nonzero root index',str_contains($joined,'userAccess.3=read-write')&&str_contains($joined,'userAccess.8=read-only')&&str_contains($joined,'userAccess.7=no-access'));
|
||||
file_put_contents(mua_cfg('test'),str_replace('shareExport="e"','shareExport="-"',file_get_contents(mua_cfg('test'))));
|
||||
$permissions=mua_plan('share',['action'=>'permissions','name'=>'test','access'=>['michael'=>'read-write','sarah'=>'read-only']]);
|
||||
check_admin('permissions preview preserves disabled export',$permissions['spec']['export']==='-');
|
||||
mua_apply_plan($permissions);
|
||||
check_admin('permissions change does not enable disabled SMB',str_contains(file_get_contents(mua_cfg('test')),'shareExport="-"'));
|
||||
rejects_admin('stale create preview refused',fn()=>mua_apply_plan($plan));
|
||||
file_put_contents($root.'/mnt/user/test/keep.txt','must remain');
|
||||
rejects_admin('nonempty delete refused',fn()=>mua_plan('share',['action'=>'remove','name'=>'test']));
|
||||
check_admin('nonempty share data untouched',file_get_contents($root.'/mnt/user/test/keep.txt')==='must remain');
|
||||
unlink($root.'/mnt/user/test/keep.txt');
|
||||
$remove=mua_plan('share',['action'=>'remove','name'=>'test']);
|
||||
file_put_contents(mua_cfg('test'),"changed=1\n");
|
||||
rejects_admin('changed config invalidates removal preview',fn()=>mua_apply_plan($remove));
|
||||
$row=share_entry(['name'=>'appdata','size'=>'0','free'=>'5116038016','used'=>'2564191488'],true);
|
||||
check_admin('share free matches exact independent df bytes',$row['free_bytes']===5238822928384);
|
||||
check_admin('share backing used matches df not dataset size',$row['filesystem_used_bytes']===2625732083712);
|
||||
check_admin('unknown share size and percentage are null',$row['share_size_bytes']===null&&$row['used_percent']===null&&$row['used_bytes']===null);
|
||||
check_admin('nonzero ambiguous size is not misreported as share contents',share_entry(['size'=>'123','free'=>'100','used'=>'20'],false)['share_size_bytes']===null);
|
||||
$missing=share_entry([],false);check_admin('missing capacity is unknown not zero',$missing['free_bytes']===null&&$missing['filesystem_size_bytes']===null);
|
||||
$d=mua_docker_spec(['action'=>'create','name'=>'native-test','image'=>'traefik/whoami:v1.11','ports'=>[['host_port'=>18766,'container_port'=>80]]]);
|
||||
$xml=mua_template_xml($d);$dom=simplexml_load_string($xml);
|
||||
check_admin('native XML v2 with empty update URL',(string)$dom['version']==='2'&&(string)$dom->TemplateURL==='');
|
||||
check_admin('loopback binding and no manual managed label',str_contains($xml,'127.0.0.1:18766')&&!str_contains($xml,'net.unraid.docker.managed'));
|
||||
check_admin('unprivileged template without mounts',(string)$dom->Privileged==='false'&&count($dom->xpath('//Config[@Type="Path"]'))===0);
|
||||
rejects_admin('image shell injection refused',fn()=>mua_docker_spec(['action'=>'create','name'=>'test','image'=>'alpine;touch /bad']));
|
||||
rejects_admin('duplicate host port refused',fn()=>mua_docker_spec(['action'=>'create','name'=>'test','image'=>'alpine:3','ports'=>[['host_port'=>18766,'container_port'=>80],['host_port'=>18766,'container_port'=>81]]]));
|
||||
rejects_admin('invalid resources refused',fn()=>mua_docker_spec(['action'=>'create','name'=>'test','image'=>'alpine:3','memory_mb'=>0]));
|
||||
echo "TOTAL: $count checks\n";
|
||||
} finally {
|
||||
$it=new RecursiveIteratorIterator(new RecursiveDirectoryIterator($root,FilesystemIterator::SKIP_DOTS),RecursiveIteratorIterator::CHILD_FIRST);
|
||||
foreach($it as $f){if($f->isDir())rmdir($f->getPathname());else unlink($f->getPathname());}rmdir($root);
|
||||
}
|
||||
Reference in new issue
Block a user