def _create_lcp_importer(self, collection): """Creates a new instance of LCPImporter :param collection: Collection object :type collection: Collection :return: New instance of LCPImporter :rtype: LCPImporter """ configuration_storage = CollectionConfigurationStorage( self, collection) configuration_factory = ConfigurationFactory() hasher_factory = HasherFactory() credential_factory = LCPCredentialFactory() lcp_encryptor = LCPEncryptor(configuration_storage, configuration_factory) lcp_server = LCPServer( configuration_storage, configuration_factory, hasher_factory, credential_factory, ) lcp_importer = LCPImporter(lcp_encryptor, lcp_server) return lcp_importer
def test_add_content(self, _, input_directory): # Arrange lcp_server = LCPServer( self._configuration_storage, self._configuration_factory, self._hasher_factory, self._credential_factory, ) encrypted_content = LCPEncryptionResult( content_id=fixtures.CONTENT_ID, content_encryption_key="12345", protected_content_location="/opt/readium/files/encrypted", protected_content_disposition="encrypted_book", protected_content_type="application/epub+zip", protected_content_length=12345, protected_content_sha256="12345", ) expected_protected_content_disposition = os.path.join( input_directory, encrypted_content.protected_content_disposition) with self._configuration_factory.create( self._configuration_storage, self._db, LCPServerConfiguration) as configuration: configuration.lcpserver_url = fixtures.LCPSERVER_URL configuration.lcpserver_user = fixtures.LCPSERVER_USER configuration.lcpserver_password = fixtures.LCPSERVER_PASSWORD configuration.lcpserver_input_directory = input_directory configuration.provider_name = fixtures.PROVIDER_NAME configuration.passphrase_hint = fixtures.TEXT_HINT configuration.encryption_algorithm = ( LCPServerConfiguration.DEFAULT_ENCRYPTION_ALGORITHM) with requests_mock.Mocker() as request_mock: url = urllib.parse.urljoin( fixtures.LCPSERVER_URL, "/contents/{0}".format(fixtures.CONTENT_ID)) request_mock.put(url) # Act lcp_server.add_content(self._db, encrypted_content) # Assert assert request_mock.called == True json_request = json.loads(request_mock.last_request.text) assert json_request[ "content-id"] == encrypted_content.content_id assert (json_request["content-encryption-key"] == encrypted_content.content_encryption_key) assert (json_request["protected-content-location"] == expected_protected_content_disposition) assert (json_request["protected-content-disposition"] == encrypted_content.protected_content_disposition) assert (json_request["protected-content-type"] == encrypted_content.protected_content_type) assert (json_request["protected-content-length"] == encrypted_content.protected_content_length) assert (json_request["protected-content-sha256"] == encrypted_content.protected_content_sha256)
def test_add_content(self, _, input_directory): # Arrange lcp_server = LCPServer(self._configuration_storage, self._configuration_factory, self._hasher_factory, self._credential_factory) encrypted_content = LCPEncryptionResult( content_id=fixtures.CONTENT_ID, content_encryption_key='12345', protected_content_location='/opt/readium/files/encrypted', protected_content_disposition='encrypted_book', protected_content_type='application/epub+zip', protected_content_length=12345, protected_content_sha256='12345') expected_protected_content_disposition = os.path.join( input_directory, encrypted_content.protected_content_disposition) with self._configuration_factory.create( self._configuration_storage, self._db, LCPServerConfiguration) as configuration: configuration.lcpserver_url = fixtures.LCPSERVER_URL configuration.lcpserver_user = fixtures.LCPSERVER_USER configuration.lcpserver_password = fixtures.LCPSERVER_PASSWORD configuration.lcpserver_input_directory = input_directory configuration.provider_name = fixtures.PROVIDER_NAME configuration.passphrase_hint = fixtures.TEXT_HINT configuration.encryption_algorithm = LCPServerConfiguration.DEFAULT_ENCRYPTION_ALGORITHM with requests_mock.Mocker() as request_mock: url = urlparse.urljoin( fixtures.LCPSERVER_URL, '/contents/{0}'.format(fixtures.CONTENT_ID)) request_mock.put(url) # Act lcp_server.add_content(self._db, encrypted_content) # Assert eq_(request_mock.called, True) json_request = json.loads(request_mock.last_request.text) eq_(json_request['content-id'], encrypted_content.content_id) eq_(json_request['content-encryption-key'], encrypted_content.content_encryption_key) eq_(json_request['protected-content-location'], expected_protected_content_disposition) eq_(json_request['protected-content-disposition'], encrypted_content.protected_content_disposition) eq_(json_request['protected-content-type'], encrypted_content.protected_content_type) eq_(json_request['protected-content-length'], encrypted_content.protected_content_length) eq_(json_request['protected-content-sha256'], encrypted_content.protected_content_sha256)
def _create_lcp_server(self): """Creates a new instance of LCPServer :return: New instance of LCPServer :rtype: LCPServer """ configuration_storage = ConfigurationStorage(self) configuration_factory = ConfigurationFactory() hasher_factory = HasherFactory() credential_factory = LCPCredentialFactory() lcp_server = LCPServer(configuration_storage, configuration_factory, hasher_factory, credential_factory) return lcp_server
def setup(self, mock_search=True): super(TestLCPServer, self).setup() self._lcp_collection = self._collection( protocol=ExternalIntegration.LCP) self._integration = self._lcp_collection.external_integration integration_owner = create_autospec(spec=HasExternalIntegration) integration_owner.external_integration = MagicMock( return_value=self._integration) self._configuration_storage = ConfigurationStorage(integration_owner) self._configuration_factory = ConfigurationFactory() self._hasher_factory = HasherFactory() self._credential_factory = LCPCredentialFactory() self._lcp_server = LCPServer(self._configuration_storage, self._configuration_factory, self._hasher_factory, self._credential_factory)
def create(self, integration_association): """Creates a new instance of LCPServer :param integration_association: Association with an external integration :type integration_association: core.model.configuration.HasExternalIntegration :return: New instance of LCPServer :rtype: LCPServer """ configuration_storage = ConfigurationStorage(integration_association) configuration_factory = ConfigurationFactory() hasher_factory = HasherFactory() credential_factory = LCPCredentialFactory() lcp_server = LCPServer(configuration_storage, configuration_factory, hasher_factory, credential_factory) return lcp_server