Back to index

python-biopython  1.60
test_NCBIStandalone.py
Go to the documentation of this file.
00001 # Copyright 1999-2009 by Jeffrey Chang and Michiel de Hoon.
00002 # All rights reserved.
00003 # This code is part of the Biopython distribution and governed by its
00004 # license.  Please see the LICENSE file that should have been included
00005 # as part of this package.
00006 
00007 import unittest
00008 from Bio.Blast import NCBIStandalone
00009 
00010 
00011 class TestNCBIStandalone(unittest.TestCase):
00012 
00013     def test_command_injection(self):
00014         #Check the simple detection of command injection,
00015         for func in [NCBIStandalone.blastall,
00016                      NCBIStandalone.blastpgp,
00017                      NCBIStandalone.rpsblast]:
00018             try:
00019                 handle = func("/somewhere/blast", "blastz", "nr",
00020                               "/tmp/example.fasta",
00021                               expectation=10**-4,
00022                               matrix="IDENTITY -F 0; cat /etc/passwd'")
00023             except ValueError, e:
00024                 self.assertEqual(str(e), "Rejecting suspicious argument for matrix")
00025                 #Good
00026             else:
00027                 self.fail("Attempted command injection not caught!")
00028 
00029     def test_pipe_redirection(self):
00030         #Now check something similar using pipe redirection
00031         for func in [NCBIStandalone.blastall,
00032                      NCBIStandalone.blastpgp,
00033                      NCBIStandalone.rpsblast]:
00034             try:
00035                 handle = func("/somewhere/blast", "blastz", "nr",
00036                               "/tmp/example.fasta",
00037                               nprocessors=4,
00038                               expectation="0.001",
00039                               filter= "F > /etc/passwd'")
00040             except ValueError, e:
00041                 self.assertEqual(str(e), "Rejecting suspicious argument for filter")
00042                 #Good
00043             else:
00044                 self.fail("Attempted output redirection not caught!")
00045 
00046 
00047 if __name__ == "__main__":
00048     runner = unittest.TextTestRunner(verbosity = 2)
00049     unittest.main(testRunner=runner)