2020-07-08 09:14:40 +12:00
|
|
|
<?php
|
|
|
|
|
2020-12-27 01:10:14 +13:00
|
|
|
namespace Tests\E2E\General;
|
2020-07-08 09:14:40 +12:00
|
|
|
|
2020-11-12 11:03:27 +13:00
|
|
|
use Exception;
|
2020-07-08 09:14:40 +12:00
|
|
|
use Tests\E2E\Client;
|
|
|
|
use Tests\E2E\Scopes\ProjectNone;
|
|
|
|
use Tests\E2E\Scopes\Scope;
|
|
|
|
use Tests\E2E\Scopes\SideNone;
|
|
|
|
|
|
|
|
class HTTPTest extends Scope
|
|
|
|
{
|
|
|
|
use ProjectNone;
|
|
|
|
use SideNone;
|
|
|
|
|
|
|
|
public function testOptions()
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
2022-01-03 05:08:27 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_OPTIONS, '/', \array_merge([
|
2020-07-08 09:14:40 +12:00
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
]), []);
|
|
|
|
|
2021-02-03 00:27:12 +13:00
|
|
|
$this->assertEquals(204, $response['headers']['status-code']);
|
2020-07-08 09:14:40 +12:00
|
|
|
$this->assertEquals('Appwrite', $response['headers']['server']);
|
|
|
|
$this->assertEquals('GET, POST, PUT, PATCH, DELETE', $response['headers']['access-control-allow-methods']);
|
2021-03-05 19:36:41 +13:00
|
|
|
$this->assertEquals('Origin, Cookie, Set-Cookie, X-Requested-With, Content-Type, Access-Control-Allow-Origin, Access-Control-Request-Headers, Accept, X-Appwrite-Project, X-Appwrite-Key, X-Appwrite-Locale, X-Appwrite-Mode, X-Appwrite-JWT, X-Appwrite-Response-Format, X-SDK-Version, Cache-Control, Expires, Pragma, X-Fallback-Cookies', $response['headers']['access-control-allow-headers']);
|
2020-07-08 09:14:40 +12:00
|
|
|
$this->assertEquals('X-Fallback-Cookies', $response['headers']['access-control-expose-headers']);
|
|
|
|
$this->assertEquals('http://localhost', $response['headers']['access-control-allow-origin']);
|
|
|
|
$this->assertEquals('true', $response['headers']['access-control-allow-credentials']);
|
|
|
|
$this->assertEmpty($response['body']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testError()
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
2022-01-03 05:08:27 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/error', \array_merge([
|
2020-07-08 09:14:40 +12:00
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
]), []);
|
|
|
|
|
|
|
|
$this->assertEquals(404, $response['headers']['status-code']);
|
|
|
|
$this->assertEquals('Not Found', $response['body']['message']);
|
|
|
|
$this->assertEquals(404, $response['body']['code']);
|
|
|
|
$this->assertEquals('dev', $response['body']['version']);
|
|
|
|
}
|
2020-10-30 10:15:45 +13:00
|
|
|
|
|
|
|
public function testManifest()
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
2022-01-03 05:08:27 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/manifest.json', \array_merge([
|
2020-10-30 10:15:45 +13:00
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
]), []);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertEquals('Appwrite', $response['body']['name']);
|
|
|
|
$this->assertEquals('Appwrite', $response['body']['short_name']);
|
|
|
|
$this->assertEquals('.', $response['body']['start_url']);
|
|
|
|
$this->assertEquals('.', $response['body']['start_url']);
|
|
|
|
$this->assertEquals('https://appwrite.io/', $response['body']['url']);
|
|
|
|
$this->assertEquals('standalone', $response['body']['display']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testHumans()
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
2022-01-03 05:08:27 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/humans.txt', \array_merge([
|
2020-10-30 10:15:45 +13:00
|
|
|
'origin' => 'http://localhost',
|
|
|
|
]), []);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertStringContainsString('# humanstxt.org/', $response['body']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testRobots()
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
2022-01-03 05:08:27 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/robots.txt', \array_merge([
|
2020-10-30 10:15:45 +13:00
|
|
|
'origin' => 'http://localhost',
|
|
|
|
]), []);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertStringContainsString('# robotstxt.org/', $response['body']);
|
|
|
|
}
|
2020-11-12 11:03:27 +13:00
|
|
|
|
2021-06-14 20:38:26 +12:00
|
|
|
// public function testSpecSwagger2()
|
|
|
|
// {
|
|
|
|
// $response = $this->client->call(Client::METHOD_GET, '/specs/swagger2?platform=client', [
|
|
|
|
// 'content-type' => 'application/json',
|
|
|
|
// ], []);
|
2020-11-12 11:03:27 +13:00
|
|
|
|
2021-06-14 20:38:26 +12:00
|
|
|
// if(!file_put_contents(__DIR__ . '/../../resources/swagger2.json', json_encode($response['body']))) {
|
|
|
|
// throw new Exception('Failed to save spec file');
|
|
|
|
// }
|
2020-11-12 11:03:27 +13:00
|
|
|
|
2021-06-14 20:38:26 +12:00
|
|
|
// $client = new Client();
|
|
|
|
// $client->setEndpoint('https://validator.swagger.io');
|
2020-11-12 11:03:27 +13:00
|
|
|
|
2021-06-14 20:38:26 +12:00
|
|
|
// /**
|
|
|
|
// * Test for SUCCESS
|
|
|
|
// */
|
|
|
|
// $response = $client->call(Client::METHOD_POST, '/validator/debug', [
|
|
|
|
// 'content-type' => 'application/json',
|
|
|
|
// ], json_decode(file_get_contents(realpath(__DIR__ . '/../../resources/swagger2.json')), true));
|
2020-11-12 11:03:27 +13:00
|
|
|
|
2021-06-14 20:38:26 +12:00
|
|
|
// $response['body'] = json_decode($response['body'], true);
|
2020-11-12 11:03:27 +13:00
|
|
|
|
2021-06-14 20:38:26 +12:00
|
|
|
// $this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
// $this->assertTrue(empty($response['body']));
|
2020-11-12 11:03:27 +13:00
|
|
|
|
2021-06-14 20:38:26 +12:00
|
|
|
// unlink(realpath(__DIR__ . '/../../resources/swagger2.json'));
|
|
|
|
// }
|
2020-11-15 02:05:18 +13:00
|
|
|
|
|
|
|
public function testSpecOpenAPI3()
|
|
|
|
{
|
2021-06-14 03:01:56 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/specs/open-api3?platform=console', [
|
2020-11-15 02:05:18 +13:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
], []);
|
|
|
|
|
2022-01-02 01:07:11 +13:00
|
|
|
$directory = __DIR__ . '/../../../app/config/specs/';
|
2020-11-15 02:05:18 +13:00
|
|
|
|
2022-01-02 01:07:11 +13:00
|
|
|
$files = scandir($directory);
|
2020-11-15 02:05:18 +13:00
|
|
|
$client = new Client();
|
2021-07-27 04:10:08 +12:00
|
|
|
$client->setEndpoint('https://validator.swagger.io');
|
2020-11-15 02:05:18 +13:00
|
|
|
|
2022-01-02 01:07:11 +13:00
|
|
|
foreach($files as $file) {
|
|
|
|
if(in_array($file, ['.', '..'])) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-01-02 01:27:52 +13:00
|
|
|
if(
|
|
|
|
(strpos($file, 'latest') === false) &&
|
|
|
|
(strpos($file, '0.12.x') === false)
|
|
|
|
) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-01-02 01:07:11 +13:00
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
$response = $client->call(Client::METHOD_POST, '/validator/debug', [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
], json_decode(file_get_contents($directory.$file), true));
|
|
|
|
|
|
|
|
$response['body'] = json_decode($response['body'], true);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertTrue(empty($response['body']));
|
|
|
|
}
|
2020-11-15 02:05:18 +13:00
|
|
|
}
|
2021-01-12 05:48:08 +13:00
|
|
|
|
|
|
|
public function testResponseHeader() {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test without header
|
|
|
|
*/
|
2022-01-03 05:08:27 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/locale/continents', \array_merge([
|
2021-01-12 05:48:08 +13:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => 'console',
|
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
$body = $response['body'];
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertEquals($body['sum'], 7);
|
|
|
|
$this->assertEquals($body['continents'][0]['name'], 'Africa');
|
|
|
|
$this->assertEquals($body['continents'][0]['code'], 'AF');
|
|
|
|
$this->assertEquals($body['continents'][1]['name'], 'Antarctica');
|
|
|
|
$this->assertEquals($body['continents'][1]['code'], 'AN');
|
|
|
|
$this->assertEquals($body['continents'][2]['name'], 'Asia');
|
|
|
|
$this->assertEquals($body['continents'][2]['code'], 'AS');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test with header
|
|
|
|
*/
|
2022-01-03 05:08:27 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/locale/continents', \array_merge([
|
2021-01-12 05:48:08 +13:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => 'console',
|
|
|
|
'x-appwrite-response-format' => '0.6.2'
|
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
$body = $response['body'];
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertEquals($body['sum'], 7);
|
|
|
|
$this->assertEquals($body['continents']['AF'], 'Africa');
|
|
|
|
$this->assertEquals($body['continents']['AN'], 'Antarctica');
|
|
|
|
$this->assertEquals($body['continents']['AS'], 'Asia');
|
|
|
|
}
|
2021-02-25 07:31:43 +13:00
|
|
|
|
|
|
|
public function testVersions() {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test without header
|
|
|
|
*/
|
2022-01-03 05:08:27 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/versions', \array_merge([
|
2021-02-25 07:31:43 +13:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
$body = $response['body'];
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertIsString($body['server']);
|
|
|
|
$this->assertIsString($body['client-web']);
|
|
|
|
$this->assertIsString($body['client-flutter']);
|
|
|
|
$this->assertIsString($body['console-web']);
|
|
|
|
$this->assertIsString($body['server-nodejs']);
|
|
|
|
$this->assertIsString($body['server-deno']);
|
|
|
|
$this->assertIsString($body['server-php']);
|
|
|
|
$this->assertIsString($body['server-python']);
|
|
|
|
$this->assertIsString($body['server-ruby']);
|
|
|
|
$this->assertIsString($body['server-cli']);
|
|
|
|
}
|
2021-06-14 20:38:26 +12:00
|
|
|
}
|