feat: convert Events to Requests and Responses to Function ResponsesUnverified
446efcb parent: 2d06656 deleted
src/.gitkeep +0 -0 | deleted file mode 100644 |
| deleted file mode 100644 |
added
src/HttpConverter.php +163 -0 | new file mode 100644 | ||
| @@ -0,0 +1,163 @@ | ||
| 1 | +<?php | |
| 2 | + | |
| 3 | +declare(strict_types=1); | |
| 4 | + | |
| 5 | +namespace JDecool\ScalewayRuntime; | |
| 6 | + | |
| 7 | +use Symfony\Component\HttpFoundation\Request; | |
| 8 | +use Symfony\Component\HttpFoundation\Response; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * Converts an Event into a Symfony Request, and a Symfony Response into a Function Response. | |
| 12 | + * | |
| 13 | + * @phpstan-type FunctionResponse array{statusCode: int, headers: array<string, string|list<string>>, body: string, isBase64Encoded?: true} | |
| 14 | + */ | |
| 15 | +final class HttpConverter | |
| 16 | +{ | |
| 17 | + /** | |
| 18 | + * The address the Request sees as its peer: Scaleway always fronts the function, | |
| 19 | + * so the peer is the platform proxy and the client comes from X-Forwarded-For. | |
| 20 | + */ | |
| 21 | + public const string PROXY_ADDRESS = '127.0.0.1'; | |
| 22 | + | |
| 23 | + public const int TRUSTED_HEADERS = Request::HEADER_X_FORWARDED_FOR | |
| 24 | + | Request::HEADER_X_FORWARDED_HOST | |
| 25 | + | Request::HEADER_X_FORWARDED_PORT | |
| 26 | + | Request::HEADER_X_FORWARDED_PROTO; | |
| 27 | + | |
| 28 | + /** | |
| 29 | + * @param array<mixed> $event | |
| 30 | + */ | |
| 31 | + public static function toRequest(array $event): Request | |
| 32 | + { | |
| 33 | + $method = strtoupper(self::string($event['method'] ?? $event['httpMethod'] ?? null) ?? 'GET'); | |
| 34 | + $path = '/'.ltrim(self::string($event['path'] ?? null) ?? '', '/'); | |
| 35 | + $queryString = http_build_query(self::stringMap($event['queryStringParameters'] ?? null)); | |
| 36 | + parse_str($queryString, $query); | |
| 37 | + | |
| 38 | + $body = self::string($event['body'] ?? null) ?? ''; | |
| 39 | + if (true === ($event['isBase64Encoded'] ?? false)) { | |
| 40 | + $body = base64_decode($body, true); | |
| 41 | + if (false === $body) { | |
| 42 | + throw new \UnexpectedValueException('The Event body is flagged as base64 but is not valid base64.'); | |
| 43 | + } | |
| 44 | + } | |
| 45 | + | |
| 46 | + $server = [ | |
| 47 | + 'REQUEST_METHOD' => $method, | |
| 48 | + 'REQUEST_URI' => '' === $queryString ? $path : $path.'?'.$queryString, | |
| 49 | + 'QUERY_STRING' => $queryString, | |
| 50 | + 'SERVER_PROTOCOL' => 'HTTP/1.1', | |
| 51 | + 'REMOTE_ADDR' => self::PROXY_ADDRESS, | |
| 52 | + 'REQUEST_TIME' => time(), | |
| 53 | + 'REQUEST_TIME_FLOAT' => microtime(true), | |
| 54 | + ]; | |
| 55 | + $cookies = []; | |
| 56 | + $contentType = ''; | |
| 57 | + foreach (self::stringMap($event['headers'] ?? null) as $name => $value) { | |
| 58 | + $key = strtoupper(str_replace('-', '_', $name)); | |
| 59 | + // PHP exposes these two without the HTTP_ prefix, and HeaderBag expects them that way. | |
| 60 | + $server[\in_array($key, ['CONTENT_TYPE', 'CONTENT_LENGTH'], true) ? $key : 'HTTP_'.$key] = $value; | |
| 61 | + if ('COOKIE' === $key) { | |
| 62 | + $cookies = self::parseCookies($value); | |
| 63 | + } elseif ('CONTENT_TYPE' === $key) { | |
| 64 | + $contentType = strtolower($value); | |
| 65 | + } | |
| 66 | + } | |
| 67 | + | |
| 68 | + // PHP only parses form bodies into $_POST for POST; Symfony's createFromGlobals() covers the other body methods. | |
| 69 | + $post = []; | |
| 70 | + if (\in_array($method, ['POST', 'PUT', 'DELETE', 'PATCH', 'QUERY'], true) | |
| 71 | + && str_starts_with($contentType, 'application/x-www-form-urlencoded') | |
| 72 | + ) { | |
| 73 | + parse_str($body, $post); | |
| 74 | + } | |
| 75 | + | |
| 76 | + return new Request($query, $post, [], $cookies, [], $server, $body); | |
| 77 | + } | |
| 78 | + | |
| 79 | + /** | |
| 80 | + * @return FunctionResponse | |
| 81 | + */ | |
| 82 | + public static function toFunctionResponse(Response $response): array | |
| 83 | + { | |
| 84 | + $body = ''; | |
| 85 | + // A callback handler keeps the chunks even when a streamed callback calls ob_flush(). | |
| 86 | + ob_start(static function (string $chunk) use (&$body): string { | |
| 87 | + $body .= $chunk; | |
| 88 | + | |
| 89 | + return ''; | |
| 90 | + }); | |
| 91 | + try { | |
| 92 | + $response->sendContent(); | |
| 93 | + } finally { | |
| 94 | + ob_end_flush(); | |
| 95 | + } | |
| 96 | + | |
| 97 | + $values = $response->headers->allPreserveCaseWithoutCookies(); | |
| 98 | + $values['Set-Cookie'] = array_map(strval(...), $response->headers->getCookies()); | |
| 99 | + $headers = []; | |
| 100 | + foreach ($values as $name => $list) { | |
| 101 | + $list = array_values(array_filter(\is_array($list) ? $list : [], \is_string(...))); | |
| 102 | + if ([] !== $list) { | |
| 103 | + $headers[(string) $name] = 1 === \count($list) ? $list[0] : $list; | |
| 104 | + } | |
| 105 | + } | |
| 106 | + | |
| 107 | + $functionResponse = [ | |
| 108 | + 'statusCode' => $response->getStatusCode(), | |
| 109 | + 'headers' => $headers, | |
| 110 | + 'body' => $body, | |
| 111 | + ]; | |
| 112 | + if (1 !== preg_match('//u', $body)) { | |
| 113 | + $functionResponse['body'] = base64_encode($body); | |
| 114 | + $functionResponse['isBase64Encoded'] = true; | |
| 115 | + } | |
| 116 | + | |
| 117 | + return $functionResponse; | |
| 118 | + } | |
| 119 | + | |
| 120 | + /** | |
| 121 | + * Mirrors how PHP fills $_COOKIE: the first occurrence of a name wins and values are URL-decoded. | |
| 122 | + * | |
| 123 | + * @return array<string, string> | |
| 124 | + */ | |
| 125 | + private static function parseCookies(string $header): array | |
| 126 | + { | |
| 127 | + $cookies = []; | |
| 128 | + foreach (explode(';', $header) as $pair) { | |
| 129 | + $parts = explode('=', $pair, 2); | |
| 130 | + $name = trim($parts[0]); | |
| 131 | + if ('' !== $name && isset($parts[1])) { | |
| 132 | + $cookies[$name] ??= urldecode(trim($parts[1])); | |
| 133 | + } | |
| 134 | + } | |
| 135 | + | |
| 136 | + return $cookies; | |
| 137 | + } | |
| 138 | + | |
| 139 | + private static function string(mixed $value): ?string | |
| 140 | + { | |
| 141 | + return \is_scalar($value) ? (string) $value : null; | |
| 142 | + } | |
| 143 | + | |
| 144 | + /** | |
| 145 | + * Keeps the scalar entries of an Event map; list values are joined like a proxy folds repeated headers. | |
| 146 | + * | |
| 147 | + * @return array<string, string> | |
| 148 | + */ | |
| 149 | + private static function stringMap(mixed $value): array | |
| 150 | + { | |
| 151 | + $map = []; | |
| 152 | + foreach (\is_array($value) ? $value : [] as $key => $item) { | |
| 153 | + if (\is_array($item)) { | |
| 154 | + $item = implode(', ', array_filter($item, is_scalar(...))); | |
| 155 | + } | |
| 156 | + if (\is_scalar($item)) { | |
| 157 | + $map[(string) $key] = (string) $item; | |
| 158 | + } | |
| 159 | + } | |
| 160 | + | |
| 161 | + return $map; | |
| 162 | + } | |
| 163 | +} | |
| new file mode 100644 | |||
| @@ -0,0 +1,163 @@ | |||
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +declare(strict_types=1); | ||
| 4 | + | ||
| 5 | +namespace JDecool\ScalewayRuntime; | ||
| 6 | + | ||
| 7 | +use Symfony\Component\HttpFoundation\Request; | ||
| 8 | +use Symfony\Component\HttpFoundation\Response; | ||
| 9 | + | ||
| 10 | +/** | ||
| 11 | + * Converts an Event into a Symfony Request, and a Symfony Response into a Function Response. | ||
| 12 | + * | ||
| 13 | + * @phpstan-type FunctionResponse array{statusCode: int, headers: array<string, string|list<string>>, body: string, isBase64Encoded?: true} | ||
| 14 | + */ | ||
| 15 | +final class HttpConverter | ||
| 16 | +{ | ||
| 17 | + /** | ||
| 18 | + * The address the Request sees as its peer: Scaleway always fronts the function, | ||
| 19 | + * so the peer is the platform proxy and the client comes from X-Forwarded-For. | ||
| 20 | + */ | ||
| 21 | + public const string PROXY_ADDRESS = '127.0.0.1'; | ||
| 22 | + | ||
| 23 | + public const int TRUSTED_HEADERS = Request::HEADER_X_FORWARDED_FOR | ||
| 24 | + | Request::HEADER_X_FORWARDED_HOST | ||
| 25 | + | Request::HEADER_X_FORWARDED_PORT | ||
| 26 | + | Request::HEADER_X_FORWARDED_PROTO; | ||
| 27 | + | ||
| 28 | + /** | ||
| 29 | + * @param array<mixed> $event | ||
| 30 | + */ | ||
| 31 | + public static function toRequest(array $event): Request | ||
| 32 | + { | ||
| 33 | + $method = strtoupper(self::string($event['method'] ?? $event['httpMethod'] ?? null) ?? 'GET'); | ||
| 34 | + $path = '/'.ltrim(self::string($event['path'] ?? null) ?? '', '/'); | ||
| 35 | + $queryString = http_build_query(self::stringMap($event['queryStringParameters'] ?? null)); | ||
| 36 | + parse_str($queryString, $query); | ||
| 37 | + | ||
| 38 | + $body = self::string($event['body'] ?? null) ?? ''; | ||
| 39 | + if (true === ($event['isBase64Encoded'] ?? false)) { | ||
| 40 | + $body = base64_decode($body, true); | ||
| 41 | + if (false === $body) { | ||
| 42 | + throw new \UnexpectedValueException('The Event body is flagged as base64 but is not valid base64.'); | ||
| 43 | + } | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + $server = [ | ||
| 47 | + 'REQUEST_METHOD' => $method, | ||
| 48 | + 'REQUEST_URI' => '' === $queryString ? $path : $path.'?'.$queryString, | ||
| 49 | + 'QUERY_STRING' => $queryString, | ||
| 50 | + 'SERVER_PROTOCOL' => 'HTTP/1.1', | ||
| 51 | + 'REMOTE_ADDR' => self::PROXY_ADDRESS, | ||
| 52 | + 'REQUEST_TIME' => time(), | ||
| 53 | + 'REQUEST_TIME_FLOAT' => microtime(true), | ||
| 54 | + ]; | ||
| 55 | + $cookies = []; | ||
| 56 | + $contentType = ''; | ||
| 57 | + foreach (self::stringMap($event['headers'] ?? null) as $name => $value) { | ||
| 58 | + $key = strtoupper(str_replace('-', '_', $name)); | ||
| 59 | + // PHP exposes these two without the HTTP_ prefix, and HeaderBag expects them that way. | ||
| 60 | + $server[\in_array($key, ['CONTENT_TYPE', 'CONTENT_LENGTH'], true) ? $key : 'HTTP_'.$key] = $value; | ||
| 61 | + if ('COOKIE' === $key) { | ||
| 62 | + $cookies = self::parseCookies($value); | ||
| 63 | + } elseif ('CONTENT_TYPE' === $key) { | ||
| 64 | + $contentType = strtolower($value); | ||
| 65 | + } | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + // PHP only parses form bodies into $_POST for POST; Symfony's createFromGlobals() covers the other body methods. | ||
| 69 | + $post = []; | ||
| 70 | + if (\in_array($method, ['POST', 'PUT', 'DELETE', 'PATCH', 'QUERY'], true) | ||
| 71 | + && str_starts_with($contentType, 'application/x-www-form-urlencoded') | ||
| 72 | + ) { | ||
| 73 | + parse_str($body, $post); | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + return new Request($query, $post, [], $cookies, [], $server, $body); | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + /** | ||
| 80 | + * @return FunctionResponse | ||
| 81 | + */ | ||
| 82 | + public static function toFunctionResponse(Response $response): array | ||
| 83 | + { | ||
| 84 | + $body = ''; | ||
| 85 | + // A callback handler keeps the chunks even when a streamed callback calls ob_flush(). | ||
| 86 | + ob_start(static function (string $chunk) use (&$body): string { | ||
| 87 | + $body .= $chunk; | ||
| 88 | + | ||
| 89 | + return ''; | ||
| 90 | + }); | ||
| 91 | + try { | ||
| 92 | + $response->sendContent(); | ||
| 93 | + } finally { | ||
| 94 | + ob_end_flush(); | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + $values = $response->headers->allPreserveCaseWithoutCookies(); | ||
| 98 | + $values['Set-Cookie'] = array_map(strval(...), $response->headers->getCookies()); | ||
| 99 | + $headers = []; | ||
| 100 | + foreach ($values as $name => $list) { | ||
| 101 | + $list = array_values(array_filter(\is_array($list) ? $list : [], \is_string(...))); | ||
| 102 | + if ([] !== $list) { | ||
| 103 | + $headers[(string) $name] = 1 === \count($list) ? $list[0] : $list; | ||
| 104 | + } | ||
| 105 | + } | ||
| 106 | + | ||
| 107 | + $functionResponse = [ | ||
| 108 | + 'statusCode' => $response->getStatusCode(), | ||
| 109 | + 'headers' => $headers, | ||
| 110 | + 'body' => $body, | ||
| 111 | + ]; | ||
| 112 | + if (1 !== preg_match('//u', $body)) { | ||
| 113 | + $functionResponse['body'] = base64_encode($body); | ||
| 114 | + $functionResponse['isBase64Encoded'] = true; | ||
| 115 | + } | ||
| 116 | + | ||
| 117 | + return $functionResponse; | ||
| 118 | + } | ||
| 119 | + | ||
| 120 | + /** | ||
| 121 | + * Mirrors how PHP fills $_COOKIE: the first occurrence of a name wins and values are URL-decoded. | ||
| 122 | + * | ||
| 123 | + * @return array<string, string> | ||
| 124 | + */ | ||
| 125 | + private static function parseCookies(string $header): array | ||
| 126 | + { | ||
| 127 | + $cookies = []; | ||
| 128 | + foreach (explode(';', $header) as $pair) { | ||
| 129 | + $parts = explode('=', $pair, 2); | ||
| 130 | + $name = trim($parts[0]); | ||
| 131 | + if ('' !== $name && isset($parts[1])) { | ||
| 132 | + $cookies[$name] ??= urldecode(trim($parts[1])); | ||
| 133 | + } | ||
| 134 | + } | ||
| 135 | + | ||
| 136 | + return $cookies; | ||
| 137 | + } | ||
| 138 | + | ||
| 139 | + private static function string(mixed $value): ?string | ||
| 140 | + { | ||
| 141 | + return \is_scalar($value) ? (string) $value : null; | ||
| 142 | + } | ||
| 143 | + | ||
| 144 | + /** | ||
| 145 | + * Keeps the scalar entries of an Event map; list values are joined like a proxy folds repeated headers. | ||
| 146 | + * | ||
| 147 | + * @return array<string, string> | ||
| 148 | + */ | ||
| 149 | + private static function stringMap(mixed $value): array | ||
| 150 | + { | ||
| 151 | + $map = []; | ||
| 152 | + foreach (\is_array($value) ? $value : [] as $key => $item) { | ||
| 153 | + if (\is_array($item)) { | ||
| 154 | + $item = implode(', ', array_filter($item, is_scalar(...))); | ||
| 155 | + } | ||
| 156 | + if (\is_scalar($item)) { | ||
| 157 | + $map[(string) $key] = (string) $item; | ||
| 158 | + } | ||
| 159 | + } | ||
| 160 | + | ||
| 161 | + return $map; | ||
| 162 | + } | ||
| 163 | +} | ||
deleted
tests/AutoloadTest.php +0 -22 | deleted file mode 100644 | ||
| @@ -1,22 +0,0 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | -declare(strict_types=1); | |
| 4 | - | |
| 5 | -namespace JDecool\ScalewayRuntime\Tests; | |
| 6 | - | |
| 7 | -use Composer\Autoload\ClassLoader; | |
| 8 | -use PHPUnit\Framework\TestCase; | |
| 9 | - | |
| 10 | -// Placeholder until Phase 2 adds real classes: guards the PSR-4 mapping the runtime code will rely on. | |
| 11 | -final class AutoloadTest extends TestCase | |
| 12 | -{ | |
| 13 | - public function testPackageNamespaceMapsToSrc(): void | |
| 14 | - { | |
| 15 | - $paths = []; | |
| 16 | - foreach (ClassLoader::getRegisteredLoaders() as $loader) { | |
| 17 | - $paths = [...$paths, ...$loader->getPrefixesPsr4()['JDecool\\ScalewayRuntime\\'] ?? []]; | |
| 18 | - } | |
| 19 | - | |
| 20 | - self::assertSame([realpath(__DIR__.'/../src')], array_map(realpath(...), $paths)); | |
| 21 | - } | |
| 22 | -} | |
| deleted file mode 100644 | |||
| @@ -1,22 +0,0 @@ | |||
| 1 | -<?php | ||
| 2 | - | ||
| 3 | -declare(strict_types=1); | ||
| 4 | - | ||
| 5 | -namespace JDecool\ScalewayRuntime\Tests; | ||
| 6 | - | ||
| 7 | -use Composer\Autoload\ClassLoader; | ||
| 8 | -use PHPUnit\Framework\TestCase; | ||
| 9 | - | ||
| 10 | -// Placeholder until Phase 2 adds real classes: guards the PSR-4 mapping the runtime code will rely on. | ||
| 11 | -final class AutoloadTest extends TestCase | ||
| 12 | -{ | ||
| 13 | - public function testPackageNamespaceMapsToSrc(): void | ||
| 14 | - { | ||
| 15 | - $paths = []; | ||
| 16 | - foreach (ClassLoader::getRegisteredLoaders() as $loader) { | ||
| 17 | - $paths = [...$paths, ...$loader->getPrefixesPsr4()['JDecool\\ScalewayRuntime\\'] ?? []]; | ||
| 18 | - } | ||
| 19 | - | ||
| 20 | - self::assertSame([realpath(__DIR__.'/../src')], array_map(realpath(...), $paths)); | ||
| 21 | - } | ||
| 22 | -} | ||
added
tests/HttpConverterTest.php +254 -0 | new file mode 100644 | ||
| @@ -0,0 +1,254 @@ | ||
| 1 | +<?php | |
| 2 | + | |
| 3 | +declare(strict_types=1); | |
| 4 | + | |
| 5 | +namespace JDecool\ScalewayRuntime\Tests; | |
| 6 | + | |
| 7 | +use JDecool\ScalewayRuntime\HttpConverter; | |
| 8 | +use PHPUnit\Framework\TestCase; | |
| 9 | +use Symfony\Component\HttpFoundation\BinaryFileResponse; | |
| 10 | +use Symfony\Component\HttpFoundation\Cookie; | |
| 11 | +use Symfony\Component\HttpFoundation\Request; | |
| 12 | +use Symfony\Component\HttpFoundation\Response; | |
| 13 | +use Symfony\Component\HttpFoundation\StreamedResponse; | |
| 14 | + | |
| 15 | +final class HttpConverterTest extends TestCase | |
| 16 | +{ | |
| 17 | + protected function tearDown(): void | |
| 18 | + { | |
| 19 | + Request::setTrustedProxies([], 0); | |
| 20 | + } | |
| 21 | + | |
| 22 | + public function testRequestFromFullEvent(): void | |
| 23 | + { | |
| 24 | + $request = HttpConverter::toRequest([ | |
| 25 | + 'path' => '/blog/post', | |
| 26 | + 'method' => 'put', | |
| 27 | + 'queryStringParameters' => ['page' => '2', 'q' => 'a b&c'], | |
| 28 | + 'headers' => ['Content-Type' => 'application/json', 'Content-Length' => '13', 'X-Custom-Header' => 'yes', 'Host' => 'example.com'], | |
| 29 | + 'body' => '{"ok": true}', | |
| 30 | + 'isBase64Encoded' => false, | |
| 31 | + ]); | |
| 32 | + | |
| 33 | + self::assertSame('PUT', $request->getMethod()); | |
| 34 | + self::assertSame('/blog/post', $request->getPathInfo()); | |
| 35 | + self::assertSame(['page' => '2', 'q' => 'a b&c'], $request->query->all()); | |
| 36 | + self::assertSame('page=2&q=a+b%26c', $request->server->get('QUERY_STRING')); | |
| 37 | + self::assertSame('/blog/post?page=2&q=a+b%26c', $request->getRequestUri()); | |
| 38 | + self::assertSame('application/json', $request->headers->get('Content-Type')); | |
| 39 | + self::assertSame('13', $request->headers->get('Content-Length')); | |
| 40 | + self::assertSame('yes', $request->headers->get('X-Custom-Header')); | |
| 41 | + self::assertSame('http://example.com/blog/post?page=2&q=a%20b%26c', $request->getUri()); | |
| 42 | + self::assertSame('{"ok": true}', $request->getContent()); | |
| 43 | + self::assertSame(['ok' => true], $request->toArray()); | |
| 44 | + } | |
| 45 | + | |
| 46 | + public function testRequestFromEmptyEvent(): void | |
| 47 | + { | |
| 48 | + $request = HttpConverter::toRequest([]); | |
| 49 | + | |
| 50 | + self::assertSame('GET', $request->getMethod()); | |
| 51 | + self::assertSame('/', $request->getPathInfo()); | |
| 52 | + self::assertSame('/', $request->getRequestUri()); | |
| 53 | + self::assertSame([], $request->query->all()); | |
| 54 | + self::assertSame('', $request->getContent()); | |
| 55 | + self::assertSame(HttpConverter::PROXY_ADDRESS, $request->getClientIp()); | |
| 56 | + } | |
| 57 | + | |
| 58 | + public function testHttpMethodFieldIsAccepted(): void | |
| 59 | + { | |
| 60 | + self::assertSame('DELETE', HttpConverter::toRequest(['httpMethod' => 'DELETE'])->getMethod()); | |
| 61 | + } | |
| 62 | + | |
| 63 | + public function testPathWithoutLeadingSlashIsNormalized(): void | |
| 64 | + { | |
| 65 | + self::assertSame('/health', HttpConverter::toRequest(['path' => 'health'])->getPathInfo()); | |
| 66 | + } | |
| 67 | + | |
| 68 | + public function testArrayQueryParametersAreParsedLikePhp(): void | |
| 69 | + { | |
| 70 | + $request = HttpConverter::toRequest(['queryStringParameters' => ['filter[status]' => 'open', 'tags[]' => 'php']]); | |
| 71 | + | |
| 72 | + self::assertSame(['filter' => ['status' => 'open'], 'tags' => ['php']], $request->query->all()); | |
| 73 | + } | |
| 74 | + | |
| 75 | + public function testBase64BodyIsDecoded(): void | |
| 76 | + { | |
| 77 | + $binary = random_bytes(64)."\xff\xfe"; | |
| 78 | + | |
| 79 | + $request = HttpConverter::toRequest(['method' => 'POST', 'body' => base64_encode($binary), 'isBase64Encoded' => true]); | |
| 80 | + | |
| 81 | + self::assertSame($binary, $request->getContent()); | |
| 82 | + } | |
| 83 | + | |
| 84 | + public function testInvalidBase64BodyIsRejected(): void | |
| 85 | + { | |
| 86 | + $this->expectException(\UnexpectedValueException::class); | |
| 87 | + | |
| 88 | + HttpConverter::toRequest(['body' => '%%%', 'isBase64Encoded' => true]); | |
| 89 | + } | |
| 90 | + | |
| 91 | + public function testFormBodyIsParsed(): void | |
| 92 | + { | |
| 93 | + $request = HttpConverter::toRequest([ | |
| 94 | + 'method' => 'PATCH', | |
| 95 | + 'headers' => ['content-type' => 'application/x-www-form-urlencoded; charset=UTF-8'], | |
| 96 | + 'body' => 'name=Jane+Doe&roles[]=admin', | |
| 97 | + ]); | |
| 98 | + | |
| 99 | + self::assertSame(['name' => 'Jane Doe', 'roles' => ['admin']], $request->request->all()); | |
| 100 | + } | |
| 101 | + | |
| 102 | + public function testFormBodyIsIgnoredForGet(): void | |
| 103 | + { | |
| 104 | + $request = HttpConverter::toRequest([ | |
| 105 | + 'headers' => ['Content-Type' => 'application/x-www-form-urlencoded'], | |
| 106 | + 'body' => 'name=Jane', | |
| 107 | + ]); | |
| 108 | + | |
| 109 | + self::assertSame([], $request->request->all()); | |
| 110 | + } | |
| 111 | + | |
| 112 | + public function testCookiesAreParsedLikePhp(): void | |
| 113 | + { | |
| 114 | + $request = HttpConverter::toRequest(['headers' => ['Cookie' => 'session=abc%3D%3D; theme=dark;session=ignored; broken; =nameless']]); | |
| 115 | + | |
| 116 | + self::assertSame(['session' => 'abc==', 'theme' => 'dark'], $request->cookies->all()); | |
| 117 | + } | |
| 118 | + | |
| 119 | + public function testMalformedEventFieldsAreIgnored(): void | |
| 120 | + { | |
| 121 | + $request = HttpConverter::toRequest([ | |
| 122 | + 'path' => ['not', 'a', 'string'], | |
| 123 | + 'headers' => 'not a map', | |
| 124 | + 'queryStringParameters' => ['ok' => '1', 'nested' => ['x' => ['y']]], | |
| 125 | + 'body' => null, | |
| 126 | + ]); | |
| 127 | + | |
| 128 | + self::assertSame('/', $request->getPathInfo()); | |
| 129 | + self::assertSame(['ok' => '1', 'nested' => ''], $request->query->all()); | |
| 130 | + self::assertSame('', $request->getContent()); | |
| 131 | + } | |
| 132 | + | |
| 133 | + public function testListHeaderValuesAreFolded(): void | |
| 134 | + { | |
| 135 | + $request = HttpConverter::toRequest(['headers' => ['Accept' => ['text/html', 'application/json']]]); | |
| 136 | + | |
| 137 | + self::assertSame('text/html, application/json', $request->headers->get('Accept')); | |
| 138 | + } | |
| 139 | + | |
| 140 | + public function testForwardedHeadersApplyOnceTheProxyIsTrusted(): void | |
| 141 | + { | |
| 142 | + Request::setTrustedProxies([HttpConverter::PROXY_ADDRESS], HttpConverter::TRUSTED_HEADERS); | |
| 143 | + | |
| 144 | + $request = HttpConverter::toRequest([ | |
| 145 | + 'path' => '/', | |
| 146 | + 'headers' => [ | |
| 147 | + 'Host' => 'internal.local', | |
| 148 | + 'X-Forwarded-For' => '203.0.113.7', | |
| 149 | + 'X-Forwarded-Host' => 'app.example.com', | |
| 150 | + 'X-Forwarded-Proto' => 'https', | |
| 151 | + 'X-Forwarded-Port' => '443', | |
| 152 | + ], | |
| 153 | + ]); | |
| 154 | + | |
| 155 | + self::assertTrue($request->isSecure()); | |
| 156 | + self::assertSame('app.example.com', $request->getHost()); | |
| 157 | + self::assertSame('https://app.example.com/', $request->getUri()); | |
| 158 | + self::assertSame('203.0.113.7', $request->getClientIp()); | |
| 159 | + } | |
| 160 | + | |
| 161 | + public function testForwardedHeadersAreIgnoredWhileTheProxyIsUntrusted(): void | |
| 162 | + { | |
| 163 | + $request = HttpConverter::toRequest(['headers' => ['Host' => 'internal.local', 'X-Forwarded-Proto' => 'https']]); | |
| 164 | + | |
| 165 | + self::assertFalse($request->isSecure()); | |
| 166 | + self::assertSame('internal.local', $request->getHost()); | |
| 167 | + } | |
| 168 | + | |
| 169 | + public function testFunctionResponseFromTextResponse(): void | |
| 170 | + { | |
| 171 | + $response = new Response('{"a":"é"}', 201, ['Content-Type' => 'application/json']); | |
| 172 | + | |
| 173 | + $functionResponse = HttpConverter::toFunctionResponse($response); | |
| 174 | + | |
| 175 | + self::assertSame(201, $functionResponse['statusCode']); | |
| 176 | + self::assertSame('{"a":"é"}', $functionResponse['body']); | |
| 177 | + self::assertSame('application/json', $functionResponse['headers']['Content-Type']); | |
| 178 | + self::assertArrayNotHasKey('isBase64Encoded', $functionResponse); | |
| 179 | + } | |
| 180 | + | |
| 181 | + public function testEmptyBody(): void | |
| 182 | + { | |
| 183 | + $functionResponse = HttpConverter::toFunctionResponse(new Response('', 204)); | |
| 184 | + | |
| 185 | + self::assertSame(204, $functionResponse['statusCode']); | |
| 186 | + self::assertSame('', $functionResponse['body']); | |
| 187 | + self::assertArrayNotHasKey('isBase64Encoded', $functionResponse); | |
| 188 | + } | |
| 189 | + | |
| 190 | + public function testBinaryBodyIsBase64Encoded(): void | |
| 191 | + { | |
| 192 | + $binary = "\x89PNG\r\n\x1a\n\x00\xff"; | |
| 193 | + | |
| 194 | + $functionResponse = HttpConverter::toFunctionResponse(new Response($binary)); | |
| 195 | + | |
| 196 | + self::assertSame(base64_encode($binary), $functionResponse['body']); | |
| 197 | + self::assertTrue($functionResponse['isBase64Encoded'] ?? null); | |
| 198 | + } | |
| 199 | + | |
| 200 | + public function testMultiValueHeadersAndCookiesAreLists(): void | |
| 201 | + { | |
| 202 | + $response = new Response(); | |
| 203 | + $response->headers->set('Vary', ['Accept', 'Accept-Language']); | |
| 204 | + $response->headers->setCookie(Cookie::create('a', '1')); | |
| 205 | + $response->headers->setCookie(Cookie::create('b', 'x y', path: '/admin')); | |
| 206 | + | |
| 207 | + $headers = HttpConverter::toFunctionResponse($response)['headers']; | |
| 208 | + | |
| 209 | + self::assertSame(['Accept', 'Accept-Language'], $headers['Vary']); | |
| 210 | + self::assertSame(['a=1; path=/; httponly; samesite=lax', 'b=x%20y; path=/admin; httponly; samesite=lax'], $headers['Set-Cookie']); | |
| 211 | + } | |
| 212 | + | |
| 213 | + public function testSingleCookieIsAString(): void | |
| 214 | + { | |
| 215 | + $response = new Response(); | |
| 216 | + $response->headers->setCookie(Cookie::create('a', '1')); | |
| 217 | + | |
| 218 | + self::assertSame('a=1; path=/; httponly; samesite=lax', HttpConverter::toFunctionResponse($response)['headers']['Set-Cookie']); | |
| 219 | + } | |
| 220 | + | |
| 221 | + public function testNoSetCookieHeaderWithoutCookies(): void | |
| 222 | + { | |
| 223 | + self::assertArrayNotHasKey('Set-Cookie', HttpConverter::toFunctionResponse(new Response())['headers']); | |
| 224 | + } | |
| 225 | + | |
| 226 | + public function testStreamedResponseIsBuffered(): void | |
| 227 | + { | |
| 228 | + $response = new StreamedResponse(static function (): void { | |
| 229 | + echo 'chunk 1, '; | |
| 230 | + // Streamed callbacks commonly flush: the chunk must still reach the Function Response. | |
| 231 | + ob_flush(); | |
| 232 | + flush(); | |
| 233 | + echo 'chunk 2'; | |
| 234 | + }); | |
| 235 | + | |
| 236 | + self::assertSame('chunk 1, chunk 2', HttpConverter::toFunctionResponse($response)['body']); | |
| 237 | + } | |
| 238 | + | |
| 239 | + public function testBinaryFileResponseIsBuffered(): void | |
| 240 | + { | |
| 241 | + $file = tempnam(sys_get_temp_dir(), 'scaleway-runtime'); | |
| 242 | + self::assertNotFalse($file); | |
| 243 | + file_put_contents($file, "\xff\xd8binary"); | |
| 244 | + | |
| 245 | + $response = new BinaryFileResponse($file); | |
| 246 | + $response->deleteFileAfterSend(); | |
| 247 | + | |
| 248 | + $functionResponse = HttpConverter::toFunctionResponse($response); | |
| 249 | + | |
| 250 | + self::assertSame(base64_encode("\xff\xd8binary"), $functionResponse['body']); | |
| 251 | + self::assertTrue($functionResponse['isBase64Encoded'] ?? null); | |
| 252 | + self::assertFileDoesNotExist($file); | |
| 253 | + } | |
| 254 | +} | |
| new file mode 100644 | |||
| @@ -0,0 +1,254 @@ | |||
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +declare(strict_types=1); | ||
| 4 | + | ||
| 5 | +namespace JDecool\ScalewayRuntime\Tests; | ||
| 6 | + | ||
| 7 | +use JDecool\ScalewayRuntime\HttpConverter; | ||
| 8 | +use PHPUnit\Framework\TestCase; | ||
| 9 | +use Symfony\Component\HttpFoundation\BinaryFileResponse; | ||
| 10 | +use Symfony\Component\HttpFoundation\Cookie; | ||
| 11 | +use Symfony\Component\HttpFoundation\Request; | ||
| 12 | +use Symfony\Component\HttpFoundation\Response; | ||
| 13 | +use Symfony\Component\HttpFoundation\StreamedResponse; | ||
| 14 | + | ||
| 15 | +final class HttpConverterTest extends TestCase | ||
| 16 | +{ | ||
| 17 | + protected function tearDown(): void | ||
| 18 | + { | ||
| 19 | + Request::setTrustedProxies([], 0); | ||
| 20 | + } | ||
| 21 | + | ||
| 22 | + public function testRequestFromFullEvent(): void | ||
| 23 | + { | ||
| 24 | + $request = HttpConverter::toRequest([ | ||
| 25 | + 'path' => '/blog/post', | ||
| 26 | + 'method' => 'put', | ||
| 27 | + 'queryStringParameters' => ['page' => '2', 'q' => 'a b&c'], | ||
| 28 | + 'headers' => ['Content-Type' => 'application/json', 'Content-Length' => '13', 'X-Custom-Header' => 'yes', 'Host' => 'example.com'], | ||
| 29 | + 'body' => '{"ok": true}', | ||
| 30 | + 'isBase64Encoded' => false, | ||
| 31 | + ]); | ||
| 32 | + | ||
| 33 | + self::assertSame('PUT', $request->getMethod()); | ||
| 34 | + self::assertSame('/blog/post', $request->getPathInfo()); | ||
| 35 | + self::assertSame(['page' => '2', 'q' => 'a b&c'], $request->query->all()); | ||
| 36 | + self::assertSame('page=2&q=a+b%26c', $request->server->get('QUERY_STRING')); | ||
| 37 | + self::assertSame('/blog/post?page=2&q=a+b%26c', $request->getRequestUri()); | ||
| 38 | + self::assertSame('application/json', $request->headers->get('Content-Type')); | ||
| 39 | + self::assertSame('13', $request->headers->get('Content-Length')); | ||
| 40 | + self::assertSame('yes', $request->headers->get('X-Custom-Header')); | ||
| 41 | + self::assertSame('http://example.com/blog/post?page=2&q=a%20b%26c', $request->getUri()); | ||
| 42 | + self::assertSame('{"ok": true}', $request->getContent()); | ||
| 43 | + self::assertSame(['ok' => true], $request->toArray()); | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + public function testRequestFromEmptyEvent(): void | ||
| 47 | + { | ||
| 48 | + $request = HttpConverter::toRequest([]); | ||
| 49 | + | ||
| 50 | + self::assertSame('GET', $request->getMethod()); | ||
| 51 | + self::assertSame('/', $request->getPathInfo()); | ||
| 52 | + self::assertSame('/', $request->getRequestUri()); | ||
| 53 | + self::assertSame([], $request->query->all()); | ||
| 54 | + self::assertSame('', $request->getContent()); | ||
| 55 | + self::assertSame(HttpConverter::PROXY_ADDRESS, $request->getClientIp()); | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + public function testHttpMethodFieldIsAccepted(): void | ||
| 59 | + { | ||
| 60 | + self::assertSame('DELETE', HttpConverter::toRequest(['httpMethod' => 'DELETE'])->getMethod()); | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + public function testPathWithoutLeadingSlashIsNormalized(): void | ||
| 64 | + { | ||
| 65 | + self::assertSame('/health', HttpConverter::toRequest(['path' => 'health'])->getPathInfo()); | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + public function testArrayQueryParametersAreParsedLikePhp(): void | ||
| 69 | + { | ||
| 70 | + $request = HttpConverter::toRequest(['queryStringParameters' => ['filter[status]' => 'open', 'tags[]' => 'php']]); | ||
| 71 | + | ||
| 72 | + self::assertSame(['filter' => ['status' => 'open'], 'tags' => ['php']], $request->query->all()); | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + public function testBase64BodyIsDecoded(): void | ||
| 76 | + { | ||
| 77 | + $binary = random_bytes(64)."\xff\xfe"; | ||
| 78 | + | ||
| 79 | + $request = HttpConverter::toRequest(['method' => 'POST', 'body' => base64_encode($binary), 'isBase64Encoded' => true]); | ||
| 80 | + | ||
| 81 | + self::assertSame($binary, $request->getContent()); | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + public function testInvalidBase64BodyIsRejected(): void | ||
| 85 | + { | ||
| 86 | + $this->expectException(\UnexpectedValueException::class); | ||
| 87 | + | ||
| 88 | + HttpConverter::toRequest(['body' => '%%%', 'isBase64Encoded' => true]); | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + public function testFormBodyIsParsed(): void | ||
| 92 | + { | ||
| 93 | + $request = HttpConverter::toRequest([ | ||
| 94 | + 'method' => 'PATCH', | ||
| 95 | + 'headers' => ['content-type' => 'application/x-www-form-urlencoded; charset=UTF-8'], | ||
| 96 | + 'body' => 'name=Jane+Doe&roles[]=admin', | ||
| 97 | + ]); | ||
| 98 | + | ||
| 99 | + self::assertSame(['name' => 'Jane Doe', 'roles' => ['admin']], $request->request->all()); | ||
| 100 | + } | ||
| 101 | + | ||
| 102 | + public function testFormBodyIsIgnoredForGet(): void | ||
| 103 | + { | ||
| 104 | + $request = HttpConverter::toRequest([ | ||
| 105 | + 'headers' => ['Content-Type' => 'application/x-www-form-urlencoded'], | ||
| 106 | + 'body' => 'name=Jane', | ||
| 107 | + ]); | ||
| 108 | + | ||
| 109 | + self::assertSame([], $request->request->all()); | ||
| 110 | + } | ||
| 111 | + | ||
| 112 | + public function testCookiesAreParsedLikePhp(): void | ||
| 113 | + { | ||
| 114 | + $request = HttpConverter::toRequest(['headers' => ['Cookie' => 'session=abc%3D%3D; theme=dark;session=ignored; broken; =nameless']]); | ||
| 115 | + | ||
| 116 | + self::assertSame(['session' => 'abc==', 'theme' => 'dark'], $request->cookies->all()); | ||
| 117 | + } | ||
| 118 | + | ||
| 119 | + public function testMalformedEventFieldsAreIgnored(): void | ||
| 120 | + { | ||
| 121 | + $request = HttpConverter::toRequest([ | ||
| 122 | + 'path' => ['not', 'a', 'string'], | ||
| 123 | + 'headers' => 'not a map', | ||
| 124 | + 'queryStringParameters' => ['ok' => '1', 'nested' => ['x' => ['y']]], | ||
| 125 | + 'body' => null, | ||
| 126 | + ]); | ||
| 127 | + | ||
| 128 | + self::assertSame('/', $request->getPathInfo()); | ||
| 129 | + self::assertSame(['ok' => '1', 'nested' => ''], $request->query->all()); | ||
| 130 | + self::assertSame('', $request->getContent()); | ||
| 131 | + } | ||
| 132 | + | ||
| 133 | + public function testListHeaderValuesAreFolded(): void | ||
| 134 | + { | ||
| 135 | + $request = HttpConverter::toRequest(['headers' => ['Accept' => ['text/html', 'application/json']]]); | ||
| 136 | + | ||
| 137 | + self::assertSame('text/html, application/json', $request->headers->get('Accept')); | ||
| 138 | + } | ||
| 139 | + | ||
| 140 | + public function testForwardedHeadersApplyOnceTheProxyIsTrusted(): void | ||
| 141 | + { | ||
| 142 | + Request::setTrustedProxies([HttpConverter::PROXY_ADDRESS], HttpConverter::TRUSTED_HEADERS); | ||
| 143 | + | ||
| 144 | + $request = HttpConverter::toRequest([ | ||
| 145 | + 'path' => '/', | ||
| 146 | + 'headers' => [ | ||
| 147 | + 'Host' => 'internal.local', | ||
| 148 | + 'X-Forwarded-For' => '203.0.113.7', | ||
| 149 | + 'X-Forwarded-Host' => 'app.example.com', | ||
| 150 | + 'X-Forwarded-Proto' => 'https', | ||
| 151 | + 'X-Forwarded-Port' => '443', | ||
| 152 | + ], | ||
| 153 | + ]); | ||
| 154 | + | ||
| 155 | + self::assertTrue($request->isSecure()); | ||
| 156 | + self::assertSame('app.example.com', $request->getHost()); | ||
| 157 | + self::assertSame('https://app.example.com/', $request->getUri()); | ||
| 158 | + self::assertSame('203.0.113.7', $request->getClientIp()); | ||
| 159 | + } | ||
| 160 | + | ||
| 161 | + public function testForwardedHeadersAreIgnoredWhileTheProxyIsUntrusted(): void | ||
| 162 | + { | ||
| 163 | + $request = HttpConverter::toRequest(['headers' => ['Host' => 'internal.local', 'X-Forwarded-Proto' => 'https']]); | ||
| 164 | + | ||
| 165 | + self::assertFalse($request->isSecure()); | ||
| 166 | + self::assertSame('internal.local', $request->getHost()); | ||
| 167 | + } | ||
| 168 | + | ||
| 169 | + public function testFunctionResponseFromTextResponse(): void | ||
| 170 | + { | ||
| 171 | + $response = new Response('{"a":"é"}', 201, ['Content-Type' => 'application/json']); | ||
| 172 | + | ||
| 173 | + $functionResponse = HttpConverter::toFunctionResponse($response); | ||
| 174 | + | ||
| 175 | + self::assertSame(201, $functionResponse['statusCode']); | ||
| 176 | + self::assertSame('{"a":"é"}', $functionResponse['body']); | ||
| 177 | + self::assertSame('application/json', $functionResponse['headers']['Content-Type']); | ||
| 178 | + self::assertArrayNotHasKey('isBase64Encoded', $functionResponse); | ||
| 179 | + } | ||
| 180 | + | ||
| 181 | + public function testEmptyBody(): void | ||
| 182 | + { | ||
| 183 | + $functionResponse = HttpConverter::toFunctionResponse(new Response('', 204)); | ||
| 184 | + | ||
| 185 | + self::assertSame(204, $functionResponse['statusCode']); | ||
| 186 | + self::assertSame('', $functionResponse['body']); | ||
| 187 | + self::assertArrayNotHasKey('isBase64Encoded', $functionResponse); | ||
| 188 | + } | ||
| 189 | + | ||
| 190 | + public function testBinaryBodyIsBase64Encoded(): void | ||
| 191 | + { | ||
| 192 | + $binary = "\x89PNG\r\n\x1a\n\x00\xff"; | ||
| 193 | + | ||
| 194 | + $functionResponse = HttpConverter::toFunctionResponse(new Response($binary)); | ||
| 195 | + | ||
| 196 | + self::assertSame(base64_encode($binary), $functionResponse['body']); | ||
| 197 | + self::assertTrue($functionResponse['isBase64Encoded'] ?? null); | ||
| 198 | + } | ||
| 199 | + | ||
| 200 | + public function testMultiValueHeadersAndCookiesAreLists(): void | ||
| 201 | + { | ||
| 202 | + $response = new Response(); | ||
| 203 | + $response->headers->set('Vary', ['Accept', 'Accept-Language']); | ||
| 204 | + $response->headers->setCookie(Cookie::create('a', '1')); | ||
| 205 | + $response->headers->setCookie(Cookie::create('b', 'x y', path: '/admin')); | ||
| 206 | + | ||
| 207 | + $headers = HttpConverter::toFunctionResponse($response)['headers']; | ||
| 208 | + | ||
| 209 | + self::assertSame(['Accept', 'Accept-Language'], $headers['Vary']); | ||
| 210 | + self::assertSame(['a=1; path=/; httponly; samesite=lax', 'b=x%20y; path=/admin; httponly; samesite=lax'], $headers['Set-Cookie']); | ||
| 211 | + } | ||
| 212 | + | ||
| 213 | + public function testSingleCookieIsAString(): void | ||
| 214 | + { | ||
| 215 | + $response = new Response(); | ||
| 216 | + $response->headers->setCookie(Cookie::create('a', '1')); | ||
| 217 | + | ||
| 218 | + self::assertSame('a=1; path=/; httponly; samesite=lax', HttpConverter::toFunctionResponse($response)['headers']['Set-Cookie']); | ||
| 219 | + } | ||
| 220 | + | ||
| 221 | + public function testNoSetCookieHeaderWithoutCookies(): void | ||
| 222 | + { | ||
| 223 | + self::assertArrayNotHasKey('Set-Cookie', HttpConverter::toFunctionResponse(new Response())['headers']); | ||
| 224 | + } | ||
| 225 | + | ||
| 226 | + public function testStreamedResponseIsBuffered(): void | ||
| 227 | + { | ||
| 228 | + $response = new StreamedResponse(static function (): void { | ||
| 229 | + echo 'chunk 1, '; | ||
| 230 | + // Streamed callbacks commonly flush: the chunk must still reach the Function Response. | ||
| 231 | + ob_flush(); | ||
| 232 | + flush(); | ||
| 233 | + echo 'chunk 2'; | ||
| 234 | + }); | ||
| 235 | + | ||
| 236 | + self::assertSame('chunk 1, chunk 2', HttpConverter::toFunctionResponse($response)['body']); | ||
| 237 | + } | ||
| 238 | + | ||
| 239 | + public function testBinaryFileResponseIsBuffered(): void | ||
| 240 | + { | ||
| 241 | + $file = tempnam(sys_get_temp_dir(), 'scaleway-runtime'); | ||
| 242 | + self::assertNotFalse($file); | ||
| 243 | + file_put_contents($file, "\xff\xd8binary"); | ||
| 244 | + | ||
| 245 | + $response = new BinaryFileResponse($file); | ||
| 246 | + $response->deleteFileAfterSend(); | ||
| 247 | + | ||
| 248 | + $functionResponse = HttpConverter::toFunctionResponse($response); | ||
| 249 | + | ||
| 250 | + self::assertSame(base64_encode("\xff\xd8binary"), $functionResponse['body']); | ||
| 251 | + self::assertTrue($functionResponse['isBase64Encoded'] ?? null); | ||
| 252 | + self::assertFileDoesNotExist($file); | ||
| 253 | + } | ||
| 254 | +} | ||