mirror of
https://github.com/nextcloud/server.git
synced 2026-06-11 01:30:50 -04:00
Merge pull request #47662 from nextcloud/fix/notification/validate-rich-object-key-value-types
This commit is contained in:
commit
979cc8712c
7 changed files with 43 additions and 10 deletions
|
|
@ -126,9 +126,9 @@ class Notifier implements INotifier {
|
|||
[
|
||||
'node' => [
|
||||
'type' => 'file',
|
||||
'id' => $node->getId(),
|
||||
'id' => (string)$node->getId(),
|
||||
'name' => $node->getName(),
|
||||
'path' => $path,
|
||||
'path' => (string)$path,
|
||||
],
|
||||
]
|
||||
);
|
||||
|
|
|
|||
|
|
@ -259,7 +259,7 @@ class Event implements IEvent {
|
|||
}
|
||||
|
||||
/**
|
||||
* @return array[]
|
||||
* @return array<string, array<string, string>>
|
||||
* @since 11.0.0
|
||||
*/
|
||||
public function getRichSubjectParameters(): array {
|
||||
|
|
@ -335,7 +335,7 @@ class Event implements IEvent {
|
|||
}
|
||||
|
||||
/**
|
||||
* @return array[]
|
||||
* @return array<string, array<string, string>>
|
||||
* @since 11.0.0
|
||||
*/
|
||||
public function getRichMessageParameters(): array {
|
||||
|
|
|
|||
|
|
@ -78,6 +78,15 @@ class Validator implements IValidator {
|
|||
if (!empty($missingKeys)) {
|
||||
throw new InvalidObjectExeption('Object is invalid, missing keys:'.json_encode($missingKeys));
|
||||
}
|
||||
|
||||
foreach ($parameter as $key => $value) {
|
||||
if (!is_string($key)) {
|
||||
throw new InvalidObjectExeption('Object is invalid, key ' . $key . ' is not a string');
|
||||
}
|
||||
if (!is_string($value)) {
|
||||
throw new InvalidObjectExeption('Object is invalid, value ' . $value . ' is not a string');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ interface IEvent {
|
|||
* See https://github.com/nextcloud/server/issues/1706 for more information.
|
||||
*
|
||||
* @param string $subject
|
||||
* @param array $parameters
|
||||
* @param array<string, array<string, string>> $parameters
|
||||
* @return $this
|
||||
* @throws InvalidValueException if the subject or parameters are invalid
|
||||
* @since 11.0.0
|
||||
|
|
@ -136,7 +136,7 @@ interface IEvent {
|
|||
public function getRichSubject(): string;
|
||||
|
||||
/**
|
||||
* @return array[]
|
||||
* @return array<string, array<string, string>>
|
||||
* @since 11.0.0
|
||||
*/
|
||||
public function getRichSubjectParameters(): array;
|
||||
|
|
@ -187,7 +187,7 @@ interface IEvent {
|
|||
* See https://github.com/nextcloud/server/issues/1706 for more information.
|
||||
*
|
||||
* @param string $message
|
||||
* @param array $parameters
|
||||
* @param array<string, array<string, string>> $parameters
|
||||
* @return $this
|
||||
* @throws \InvalidArgumentException if the message or parameters are invalid
|
||||
* @since 11.0.0
|
||||
|
|
@ -202,7 +202,7 @@ interface IEvent {
|
|||
public function getRichMessage(): string;
|
||||
|
||||
/**
|
||||
* @return array[]
|
||||
* @return array<string, array<string, string>>
|
||||
* @since 11.0.0
|
||||
*/
|
||||
public function getRichMessageParameters(): array;
|
||||
|
|
|
|||
|
|
@ -137,7 +137,7 @@ interface INotification {
|
|||
* See https://github.com/nextcloud/server/issues/1706 for more information.
|
||||
*
|
||||
* @param string $subject
|
||||
* @param array $parameters
|
||||
* @param array<string, array<string, string>> $parameters
|
||||
* @return $this
|
||||
* @throws InvalidValueException if the subject or parameters are invalid
|
||||
* @since 11.0.0
|
||||
|
|
@ -213,7 +213,7 @@ interface INotification {
|
|||
* See https://github.com/nextcloud/server/issues/1706 for more information.
|
||||
*
|
||||
* @param string $message
|
||||
* @param array $parameters
|
||||
* @param array<string, array<string, string>> $parameters
|
||||
* @return $this
|
||||
* @throws InvalidValueException if the message or parameters are invalid
|
||||
* @since 11.0.0
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ class SetupResult implements \JsonSerializable {
|
|||
/**
|
||||
* @brief Private constructor, use success()/info()/warning()/error() instead
|
||||
* @param self::SUCCESS|self::INFO|self::WARNING|self::ERROR $severity
|
||||
* @param array<string, array<string, string>> $descriptionParameters
|
||||
* @throws \OCP\RichObjectStrings\InvalidObjectExeption
|
||||
* @since 28.0.0
|
||||
* @since 28.0.2 Optional parameter ?array $descriptionParameters
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ namespace Test\RichObjectStrings;
|
|||
|
||||
use OC\RichObjectStrings\Validator;
|
||||
use OCP\RichObjectStrings\Definitions;
|
||||
use OCP\RichObjectStrings\InvalidObjectExeption;
|
||||
use Test\TestCase;
|
||||
|
||||
class ValidatorTest extends TestCase {
|
||||
|
|
@ -33,5 +34,27 @@ class ValidatorTest extends TestCase {
|
|||
],
|
||||
]);
|
||||
$this->addToAssertionCount(2);
|
||||
|
||||
$this->expectException(InvalidObjectExeption::class);
|
||||
|
||||
$this->expectExceptionMessage('Object is invalid, value 123 is not a string');
|
||||
$v->validate('test {string1} test.', [
|
||||
'string1' => [
|
||||
'type' => 'user',
|
||||
'id' => 'johndoe',
|
||||
'name' => 'John Doe',
|
||||
'key' => 123,
|
||||
],
|
||||
]);
|
||||
|
||||
$this->expectExceptionMessage('Object is invalid, key 456 is not a string');
|
||||
$v->validate('test {string1} test.', [
|
||||
'string1' => [
|
||||
'type' => 'user',
|
||||
'id' => 'johndoe',
|
||||
'name' => 'John Doe',
|
||||
456 => 'value',
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue