mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Merge branch '1.6.1' into feat-string-attribute-resizing
# Conflicts: # app/config/specs/open-api3-latest-console.json # app/config/specs/open-api3-latest-server.json # app/config/specs/swagger2-latest-console.json # app/config/specs/swagger2-latest-server.json # composer.lock
This commit is contained in:
Binary file not shown.
Binary file not shown.
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -392,7 +392,7 @@ App::post('/v1/account')
|
||||
$existingTarget = $dbForProject->findOne('targets', [
|
||||
Query::equal('identifier', [$email]),
|
||||
]);
|
||||
if($existingTarget) {
|
||||
if ($existingTarget) {
|
||||
$user->setAttribute('targets', $existingTarget, Document::SET_TYPE_APPEND);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -296,7 +296,7 @@ App::post('/v1/functions')
|
||||
if (!empty($providerRepositoryId)) {
|
||||
// Deploy VCS
|
||||
$redeployVcs($request, $function, $project, $installation, $dbForProject, $queueForBuilds, $template, $github);
|
||||
} elseif(!$template->isEmpty()) {
|
||||
} elseif (!$template->isEmpty()) {
|
||||
// Deploy non-VCS from template
|
||||
$deploymentId = ID::unique();
|
||||
$deployment = $dbForProject->createDocument('deployments', new Document([
|
||||
@@ -1152,6 +1152,7 @@ App::post('/v1/functions/:functionId/deployments')
|
||||
->label('sdk.auth', [APP_AUTH_TYPE_KEY])
|
||||
->label('sdk.namespace', 'functions')
|
||||
->label('sdk.method', 'createDeployment')
|
||||
->label('sdk.methodType', 'upload')
|
||||
->label('sdk.description', '/docs/references/functions/create-deployment.md')
|
||||
->label('sdk.packaging', true)
|
||||
->label('sdk.request.type', 'multipart/form-data')
|
||||
@@ -1580,7 +1581,7 @@ App::post('/v1/functions/:functionId/deployments/:deploymentId/build')
|
||||
}
|
||||
|
||||
$path = $deployment->getAttribute('path');
|
||||
if(empty($path) || !$deviceForFunctions->exists($path)) {
|
||||
if (empty($path) || !$deviceForFunctions->exists($path)) {
|
||||
throw new Exception(Exception::DEPLOYMENT_NOT_FOUND);
|
||||
}
|
||||
|
||||
@@ -1734,7 +1735,7 @@ App::post('/v1/functions/:functionId/executions')
|
||||
->inject('geodb')
|
||||
->action(function (string $functionId, string $body, bool $async, string $path, string $method, mixed $headers, ?string $scheduledAt, Response $response, Request $request, Document $project, Database $dbForProject, Database $dbForConsole, Document $user, Event $queueForEvents, Usage $queueForUsage, Func $queueForFunctions, Reader $geodb) {
|
||||
|
||||
if(!$async && !is_null($scheduledAt)) {
|
||||
if (!$async && !is_null($scheduledAt)) {
|
||||
throw new Exception(Exception::GENERAL_BAD_REQUEST, 'Scheduled executions must run asynchronously. Set scheduledAt to a future date, or set async to true.');
|
||||
}
|
||||
|
||||
@@ -1867,7 +1868,7 @@ App::post('/v1/functions/:functionId/executions')
|
||||
|
||||
$status = $async ? 'waiting' : 'processing';
|
||||
|
||||
if(!is_null($scheduledAt)) {
|
||||
if (!is_null($scheduledAt)) {
|
||||
$status = 'scheduled';
|
||||
}
|
||||
|
||||
@@ -1897,7 +1898,7 @@ App::post('/v1/functions/:functionId/executions')
|
||||
->setContext('function', $function);
|
||||
|
||||
if ($async) {
|
||||
if(is_null($scheduledAt)) {
|
||||
if (is_null($scheduledAt)) {
|
||||
$execution = Authorization::skip(fn () => $dbForProject->createDocument('executions', $execution));
|
||||
$queueForFunctions
|
||||
->setType('http')
|
||||
@@ -2076,7 +2077,7 @@ App::post('/v1/functions/:functionId/executions')
|
||||
|
||||
$acceptTypes = \explode(', ', $request->getHeader('accept'));
|
||||
foreach ($acceptTypes as $acceptType) {
|
||||
if(\str_starts_with($acceptType, 'application/json') || \str_starts_with($acceptType, 'application/*')) {
|
||||
if (\str_starts_with($acceptType, 'application/json') || \str_starts_with($acceptType, 'application/*')) {
|
||||
$response->setContentType(Response::CONTENT_TYPE_JSON);
|
||||
break;
|
||||
} elseif (\str_starts_with($acceptType, 'multipart/form-data') || \str_starts_with($acceptType, 'multipart/*')) {
|
||||
|
||||
@@ -140,7 +140,7 @@ function createUser(string $hash, mixed $hashOptions, string $userId, ?string $e
|
||||
$existingTarget = $dbForProject->findOne('targets', [
|
||||
Query::equal('identifier', [$email]),
|
||||
]);
|
||||
if($existingTarget) {
|
||||
if ($existingTarget) {
|
||||
$user->setAttribute('targets', $existingTarget, Document::SET_TYPE_APPEND);
|
||||
}
|
||||
}
|
||||
@@ -164,7 +164,7 @@ function createUser(string $hash, mixed $hashOptions, string $userId, ?string $e
|
||||
$existingTarget = $dbForProject->findOne('targets', [
|
||||
Query::equal('identifier', [$phone]),
|
||||
]);
|
||||
if($existingTarget) {
|
||||
if ($existingTarget) {
|
||||
$user->setAttribute('targets', $existingTarget, Document::SET_TYPE_APPEND);
|
||||
}
|
||||
}
|
||||
@@ -2124,7 +2124,7 @@ App::post('/v1/users/:userId/jwts')
|
||||
$sessions = $user->getAttribute('sessions', []);
|
||||
$session = new Document();
|
||||
|
||||
if($sessionId === 'recent') {
|
||||
if ($sessionId === 'recent') {
|
||||
// Get most recent
|
||||
$session = \count($sessions) > 0 ? $sessions[\count($sessions) - 1] : new Document();
|
||||
} else {
|
||||
|
||||
@@ -509,7 +509,7 @@ App::get('/v1/vcs/github/installations/:installationId/providerRepositories/:pro
|
||||
$vcsContents = [];
|
||||
foreach ($contents as $content) {
|
||||
$isDirectory = false;
|
||||
if($content['type'] === GitHub::CONTENTS_DIRECTORY) {
|
||||
if ($content['type'] === GitHub::CONTENTS_DIRECTORY) {
|
||||
$isDirectory = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -330,7 +330,16 @@ function router(App $utopia, Database $dbForConsole, callable $getProjectDB, Swo
|
||||
throw $th;
|
||||
}
|
||||
} finally {
|
||||
$fileSize = 0;
|
||||
$file = $request->getFiles('file');
|
||||
if (!empty($file)) {
|
||||
$fileSize = (\is_array($file['size']) && isset($file['size'][0])) ? $file['size'][0] : $file['size'];
|
||||
}
|
||||
|
||||
$queueForUsage
|
||||
->addMetric(METRIC_NETWORK_REQUESTS, 1)
|
||||
->addMetric(METRIC_NETWORK_INBOUND, $request->getSize() + $fileSize)
|
||||
->addMetric(METRIC_NETWORK_OUTBOUND, $response->getSize())
|
||||
->addMetric(METRIC_EXECUTIONS, 1)
|
||||
->addMetric(str_replace('{functionInternalId}', $function->getInternalId(), METRIC_FUNCTION_ID_EXECUTIONS), 1)
|
||||
->addMetric(METRIC_EXECUTIONS_COMPUTE, (int)($execution->getAttribute('duration') * 1000)) // per project
|
||||
|
||||
@@ -207,14 +207,14 @@ App::init()
|
||||
}
|
||||
|
||||
// Remove after migration
|
||||
if(!\str_contains($apiKey, '_')) {
|
||||
if (!\str_contains($apiKey, '_')) {
|
||||
$keyType = API_KEY_STANDARD;
|
||||
$authKey = $apiKey;
|
||||
} else {
|
||||
[ $keyType, $authKey ] = \explode('_', $apiKey, 2);
|
||||
}
|
||||
|
||||
if($keyType === API_KEY_DYNAMIC) {
|
||||
if ($keyType === API_KEY_DYNAMIC) {
|
||||
// Dynamic key
|
||||
|
||||
$jwtObj = new JWT(System::getEnv('_APP_OPENSSL_KEY_V1'), 'HS256', 3600, 0);
|
||||
@@ -244,7 +244,7 @@ App::init()
|
||||
Authorization::setRole(Auth::USER_ROLE_APPS);
|
||||
Authorization::setDefaultStatus(false); // Cancel security segmentation for API keys.
|
||||
}
|
||||
} elseif($keyType === API_KEY_STANDARD) {
|
||||
} elseif ($keyType === API_KEY_STANDARD) {
|
||||
// No underline means no prefix. Backwards compatibility.
|
||||
// Regular key
|
||||
|
||||
|
||||
+3
-3
@@ -791,7 +791,7 @@ $register->set('logger', function () {
|
||||
$adapter = null;
|
||||
}
|
||||
|
||||
if($adapter === null) {
|
||||
if ($adapter === null) {
|
||||
Console::error("Logging provider not supported. Logging is disabled");
|
||||
return;
|
||||
}
|
||||
@@ -1018,7 +1018,7 @@ $register->set('smtp', function () {
|
||||
return $mail;
|
||||
});
|
||||
$register->set('geodb', function () {
|
||||
return new Reader(__DIR__ . '/assets/dbip/dbip-country-lite-2024-08.mmdb');
|
||||
return new Reader(__DIR__ . '/assets/dbip/dbip-country-lite-2024-09.mmdb');
|
||||
});
|
||||
$register->set('passwordsDictionary', function () {
|
||||
$content = \file_get_contents(__DIR__ . '/assets/security/10k-common-passwords');
|
||||
@@ -1267,7 +1267,7 @@ App::setResource('user', function ($mode, $project, $console, $request, $respons
|
||||
}
|
||||
|
||||
$jwtSessionId = $payload['sessionId'] ?? '';
|
||||
if(!empty($jwtSessionId)) {
|
||||
if (!empty($jwtSessionId)) {
|
||||
if (empty($user->find('$id', $jwtSessionId, 'sessions'))) { // Match JWT to active token
|
||||
$user = new Document([]);
|
||||
}
|
||||
|
||||
Generated
+38
-38
@@ -1723,16 +1723,16 @@
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/database",
|
||||
"version": "0.53.2",
|
||||
"version": "0.53.3",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/utopia-php/database.git",
|
||||
"reference": "87fa42f15e9ff43bcb6523f5f8be4b53ad4bbb78"
|
||||
"reference": "24b29bcac7eb7a8b81698a80bb75fc5909f4975e"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/utopia-php/database/zipball/87fa42f15e9ff43bcb6523f5f8be4b53ad4bbb78",
|
||||
"reference": "87fa42f15e9ff43bcb6523f5f8be4b53ad4bbb78",
|
||||
"url": "https://api.github.com/repos/utopia-php/database/zipball/24b29bcac7eb7a8b81698a80bb75fc5909f4975e",
|
||||
"reference": "24b29bcac7eb7a8b81698a80bb75fc5909f4975e",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -1773,9 +1773,9 @@
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/utopia-php/database/issues",
|
||||
"source": "https://github.com/utopia-php/database/tree/0.53.2"
|
||||
"source": "https://github.com/utopia-php/database/tree/0.53.3"
|
||||
},
|
||||
"time": "2024-08-30T10:14:51+00:00"
|
||||
"time": "2024-09-02T06:28:50+00:00"
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/domains",
|
||||
@@ -2599,16 +2599,16 @@
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/storage",
|
||||
"version": "0.18.4",
|
||||
"version": "0.18.5",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/utopia-php/storage.git",
|
||||
"reference": "94ab8758fabcefee5c5fa723616e45719833f922"
|
||||
"reference": "7d355c5e3ccc8ecebc0266f8ddd30088a43be919"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/utopia-php/storage/zipball/94ab8758fabcefee5c5fa723616e45719833f922",
|
||||
"reference": "94ab8758fabcefee5c5fa723616e45719833f922",
|
||||
"url": "https://api.github.com/repos/utopia-php/storage/zipball/7d355c5e3ccc8ecebc0266f8ddd30088a43be919",
|
||||
"reference": "7d355c5e3ccc8ecebc0266f8ddd30088a43be919",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -2648,9 +2648,9 @@
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/utopia-php/storage/issues",
|
||||
"source": "https://github.com/utopia-php/storage/tree/0.18.4"
|
||||
"source": "https://github.com/utopia-php/storage/tree/0.18.5"
|
||||
},
|
||||
"time": "2024-04-02T08:24:09+00:00"
|
||||
"time": "2024-09-04T08:57:27+00:00"
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/swoole",
|
||||
@@ -3314,16 +3314,16 @@
|
||||
},
|
||||
{
|
||||
"name": "laravel/pint",
|
||||
"version": "v1.17.2",
|
||||
"version": "v1.17.3",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/laravel/pint.git",
|
||||
"reference": "e8a88130a25e3f9d4d5785e6a1afca98268ab110"
|
||||
"reference": "9d77be916e145864f10788bb94531d03e1f7b482"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/laravel/pint/zipball/e8a88130a25e3f9d4d5785e6a1afca98268ab110",
|
||||
"reference": "e8a88130a25e3f9d4d5785e6a1afca98268ab110",
|
||||
"url": "https://api.github.com/repos/laravel/pint/zipball/9d77be916e145864f10788bb94531d03e1f7b482",
|
||||
"reference": "9d77be916e145864f10788bb94531d03e1f7b482",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -3334,13 +3334,13 @@
|
||||
"php": "^8.1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"friendsofphp/php-cs-fixer": "^3.61.1",
|
||||
"illuminate/view": "^10.48.18",
|
||||
"friendsofphp/php-cs-fixer": "^3.64.0",
|
||||
"illuminate/view": "^10.48.20",
|
||||
"larastan/larastan": "^2.9.8",
|
||||
"laravel-zero/framework": "^10.4.0",
|
||||
"mockery/mockery": "^1.6.12",
|
||||
"nunomaduro/termwind": "^1.15.1",
|
||||
"pestphp/pest": "^2.35.0"
|
||||
"pestphp/pest": "^2.35.1"
|
||||
},
|
||||
"bin": [
|
||||
"builds/pint"
|
||||
@@ -3376,7 +3376,7 @@
|
||||
"issues": "https://github.com/laravel/pint/issues",
|
||||
"source": "https://github.com/laravel/pint"
|
||||
},
|
||||
"time": "2024-08-06T15:11:54+00:00"
|
||||
"time": "2024-09-03T15:00:28+00:00"
|
||||
},
|
||||
{
|
||||
"name": "matthiasmullie/minify",
|
||||
@@ -5865,16 +5865,16 @@
|
||||
},
|
||||
{
|
||||
"name": "symfony/console",
|
||||
"version": "v7.1.3",
|
||||
"version": "v7.1.4",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/console.git",
|
||||
"reference": "cb1dcb30ebc7005c29864ee78adb47b5fb7c3cd9"
|
||||
"reference": "1eed7af6961d763e7832e874d7f9b21c3ea9c111"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/console/zipball/cb1dcb30ebc7005c29864ee78adb47b5fb7c3cd9",
|
||||
"reference": "cb1dcb30ebc7005c29864ee78adb47b5fb7c3cd9",
|
||||
"url": "https://api.github.com/repos/symfony/console/zipball/1eed7af6961d763e7832e874d7f9b21c3ea9c111",
|
||||
"reference": "1eed7af6961d763e7832e874d7f9b21c3ea9c111",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -5938,7 +5938,7 @@
|
||||
"terminal"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/console/tree/v7.1.3"
|
||||
"source": "https://github.com/symfony/console/tree/v7.1.4"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
@@ -5954,7 +5954,7 @@
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2024-07-26T12:41:01+00:00"
|
||||
"time": "2024-08-15T22:48:53+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/deprecation-contracts",
|
||||
@@ -6091,16 +6091,16 @@
|
||||
},
|
||||
{
|
||||
"name": "symfony/finder",
|
||||
"version": "v7.1.3",
|
||||
"version": "v7.1.4",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/finder.git",
|
||||
"reference": "717c6329886f32dc65e27461f80f2a465412fdca"
|
||||
"reference": "d95bbf319f7d052082fb7af147e0f835a695e823"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/finder/zipball/717c6329886f32dc65e27461f80f2a465412fdca",
|
||||
"reference": "717c6329886f32dc65e27461f80f2a465412fdca",
|
||||
"url": "https://api.github.com/repos/symfony/finder/zipball/d95bbf319f7d052082fb7af147e0f835a695e823",
|
||||
"reference": "d95bbf319f7d052082fb7af147e0f835a695e823",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -6135,7 +6135,7 @@
|
||||
"description": "Finds files and directories via an intuitive fluent interface",
|
||||
"homepage": "https://symfony.com",
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/finder/tree/v7.1.3"
|
||||
"source": "https://github.com/symfony/finder/tree/v7.1.4"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
@@ -6151,7 +6151,7 @@
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2024-07-24T07:08:44+00:00"
|
||||
"time": "2024-08-13T14:28:19+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/options-resolver",
|
||||
@@ -6604,16 +6604,16 @@
|
||||
},
|
||||
{
|
||||
"name": "symfony/string",
|
||||
"version": "v7.1.3",
|
||||
"version": "v7.1.4",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/string.git",
|
||||
"reference": "ea272a882be7f20cad58d5d78c215001617b7f07"
|
||||
"reference": "6cd670a6d968eaeb1c77c2e76091c45c56bc367b"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/string/zipball/ea272a882be7f20cad58d5d78c215001617b7f07",
|
||||
"reference": "ea272a882be7f20cad58d5d78c215001617b7f07",
|
||||
"url": "https://api.github.com/repos/symfony/string/zipball/6cd670a6d968eaeb1c77c2e76091c45c56bc367b",
|
||||
"reference": "6cd670a6d968eaeb1c77c2e76091c45c56bc367b",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -6671,7 +6671,7 @@
|
||||
"utf8"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/string/tree/v7.1.3"
|
||||
"source": "https://github.com/symfony/string/tree/v7.1.4"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
@@ -6687,7 +6687,7 @@
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2024-07-22T10:25:37+00:00"
|
||||
"time": "2024-08-12T09:59:40+00:00"
|
||||
},
|
||||
{
|
||||
"name": "textalk/websocket",
|
||||
|
||||
@@ -6,6 +6,7 @@ use Appwrite\Functions\Specification;
|
||||
use Appwrite\Tests\Retry;
|
||||
use CURLFile;
|
||||
use DateTime;
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
use Tests\E2E\Client;
|
||||
use Tests\E2E\Scopes\ProjectCustom;
|
||||
use Tests\E2E\Scopes\Scope;
|
||||
@@ -13,6 +14,7 @@ use Tests\E2E\Scopes\SideServer;
|
||||
use Tests\E2E\Services\Functions\FunctionsBase;
|
||||
use Utopia\Database\Helpers\Permission;
|
||||
use Utopia\Database\Helpers\Role;
|
||||
use Utopia\Database\Query;
|
||||
use Utopia\Database\Validator\Datetime as DatetimeValidator;
|
||||
|
||||
class UsageTest extends Scope
|
||||
@@ -761,7 +763,7 @@ class UsageTest extends Scope
|
||||
|
||||
/** @depends testPrepareFunctionsStats */
|
||||
#[Retry(count: 1)]
|
||||
public function testFunctionsStats(array $data): void
|
||||
public function testFunctionsStats(array $data): array
|
||||
{
|
||||
$functionId = $data['functionId'];
|
||||
$executionTime = $data['executionTime'];
|
||||
@@ -818,6 +820,126 @@ class UsageTest extends Scope
|
||||
$this->validateDates($response['body']['executionsTime']);
|
||||
$this->assertGreaterThan(0, $response['body']['buildsTime'][array_key_last($response['body']['buildsTime'])]['value']);
|
||||
$this->validateDates($response['body']['buildsTime']);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/** @depends testFunctionsStats */
|
||||
public function testCustomDomainsFunctionStats(array $data): void
|
||||
{
|
||||
$functionId = $data['functionId'];
|
||||
|
||||
$response = $this->client->call(Client::METHOD_PUT, '/functions/' . $functionId, array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id']
|
||||
], $this->getHeaders()), [
|
||||
'name' => 'Test',
|
||||
'execute' => ['any']
|
||||
]);
|
||||
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
|
||||
$rules = $this->client->call(Client::METHOD_GET, '/proxy/rules', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'queries' => [
|
||||
Query::equal('resourceId', [$functionId])->toString(),
|
||||
Query::equal('resourceType', ['function'])->toString(),
|
||||
],
|
||||
]);
|
||||
|
||||
$this->assertEquals(200, $rules['headers']['status-code']);
|
||||
$this->assertEquals(1, $rules['body']['total']);
|
||||
$this->assertCount(1, $rules['body']['rules']);
|
||||
$this->assertNotEmpty($rules['body']['rules'][0]['domain']);
|
||||
|
||||
$domain = $rules['body']['rules'][0]['domain'];
|
||||
|
||||
$response = $this->client->call(
|
||||
Client::METHOD_GET,
|
||||
'/functions/' . $functionId . '/usage?range=30d',
|
||||
$this->getConsoleHeaders()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertEquals(19, count($response['body']));
|
||||
$this->assertEquals('30d', $response['body']['range']);
|
||||
|
||||
$functionsMetrics = $response['body'];
|
||||
|
||||
$response = $this->client->call(
|
||||
Client::METHOD_GET,
|
||||
'/project/usage',
|
||||
$this->getConsoleHeaders(),
|
||||
[
|
||||
'period' => '1h',
|
||||
'startDate' => self::getToday(),
|
||||
'endDate' => self::getTomorrow(),
|
||||
]
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
|
||||
$projectMetrics = $response['body'];
|
||||
|
||||
// Create custom domain execution
|
||||
$proxyClient = new Client();
|
||||
$proxyClient->setEndpoint('http://' . $domain);
|
||||
|
||||
$response = $proxyClient->call(Client::METHOD_GET, '/', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id']
|
||||
]));
|
||||
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
|
||||
sleep(self::WAIT + 20);
|
||||
$tries = 0;
|
||||
|
||||
while (true) {
|
||||
try {
|
||||
// Compare new values with old values
|
||||
$response = $this->client->call(
|
||||
Client::METHOD_GET,
|
||||
'/functions/' . $functionId . '/usage?range=30d',
|
||||
$this->getConsoleHeaders()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertEquals(19, count($response['body']));
|
||||
$this->assertEquals('30d', $response['body']['range']);
|
||||
|
||||
// Check if the new values are greater than the old values
|
||||
$this->assertEquals($functionsMetrics['executionsTotal'] + 1, $response['body']['executionsTotal']);
|
||||
$this->assertGreaterThan($functionsMetrics['executionsTimeTotal'], $response['body']['executionsTimeTotal']);
|
||||
$this->assertGreaterThan($functionsMetrics['executionsMbSecondsTotal'], $response['body']['executionsMbSecondsTotal']);
|
||||
|
||||
$response = $this->client->call(
|
||||
Client::METHOD_GET,
|
||||
'/project/usage',
|
||||
$this->getConsoleHeaders(),
|
||||
[
|
||||
'period' => '1h',
|
||||
'startDate' => self::getToday(),
|
||||
'endDate' => self::getTomorrow(),
|
||||
]
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertEquals($projectMetrics['executionsTotal'] + 1, $response['body']['executionsTotal']);
|
||||
$this->assertGreaterThan($projectMetrics['executionsMbSecondsTotal'], $response['body']['executionsMbSecondsTotal']);
|
||||
|
||||
break;
|
||||
} catch (ExpectationFailedException $th) {
|
||||
if ($tries >= 5) {
|
||||
throw $th;
|
||||
} else {
|
||||
$tries++;
|
||||
sleep(5);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace Tests\E2E\Services\Functions;
|
||||
use Appwrite\Functions\Specification;
|
||||
use Appwrite\Tests\Retry;
|
||||
use CURLFile;
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
use Tests\E2E\Client;
|
||||
use Tests\E2E\Scopes\ProjectCustom;
|
||||
use Tests\E2E\Scopes\Scope;
|
||||
@@ -2435,16 +2436,31 @@ class FunctionsCustomServerTest extends Scope
|
||||
// Await Aggregation
|
||||
sleep(App::getEnv('_APP_USAGE_AGGREGATION_INTERVAL', 30));
|
||||
|
||||
$response = $this->client->call(Client::METHOD_GET, '/functions/' . $functionId . '/usage', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id']
|
||||
], $this->getHeaders()), [
|
||||
'range' => '24h'
|
||||
]);
|
||||
$tries = 0;
|
||||
while (true) {
|
||||
try {
|
||||
$response = $this->client->call(Client::METHOD_GET, '/functions/' . $functionId . '/usage', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id']
|
||||
], $this->getHeaders()), [
|
||||
'range' => '24h'
|
||||
]);
|
||||
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertEquals(19, count($response['body']));
|
||||
$this->assertEquals('24h', $response['body']['range']);
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertEquals(19, count($response['body']));
|
||||
$this->assertEquals('24h', $response['body']['range']);
|
||||
$this->assertEquals(1, $response['body']['executionsTotal']);
|
||||
|
||||
break;
|
||||
} catch (ExpectationFailedException $th) {
|
||||
if ($tries >= 5) {
|
||||
throw $th;
|
||||
} else {
|
||||
$tries++;
|
||||
sleep(5);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Cleanup : Delete function
|
||||
$response = $this->client->call(Client::METHOD_DELETE, '/functions/' . $functionId, [
|
||||
|
||||
@@ -27,19 +27,19 @@ final class HeadersBench
|
||||
yield 'empty' => [ 'value' => [] ];
|
||||
|
||||
$value = [];
|
||||
for($i = 0; $i < 10; $i++) {
|
||||
for ($i = 0; $i < 10; $i++) {
|
||||
$value[bin2hex(random_bytes(8))] = bin2hex(random_bytes(8));
|
||||
}
|
||||
yield 'items_10-size_320' => [ 'value' => $value ];
|
||||
|
||||
$value = [];
|
||||
for($i = 0; $i < 100; $i++) {
|
||||
for ($i = 0; $i < 100; $i++) {
|
||||
$value[bin2hex(random_bytes(8))] = bin2hex(random_bytes(8));
|
||||
}
|
||||
yield 'items_100-size_3200' => [ 'value' => $value ];
|
||||
|
||||
$value = [];
|
||||
for($i = 0; $i < 100; $i++) {
|
||||
for ($i = 0; $i < 100; $i++) {
|
||||
$value[bin2hex(random_bytes(32))] = bin2hex(random_bytes(32));
|
||||
}
|
||||
yield 'items_100-size_12800' => [ 'value' => $value ];
|
||||
@@ -53,7 +53,7 @@ final class HeadersBench
|
||||
public function benchHeadersValidator(array $data): void
|
||||
{
|
||||
$assertion = $this->validator->isValid($data['value']);
|
||||
if(!$assertion) {
|
||||
if (!$assertion) {
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ class HeadersTest extends TestCase
|
||||
$this->assertTrue($this->object->isValid($headers));
|
||||
|
||||
$headers = [];
|
||||
for($i = 0; $i < 100; $i++) {
|
||||
for ($i = 0; $i < 100; $i++) {
|
||||
$headers['key-' . $i] = 'value_' . $i;
|
||||
}
|
||||
$this->assertTrue($this->object->isValid($headers));
|
||||
|
||||
Reference in New Issue
Block a user