diff options
| author | Simon Rettberg | 2025-11-26 10:46:51 +0100 |
|---|---|---|
| committer | Simon Rettberg | 2025-12-12 15:16:59 +0100 |
| commit | 7c173411785f959d250d3dfbd7d4cfcb0e20f0e0 (patch) | |
| tree | 242157791a76afb7af23ec2cd3d22b599e54ce9d /modules-available | |
| parent | [exams] Fix incorrect count() clause (diff) | |
| download | slx-admin-7c173411785f959d250d3dfbd7d4cfcb0e20f0e0.tar.gz slx-admin-7c173411785f959d250d3dfbd7d4cfcb0e20f0e0.tar.xz slx-admin-7c173411785f959d250d3dfbd7d4cfcb0e20f0e0.zip | |
Add tests using PHPUnit
Tests generated by Junie AI. Might not have the best possible quality
but at least we got something, and if it turns out to be complete
rubbish, we can just throw it out again without any issues, as this is
independent of the actual code base.
Diffstat (limited to 'modules-available')
7 files changed, 27 insertions, 12 deletions
diff --git a/modules-available/exams/page.inc.php b/modules-available/exams/page.inc.php index 42294990..f42711a2 100644 --- a/modules-available/exams/page.inc.php +++ b/modules-available/exams/page.inc.php @@ -79,13 +79,14 @@ class Page_Exams extends Page protected function readLectures() { $tmp = Database::simpleQuery( - "SELECT lectureid, Group_Concat(locationid) as lids, islocationprivate, displayname, starttime, endtime, isenabled, firstname, lastname, email " . - "FROM sat.lecture " . - "INNER JOIN sat.user ON (user.userid = lecture.ownerid) " . - "NATURAL LEFT JOIN sat.lecture_x_location " . - "WHERE isexam <> 0 AND starttime < :rangeMax AND endtime > :rangeMin " . - "GROUP BY lectureid " . - "ORDER BY starttime ASC, displayname ASC", + "SELECT lectureid, Group_Concat(locationid) as lids, islocationprivate, + displayname, starttime, endtime, isenabled, firstname, lastname, email + FROM sat.lecture sl + INNER JOIN sat.user su ON (su.userid = sl.ownerid) + NATURAL LEFT JOIN sat.lecture_x_location + WHERE isexam <> 0 AND starttime < :rangeMax AND endtime > :rangeMin + GROUP BY lectureid + ORDER BY starttime ASC, displayname ASC", ['rangeMax' => $this->rangeMax, 'rangeMin' => $this->rangeMin]); foreach ($tmp as $lecture) { $this->lectures[] = $lecture; diff --git a/modules-available/permissionmanager/inc/getpermissiondata.inc.php b/modules-available/permissionmanager/inc/getpermissiondata.inc.php index 83752a05..046e6c0e 100644 --- a/modules-available/permissionmanager/inc/getpermissiondata.inc.php +++ b/modules-available/permissionmanager/inc/getpermissiondata.inc.php @@ -47,7 +47,7 @@ class GetPermissionData $res = Database::simpleQuery("SELECT role.roleid AS roleid, rolename, GROUP_CONCAT(COALESCE(locationid, 0)) AS locationids FROM role INNER JOIN role_x_location ON (role.roleid = role_x_location.roleid) - GROUP BY roleid, rolename ORDER BY rolename ASC"); + GROUP BY role.roleid, rolename ORDER BY rolename ASC"); $locations = Location::getLocations(0, 0, true, true); $tree = Location::getLocationsAssoc(); $locations[0]['locationname'] = Dictionary::translate('global', true); diff --git a/modules-available/permissionmanager/inc/permissionutil.inc.php b/modules-available/permissionmanager/inc/permissionutil.inc.php index 2dcd4d3c..862de089 100644 --- a/modules-available/permissionmanager/inc/permissionutil.inc.php +++ b/modules-available/permissionmanager/inc/permissionutil.inc.php @@ -45,6 +45,11 @@ class PermissionUtil /** * Check if the user has the given permission (for the given location). + * Permissions are hierarchical. For example if there is a permission + * called foo.bar.baz, then having the permission foo.* or foo.bar.* + * would match, as well as the obvious exact match. + * Some permissions can apply only to a specific location, while others + * are independent of a location. * * @param int $userid userid to check * @param string $permissionid permissionid to check diff --git a/modules-available/rebootcontrol/api.inc.php b/modules-available/rebootcontrol/api.inc.php index b3e9e976..c230b4c5 100644 --- a/modules-available/rebootcontrol/api.inc.php +++ b/modules-available/rebootcontrol/api.inc.php @@ -4,6 +4,7 @@ if (Request::any('action') === 'rebuild' && isLocalExecution()) { if (Module::isAvailable('sysconfig')) { SSHKey::getPrivateKey($regen); if (!$regen) { + // Was not regenerated, in which case getPrivateKey() would've already called rebuildAllConfigs() ConfigTgz::rebuildAllConfigs(); } echo "OK"; diff --git a/modules-available/rebootcontrol/inc/rebootcontrol.inc.php b/modules-available/rebootcontrol/inc/rebootcontrol.inc.php index 480d2fe9..ec94db63 100644 --- a/modules-available/rebootcontrol/inc/rebootcontrol.inc.php +++ b/modules-available/rebootcontrol/inc/rebootcontrol.inc.php @@ -89,7 +89,7 @@ class RebootControl } /** - * @param int[]|null $locations filter by these locations + * @param int[]|null $locations filter by these locations. Any matching location is enough. * @param ?string $id only with this TaskID * @return array|false list of active tasks for reboots/shutdowns. */ @@ -106,8 +106,8 @@ class RebootControl Property::removeFromListByKey(RebootControl::KEY_TASKLIST, $subkey); continue; } - if (is_array($locations) && is_array($p['locations']) && array_diff($p['locations'], $locations) !== []) - continue; // Not allowed + if (is_array($locations) && is_array($p['locations']) && empty(array_intersect($p['locations'], $locations))) + continue; // No overlap with requested locations if ($id !== null) { if ($p['id'] === $id) return $p; diff --git a/modules-available/rebootcontrol/inc/sshkey.inc.php b/modules-available/rebootcontrol/inc/sshkey.inc.php index e0954415..ba8e3b72 100644 --- a/modules-available/rebootcontrol/inc/sshkey.inc.php +++ b/modules-available/rebootcontrol/inc/sshkey.inc.php @@ -3,15 +3,22 @@ class SSHKey { + /** + * Retrieves the private key from storage or generates a new one if it does not exist. + * + * @param bool|null &$regen A reference parameter that indicates whether a new private + * key was generated (true if regenerated, false otherwise). + * @return string|null Returns the private key as a string if successful, or null if the key could not be generated. + */ public static function getPrivateKey(?bool &$regen = false): ?string { + $regen = false; $privKey = Property::get("rebootcontrol-private-key"); if (!$privKey) { $rsaKey = openssl_pkey_new([ 'private_key_bits' => 2048, 'private_key_type' => OPENSSL_KEYTYPE_RSA]); if (!openssl_pkey_export( openssl_pkey_get_private($rsaKey), $privKey)) { - $regen = false; return null; } Property::set("rebootcontrol-private-key", $privKey); diff --git a/modules-available/rebootcontrol/pages/task.inc.php b/modules-available/rebootcontrol/pages/task.inc.php index 7db2a90b..67a747c5 100644 --- a/modules-available/rebootcontrol/pages/task.inc.php +++ b/modules-available/rebootcontrol/pages/task.inc.php @@ -75,6 +75,7 @@ class SubPage } if (!empty($job['locations'])) { $allowedLocs = User::getAllowedLocations("action.$perm"); + // Need to have permission for all affected locations to see job details if (!in_array(0, $allowedLocs) && array_diff($job['locations'], $allowedLocs) !== []) { Message::addError('main.no-permission'); return; |
