Skip to content

Commit f645c2c

Browse files
committed
Update service checks to ignore server app users
1 parent 5407381 commit f645c2c

File tree

2 files changed

+100
-1
lines changed

2 files changed

+100
-1
lines changed

app/controllers/general.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,11 @@
292292

293293
$service = $route->getLabel('sdk.namespace', '');
294294
if (!empty($service)) {
295+
$roles = Authorization::getRoles();
295296
if (
296297
array_key_exists($service, $project->getAttribute('services', []))
297298
&& !$project->getAttribute('services', [])[$service]
298-
&& !Auth::isPrivilegedUser(Authorization::getRoles())
299+
&& !(Auth::isPrivilegedUser($roles) || Auth::isAppUser($roles))
299300
) {
300301
throw new AppwriteException('Service is disabled', 503, AppwriteException::GENERAL_SERVICE_DISABLED);
301302
}

tests/e2e/Services/Projects/ProjectsConsoleClientTest.php

+98
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,104 @@ public function testUpdateProjectServiceStatus($data): void
786786
}
787787
}
788788

789+
/** @depends testUpdateProjectServiceStatusAdmin */
790+
public function testUpdateProjectServiceStatusServer($data): void
791+
{
792+
$id = $data['projectId'];
793+
794+
$services = require('app/config/services.php');
795+
796+
/**
797+
* Test for Disabled
798+
*/
799+
foreach ($services as $service) {
800+
if (!$service['optional']) {
801+
continue;
802+
}
803+
804+
$key = $service['key'] ?? '';
805+
806+
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/service', array_merge([
807+
'content-type' => 'application/json',
808+
'x-appwrite-project' => $this->getProject()['$id'],
809+
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
810+
]), [
811+
'service' => $key,
812+
'status' => false,
813+
]);
814+
815+
$this->assertEquals(200, $response['headers']['status-code']);
816+
$this->assertNotEmpty($response['body']['$id']);
817+
818+
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([
819+
'content-type' => 'application/json',
820+
'x-appwrite-project' => $this->getProject()['$id'],
821+
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
822+
]));
823+
824+
$this->assertEquals(200, $response['headers']['status-code']);
825+
$this->assertNotEmpty($response['body']['$id']);
826+
$this->assertEquals(false, $response['body']['serviceStatusFor' . ucfirst($key)]);
827+
}
828+
829+
// Create API Key
830+
$response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/keys', array_merge([
831+
'content-type' => 'application/json',
832+
'x-appwrite-project' => $this->getProject()['$id'],
833+
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
834+
]), [
835+
'name' => 'Key Test',
836+
'scopes' => ['functions.read', 'teams.write'],
837+
]);
838+
839+
$this->assertEquals(201, $response['headers']['status-code']);
840+
841+
$keyId = $response['body']['$id'];
842+
$keySecret = $response['body']['secret'];
843+
844+
/**
845+
* Request with API Key must succeed
846+
*/
847+
$response = $this->client->call(Client::METHOD_GET, '/functions', array_merge([
848+
'content-type' => 'application/json',
849+
'x-appwrite-project' => $id,
850+
'x-appwrite-key' => $keySecret,
851+
]));
852+
853+
$this->assertEquals(200, $response['headers']['status-code']);
854+
855+
$response = $this->client->call(Client::METHOD_POST, '/teams', array_merge([
856+
'content-type' => 'application/json',
857+
'x-appwrite-project' => $id,
858+
'x-appwrite-key' => $keySecret,
859+
]), [
860+
'teamId' => 'unique()',
861+
'name' => 'Arsenal'
862+
]);
863+
864+
$this->assertEquals(201, $response['headers']['status-code']);
865+
866+
// Cleanup
867+
868+
$response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $id . '/keys/' . $keyId, array_merge([
869+
'content-type' => 'application/json',
870+
'x-appwrite-project' => $this->getProject()['$id'],
871+
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
872+
]), []);
873+
874+
$this->assertEquals(204, $response['headers']['status-code']);
875+
876+
foreach ($services as $service) {
877+
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/service/', array_merge([
878+
'content-type' => 'application/json',
879+
'x-appwrite-project' => $this->getProject()['$id'],
880+
], $this->getHeaders()), [
881+
'service' => $service,
882+
'status' => true,
883+
]);
884+
}
885+
}
886+
789887
/**
790888
* @depends testCreateProject
791889
*/

0 commit comments

Comments
 (0)