diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Controllers/KeyController.php | 10 | ||||
-rwxr-xr-x | src/Controllers/SyncController.php | 26 | ||||
-rwxr-xr-x | src/Errors/UnauthorizedError.php | 18 | ||||
-rw-r--r-- | src/Router/Router.php | 6 | ||||
-rw-r--r-- | src/Router/routes_client_server.php | 12 | ||||
-rw-r--r-- | src/Support/Logger.php | 23 | ||||
-rwxr-xr-x | src/Types/EncryptionAlgorithm.php | 9 |
7 files changed, 103 insertions, 1 deletions
diff --git a/src/Controllers/KeyController.php b/src/Controllers/KeyController.php index 04f2c6d..a999e40 100644 --- a/src/Controllers/KeyController.php +++ b/src/Controllers/KeyController.php @@ -2,6 +2,7 @@ namespace App\Controllers; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\JsonResponse; @@ -17,6 +18,15 @@ class KeyController ]); } + public function upload(): Response + { + $request = Request::createFromGlobals(); + + return new JsonResponse([ + "one_time_key_counts" => [], + ]); + } + public function query(string $serverName): Response {} } diff --git a/src/Controllers/SyncController.php b/src/Controllers/SyncController.php new file mode 100755 index 0000000..19da1b5 --- /dev/null +++ b/src/Controllers/SyncController.php @@ -0,0 +1,26 @@ +<?php + +namespace App\Controllers; + +use App\Errors\UnauthorizedError; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpFoundation\JsonResponse; + +class SyncController +{ + public function sync(): Response + { + $request = Request::createFromGlobals(); + + if ($request->headers->get("authorization") != "Bearer abc123") { + # TODO: get user based on bearer token + throw new UnauthorizedError(); + } + + return new JsonResponse([ + "account_data" => [], + "next_batch" => "", + ]); + } +} diff --git a/src/Errors/UnauthorizedError.php b/src/Errors/UnauthorizedError.php new file mode 100755 index 0000000..97df025 --- /dev/null +++ b/src/Errors/UnauthorizedError.php @@ -0,0 +1,18 @@ +<?php + +namespace App\Errors; + +use Symfony\Component\HttpFoundation\Response; + +class UnauthorizedError extends Exception +{ + public function __construct() + { + parent::__construct(ErrorCode::FORBIDDEN, "Unauthorized", Response::HTTP_UNAUTHORIZED); + } + + public function getAdditionalData(): array + { + return []; + } +} diff --git a/src/Router/Router.php b/src/Router/Router.php index b167142..1739e7c 100644 --- a/src/Router/Router.php +++ b/src/Router/Router.php @@ -67,7 +67,11 @@ class Router } catch (MethodNotAllowedException $exception) { return new ErrorResponse(ErrorCode::FORBIDDEN, "403", Response::HTTP_FORBIDDEN); } catch (\Exception $exception) { - return new ErrorResponse(ErrorCode::UNKNOWN, "Unknown error occured", Response::HTTP_INTERNAL_SERVER_ERROR); + return new ErrorResponse( + ErrorCode::UNKNOWN, + $exception->getMessage() ?: "Unknown error occured", + Response::HTTP_INTERNAL_SERVER_ERROR + ); } } diff --git a/src/Router/routes_client_server.php b/src/Router/routes_client_server.php index eff0be5..78e2e48 100644 --- a/src/Router/routes_client_server.php +++ b/src/Router/routes_client_server.php @@ -2,9 +2,11 @@ namespace App\Router; +use App\Controllers\KeyController; use App\Controllers\LoginController; use App\Controllers\ServerDiscoveryController; use App\Controllers\ServerImplementationController; +use App\Controllers\SyncController; use Symfony\Component\Routing\Loader\Configurator\RouteConfigurator; return function (RouteConfigurator $routes): void @@ -38,4 +40,14 @@ return function (RouteConfigurator $routes): void ->add("matrix_client_v3_login", "/_matrix/client/v3/login") ->controller([LoginController::class, "login"]) ->methods(["POST"]); + + $routes + ->add("matrix_client_v3_keys_upload", "/_matrix/client/v3/keys/upload") + ->controller([KeyController::class, "upload"]) + ->methods(["POST"]); + + $routes + ->add("matrix_client_v3_sync", "/_matrix/client/v3/sync") + ->controller([SyncController::class, "sync"]) + ->methods(["GET"]); }; diff --git a/src/Support/Logger.php b/src/Support/Logger.php new file mode 100644 index 0000000..fb86166 --- /dev/null +++ b/src/Support/Logger.php @@ -0,0 +1,23 @@ +<?php + +namespace App\Support; + +use Symfony\Component\HttpFoundation\Request; + +class Logger +{ + public static function logRequestToFile(Request $request): void + { + $basePath = dirname(dirname(__DIR__)) . "/.phpunit.cache/" . str_replace("/", "_", $request->getPathInfo()); + + file_put_contents( + $basePath . "-body.json", + $request->getContent() + ); + + file_put_contents( + $basePath . "-header.json", + json_encode($request->headers->all()) + ); + } +} diff --git a/src/Types/EncryptionAlgorithm.php b/src/Types/EncryptionAlgorithm.php new file mode 100755 index 0000000..5ee89e4 --- /dev/null +++ b/src/Types/EncryptionAlgorithm.php @@ -0,0 +1,9 @@ +<?php + +namespace App\Types; + +enum EncryptionAlgorithm: string +{ + case A = "m.olm.v1.curve25519-aes-sha2"; + case B = "m.megolm.v1.aes-sha2"; +} |