diff --git a/src/Database/Helpers/Permission.php b/src/Database/Helpers/Permission.php index 82113223b..df0f1a5c0 100644 --- a/src/Database/Helpers/Permission.php +++ b/src/Database/Helpers/Permission.php @@ -89,6 +89,10 @@ public static function parse(string $permission): self } $permission = $permissionParts[0]; + + if (!\in_array($permission, array_merge(Database::PERMISSIONS, [Database::PERMISSION_WRITE]))) { + throw new DatabaseException('Invalid permission type: "' . $permission . '".'); + } $fullRole = \str_replace('")', '', $permissionParts[1]); $roleParts = \explode(':', $fullRole); $role = $roleParts[0]; diff --git a/tests/Database/PermissionTest.php b/tests/Database/PermissionTest.php index 2e332f1b3..a436d743a 100644 --- a/tests/Database/PermissionTest.php +++ b/tests/Database/PermissionTest.php @@ -260,20 +260,33 @@ public function testInputFromRoles(): void public function testInvalidFormats(): void { - $this->expectException(\Exception::class); - Permission::parse('read'); - - $this->expectException(\Exception::class); - Permission::parse('read(("any")'); - - $this->expectException(\Exception::class); - Permission::parse('read("users/un/verified")'); - - $this->expectException(\Exception::class); - Permission::parse('read("users/")'); - - $this->expectException(\Exception::class); - Permission::parse('read("label:alphanumeric-only")'); + try { + Permission::parse('read'); + $this->fail('Failed to throw Exception'); + } catch (\Exception $e) { + $this->assertEquals('Invalid permission string format: "read".', $e->getMessage()); + } + + try { + Permission::parse('read(("any")'); + $this->fail('Failed to throw Exception'); + } catch (\Exception $e) { + $this->assertEquals('Invalid permission type: "read(".', $e->getMessage()); + } + + try { + Permission::parse('read("users/un/verified")'); + $this->fail('Failed to throw Exception'); + } catch (\Exception $e) { + $this->assertEquals('Only one dimension can be provided', $e->getMessage()); + } + + try { + Permission::parse('read("users/")'); + $this->fail('Failed to throw Exception'); + } catch (\Exception $e) { + $this->assertEquals('Dimension must not be empty', $e->getMessage()); + } } /**