def create_file_upload_tasks(self, upload_pk, channel, is_mozilla_signed): """ This method creates the validation chain used during the submission process, combining tasks in parallel (chord) with tasks chained together (where the output is used as input of the next task). """ tasks_in_parallel = [tasks.forward_linter_results.s(upload_pk)] if waffle.switch_is_active('enable-yara'): tasks_in_parallel.append(run_yara.s(upload_pk)) if waffle.switch_is_active('enable-customs'): tasks_in_parallel.append(run_customs.s(upload_pk)) if waffle.switch_is_active('enable-wat'): tasks_in_parallel.append(run_wat.s(upload_pk)) return [ tasks.create_initial_validation_results.si(), repack_fileupload.s(upload_pk), tasks.validate_upload.s(upload_pk, channel), tasks.check_for_api_keys_in_file.s(upload_pk), chord(tasks_in_parallel, call_ml_api.s(upload_pk)), tasks.handle_upload_validation_result.s(upload_pk, channel, is_mozilla_signed) ]
def test_adds_all_scanners(self, mock_chain): self.create_switch('enable-customs', active=True) self.create_switch('enable-wat', active=True) self.create_switch('enable-yara', active=True) file_upload = self.get_upload('webextension.xpi', with_validation=False) channel = amo.RELEASE_CHANNEL_LISTED utils.Validator(file_upload, listed=True) mock_chain.assert_called_once_with( tasks.create_initial_validation_results.si(), repack_fileupload.s(file_upload.pk), tasks.validate_upload.s(file_upload.pk, channel), tasks.check_for_api_keys_in_file.s(file_upload.pk), chord( [ tasks.forward_linter_results.s(file_upload.pk), run_yara.s(file_upload.pk), run_customs.s(file_upload.pk), run_wat.s(file_upload.pk), ], call_ml_api.s(file_upload.pk), ), tasks.handle_upload_validation_result.s(file_upload.pk, channel, False))
def check_upload(self, file_upload, listed=True): """Check that the given new file upload is validated properly.""" # Run validator. utils.Validator(file_upload, listed=listed) channel = (amo.RELEASE_CHANNEL_LISTED if listed else amo.RELEASE_CHANNEL_UNLISTED) # Make sure we setup the correct validation task. self.mock_chain.assert_called_once_with( tasks.create_initial_validation_results.si(), repack_fileupload.s(file_upload.pk), tasks.validate_upload.s(file_upload.pk, channel), tasks.check_for_api_keys_in_file.s(file_upload.pk), chord([tasks.forward_linter_results.s(file_upload.pk)], call_ml_api.s(file_upload.pk)), tasks.handle_upload_validation_result.s(file_upload.pk, channel, False))
def test_appends_final_task_for_file_uploads(self, mock_chain): final_task = mock.Mock() file_upload = self.get_upload('webextension.xpi', with_validation=False) channel = amo.RELEASE_CHANNEL_LISTED utils.Validator(file_upload, listed=True, final_task=final_task) mock_chain.assert_called_once_with( tasks.create_initial_validation_results.si(), repack_fileupload.s(file_upload.pk), tasks.validate_upload.s(file_upload.pk, channel), tasks.check_for_api_keys_in_file.s(file_upload.pk), chord([tasks.forward_linter_results.s(file_upload.pk)], call_ml_api.s(file_upload.pk)), tasks.handle_upload_validation_result.s(file_upload.pk, channel, False), final_task, )