Package rekall :: Module io_manager_test
[frames] | no frames]

Source Code for Module rekall.io_manager_test

 1  # Rekall Memory Forensics 
 2  # Copyright 2013 Google Inc. All Rights Reserved. 
 3  # 
 4  # Author: Michael Cohen scudette@google.com 
 5  # 
 6  # This program is free software; you can redistribute it and/or modify 
 7  # it under the terms of the GNU General Public License as published by 
 8  # the Free Software Foundation; either version 2 of the License, or (at 
 9  # your option) any later version. 
10  # 
11  # This program is distributed in the hope that it will be useful, but 
12  # WITHOUT ANY WARRANTY; without even the implied warranty of 
13  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
14  # General Public License for more details. 
15  # 
16  # You should have received a copy of the GNU General Public License 
17  # along with this program; if not, write to the Free Software 
18  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
19  # 
20  import gzip 
21  import os 
22   
23  from rekall import constants 
24  from rekall import io_manager 
25  from rekall import testlib 
26   
27   
28 -class IOManagerTest(testlib.RekallBaseUnitTestCase):
29 """Test the IO Manager.""" 30 31 DATA = { 32 "foo.gz": "hello", 33 "bar": "goodbye" 34 } 35
36 - def setUp(self):
37 super(IOManagerTest, self).setUp() 38 39 # Create a new repository in the temp directory. 40 self.version = constants.PROFILE_REPOSITORY_VERSION 41 for filename, data in self.DATA.iteritems(): 42 path = os.path.join(self.temp_directory, self.version, 43 filename) 44 45 if path.endswith("gz"): 46 opener = gzip.open 47 else: 48 opener = open 49 50 try: 51 os.makedirs(os.path.dirname(path)) 52 except (OSError, IOError): 53 pass 54 55 with opener(path, "wb") as fd: 56 57 fd.write(data)
58
59 - def testDirectoryIOManager(self):
60 manager = io_manager.DirectoryIOManager( 61 self.temp_directory, 62 session=self.MakeUserSession()) 63 64 # Cant decode from json. 65 self.assertEqual(manager.GetData("foo"), None) 66 self.assertEqual(manager.GetData("foo", raw=True), 67 "hello") 68 69 # Test ListFiles(). 70 self.assertListEqual(sorted(manager.ListFiles()), 71 ["bar", "foo"]) 72 73 # Storing a data structure. 74 data = dict(a=1) 75 manager.StoreData("baz", data) 76 self.assertDictEqual(manager.GetData("baz"), 77 data) 78 79 self.assertTrue( 80 isinstance(manager.GetData("baz", raw=True), basestring))
81