|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/** |
| 6 | + * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors |
| 7 | + * SPDX-License-Identifier: AGPL-3.0-or-later |
| 8 | + */ |
| 9 | + |
| 10 | +namespace OCA\AppAPI\Tests\php\Db; |
| 11 | + |
| 12 | +use OCA\AppAPI\Db\ExAppMapper; |
| 13 | +use PHPUnit\Framework\Attributes\DataProvider; |
| 14 | +use PHPUnit\Framework\TestCase; |
| 15 | + |
| 16 | +class ExAppMapperTest extends TestCase { |
| 17 | + |
| 18 | + /** |
| 19 | + * `parseJsonList` is used by the proxy controller and HaRP route serializer to read the |
| 20 | + * nullable `bruteforce_protection` / `headers_to_exclude` columns. The matrix below covers |
| 21 | + * every row shape we have seen or can construct: legacy NULLs, malformed JSON, non-string |
| 22 | + * inputs, and well-formed payloads. |
| 23 | + */ |
| 24 | + #[DataProvider('jsonListProvider')] |
| 25 | + public function testParseJsonList(mixed $raw, array $expected): void { |
| 26 | + self::assertSame($expected, ExAppMapper::parseJsonList($raw)); |
| 27 | + } |
| 28 | + |
| 29 | + public static function jsonListProvider(): array { |
| 30 | + return [ |
| 31 | + 'null' => [null, []], |
| 32 | + 'empty string' => ['', []], |
| 33 | + 'empty array string' => ['[]', []], |
| 34 | + 'valid array of ints' => ['[401,403]', [401, 403]], |
| 35 | + 'valid array of strings' => ['["Cookie","Authorization"]', ['Cookie', 'Authorization']], |
| 36 | + 'invalid json' => ['{broken', []], |
| 37 | + 'json literal "null"' => ['null', []], |
| 38 | + 'json scalar string' => ['"foo"', []], |
| 39 | + 'json scalar int' => ['42', []], |
| 40 | + 'non-string input (array)' => [['Cookie'], []], |
| 41 | + 'non-string input (int)' => [42, []], |
| 42 | + 'non-string input (bool)' => [false, []], |
| 43 | + ]; |
| 44 | + } |
| 45 | +} |
0 commit comments