diff --git a/composer.lock b/composer.lock index 653d1841d5..ec39039b91 100644 --- a/composer.lock +++ b/composer.lock @@ -8239,7 +8239,7 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": {}, + "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, "platform": { @@ -8263,5 +8263,5 @@ "platform-overrides": { "php": "8.3" }, - "plugin-api-version": "2.6.0" + "plugin-api-version": "2.3.0" } diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index d562e52e52..4d0646b12e 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -35,7 +35,7 @@ class FunctionsCustomServerTest extends Scope $function = $this->createFunction([ 'functionId' => ID::unique(), 'name' => 'Specs function', - 'runtime' => 'php-8.0', + 'runtime' => 'node-22', 'specification' => $specifications['body']['specifications'][0]['slug'] ]); $this->assertEquals(201, $function['headers']['status-code']); @@ -50,7 +50,7 @@ class FunctionsCustomServerTest extends Scope $function = $this->createFunction([ 'functionId' => ID::unique(), 'name' => 'Specs function', - 'runtime' => 'php-8.0', + 'runtime' => 'node-22', 'specification' => 'cheap-please' ]); $this->assertEquals(400, $function['headers']['status-code']); @@ -64,8 +64,8 @@ class FunctionsCustomServerTest extends Scope $function = $this->createFunction([ 'functionId' => ID::unique(), 'name' => 'Test', - 'runtime' => 'php-8.0', - 'entrypoint' => 'index.php', + 'runtime' => 'node-22', + 'entrypoint' => 'index.js', 'events' => [ 'buckets.*.create', 'buckets.*.delete', @@ -79,7 +79,7 @@ class FunctionsCustomServerTest extends Scope $this->assertEquals(201, $function['headers']['status-code']); $this->assertNotEmpty($function['body']['$id']); $this->assertEquals('Test', $function['body']['name']); - $this->assertEquals('php-8.0', $function['body']['runtime']); + $this->assertEquals('node-22', $function['body']['runtime']); $this->assertEquals(true, $dateValidator->isValid($function['body']['$createdAt'])); $this->assertEquals(true, $dateValidator->isValid($function['body']['$updatedAt'])); $this->assertEquals('', $function['body']['deploymentId']); @@ -180,7 +180,7 @@ class FunctionsCustomServerTest extends Scope // Test search runtime $functions = $this->listFunctions([ - 'search' => 'php-8.0' + 'search' => 'node-22' ]); $this->assertEquals($functions['headers']['status-code'], 200); @@ -193,8 +193,8 @@ class FunctionsCustomServerTest extends Scope $this->setupFunction([ 'functionId' => ID::unique(), 'name' => 'Test 2', - 'runtime' => 'php-8.0', - 'entrypoint' => 'index.php', + 'runtime' => 'node-22', + 'entrypoint' => 'index.js', 'events' => [ 'buckets.*.create', 'buckets.*.delete', @@ -286,8 +286,8 @@ class FunctionsCustomServerTest extends Scope ], 'schedule' => '0 0 1 1 *', 'timeout' => 15, - 'runtime' => 'php-8.0', - 'entrypoint' => 'index.php', + 'runtime' => 'node-22', + 'entrypoint' => 'index.js', ]); $dateValidator = new DatetimeValidator(); @@ -362,7 +362,7 @@ class FunctionsCustomServerTest extends Scope $this->assertEquals(200, $starterTemplate['headers']['status-code']); $phpRuntime = array_values(array_filter($starterTemplate['body']['runtimes'], function ($runtime) { - return $runtime['name'] === 'php-8.0'; + return $runtime['name'] === 'node-22'; }))[0]; // If this fails, the template has variables, and this test needs to be updated @@ -372,7 +372,7 @@ class FunctionsCustomServerTest extends Scope [ 'functionId' => ID::unique(), 'name' => $starterTemplate['body']['name'], - 'runtime' => 'php-8.0', + 'runtime' => 'node-22', 'execute' => $starterTemplate['body']['permissions'], 'entrypoint' => $phpRuntime['entrypoint'], 'events' => $starterTemplate['body']['events'], @@ -521,7 +521,7 @@ class FunctionsCustomServerTest extends Scope $this->assertNotEmpty($deployment['body']['$id']); $this->assertEquals('waiting', $deployment['body']['status']); $this->assertEquals(true, (new DatetimeValidator())->isValid($deployment['body']['$createdAt'])); - $this->assertEquals('index.php', $deployment['body']['entrypoint']); + $this->assertEquals('index.js', $deployment['body']['entrypoint']); $deploymentIdActive = $deployment['body']['$id'] ?? ''; @@ -581,7 +581,7 @@ class FunctionsCustomServerTest extends Scope $this->assertEquals(202, $deployment['headers']['status-code']); $this->assertNotEmpty($deployment['body']['$id']); $this->assertEquals(true, (new DatetimeValidator())->isValid($deployment['body']['$createdAt'])); - $this->assertEquals('index.php', $deployment['body']['entrypoint']); + $this->assertEquals('index.js', $deployment['body']['entrypoint']); $this->assertEventually(function () use ($functionId, $deploymentId) { $deployment = $this->getDeployment($functionId, $deploymentId); @@ -617,7 +617,7 @@ class FunctionsCustomServerTest extends Scope */ $functionId = $data['functionId']; - $folder = 'php-large'; + $folder = 'large'; $code = realpath(__DIR__ . '/../../../resources/functions') . "/$folder/code.tar.gz"; Console::execute('cd ' . realpath(__DIR__ . "/../../../resources/functions") . "/$folder && tar --exclude code.tar.gz -czf code.tar.gz .", '', $this->stdout, $this->stderr); @@ -632,13 +632,13 @@ class FunctionsCustomServerTest extends Scope ]; $id = ''; while (!feof($handle)) { - $curlFile = new \CURLFile('data://' . $mimeType . ';base64,' . base64_encode(@fread($handle, $chunkSize)), $mimeType, 'php-large-fx.tar.gz'); + $curlFile = new \CURLFile('data://' . $mimeType . ';base64,' . base64_encode(@fread($handle, $chunkSize)), $mimeType, 'large-fx.tar.gz'); $headers['content-range'] = 'bytes ' . ($counter * $chunkSize) . '-' . min(((($counter * $chunkSize) + $chunkSize) - 1), $size - 1) . '/' . $size; if (!empty($id)) { $headers['x-appwrite-id'] = $id; } $largeTag = $this->client->call(Client::METHOD_POST, '/functions/' . $functionId . '/deployments', array_merge($headers, $this->getHeaders()), [ - 'entrypoint' => 'index.php', + 'entrypoint' => 'index.js', 'code' => $curlFile, 'activate' => true, 'commands' => 'cp blue.mp4 copy.mp4 && ls -al' // +7MB buildSize @@ -651,7 +651,7 @@ class FunctionsCustomServerTest extends Scope $this->assertEquals(202, $largeTag['headers']['status-code']); $this->assertNotEmpty($largeTag['body']['$id']); $this->assertEquals(true, (new DatetimeValidator())->isValid($largeTag['body']['$createdAt'])); - $this->assertEquals('index.php', $largeTag['body']['entrypoint']); + $this->assertEquals('index.js', $largeTag['body']['entrypoint']); $this->assertGreaterThan(1024 * 1024 * 5, $largeTag['body']['sourceSize']); // ~7MB video file $this->assertLessThan(1024 * 1024 * 10, $largeTag['body']['sourceSize']); // ~7MB video file @@ -1119,8 +1119,8 @@ class FunctionsCustomServerTest extends Scope 'users.*.update.email', ], 'timeout' => 15, - 'runtime' => 'php-8.0', - 'entrypoint' => 'index.php', + 'runtime' => 'node-22', + 'entrypoint' => 'index.js', 'specification' => Specification::S_1VCPU_1GB, ]); @@ -1147,8 +1147,8 @@ class FunctionsCustomServerTest extends Scope 'users.*.update.email', ], 'timeout' => 15, - 'runtime' => 'php-8.0', - 'entrypoint' => 'index.php', + 'runtime' => 'node-22', + 'entrypoint' => 'index.js', 'specification' => Specification::S_1VCPU_512MB, ]); @@ -1177,8 +1177,8 @@ class FunctionsCustomServerTest extends Scope 'users.*.update.email', ], 'timeout' => 15, - 'runtime' => 'php-8.0', - 'entrypoint' => 'index.php', + 'runtime' => 'node-22', + 'entrypoint' => 'index.js', 'specification' => 's-2vcpu-512mb', // Invalid specification ]); @@ -1279,12 +1279,12 @@ class FunctionsCustomServerTest extends Scope */ public function provideCustomExecutions(): array { + // Most disabled to keep tests fast return [ - ['folder' => 'php-fn', 'name' => 'php-8.0', 'entrypoint' => 'index.php', 'runtimeName' => 'PHP', 'runtimeVersion' => '8.0'], + // ['folder' => 'php-fn', 'name' => 'php-8.0', 'entrypoint' => 'index.php', 'runtimeName' => 'PHP', 'runtimeVersion' => '8.0'], ['folder' => 'node', 'name' => 'node-18.0', 'entrypoint' => 'index.js', 'runtimeName' => 'Node.js', 'runtimeVersion' => '18.0'], - ['folder' => 'python', 'name' => 'python-3.9', 'entrypoint' => 'main.py', 'runtimeName' => 'Python', 'runtimeVersion' => '3.9'], - ['folder' => 'ruby', 'name' => 'ruby-3.1', 'entrypoint' => 'main.rb', 'runtimeName' => 'Ruby', 'runtimeVersion' => '3.1'], - // Swift and Dart disabled on purpose, as it's very slow. + // ['folder' => 'python', 'name' => 'python-3.9', 'entrypoint' => 'main.py', 'runtimeName' => 'Python', 'runtimeVersion' => '3.9'], + // ['folder' => 'ruby', 'name' => 'ruby-3.1', 'entrypoint' => 'main.rb', 'runtimeName' => 'Ruby', 'runtimeVersion' => '3.1'], // [ 'folder' => 'dart', 'name' => 'dart-2.15', 'entrypoint' => 'main.dart', 'runtimeName' => 'Dart', 'runtimeVersion' => '2.15' ], // [ 'folder' => 'swift', 'name' => 'swift-5.5', 'entrypoint' => 'index.swift', 'runtimeName' => 'Swift', 'runtimeVersion' => '5.5' ], ]; @@ -1365,15 +1365,14 @@ class FunctionsCustomServerTest extends Scope { $functionId = $this->setupFunction([ 'functionId' => ID::unique(), - 'name' => 'Test PHP Binary executions', - 'runtime' => 'php-8.0', - 'entrypoint' => 'index.php', + 'name' => 'Test Binary executions', + 'runtime' => 'node-22', + 'entrypoint' => 'index.js', 'timeout' => 15, 'execute' => ['any'] ]); $this->setupDeployment($functionId, [ - 'entrypoint' => 'index.php', - 'code' => $this->packageFunction('php-binary-response'), + 'code' => $this->packageFunction('binary-response'), 'activate' => true ]); @@ -1414,15 +1413,14 @@ class FunctionsCustomServerTest extends Scope { $functionId = $this->setupFunction([ 'functionId' => ID::unique(), - 'name' => 'Test PHP Binary executions', - 'runtime' => 'php-8.0', - 'entrypoint' => 'index.php', + 'name' => 'Test Binary executions', + 'runtime' => 'node-22', + 'entrypoint' => 'index.js', 'timeout' => 15, 'execute' => ['any'] ]); $this->setupDeployment($functionId, [ - 'entrypoint' => 'index.php', - 'code' => $this->packageFunction('php-binary-request'), + 'code' => $this->packageFunction('binary-request'), 'activate' => true ]); @@ -1695,9 +1693,9 @@ class FunctionsCustomServerTest extends Scope { $functionId = $this->setupFunction([ 'functionId' => ID::unique(), - 'name' => 'Test PHP Binary executions', - 'runtime' => 'php-8.0', - 'entrypoint' => 'index.php', + 'name' => 'Test Binary executions', + 'runtime' => 'node-22', + 'entrypoint' => 'index.js', 'timeout' => 15, 'execute' => ['any'] ]); @@ -1705,8 +1703,7 @@ class FunctionsCustomServerTest extends Scope $domain = $this->setupFunctionDomain($functionId); $this->setupDeployment($functionId, [ - 'entrypoint' => 'index.php', - 'code' => $this->packageFunction('php-binary-response'), + 'code' => $this->packageFunction('binary-response'), 'activate' => true ]); @@ -1730,9 +1727,9 @@ class FunctionsCustomServerTest extends Scope { $functionId = $this->setupFunction([ 'functionId' => ID::unique(), - 'name' => 'Test PHP Binary executions', - 'runtime' => 'php-8.0', - 'entrypoint' => 'index.php', + 'name' => 'Test Binary executions', + 'runtime' => 'node-22', + 'entrypoint' => 'index.js', 'timeout' => 15, 'execute' => ['any'] ]); @@ -1740,8 +1737,7 @@ class FunctionsCustomServerTest extends Scope $domain = $this->setupFunctionDomain($functionId); $this->setupDeployment($functionId, [ - 'entrypoint' => 'index.php', - 'code' => $this->packageFunction('php-binary-request'), + 'code' => $this->packageFunction('binary-request'), 'activate' => true ]); @@ -1768,8 +1764,8 @@ class FunctionsCustomServerTest extends Scope ], $this->getHeaders()), [ 'functionId' => ID::unique(), 'name' => 'Test', - 'runtime' => 'php-8.0', - 'entrypoint' => 'index.php', + 'runtime' => 'node-22', + 'entrypoint' => 'index.js', 'timeout' => 15, ]); @@ -1803,8 +1799,8 @@ class FunctionsCustomServerTest extends Scope $function1Id = $this->setupFunction([ 'functionId' => ID::unique(), 'name' => 'Test', - 'runtime' => 'php-8.0', - 'entrypoint' => 'index.php', + 'runtime' => 'node-22', + 'entrypoint' => 'index.js', 'timeout' => 15, 'execute' => ['any'] ]); @@ -1812,8 +1808,8 @@ class FunctionsCustomServerTest extends Scope $function2Id = $this->setupFunction([ 'functionId' => ID::unique(), 'name' => 'Test2', - 'runtime' => 'php-8.0', - 'entrypoint' => 'index.php', + 'runtime' => 'node-22', + 'entrypoint' => 'index.js', 'timeout' => 15, 'execute' => ['any'] ]); diff --git a/tests/resources/functions/basic/index.js b/tests/resources/functions/basic/index.js index b35c2a724d..1eb9d38c58 100644 --- a/tests/resources/functions/basic/index.js +++ b/tests/resources/functions/basic/index.js @@ -3,9 +3,9 @@ module.exports = async(context) => { context.error('error-log-works'); if(context.req.headers['x-appwrite-user-jwt']) { - context.log('jwt-is-invalid'); - } else { context.log('jwt-is-valid'); + } else { + context.log('jwt-is-invalid'); } if(context.req.path === '/custom-response') { @@ -18,7 +18,7 @@ module.exports = async(context) => { context.log('custom-header-is-' + (context.req.headers['x-custom-header'] ?? '')); context.log('method-is-' + (context.req.method ?? '').toLowerCase()); context.log('path-is-' + (context.req.path ?? '')); - context.log('user-is-' + context.req.headers['x-appwrite-user-id'] ?? ''); + context.log('user-is-' + (context.req.headers['x-appwrite-user-id'] ?? '')); const statusCode = context.req.query['code'] || '200'; diff --git a/tests/resources/functions/binary-request/index.js b/tests/resources/functions/binary-request/index.js new file mode 100644 index 0000000000..227df8dce6 --- /dev/null +++ b/tests/resources/functions/binary-request/index.js @@ -0,0 +1,6 @@ +const crypto = require('crypto') + +module.exports = async(context) => { + const hash = crypto.createHash('md5').update(context.req.bodyBinary).digest("hex") + return context.res.send(hash); +}; diff --git a/tests/resources/functions/binary-response/index.js b/tests/resources/functions/binary-response/index.js new file mode 100644 index 0000000000..284a593df0 --- /dev/null +++ b/tests/resources/functions/binary-response/index.js @@ -0,0 +1,4 @@ +module.exports = async(context) => { + const bytes = Buffer.from(Uint8Array.from([0, 10, 255])); + return context.res.binary(bytes); +}; diff --git a/tests/resources/functions/php-large/blue.mp4 b/tests/resources/functions/large/blue.mp4 similarity index 100% rename from tests/resources/functions/php-large/blue.mp4 rename to tests/resources/functions/large/blue.mp4 diff --git a/tests/resources/functions/large/index.js b/tests/resources/functions/large/index.js new file mode 100644 index 0000000000..5e8719bcf3 --- /dev/null +++ b/tests/resources/functions/large/index.js @@ -0,0 +1,3 @@ +module.exports = async(context) => { + return context.res.empty(); +}; diff --git a/tests/resources/functions/php-binary-request/index.php b/tests/resources/functions/php-binary-request/index.php deleted file mode 100644 index 53df8705e5..0000000000 --- a/tests/resources/functions/php-binary-request/index.php +++ /dev/null @@ -1,6 +0,0 @@ -req->bodyBinary); - return $context->res->send($hash); -}; diff --git a/tests/resources/functions/php-binary-response/index.php b/tests/resources/functions/php-binary-response/index.php deleted file mode 100644 index 7715663388..0000000000 --- a/tests/resources/functions/php-binary-response/index.php +++ /dev/null @@ -1,6 +0,0 @@ -res->binary($bytes); -}; diff --git a/tests/resources/functions/php-large/composer.json b/tests/resources/functions/php-large/composer.json deleted file mode 100644 index e3c6db23e9..0000000000 --- a/tests/resources/functions/php-large/composer.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "name": "appwrite/cloud-function-demo", - "description": "Demo cloud function script", - "type": "library", - "license": "BSD-3-Clause", - "authors": [ - { - "name": "Team Appwrite", - "email": "team@appwrite.io" - } - ], - "require": { - "php": ">=7.4.0", - "ext-curl": "*", - "ext-json": "*", - "appwrite/appwrite": "1.1.*" - } -} diff --git a/tests/resources/functions/php-large/composer.lock b/tests/resources/functions/php-large/composer.lock deleted file mode 100644 index 758c73c3f9..0000000000 --- a/tests/resources/functions/php-large/composer.lock +++ /dev/null @@ -1,64 +0,0 @@ -{ - "_readme": [ - "This file locks the dependencies of your project to a known state", - "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", - "This file is @generated automatically" - ], - "content-hash": "afdff6a172e6c44aee11f1562175f81a", - "packages": [ - { - "name": "appwrite/appwrite", - "version": "1.1.2", - "source": { - "type": "git", - "url": "https://github.com/appwrite/sdk-for-php.git", - "reference": "98b327d3fd18a72f4582019916afd735a0e9e0e7" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/appwrite/sdk-for-php/zipball/98b327d3fd18a72f4582019916afd735a0e9e0e7", - "reference": "98b327d3fd18a72f4582019916afd735a0e9e0e7", - "shasum": "" - }, - "require": { - "ext-curl": "*", - "ext-json": "*", - "php": ">=7.1.0" - }, - "require-dev": { - "phpunit/phpunit": "3.7.35" - }, - "type": "library", - "autoload": { - "psr-4": { - "Appwrite\\": "src/Appwrite" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "description": "Appwrite is an open-source backend as a service server that abstract and simplify complex and repetitive development tasks", - "support": { - "email": "team@localhost.test", - "issues": "https://github.com/appwrite/sdk-for-php/issues", - "source": "https://github.com/appwrite/sdk-for-php/tree/1.1.2", - "url": "https://appwrite.io/support" - }, - "time": "2020-08-15T18:24:32+00:00" - } - ], - "packages-dev": [], - "aliases": [], - "minimum-stability": "stable", - "stability-flags": [], - "prefer-stable": false, - "prefer-lowest": false, - "platform": { - "php": ">=7.4.0", - "ext-curl": "*", - "ext-json": "*" - }, - "platform-dev": [], - "plugin-api-version": "2.0.0" -} diff --git a/tests/resources/functions/php-large/index.php b/tests/resources/functions/php-large/index.php deleted file mode 100644 index abcb2e53d9..0000000000 --- a/tests/resources/functions/php-large/index.php +++ /dev/null @@ -1,16 +0,0 @@ -res->json([ - 'APPWRITE_FUNCTION_ID' => \getenv('APPWRITE_FUNCTION_ID') ?: '', - 'APPWRITE_FUNCTION_NAME' => \getenv('APPWRITE_FUNCTION_NAME') ?: '', - 'APPWRITE_FUNCTION_DEPLOYMENT' => \getenv('APPWRITE_FUNCTION_DEPLOYMENT') ?: '', - 'APPWRITE_FUNCTION_TRIGGER' => $context->req->headers['x-appwrite-trigger'] ?? '', - 'APPWRITE_FUNCTION_RUNTIME_NAME' => \getenv('APPWRITE_FUNCTION_RUNTIME_NAME') ?: '', - 'APPWRITE_FUNCTION_RUNTIME_VERSION' => \getenv('APPWRITE_FUNCTION_RUNTIME_VERSION') ?: '', - 'APPWRITE_REGION' => \getenv('APPWRITE_REGION') ?: '', - 'APPWRITE_FUNCTION_CPUS' => \getenv('APPWRITE_FUNCTION_CPUS') ?: '', - 'APPWRITE_FUNCTION_MEMORY' => \getenv('APPWRITE_FUNCTION_MEMORY') ?: '', - 'UNICODE_TEST' => "êä" - ]); -};