mirror of
https://github.com/coollabsio/coolify.git
synced 2026-11-04 10:42:23 +00:00
An all-databases MySQL/MariaDB restore also restored the mysql system database, so after the next restart the root and app passwords were the source ones and the MariaDB health check failed. The restore now skips mysql, sys, performance_schema and information_schema by default. The new option "Restore users and privileges" (restore_mysql_users in the API) keeps the old behaviour.
103 lines
4.9 KiB
PHP
103 lines
4.9 KiB
PHP
<?php
|
|
|
|
test('documents standalone and service database import endpoints', function () {
|
|
$document = json_decode((string) file_get_contents(__DIR__.'/../../openapi.json'), true, flags: JSON_THROW_ON_ERROR);
|
|
|
|
expect($document['paths'])
|
|
->toHaveKey('/databases/{uuid}/imports/uploads')
|
|
->toHaveKey('/databases/{uuid}/imports')
|
|
->toHaveKey('/databases/{uuid}/imports/{activity_id}')
|
|
->toHaveKey('/services/{uuid}/databases/{database_uuid}/imports/uploads')
|
|
->toHaveKey('/services/{uuid}/databases/{database_uuid}/imports')
|
|
->toHaveKey('/services/{uuid}/databases/{database_uuid}/imports/{activity_id}');
|
|
|
|
foreach ($document['components']['schemas']['DatabaseImportRequest']['oneOf'] as $source) {
|
|
expect($source['properties']['replace_existing'])
|
|
->toMatchArray(['type' => 'boolean', 'default' => false]);
|
|
}
|
|
|
|
$statusRef = [
|
|
'description' => 'Import status',
|
|
'content' => [
|
|
'application/json' => [
|
|
'schema' => [
|
|
'$ref' => '#/components/schemas/DatabaseImportStatus',
|
|
],
|
|
],
|
|
],
|
|
];
|
|
|
|
expect($document['paths']['/databases/{uuid}/imports/{activity_id}']['get']['responses']['200'])
|
|
->toMatchArray($statusRef)
|
|
->and($document['paths']['/services/{uuid}/databases/{database_uuid}/imports/{activity_id}']['get']['responses']['200'])
|
|
->toMatchArray($statusRef)
|
|
->and($document['components']['schemas'])
|
|
->toHaveKey('DatabaseImportStatus');
|
|
});
|
|
|
|
test('documents path parameters for database import endpoints', function () {
|
|
$document = json_decode((string) file_get_contents(__DIR__.'/../../openapi.json'), true, flags: JSON_THROW_ON_ERROR);
|
|
|
|
$operations = [
|
|
['/databases/{uuid}/imports/uploads', 'post', ['uuid']],
|
|
['/databases/{uuid}/imports', 'post', ['uuid']],
|
|
['/databases/{uuid}/imports/{activity_id}', 'get', ['uuid', 'activity_id']],
|
|
['/services/{uuid}/databases/{database_uuid}/imports/uploads', 'post', ['uuid', 'database_uuid']],
|
|
['/services/{uuid}/databases/{database_uuid}/imports', 'post', ['uuid', 'database_uuid']],
|
|
['/services/{uuid}/databases/{database_uuid}/imports/{activity_id}', 'get', ['uuid', 'database_uuid', 'activity_id']],
|
|
];
|
|
|
|
foreach ($operations as [$path, $method, $expectedNames]) {
|
|
$parameters = $document['paths'][$path][$method]['parameters'] ?? [];
|
|
$pathParameters = collect($parameters)
|
|
->filter(fn (array $parameter): bool => ($parameter['in'] ?? null) === 'path')
|
|
->map(fn (array $parameter): string => $parameter['name'])
|
|
->values()
|
|
->all();
|
|
|
|
expect($pathParameters)->toEqual($expectedNames);
|
|
}
|
|
});
|
|
|
|
test('constrains additional properties on each database import source branch', function () {
|
|
$document = json_decode((string) file_get_contents(__DIR__.'/../../openapi.json'), true, flags: JSON_THROW_ON_ERROR);
|
|
$schema = $document['components']['schemas']['DatabaseImportRequest'];
|
|
|
|
expect($schema)->not->toHaveKey('additionalProperties');
|
|
|
|
$expectedProperties = [
|
|
['source', 'upload_id', 'dump_all', 'replace_existing', 'keep_owners', 'restore_mysql_users', 'sqlite_database'],
|
|
['source', 's3_storage_uuid', 'path', 'dump_all', 'replace_existing', 'keep_owners', 'restore_mysql_users', 'sqlite_database'],
|
|
['source', 'path', 'dump_all', 'replace_existing', 'keep_owners', 'restore_mysql_users', 'sqlite_database'],
|
|
];
|
|
|
|
expect($schema['oneOf'])->toHaveCount(count($expectedProperties));
|
|
|
|
foreach ($schema['oneOf'] as $index => $source) {
|
|
expect($source['additionalProperties'])->toBeFalse()
|
|
->and($source['properties'])->toHaveKeys($expectedProperties[$index])
|
|
->and($source['properties']['replace_existing'])
|
|
->toMatchArray(['type' => 'boolean', 'default' => false])
|
|
->and($source['properties']['keep_owners'])
|
|
->toMatchArray(['type' => 'boolean', 'default' => false])
|
|
->and($source['properties']['restore_mysql_users'])
|
|
->toMatchArray(['type' => 'boolean', 'default' => false])
|
|
->and($source['properties']['sqlite_database'])
|
|
->toMatchArray(['type' => 'string']);
|
|
}
|
|
});
|
|
|
|
test('documents the 409 response of database start, restart, and import endpoints', function () {
|
|
$document = json_decode((string) file_get_contents(__DIR__.'/../../openapi.json'), true, flags: JSON_THROW_ON_ERROR);
|
|
$inProgress = 'Another start, restart or import of this database is already in progress.';
|
|
|
|
foreach ([
|
|
['/databases/{uuid}/start', 'post'],
|
|
['/databases/{uuid}/restart', 'post'],
|
|
['/databases/{uuid}/imports', 'post'],
|
|
['/services/{uuid}/databases/{database_uuid}/imports', 'post'],
|
|
] as [$path, $method]) {
|
|
expect($document['paths'][$path][$method]['responses']['409']['description'] ?? null)->toBe($inProgress);
|
|
}
|
|
});
|