From 2b7ab33b5e5b1a34e15b7d41db1c7684b3e42977 Mon Sep 17 00:00:00 2001 From: Stefan Bienert <stefan.bienert@unibas.ch> Date: Tue, 16 May 2017 18:28:23 +0200 Subject: [PATCH] Making naccess a bit more secure with dots --- modules/bindings/pymod/naccess.py | 4 +-- modules/bindings/tests/CMakeLists.txt | 1 + modules/bindings/tests/test_naccess.py | 42 ++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 modules/bindings/tests/test_naccess.py diff --git a/modules/bindings/pymod/naccess.py b/modules/bindings/pymod/naccess.py index 621067e7b..268b72ac1 100644 --- a/modules/bindings/pymod/naccess.py +++ b/modules/bindings/pymod/naccess.py @@ -60,9 +60,9 @@ def _SetupFiles(entity, selection, scratch_dir, max_number_of_atoms): raise RuntimeError, "Could not create view for selection (%s)"%(selection) # write entity to tmp file - tmp_file_name=os.path.join(tmp_dir_name,"entity.pdb") + tmp_file_name = "entity.pdb" tmp_file_base = os.path.join(tmp_dir_name,"entity") - io.SavePDB(entity_view, tmp_file_name) + io.SavePDB(entity_view, os.path.join(tmp_dir_name, tmp_file_name)) return (tmp_dir_name, tmp_file_name, tmp_file_base) diff --git a/modules/bindings/tests/CMakeLists.txt b/modules/bindings/tests/CMakeLists.txt index c443de132..dd257c1cb 100644 --- a/modules/bindings/tests/CMakeLists.txt +++ b/modules/bindings/tests/CMakeLists.txt @@ -4,6 +4,7 @@ set(OST_BINDINGS_UNIT_TESTS test_hhblits.py test_blast.py test_kclust.py + test_naccess.py ) ost_unittest(MODULE bindings diff --git a/modules/bindings/tests/test_naccess.py b/modules/bindings/tests/test_naccess.py new file mode 100644 index 000000000..891f01bd7 --- /dev/null +++ b/modules/bindings/tests/test_naccess.py @@ -0,0 +1,42 @@ +''' Unit tests for the Naccess wrapper +''' + +import unittest +import os +import sys +import shutil +import tempfile + +from ost.bindings import naccess +from ost import io + +class TestNaccessBindings(unittest.TestCase): + def testTempDirWithDot(self): + # naccess itself has problems with '.' in the path. So we need to test + # that it works when data is used which has a correpsonding path. + na_tmp_dir = tempfile.mkdtemp(prefix="ih.") + def cleanup(): + shutil.rmtree(na_tmp_dir) + self.addCleanup(cleanup) + na_bin = os.path.join(os.getenv('EBROOTNACCESS'), 'naccess') + ost_ent = io.LoadPDB('testfiles/testprotein.pdb') + excp_raised = False + try: + sasa = naccess.CalculateSurfaceArea(ost_ent, + scratch_dir=na_tmp_dir, + naccess_exe=na_bin) + except: + excp_raised = True + raise + self.assertEquals(excp_raised, False, msg="Naccess raised an "+ + "exception on a path containing a '.'. This is not "+ + "supposed to happen.") + +if __name__ == "__main__": + naccess_dir = os.getenv('EBROOTNACCESS') + if not naccess_dir: + print "No environment variable 'EBROOTNACCESS'. To enable the "+\ + "unit test, this needs to point to your Naccess installation." + sys.exit(0) + from ost import testutils + testutils.RunTests() -- GitLab