Skip to content

Commit

Permalink
Updated the README and expected request methods
Browse files Browse the repository at this point in the history
  • Loading branch information
stevandoMoodle committed Mar 13, 2023
1 parent df240cc commit 3a5c7ce
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 3 deletions.
46 changes: 43 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ http://localhost:8001/serverID/API
In addition to the standard endpoints, additional endpoints are provided for creating an Admin user:

```
/backoffice/createAdmin
/backoffice/create-admin
```

In addition, the following endpoint can be used to trigger a reset between tests:
Expand All @@ -28,6 +28,46 @@ In addition, the following endpoint can be used to trigger a reset between tests
/backoffice/reset
```

Back office request example:
```
curl -i GET http://elementmock:8001/serverID/backoffice/create-admin
```
Error response example
```
{
"errcode" : "M_UNRECOGNIZED",
"error" : "Unrecognized request"
}
```

## API Documentations
### Synapse API documentation:
```
https://matrix-org.github.io/synapse/latest/usage/administration/admin_api/index.html
```

### Synapse-Mock API functions
* Register new user: expected method (PUT)
* Update existing user: expected method (PUT)
* Get user info: expected method (GET)
* Add user to matrix room: expected method (POST)
* Delete existing matrix room: expected method (DELETE)
* Get room info: expected method (GET)

### Matrix API documentation:
```
https://spec.matrix.org/v1.5/client-server-api/
```

### Matrix-Mock API functions
* Login: expected method (POST)
* Refresh token: expected method (POST)
* Create matrix room: expected method (POST)
* Remove user from room: expected method (POST)
* Room manipulations (Update room topic, name and avatar): expected method (PUT)
* Get members of existing room: expected method (GET)
* Upload media: expected method (POST)

## API coverage
The following are the currently mocked API endpoints. These should respond with the same HTTP status code, content type and response content as a real Synapse server.

Expand Down Expand Up @@ -56,12 +96,12 @@ http://localhost:8001/someServerID/_synapse/admin/v2/users/@anewuser:synapse
```

## Automated tests
You need to define `TEST_MOD_SYNAPSE_MOCK_SERVER` in your config.php when running automated tests like PHPUnit and Behat.
You need to define `TEST_COMMUNICATION_MATRIX_MOCK_SERVER` in your config.php when running automated tests like PHPUnit and Behat.
Otherwise, most of the Matrix tests will be marked skipped.

For example, add the following to your config.php after the `$CFG->wwwroot` line:
```
define('TEST_MOD_SYNAPSE_MOCK_SERVER', "http://localhost:8001/hash" . sha1($CFG->wwwroot));
define('TEST_COMMUNICATION_MATRIX_MOCK_SERVER', "http://localhost:8001/hash" . sha1($CFG->wwwroot));
```

## Local development
Expand Down
19 changes: 19 additions & 0 deletions application/src/Controller/MatrixController.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ public function endpoint(): JsonResponse
* @return JsonResponse
*/
public function login(string $serverID, Request $request) : JsonResponse {
// 1. Check HTTP method is accepted.
$accessCheck = $this->authHttpCheck(['POST'], $request, false);
if (!$accessCheck['status']) {
return $accessCheck['message'];
}

$payload = json_decode($request->getContent());
$check = $this->validateRequest((array)$payload, ['identifier', 'type']);
if (!$check['status']) {
Expand Down Expand Up @@ -124,6 +130,12 @@ public function login(string $serverID, Request $request) : JsonResponse {
* @return JsonResponse
*/
public function refresh(string $serverID, Request $request) : JsonResponse {
// 1. Check HTTP method is accepted.
$accessCheck = $this->authHttpCheck(['POST'], $request, false);
if (!$accessCheck['status']) {
return $accessCheck['message'];
}

$payload = json_decode($request->getContent());
$check = $this->validateRequest((array)$payload, ['refresh_token']);
if (!$check['status']) {
Expand Down Expand Up @@ -213,6 +225,13 @@ public function createRoom(string $serverID, Request $request) : JsonResponse {
* @return JsonResponse
*/
public function kick(string $roomID, Request $request) : JsonResponse {
// 1. Check call auth.
// 2. Check HTTP method is accepted.
$accessCheck = $this->authHttpCheck(['POST'], $request);
if (!$accessCheck['status']) {
return $accessCheck['message'];
}

// Check room exists.
$roomCheck = $this->roomExists($roomID);
if (!$roomCheck['status']) {
Expand Down

0 comments on commit 3a5c7ce

Please sign in to comment.