-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add test; ensure metaData is serialized as json object; update authz …
…policies
- Loading branch information
Showing
9 changed files
with
141 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Dbp\Relay\BlobConnectorCampusonlineDmsBundle\Tests; | ||
|
||
use ApiPlatform\Symfony\Bundle\Test\ApiTestCase; | ||
use Dbp\Relay\BlobBundle\TestUtils\TestEntityManager; | ||
use Dbp\Relay\CoreBundle\TestUtils\TestClient; | ||
use Symfony\Component\HttpFoundation\BinaryFileResponse; | ||
use Symfony\Component\HttpFoundation\File\UploadedFile; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
class ApiTest extends ApiTestCase | ||
{ | ||
private const TEST_FILE_NAME = 'test.txt'; | ||
private const TEST_FILE_PATH = __DIR__.'/'.self::TEST_FILE_NAME; | ||
private const TEST_DOCUMENT_TYPE = 'doc_type'; | ||
|
||
private ?TestClient $testClient = null; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->testClient = new TestClient(self::createClient()); | ||
$this->testClient->setUpUser(userAttributes: ['MAY_USE_CO_DMS_API' => true]); | ||
$this->testClient->getClient()->disableReboot(); | ||
TestEntityManager::setUpEntityManager($this->testClient->getContainer()); | ||
} | ||
|
||
public function testCreateDocument(): void | ||
{ | ||
$file = new UploadedFile(self::TEST_FILE_PATH, self::TEST_FILE_NAME); | ||
$response = $this->testClient->request('POST', '/co-dms-api/api/documents', [ | ||
'headers' => [ | ||
'Content-Type' => 'multipart/form-data', | ||
'Accept' => 'application/json', | ||
], | ||
'extra' => [ | ||
'files' => [ | ||
'binary_content' => $file, | ||
], | ||
'parameters' => [ | ||
'name' => self::TEST_FILE_NAME, | ||
'document_type' => self::TEST_DOCUMENT_TYPE, | ||
'metadata' => '{"foo": "bar"}', | ||
'doc_version_metadata' => '{"bar": "baz"}', | ||
], | ||
], | ||
]); | ||
$this->assertEquals(Response::HTTP_CREATED, $response->getStatusCode()); | ||
$document = json_decode($response->getContent(false), true); | ||
$documentUid = $document['uid']; | ||
$this->assertNotEmpty($documentUid); | ||
$this->assertEquals(['foo' => 'bar'], $document['metaData']); | ||
|
||
$documentVersionUid = $document['latestVersion']['uid']; | ||
$this->assertNotEmpty($documentVersionUid); | ||
$this->assertEquals(self::TEST_FILE_NAME, $document['latestVersion']['name']); | ||
$this->assertEquals('1', $document['latestVersion']['versionNumber']); | ||
$this->assertEquals('text/plain', $document['latestVersion']['mediaType']); | ||
$this->assertEquals($file->getSize(), $document['latestVersion']['size']); | ||
$this->assertEquals(['bar' => 'baz'], $document['latestVersion']['metaData']); | ||
|
||
$response = $this->testClient->get('/co-dms-api/api/documents/'.$documentUid, options: [ | ||
'headers' => [ | ||
'Accept' => 'application/json', | ||
], | ||
]); | ||
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode()); | ||
$document = json_decode($response->getContent(false), true); | ||
$this->assertEquals($documentUid, $document['uid']); | ||
$this->assertEquals(['foo' => 'bar'], $document['metaData']); | ||
$this->assertEquals($documentVersionUid, $document['latestVersion']['uid']); | ||
$this->assertEquals(self::TEST_FILE_NAME, $document['latestVersion']['name']); | ||
$this->assertEquals('1', $document['latestVersion']['versionNumber']); | ||
$this->assertEquals('text/plain', $document['latestVersion']['mediaType']); | ||
$this->assertEquals($file->getSize(), $document['latestVersion']['size']); | ||
$this->assertEquals(['bar' => 'baz'], $document['latestVersion']['metaData']); | ||
|
||
$response = $this->testClient->get( | ||
'/co-dms-api/api/documents/version/'.$documentVersionUid.'/metadata', | ||
options: [ | ||
'headers' => [ | ||
'Accept' => 'application/json', | ||
]]); | ||
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode()); | ||
$documentVersion = json_decode($response->getContent(false), true); | ||
$this->assertNotEmpty($documentVersion['uid']); | ||
$this->assertEquals(self::TEST_FILE_NAME, $documentVersion['name']); | ||
$this->assertEquals('1', $documentVersion['versionNumber']); | ||
$this->assertEquals('text/plain', $documentVersion['mediaType']); | ||
$this->assertEquals($file->getSize(), $documentVersion['size']); | ||
$this->assertEquals(['bar' => 'baz'], $documentVersion['metaData']); | ||
|
||
/** @var \ApiPlatform\Symfony\Bundle\Test\Response $response */ | ||
$response = $this->testClient->get( | ||
'/co-dms-api/api/documents/version/'.$documentVersionUid.'/content', | ||
options: [ | ||
'headers' => [ | ||
'Accept' => 'application/octet-stream', | ||
]]); | ||
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode()); | ||
assert($response->getKernelResponse() instanceof BinaryFileResponse); | ||
$this->assertEquals($file->getContent(), $response->getKernelResponse()->getFile()->getContent()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,9 @@ | |
|
||
use ApiPlatform\Symfony\Bundle\ApiPlatformBundle; | ||
use Dbp\Relay\BlobBundle\DbpRelayBlobBundle; | ||
use Dbp\Relay\BlobBundle\TestUtils\BlobTestUtils; | ||
use Dbp\Relay\BlobConnectorCampusonlineDmsBundle\DbpRelayBlobConnectorCampusonlineDmsBundle; | ||
use Dbp\Relay\BlobConnectorCampusonlineDmsBundle\Service\DocumentService; | ||
use Dbp\Relay\CoreBundle\DbpRelayCoreBundle; | ||
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle; | ||
use Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle; | ||
|
@@ -54,45 +56,19 @@ protected function configureContainer(ContainerConfigurator $container, LoaderIn | |
'annotations' => false, | ||
]); | ||
|
||
$container->extension('dbp_relay_blob_connector_campusonline_dms', []); | ||
|
||
$container->extension('dbp_relay_blob', [ | ||
'database_url' => 'sqlite:///:memory:', | ||
'reporting_interval' => '0 9 * * MON', | ||
'cleanup_interval' => '0 * * * *', | ||
'file_integrity_checks' => false, | ||
'additional_auth' => false, | ||
'integrity_check_interval' => '0 0 1 * *', | ||
'bucket_size_check_interval' => '0 2 * * 1', | ||
'quota_warning_interval' => '0 6 * * *', | ||
'buckets' => [ | ||
'test-bucket' => [ | ||
'service' => 'Dbp\Relay\BlobBundle\Tests\DummyFileSystemService', | ||
'internal_bucket_id' => '018e0ed8-e6d7-794f-8f60-42efe27ef49e', | ||
'bucket_id' => 'test-bucket', | ||
'key' => '08d848fd868d83646778b87dd0695b10f59c78e23b286e9884504d1bb43cce93', | ||
'quota' => 500, // in MB | ||
'output_validation' => true, | ||
'notify_when_quota_over' => 70, // in percent of quota | ||
'report_when_expiry_in' => 'P62D', // in Days, 62 = two 31 day months | ||
'bucket_owner' => '[email protected]', | ||
'link_expire_time' => 'PT1M', | ||
'reporting' => [ | ||
'dsn' => 'smtp:localhost', | ||
'from' => '[email protected]', | ||
'to' => '[email protected]', | ||
'subject' => 'Blob file deletion reporting', | ||
'html_template' => 'emails/reporting.html.twig', | ||
], | ||
'integrity' => [ | ||
'dsn' => 'smtp:localhost', | ||
'from' => '[email protected]', | ||
'to' => '[email protected]', | ||
'subject' => 'Blob file integrity check report', | ||
'html_template' => 'emails/integrity.html.twig', | ||
], | ||
$container->extension('dbp_relay_blob_connector_campusonline_dms', [ | ||
'authorization' => [ | ||
'roles' => [ | ||
'ROLE_USER' => 'user.get("MAY_USE_CO_DMS_API")', | ||
], | ||
], | ||
]); | ||
|
||
$blobTestConfig = BlobTestUtils::getTestConfig(); | ||
$blobTestConfig['buckets'][0]['bucket_id'] = DocumentService::BUCKET_ID; | ||
$blobTestConfig['buckets'][0]['additional_types'] = [ | ||
['document_version' => __DIR__.'/document_version.schema.json'], | ||
]; | ||
$container->extension('dbp_relay_blob', $blobTestConfig); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.