1
0
Fork 0
mirror of synced 2024-06-14 00:34:51 +12:00

Merge pull request #5605 from appwrite/fix-cloud-route-mistmatch

Update framework to fix route mismatches
This commit is contained in:
Jake Barnby 2023-05-30 23:39:40 +12:00 committed by GitHub
commit 37f690c3bd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 86 additions and 94 deletions

View file

@ -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);

View file

@ -50,18 +50,18 @@
"utopia-php/cli": "0.15.*",
"utopia-php/config": "0.2.*",
"utopia-php/database": "0.28.*",
"utopia-php/queue": "0.5.*",
"utopia-php/domains": "1.1.*",
"utopia-php/dsn": "0.1.*",
"utopia-php/framework": "0.26.*",
"utopia-php/image": "0.5.*",
"utopia-php/locale": "0.4.*",
"utopia-php/logger": "0.3.*",
"utopia-php/messaging": "0.1.*",
"utopia-php/orchestration": "0.9.*",
"utopia-php/platform": "0.3.*",
"utopia-php/pools": "0.4.*",
"utopia-php/preloader": "0.2.*",
"utopia-php/domains": "1.1.*",
"utopia-php/framework": "0.26.*",
"utopia-php/image": "0.5.*",
"utopia-php/dsn": "0.1.*",
"utopia-php/locale": "0.4.*",
"utopia-php/logger": "0.3.*",
"utopia-php/messaging": "0.1.*",
"utopia-php/queue": "0.5.*",
"utopia-php/registry": "0.5.*",
"utopia-php/storage": "0.13.*",
"utopia-php/swoole": "0.5.*",

40
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "146a894efdd38248478ef09e28f31978",
"content-hash": "329498d12fabaa764c4178881cb07788",
"packages": [
{
"name": "adhocore/jwt",
@ -2058,16 +2058,16 @@
},
{
"name": "utopia-php/framework",
"version": "0.26.0",
"version": "0.26.1",
"source": {
"type": "git",
"url": "https://github.com/utopia-php/framework.git",
"reference": "e8da5576370366d3bf9c574ec855f8c96fe4f34e"
"reference": "feb8941f8dbd37f869986ca56c81a0f76b29fbcd"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/utopia-php/framework/zipball/e8da5576370366d3bf9c574ec855f8c96fe4f34e",
"reference": "e8da5576370366d3bf9c574ec855f8c96fe4f34e",
"url": "https://api.github.com/repos/utopia-php/framework/zipball/feb8941f8dbd37f869986ca56c81a0f76b29fbcd",
"reference": "feb8941f8dbd37f869986ca56c81a0f76b29fbcd",
"shasum": ""
},
"require": {
@ -2096,9 +2096,9 @@
],
"support": {
"issues": "https://github.com/utopia-php/framework/issues",
"source": "https://github.com/utopia-php/framework/tree/0.26.0"
"source": "https://github.com/utopia-php/framework/tree/0.26.1"
},
"time": "2023-01-13T08:14:43+00:00"
"time": "2023-05-30T07:18:22+00:00"
},
{
"name": "utopia-php/image",
@ -2953,16 +2953,16 @@
},
{
"name": "doctrine/deprecations",
"version": "v1.0.0",
"version": "v1.1.0",
"source": {
"type": "git",
"url": "https://github.com/doctrine/deprecations.git",
"reference": "0e2a4f1f8cdfc7a92ec3b01c9334898c806b30de"
"reference": "8cffffb2218e01f3b370bf763e00e81697725259"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/deprecations/zipball/0e2a4f1f8cdfc7a92ec3b01c9334898c806b30de",
"reference": "0e2a4f1f8cdfc7a92ec3b01c9334898c806b30de",
"url": "https://api.github.com/repos/doctrine/deprecations/zipball/8cffffb2218e01f3b370bf763e00e81697725259",
"reference": "8cffffb2218e01f3b370bf763e00e81697725259",
"shasum": ""
},
"require": {
@ -2990,9 +2990,9 @@
"homepage": "https://www.doctrine-project.org/",
"support": {
"issues": "https://github.com/doctrine/deprecations/issues",
"source": "https://github.com/doctrine/deprecations/tree/v1.0.0"
"source": "https://github.com/doctrine/deprecations/tree/v1.1.0"
},
"time": "2022-05-02T15:47:09+00:00"
"time": "2023-05-29T18:55:17+00:00"
},
{
"name": "doctrine/instantiator",
@ -3652,16 +3652,16 @@
},
{
"name": "phpstan/phpdoc-parser",
"version": "1.21.0",
"version": "1.21.3",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpdoc-parser.git",
"reference": "6df62b08faef4f899772bc7c3bbabb93d2b7a21c"
"reference": "b0c366dd2cea79407d635839d25423ba07c55dd6"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/6df62b08faef4f899772bc7c3bbabb93d2b7a21c",
"reference": "6df62b08faef4f899772bc7c3bbabb93d2b7a21c",
"url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/b0c366dd2cea79407d635839d25423ba07c55dd6",
"reference": "b0c366dd2cea79407d635839d25423ba07c55dd6",
"shasum": ""
},
"require": {
@ -3692,9 +3692,9 @@
"description": "PHPDoc parser with support for nullable, intersection and generic types",
"support": {
"issues": "https://github.com/phpstan/phpdoc-parser/issues",
"source": "https://github.com/phpstan/phpdoc-parser/tree/1.21.0"
"source": "https://github.com/phpstan/phpdoc-parser/tree/1.21.3"
},
"time": "2023-05-17T13:13:44+00:00"
"time": "2023-05-29T19:31:28+00:00"
},
{
"name": "phpunit/php-code-coverage",
@ -5542,5 +5542,5 @@
"platform-overrides": {
"php": "8.0"
},
"plugin-api-version": "2.2.0"
"plugin-api-version": "2.3.0"
}

View file

@ -160,31 +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;
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;
@ -216,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);
@ -226,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);
}
@ -269,7 +255,7 @@ class Client
{
$cookies = [];
parse_str(strtr($cookie, array('&' => '%26', '+' => '%2B', ';' => '&')), $cookies);
parse_str(strtr($cookie, ['&' => '%26', '+' => '%2B', ';' => '&']), $cookies);
return $cookies;
}

View file

@ -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);

View file

@ -24,10 +24,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
@ -52,10 +49,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;
}
/**

View file

@ -981,6 +981,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;
}
@ -2868,7 +2874,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']

View file

@ -814,11 +814,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);
@ -874,6 +874,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);
/**
@ -889,6 +902,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',