diff --git a/nanopub/java_wrapper.py b/nanopub/java_wrapper.py index 8a5da947..88e46d52 100644 --- a/nanopub/java_wrapper.py +++ b/nanopub/java_wrapper.py @@ -38,6 +38,13 @@ def _run_command(command): raise RuntimeError('Nanopub RSA key appears to be missing,\n' + PROFILE_INSTRUCTIONS_MESSAGE + '\nDetailed error message:\n' + stderr) + elif all(m in stderr for m in ['SignatureException', 'Seems to have signature']): + raise RuntimeError('The Publication you are trying to publish already has a signature, ' + 'this means it is likely already published. ' + 'If you want to publish a modified existing nanopublication ' + 'you need to do a few extra steps before you can publish. ' + 'See the discussion in: ' + 'https://github.com/fair-workflows/nanopub/issues/110') elif result.returncode != 0: raise RuntimeError(f'Error in nanopub-java when running {command}: {stderr}') diff --git a/tests/test_java_wrapper.py b/tests/test_java_wrapper.py index 492335e9..92e017da 100644 --- a/tests/test_java_wrapper.py +++ b/tests/test_java_wrapper.py @@ -40,6 +40,15 @@ def test_sign_fails_on_invalid_nanopub(tmp_path): java_wrapper.sign(invalid_file) +def test_sign_fails_on_already_signed_publication(tmp_path): + java_wrapper = JavaWrapper(use_test_server=True) + temp_signed_file = tmp_path / 'signed.trig' + shutil.copy(NANOPUB_SAMPLE_SIGNED, temp_signed_file) + with pytest.raises(RuntimeError) as e: + java_wrapper.sign(unsigned_file=temp_signed_file) + assert 'The Publication you are trying to publish already has a signature' in str(e.value) + + @pytest.mark.no_rsa_key def test_sign_nanopub_no_rsa_key(tmp_path): """Test signing when no RSA key exists, only run if RSA keys are not set up."""