Skip to content

Commit

Permalink
Merge pull request #142 from fair-workflows/fix-republishing
Browse files Browse the repository at this point in the history
Add userfriendly error message in case of signing an already signed file
  • Loading branch information
svenvanderburg authored Aug 11, 2021
2 parents ed39c5e + c82fa2a commit 5a379bd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
7 changes: 7 additions & 0 deletions nanopub/java_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}')

Expand Down
9 changes: 9 additions & 0 deletions tests/test_java_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down

0 comments on commit 5a379bd

Please sign in to comment.