mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Some changes
This commit is contained in:
@@ -3587,7 +3587,7 @@ $collections = [
|
||||
'filters' => ['json'],
|
||||
],
|
||||
[
|
||||
'$id' => ID::custom('route'),
|
||||
'$id' => ID::custom('path'),
|
||||
'type' => Database::VAR_STRING,
|
||||
'format' => '',
|
||||
'size' => 2500,
|
||||
|
||||
@@ -157,7 +157,7 @@ App::init()
|
||||
->inject('request')
|
||||
->inject('dbForProject')
|
||||
->action(function (Request $request, Database $dbForProject) {
|
||||
var_dump("App::init()");
|
||||
var_dump("App::init() start -------------------------------------");
|
||||
$queries = $request->getParam('queries'); // validate malicious
|
||||
$uri = $request->getURI();
|
||||
$key = md5(json_encode([$uri, $queries]));
|
||||
@@ -165,11 +165,12 @@ App::init()
|
||||
var_dump($queries);
|
||||
/* @var $document Document */
|
||||
$document = Authorization::skip(fn() => $dbForProject->getDocument('timeouts', $key));
|
||||
var_dump($document);
|
||||
if (!$document->isEmpty() && $document->getAttribute('blocked') === true) {
|
||||
var_dump("document->isEmpty()");
|
||||
var_dump($document);
|
||||
var_dump("App::init() Exception::TIMEOUT_ROUTE_BLOCKED -------------------------------------");
|
||||
throw new Exception(Exception::TIMEOUT_ROUTE_BLOCKED);
|
||||
}
|
||||
var_dump("App::init() end -------------------------------------");
|
||||
});
|
||||
|
||||
App::error()
|
||||
@@ -179,11 +180,10 @@ App::error()
|
||||
->inject('request')
|
||||
->inject('dbForProject')
|
||||
->action(function (App $utopia, throwable $error, Request $request, Database $dbForProject) {
|
||||
var_dump("App::error");
|
||||
var_dump("getCode=" . $error->getCode());
|
||||
var_dump($error->getMessage());
|
||||
if ($error instanceof Timeout) {
|
||||
var_dump("App::error() in in in in in in in in in in in in in");
|
||||
var_dump("start App::error -------------------------------------");
|
||||
var_dump("getCode=" . $error->getCode());
|
||||
var_dump($error->getMessage());
|
||||
var_dump($request->getParams());
|
||||
$queries = $request->getParam('queries'); // validate malicious
|
||||
$uri = $request->getURI();
|
||||
@@ -193,14 +193,16 @@ App::error()
|
||||
/* @var $document Document */
|
||||
$document = Authorization::skip(fn() => $dbForProject->getDocument('timeouts', $key));
|
||||
if ($document->isEmpty()) {
|
||||
var_dump("createDocument createDocument createDocument createDocument createDocument createDocument");
|
||||
$document = Authorization::skip(fn()=>$dbForProject->createDocument('timeouts', new Document([
|
||||
'$id' => $key,
|
||||
'blocked' => false,
|
||||
'count' => 1,
|
||||
'queries' => $request->getParam('queries'),
|
||||
'route' => $request->getURI(),
|
||||
'path' => $request->getURI(),
|
||||
])));
|
||||
} else {
|
||||
var_dump("updateDocument updateDocument updateDocument updateDocument updateDocument updateDocument updateDocument");
|
||||
$document['count']++;
|
||||
if ($document['count'] > 1) { // todo: make this configurable
|
||||
$document['blocked'] = true;
|
||||
@@ -208,11 +210,12 @@ App::error()
|
||||
$document = Authorization::skip(fn() => $dbForProject->updateDocument('timeouts', $document->getId(), $document));
|
||||
}
|
||||
|
||||
var_dump($document);
|
||||
if ($document['blocked'] === true) {
|
||||
var_dump("blocked throwing exception");
|
||||
throw new Exception(Exception::TIMEOUT_ROUTE_BLOCKED);
|
||||
}
|
||||
|
||||
var_dump($document);
|
||||
var_dump("end App::error-------------------------------------");
|
||||
}
|
||||
|
||||
throw $error;
|
||||
|
||||
Generated
+10
-10
@@ -2121,12 +2121,12 @@
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/utopia-php/database.git",
|
||||
"reference": "69ac17333125987ffbde393df3797063446d94f5"
|
||||
"reference": "bd569398141b8e2098066ef2958a5038581a836f"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/utopia-php/database/zipball/69ac17333125987ffbde393df3797063446d94f5",
|
||||
"reference": "69ac17333125987ffbde393df3797063446d94f5",
|
||||
"url": "https://api.github.com/repos/utopia-php/database/zipball/bd569398141b8e2098066ef2958a5038581a836f",
|
||||
"reference": "bd569398141b8e2098066ef2958a5038581a836f",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -2168,7 +2168,7 @@
|
||||
"issues": "https://github.com/utopia-php/database/issues",
|
||||
"source": "https://github.com/utopia-php/database/tree/timeout"
|
||||
},
|
||||
"time": "2023-01-15T14:47:30+00:00"
|
||||
"time": "2023-01-17T13:42:38+00:00"
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/domains",
|
||||
@@ -3365,16 +3365,16 @@
|
||||
},
|
||||
{
|
||||
"name": "nikic/php-parser",
|
||||
"version": "v4.15.2",
|
||||
"version": "v4.15.3",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/nikic/PHP-Parser.git",
|
||||
"reference": "f59bbe44bf7d96f24f3e2b4ddc21cd52c1d2adbc"
|
||||
"reference": "570e980a201d8ed0236b0a62ddf2c9cbb2034039"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/f59bbe44bf7d96f24f3e2b4ddc21cd52c1d2adbc",
|
||||
"reference": "f59bbe44bf7d96f24f3e2b4ddc21cd52c1d2adbc",
|
||||
"url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/570e980a201d8ed0236b0a62ddf2c9cbb2034039",
|
||||
"reference": "570e980a201d8ed0236b0a62ddf2c9cbb2034039",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -3415,9 +3415,9 @@
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/nikic/PHP-Parser/issues",
|
||||
"source": "https://github.com/nikic/PHP-Parser/tree/v4.15.2"
|
||||
"source": "https://github.com/nikic/PHP-Parser/tree/v4.15.3"
|
||||
},
|
||||
"time": "2022-11-12T15:38:23+00:00"
|
||||
"time": "2023-01-16T22:05:37+00:00"
|
||||
},
|
||||
{
|
||||
"name": "phar-io/manifest",
|
||||
|
||||
@@ -988,7 +988,7 @@ trait DatabasesBase
|
||||
/**
|
||||
* @depends testCreateDocument
|
||||
*/
|
||||
public function testTimeout(array $data): array
|
||||
public function testCreateTimeout(array $data): void
|
||||
{
|
||||
$databaseId = $data['databaseId'];
|
||||
$documents = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/documents', array_merge([
|
||||
@@ -998,19 +998,40 @@ trait DatabasesBase
|
||||
'queries' => ['sleep("$id", 1)'],
|
||||
]);
|
||||
|
||||
var_dump($documents);
|
||||
$this->assertEquals(500, $documents['headers']['status-code']);
|
||||
}
|
||||
|
||||
die;
|
||||
|
||||
/**
|
||||
* @depends testCreateDocument
|
||||
*/
|
||||
public function testUpdateAndBlockTimeout(array $data): void
|
||||
{
|
||||
$databaseId = $data['databaseId'];
|
||||
$documents = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/documents', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'queries' => ['orderAsc("releaseYear")', 'sleep(1)'],
|
||||
|
||||
'queries' => ['sleep("$id", 1)'],
|
||||
]);
|
||||
|
||||
var_dump($documents);
|
||||
$this->assertEquals(500, $documents['headers']['status-code']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreateDocument
|
||||
*/
|
||||
public function testBlockedAtInitTimeout(array $data): void
|
||||
{
|
||||
$databaseId = $data['databaseId'];
|
||||
$documents = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/documents', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'queries' => ['sleep("$id", 1)'],
|
||||
]);
|
||||
|
||||
$this->assertEquals(500, $documents['headers']['status-code']);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user