mirror of
https://git.proxmox.com/git/pve-access-control
synced 2025-08-03 08:21:10 +00:00

it was useful for test-cases to verify the behaviour when pools where introduced, but it is not used anywhere else in the code base and those tests can also just check on permission-level. Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
54 lines
1.3 KiB
Perl
Executable File
54 lines
1.3 KiB
Perl
Executable File
#!/usr/bin/perl -w
|
|
|
|
use strict;
|
|
use PVE::Tools;
|
|
use PVE::AccessControl;
|
|
use PVE::RPCEnvironment;
|
|
use Getopt::Long;
|
|
|
|
my $rpcenv = PVE::RPCEnvironment->init('cli');
|
|
|
|
my $cfgfn = "test7.cfg";
|
|
$rpcenv->init_request(userconfig => $cfgfn);
|
|
|
|
sub check_roles {
|
|
my ($user, $path, $expected_result) = @_;
|
|
|
|
my @ra = PVE::AccessControl::roles($rpcenv->{user_cfg}, $user, $path);
|
|
my $res = join(',', sort @ra);
|
|
|
|
die "unexpected result\nneed '${expected_result}'\ngot '$res'\n"
|
|
if $res ne $expected_result;
|
|
|
|
print "ROLES:$path:$user:$res\n";
|
|
}
|
|
|
|
sub check_permissions {
|
|
my ($user, $path, $expected_result) = @_;
|
|
|
|
my $perm = $rpcenv->permissions($user, $path);
|
|
my $res = join(',', sort keys %$perm);
|
|
|
|
die "unexpected result\nneed '${expected_result}'\ngot '$res'\n"
|
|
if $res ne $expected_result;
|
|
|
|
$perm = $rpcenv->permissions($user, $path);
|
|
$res = join(',', sort keys %$perm);
|
|
die "unexpected result (compiled)\nneed '${expected_result}'\ngot '$res'\n"
|
|
if $res ne $expected_result;
|
|
|
|
print "PERM:$path:$user:$res\n";
|
|
}
|
|
|
|
check_roles('User1@pve', '/vms', 'Role1');
|
|
check_roles('User1@pve', '/vms/200', 'Role1');
|
|
|
|
# no pool
|
|
check_roles('User1@pve', '/vms/100', 'Role1');
|
|
# with pool
|
|
check_permissions('User1@pve', '/vms/100', '');
|
|
|
|
print "all tests passed\n";
|
|
|
|
exit (0);
|