mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Merge pull request #5603 from appwrite/hotfix-route-mismatch
Update framework to fix route mismatches
This commit is contained in:
@@ -437,7 +437,7 @@ App::error()
|
||||
$log->addExtra('line', $error->getLine());
|
||||
$log->addExtra('trace', $error->getTraceAsString());
|
||||
$log->addExtra('detailedTrace', $error->getTrace());
|
||||
$log->addExtra('roles', Authorization::$roles);
|
||||
$log->addExtra('roles', Authorization::getRoles());
|
||||
|
||||
$action = $route->getLabel("sdk.namespace", "UNKNOWN_NAMESPACE") . '.' . $route->getLabel("sdk.method", "UNKNOWN_METHOD");
|
||||
$log->setAction($action);
|
||||
|
||||
Generated
+8
-7
@@ -2221,23 +2221,24 @@
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/framework",
|
||||
"version": "0.28.1",
|
||||
"version": "0.28.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/utopia-php/framework.git",
|
||||
"reference": "7f22c556fc5991e54e5811a68fb39809b21bda55"
|
||||
"reference": "bc0144ff3983afa6724c43f2ce578fdbceec21f9"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/utopia-php/framework/zipball/7f22c556fc5991e54e5811a68fb39809b21bda55",
|
||||
"reference": "7f22c556fc5991e54e5811a68fb39809b21bda55",
|
||||
"url": "https://api.github.com/repos/utopia-php/framework/zipball/bc0144ff3983afa6724c43f2ce578fdbceec21f9",
|
||||
"reference": "bc0144ff3983afa6724c43f2ce578fdbceec21f9",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=8.0.0"
|
||||
"php": ">=8.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"laravel/pint": "^1.2",
|
||||
"phpstan/phpstan": "1.9.x-dev",
|
||||
"phpunit/phpunit": "^9.5.25",
|
||||
"vimeo/psalm": "4.27.0"
|
||||
},
|
||||
@@ -2259,9 +2260,9 @@
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/utopia-php/framework/issues",
|
||||
"source": "https://github.com/utopia-php/framework/tree/0.28.1"
|
||||
"source": "https://github.com/utopia-php/framework/tree/0.28.2"
|
||||
},
|
||||
"time": "2023-03-02T08:16:01+00:00"
|
||||
"time": "2023-05-30T06:47:57+00:00"
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/image",
|
||||
|
||||
+18
-36
@@ -160,35 +160,21 @@ class Client
|
||||
* @param array $params
|
||||
* @param array $headers
|
||||
* @param bool $decode
|
||||
* @return array|string
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public function call(string $method, string $path = '', array $headers = [], array $params = [], bool $decode = true)
|
||||
public function call(string $method, string $path = '', array $headers = [], array $params = [], bool $decode = true): array
|
||||
{
|
||||
$headers = array_merge($this->headers, $headers);
|
||||
$ch = curl_init($this->endpoint . $path . (($method == self::METHOD_GET && !empty($params)) ? '?' . http_build_query($params) : ''));
|
||||
$responseHeaders = [];
|
||||
$responseStatus = -1;
|
||||
$responseType = '';
|
||||
$responseBody = '';
|
||||
|
||||
switch ($headers['content-type']) {
|
||||
case 'application/json':
|
||||
$query = json_encode($params);
|
||||
break;
|
||||
|
||||
case 'multipart/form-data':
|
||||
$query = $this->flatten($params);
|
||||
break;
|
||||
|
||||
case 'application/graphql':
|
||||
$query = $params[0];
|
||||
break;
|
||||
|
||||
default:
|
||||
$query = http_build_query($params);
|
||||
break;
|
||||
}
|
||||
$query = match ($headers['content-type']) {
|
||||
'application/json' => json_encode($params),
|
||||
'multipart/form-data' => $this->flatten($params),
|
||||
'application/graphql' => $params[0],
|
||||
default => http_build_query($params),
|
||||
};
|
||||
|
||||
foreach ($headers as $i => $header) {
|
||||
$headers[] = $i . ':' . $header;
|
||||
@@ -220,7 +206,7 @@ class Client
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
|
||||
}
|
||||
|
||||
// Allow self signed certificates
|
||||
// Allow self-signed certificates
|
||||
if ($this->selfSigned) {
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
@@ -230,22 +216,18 @@ class Client
|
||||
$responseType = $responseHeaders['content-type'] ?? '';
|
||||
$responseStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
|
||||
if ($decode) {
|
||||
switch (substr($responseType, 0, strpos($responseType, ';'))) {
|
||||
case 'application/json':
|
||||
$json = json_decode($responseBody, true);
|
||||
if ($decode && substr($responseType, 0, strpos($responseType, ';')) == 'application/json') {
|
||||
$json = json_decode($responseBody, true);
|
||||
|
||||
if ($json === null) {
|
||||
throw new Exception('Failed to parse response: ' . $responseBody);
|
||||
}
|
||||
|
||||
$responseBody = $json;
|
||||
$json = null;
|
||||
break;
|
||||
if ($json === null) {
|
||||
throw new Exception('Failed to parse response: ' . $responseBody);
|
||||
}
|
||||
|
||||
$responseBody = $json;
|
||||
$json = null;
|
||||
}
|
||||
|
||||
if ((curl_errno($ch)/* || 200 != $responseStatus*/)) {
|
||||
if ((curl_errno($ch))) {
|
||||
throw new Exception(curl_error($ch) . ' with status code ' . $responseStatus, $responseStatus);
|
||||
}
|
||||
|
||||
@@ -273,7 +255,7 @@ class Client
|
||||
{
|
||||
$cookies = [];
|
||||
|
||||
parse_str(strtr($cookie, array('&' => '%26', '+' => '%2B', ';' => '&')), $cookies);
|
||||
parse_str(strtr($cookie, ['&' => '%26', '+' => '%2B', ';' => '&']), $cookies);
|
||||
|
||||
return $cookies;
|
||||
}
|
||||
|
||||
@@ -12,6 +12,12 @@ class HTTPTest extends Scope
|
||||
use ProjectNone;
|
||||
use SideNone;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->client->setEndpoint('http://localhost');
|
||||
}
|
||||
|
||||
public function testOptions()
|
||||
{
|
||||
/**
|
||||
@@ -32,24 +38,6 @@ class HTTPTest extends Scope
|
||||
$this->assertEmpty($response['body']);
|
||||
}
|
||||
|
||||
public function testError()
|
||||
{
|
||||
/**
|
||||
* Test for SUCCESS
|
||||
*/
|
||||
$this->markTestIncomplete('This test needs to be updated for the new console.');
|
||||
// $response = $this->client->call(Client::METHOD_GET, '/error', \array_merge([
|
||||
// 'origin' => 'http://localhost',
|
||||
// 'content-type' => 'application/json',
|
||||
// ]), []);
|
||||
|
||||
// $this->assertEquals(404, $response['headers']['status-code']);
|
||||
// $this->assertEquals('Not Found', $response['body']['message']);
|
||||
// $this->assertEquals(Exception::GENERAL_ROUTE_NOT_FOUND, $response['body']['type']);
|
||||
// $this->assertEquals(404, $response['body']['code']);
|
||||
// $this->assertEquals('dev', $response['body']['version']);
|
||||
}
|
||||
|
||||
public function testHumans()
|
||||
{
|
||||
/**
|
||||
@@ -57,7 +45,7 @@ class HTTPTest extends Scope
|
||||
*/
|
||||
$response = $this->client->call(Client::METHOD_GET, '/humans.txt', \array_merge([
|
||||
'origin' => 'http://localhost',
|
||||
]), []);
|
||||
]));
|
||||
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertStringContainsString('# humanstxt.org/', $response['body']);
|
||||
@@ -70,7 +58,7 @@ class HTTPTest extends Scope
|
||||
*/
|
||||
$response = $this->client->call(Client::METHOD_GET, '/robots.txt', \array_merge([
|
||||
'origin' => 'http://localhost',
|
||||
]), []);
|
||||
]));
|
||||
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertStringContainsString('# robotstxt.org/', $response['body']);
|
||||
@@ -87,7 +75,7 @@ class HTTPTest extends Scope
|
||||
*/
|
||||
$response = $this->client->call(Client::METHOD_GET, '/.well-known/acme-challenge/8DdIKX257k6Dih5s_saeVMpTnjPJdKO5Ase0OCiJrIg', \array_merge([
|
||||
'origin' => 'http://localhost',
|
||||
]), []);
|
||||
]));
|
||||
|
||||
$this->assertEquals(404, $response['headers']['status-code']);
|
||||
// 'Unknown path', but validation passed
|
||||
@@ -97,9 +85,9 @@ class HTTPTest extends Scope
|
||||
*/
|
||||
$response = $this->client->call(Client::METHOD_GET, '/.well-known/acme-challenge/../../../../../../../etc/passwd', \array_merge([
|
||||
'origin' => 'http://localhost',
|
||||
]), []);
|
||||
]));
|
||||
|
||||
$this->assertEquals(400, $response['headers']['status-code']);
|
||||
$this->assertEquals(404, $response['headers']['status-code']);
|
||||
|
||||
// Cleanup
|
||||
$this->client->setEndpoint($previousEndpoint);
|
||||
|
||||
@@ -17,10 +17,7 @@ abstract class Scope extends TestCase
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->client = new Client();
|
||||
|
||||
$this->client
|
||||
->setEndpoint($this->endpoint)
|
||||
;
|
||||
$this->client->setEndpoint($this->endpoint);
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
@@ -45,10 +42,10 @@ abstract class Scope extends TestCase
|
||||
{
|
||||
sleep(2);
|
||||
|
||||
$resquest = json_decode(file_get_contents('http://request-catcher:5000/__last_request__'), true);
|
||||
$resquest['data'] = json_decode($resquest['data'], true);
|
||||
$request = json_decode(file_get_contents('http://request-catcher:5000/__last_request__'), true);
|
||||
$request['data'] = json_decode($request['data'], true);
|
||||
|
||||
return $resquest;
|
||||
return $request;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1106,6 +1106,12 @@ trait DatabasesBase
|
||||
|
||||
$this->assertEquals(400, $document4['headers']['status-code']);
|
||||
|
||||
// Delete document 4 with incomplete path
|
||||
$this->assertEquals(404, $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/documents/', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()))['headers']['status-code']);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
@@ -3067,7 +3073,7 @@ trait DatabasesBase
|
||||
$databaseId = $database['body']['$id'];
|
||||
|
||||
// Create collection
|
||||
$movies = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/', array_merge([
|
||||
$movies = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
|
||||
@@ -77,7 +77,7 @@ class StorageServerTest extends Scope
|
||||
'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/logo.png'), 'image/png', 'logo.png'),
|
||||
];
|
||||
|
||||
$file = $this->client->call(Client::METHOD_POST, '/graphql/upload', \array_merge([
|
||||
$file = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([
|
||||
'content-type' => 'multipart/form-data',
|
||||
'x-appwrite-project' => $projectId,
|
||||
], $this->getHeaders()), $gqlPayload);
|
||||
|
||||
@@ -783,11 +783,11 @@ class ProjectsConsoleClientTest extends Scope
|
||||
|
||||
$this->assertEquals($response['headers']['status-code'], 501);
|
||||
|
||||
$response = $this->client->call(Client::METHOD_POST, '/account/anonymous', array_merge([
|
||||
$response = $this->client->call(Client::METHOD_POST, '/account/sessions/anonymous', array_merge([
|
||||
'origin' => 'http://localhost',
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $id,
|
||||
]), []);
|
||||
]));
|
||||
|
||||
$this->assertEquals($response['headers']['status-code'], 501);
|
||||
|
||||
@@ -843,6 +843,19 @@ class ProjectsConsoleClientTest extends Scope
|
||||
'name' => $name,
|
||||
]);
|
||||
|
||||
$email = uniqid() . 'user@localhost.test';
|
||||
|
||||
$response = $this->client->call(Client::METHOD_POST, '/account', array_merge([
|
||||
'origin' => 'http://localhost',
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $id,
|
||||
]), [
|
||||
'userId' => ID::unique(),
|
||||
'email' => $email,
|
||||
'password' => $password,
|
||||
'name' => $name,
|
||||
]);
|
||||
|
||||
$this->assertEquals($response['headers']['status-code'], 501);
|
||||
|
||||
/**
|
||||
@@ -858,6 +871,8 @@ class ProjectsConsoleClientTest extends Scope
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertNotEmpty($response['body']['$id']);
|
||||
|
||||
$email = uniqid() . 'user@localhost.test';
|
||||
|
||||
$response = $this->client->call(Client::METHOD_POST, '/account', array_merge([
|
||||
'origin' => 'http://localhost',
|
||||
'content-type' => 'application/json',
|
||||
|
||||
Reference in New Issue
Block a user