def _test_service_creation( self ): self._tag_service_key = HydrusData.GenerateKey() self._file_service_key = HydrusData.GenerateKey() current_services = self._read( 'services' ) self._tag_service = HydrusNetwork.GenerateService( self._tag_service_key, HC.TAG_REPOSITORY, 'tag repo', 100 ) self._file_service = HydrusNetwork.GenerateService( self._file_service_key, HC.FILE_REPOSITORY, 'file repo', 101 ) new_services = list( current_services ) new_services.append( self._tag_service ) new_services.append( self._file_service ) service_keys_to_access_keys = self._write( 'services', self._admin_account, new_services ) self.assertEqual( set( service_keys_to_access_keys.keys() ), { self._tag_service_key, self._file_service_key } ) self._tag_service_access_key = service_keys_to_access_keys[ self._tag_service_key ] self._file_service_access_key = service_keys_to_access_keys[ self._file_service_key ] self._tag_service_account_key = self._read( 'account_key_from_access_key', self._tag_service_key, self._tag_service_access_key ) self._file_service_account_key = self._read( 'account_key_from_access_key', self._file_service_key, self._file_service_access_key ) self._tag_service_account = self._read( 'account', self._tag_service_key, self._tag_service_account_key ) self._file_service_account = self._read( 'account', self._file_service_key, self._file_service_account_key ) self.assertEqual( self._tag_service_account.GetAccountKey(), self._tag_service_account_key ) self.assertEqual( self._file_service_account.GetAccountKey(), self._file_service_account_key )
def _Add(self, service_type): service_key = HydrusData.GenerateKey() port = self._GetNextPort() name = 'new service' dictionary = HydrusNetwork.GenerateDefaultServiceDictionary( service_type) service = HydrusNetwork.GenerateService(service_key, service_type, name, port, dictionary) with ClientGUITopLevelWindowsPanels.DialogEdit( self, 'edit serverside service') as dlg_edit: panel = EditServersideService(dlg_edit, service) dlg_edit.SetPanel(panel) if dlg_edit.exec() == QW.QDialog.Accepted: new_service = panel.GetValue() self._services_listctrl.SetNonDupeName(new_service) self._SetNonDupePort(new_service) self._services_listctrl.AddDatas((new_service, ))
def GetValue( self ) -> HydrusNetwork.ServerService: ( name, port, dictionary_part ) = self._service_panel.GetValue() dictionary = self._dictionary.Duplicate() dictionary.update( dictionary_part ) for panel in self._panels: dictionary_part = panel.GetValue() dictionary.update( dictionary_part ) return HydrusNetwork.GenerateService( self._service_key, self._service_type, name, port, dictionary )
def setUpClass(cls): cls._access_key = HydrusData.GenerateKey() cls._serverside_file_service = HydrusNetwork.GenerateService( HydrusData.GenerateKey(), HC.FILE_REPOSITORY, 'file repo', HC.DEFAULT_SERVICE_PORT + 1) cls._serverside_tag_service = HydrusNetwork.GenerateService( HydrusData.GenerateKey(), HC.TAG_REPOSITORY, 'tag repo', HC.DEFAULT_SERVICE_PORT) cls._serverside_admin_service = HydrusNetwork.GenerateService( HydrusData.GenerateKey(), HC.SERVER_ADMIN, 'server admin', HC.DEFAULT_SERVER_ADMIN_PORT) cls._clientside_file_service = ClientServices.GenerateService( HydrusData.GenerateKey(), HC.FILE_REPOSITORY, 'file repo') cls._clientside_tag_service = ClientServices.GenerateService( HydrusData.GenerateKey(), HC.TAG_REPOSITORY, 'tag repo') cls._clientside_admin_service = ClientServices.GenerateService( HydrusData.GenerateKey(), HC.SERVER_ADMIN, 'server admin') cls._clientside_file_service.SetCredentials( HydrusNetwork.Credentials('127.0.0.1', HC.DEFAULT_SERVICE_PORT + 1, cls._access_key)) cls._clientside_tag_service.SetCredentials( HydrusNetwork.Credentials('127.0.0.1', HC.DEFAULT_SERVICE_PORT, cls._access_key)) cls._clientside_admin_service.SetCredentials( HydrusNetwork.Credentials('127.0.0.1', HC.DEFAULT_SERVER_ADMIN_PORT, cls._access_key)) cls._local_booru = ClientServices.GenerateService( CC.LOCAL_BOORU_SERVICE_KEY, HC.LOCAL_BOORU, 'local booru') services_manager = HG.test_controller.services_manager services_manager._keys_to_services[ cls._clientside_file_service.GetServiceKey( )] = cls._clientside_file_service services_manager._keys_to_services[ cls._clientside_tag_service.GetServiceKey( )] = cls._clientside_tag_service services_manager._keys_to_services[ cls._clientside_admin_service.GetServiceKey( )] = cls._clientside_admin_service account_key = HydrusData.GenerateKey() account_type = HydrusNetwork.AccountType.GenerateAdminAccountType( HC.SERVER_ADMIN) created = HydrusData.GetNow() - 100000 expires = None cls._account = HydrusNetwork.Account(account_key, account_type, created, expires) cls._service_keys_to_empty_account_types = {} cls._service_keys_to_empty_accounts = {} cls._file_hash = HydrusData.GenerateKey() def TWISTEDSetup(): cls._ssl_cert_path = os.path.join(TestController.DB_DIR, 'server.crt') cls._ssl_key_path = os.path.join(TestController.DB_DIR, 'server.key') # if db test ran, this is still hanging around and read-only, so don't bother to fail overwriting if not os.path.exists(cls._ssl_cert_path): HydrusEncryption.GenerateOpenSSLCertAndKeyFile( cls._ssl_cert_path, cls._ssl_key_path) context_factory = twisted.internet.ssl.DefaultOpenSSLContextFactory( cls._ssl_key_path, cls._ssl_cert_path) reactor.listenSSL( HC.DEFAULT_SERVER_ADMIN_PORT, ServerServer.HydrusServiceAdmin(cls._serverside_admin_service), context_factory) reactor.listenSSL( HC.DEFAULT_SERVICE_PORT + 1, ServerServer.HydrusServiceRepositoryFile( cls._serverside_file_service), context_factory) reactor.listenSSL( HC.DEFAULT_SERVICE_PORT, ServerServer.HydrusServiceRepositoryTag( cls._serverside_tag_service), context_factory) reactor.listenTCP( 45866, ClientLocalServer.HydrusServiceBooru( cls._local_booru, allow_non_local_connections=False)) reactor.callFromThread(TWISTEDSetup) time.sleep(3)