Compare commits

...
Author SHA1 Message Date
Matej Bačo d6717bfc67 Rename to platform key 2025-12-31 14:44:55 +01:00
Matej Bačo 81b5abd756 Add Console dev key 2025-12-23 15:32:07 +01:00
5 changed files with 78 additions and 1 deletions
+2 -1
View File
@@ -125,4 +125,5 @@ _APP_WEBHOOK_MAX_FAILED_ATTEMPTS=10
_APP_PROJECT_REGIONS=default
_APP_FUNCTIONS_CREATION_ABUSE_LIMIT=5000
_APP_STATS_USAGE_DUAL_WRITING_DBS=database_db_main
_APP_TRUSTED_HEADERS=x-forwarded-for
_APP_TRUSTED_HEADERS=x-forwarded-for
_APP_PLATFORM_DEV_KEY_SECRET=a-secret-key
+14
View File
@@ -5,6 +5,7 @@
*/
use Appwrite\Network\Platform;
use Utopia\Database\Document;
use Utopia\Database\Helpers\ID;
use Utopia\System\System;
@@ -49,6 +50,19 @@ $console = [
'githubAppid' => System::getEnv('_APP_CONSOLE_GITHUB_APP_ID', '')
],
'smtpBaseTemplate' => APP_BRANDED_EMAIL_BASE_TEMPLATE,
'devKeys' => [
new Document([
'$id' => ID::custom('platformDevKey'),
'$permissions' => [],
'projectInternalId' => ID::custom('console'),
'projectId' => ID::custom('console'),
'name' => 'Platform dev key',
'expire' => null,
'sdks' => [],
'accessedAt' => null,
'secret' => System::getEnv('_APP_PLATFORM_DEV_KEY_SECRET')
])
]
];
return $console;
+15
View File
@@ -19,6 +19,21 @@ use Utopia\Validator\Text;
use Utopia\Validator\WhiteList;
use Utopia\VCS\Adapter\Git\GitHub;
App::get('/v1/mock/tests/abuse')
->desc('Abuse-protected mock endpoint')
->groups(['mock', 'api'])
->label('scope', 'public')
->label('docs', false)
->label('mock', true)
->label('abuse-limit', 3)
->label('abuse-time', 3600)
->label('abuse-key', '{param-abuseKey}')
->param('abuseKey', '', new Text(100), 'Any string to be used as abuse key.')
->inject('response')
->action(function (string $abuseKey, Response $response) {
$response->noContent();
});
App::get('/v1/mock/tests/general/oauth2')
->desc('OAuth Login')
->groups(['mock'])
+1
View File
@@ -224,6 +224,7 @@ services:
- _APP_FUNCTIONS_CREATION_ABUSE_LIMIT
- _APP_CUSTOM_DOMAIN_DENY_LIST
- _APP_TRUSTED_HEADERS
- _APP_PLATFORM_DEV_KEY_SECRET
extra_hosts:
- "host.docker.internal:host-gateway"
@@ -5377,6 +5377,52 @@ class ProjectsConsoleClientTest extends Scope
$this->assertEquals(404, $response['headers']['status-code']);
}
/**
* @group devKeys
*/
public function testConsoleDevKeys(): void
{
$platformDevKey = System::getEnv('_APP_PLATFORM_DEV_KEY_SECRET', '');
$abuseMockKey = 'key_' . \uniqid();
$this->assertNotEmpty($platformDevKey);
$client = $this->client;
$hitMockEndpoint = function (bool $withDevKey) use ($client, $platformDevKey, $abuseMockKey) {
$headers = [];
if ($withDevKey) {
$headers['x-appwrite-dev-key'] = $platformDevKey;
}
$response = $client->call(Client::METHOD_GET, '/mock/tests/abuse', $headers, [
'abuseKey' => $abuseMockKey
]);
return $response;
};
// 3 are OK
$response = $hitMockEndpoint(withDevKey: false);
$this->assertEquals(204, $response['headers']['status-code']);
$response = $hitMockEndpoint(withDevKey: false);
$this->assertEquals(204, $response['headers']['status-code']);
$response = $hitMockEndpoint(withDevKey: false);
$this->assertEquals(204, $response['headers']['status-code']);
// Next is FAIL
$response = $hitMockEndpoint(withDevKey: false);
$this->assertEquals(429, $response['headers']['status-code']);
// Next SUCCEEDS with devkey
$response = $hitMockEndpoint(withDevKey: true);
$this->assertEquals(204, $response['headers']['status-code']);
$response = $hitMockEndpoint(withDevKey: true);
$this->assertEquals(204, $response['headers']['status-code']);
$response = $hitMockEndpoint(withDevKey: true);
$this->assertEquals(204, $response['headers']['status-code']);
$response = $hitMockEndpoint(withDevKey: true);
$this->assertEquals(204, $response['headers']['status-code']);
}
/**
* Devkeys Tests ends here ------------------------------------------------
*/