Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def testUnsetKeyConfig(self):
"""Test that config errors out when not all variables are set."""
self.WriteConfig('UNSETKEY = None\nSETKEY = "bar"\n')
config.CONFIGVARS = ['UNSETKEY', 'SETKEY']
self.assertRaises(config.TurbiniaConfigException, config.LoadConfig)
def testEvidenceSerialization(self):
"""Test that evidence serializes/unserializes."""
rawdisk = evidence.RawDisk(
name='My Evidence', local_path='/tmp/foo', mount_path='/mnt/foo')
rawdisk_json = rawdisk.to_json()
self.assertTrue(isinstance(rawdisk_json, str))
rawdisk_new = evidence.evidence_decode(json.loads(rawdisk_json))
self.assertTrue(isinstance(rawdisk_new, evidence.RawDisk))
self.assertEqual(rawdisk_new.name, 'My Evidence')
self.assertEqual(rawdisk_new.mount_path, '/mnt/foo')
def getTurbiniaRequest():
"""Get a Turbinia Request object with valid evidence attached.
Returns:
TurbiniaRequest object.
"""
request = message.TurbiniaRequest(
request_id='deadbeef', context={'kw': [1, 2]})
rawdisk = evidence.RawDisk(
name='My Evidence', local_path='/tmp/foo', mount_path='/mnt/foo')
request.evidence.append(rawdisk)
return request
def testTurbiniaRequestSerializationBadJSON(self):
"""Tests that TurbiniaRequest will raise error on wrong JSON object."""
rawdisk = evidence.RawDisk(name='My Evidence', local_path='/tmp/foo')
rawdisk_json = rawdisk.to_json()
self.assertTrue(isinstance(rawdisk_json, str))
request_new = message.TurbiniaRequest()
# Try to load serialization RawDisk() into a TurbiniaRequest, which should
# error because this is not the correct type.
self.assertRaises(TurbiniaException, request_new.from_json, rawdisk_json)
def testEvidenceSerializationNoTypeAttribute(self):
"""Test that evidence_decode throws error on dict with no type attribute."""
test = {1: 2, 3: 4}
self.assertRaises(TurbiniaException, evidence.evidence_decode, test)
def testTurbiniaRequestSerializationBadData(self):
"""Tests that TurbiniaRequest will raise error on non-json data."""
request_new = message.TurbiniaRequest()
self.assertRaises(TurbiniaException, request_new.from_json, 'non-json-data')
def getTurbiniaRequest():
"""Get a Turbinia Request object with valid evidence attached.
Returns:
TurbiniaRequest object.
"""
request = message.TurbiniaRequest(
request_id='deadbeef', context={'kw': [1, 2]})
rawdisk = evidence.RawDisk(
name='My Evidence', local_path='/tmp/foo', mount_path='/mnt/foo')
request.evidence.append(rawdisk)
return request
def testTurbiniaRequestSerialization(self):
"""Test that TurbiniaRequests serializes/unserializes."""
request = getTurbiniaRequest()
request_json = request.to_json()
self.assertTrue(isinstance(request_json, str))
# Create a new Turbinia Request object to load our results into
request_new = message.TurbiniaRequest()
request_new.from_json(request_json)
self.assertTrue(isinstance(request_new, message.TurbiniaRequest))
self.assertTrue(request_new.context['kw'][1], 2)
self.assertTrue(request_new.request_id, 'deadbeef')
self.assertTrue(isinstance(request_new.evidence[0], evidence.RawDisk))
self.assertEqual(request_new.evidence[0].name, 'My Evidence')
def testTurbiniaRequestSerializationBadJSON(self):
"""Tests that TurbiniaRequest will raise error on wrong JSON object."""
rawdisk = evidence.RawDisk(name='My Evidence', local_path='/tmp/foo')
rawdisk_json = rawdisk.to_json()
self.assertTrue(isinstance(rawdisk_json, str))
request_new = message.TurbiniaRequest()
# Try to load serialization RawDisk() into a TurbiniaRequest, which should
# error because this is not the correct type.
self.assertRaises(TurbiniaException, request_new.from_json, rawdisk_json)
'-t', '--task_id', help='Show task for given Task ID', required=False)
parser_status.add_argument(
'-u', '--user', help='Show task for given user', required=False)
# Server
subparsers.add_parser('server', help='Run Turbinia Server')
args = parser.parse_args()
# Load the config before final logger setup so we can the find the path to the
# log file.
try:
if args.config_file:
config.LoadConfig(config_file=args.config_file)
else:
config.LoadConfig()
except TurbiniaException as exception:
print(
'Could not load config file ({0!s}).\n{1:s}'.format(
exception, config.CONFIG_MSG))
sys.exit(1)
if args.log_file:
config.LOG_FILE = args.log_file
if args.output_dir:
config.OUTPUT_DIR = args.output_dir
# Run logger setup again to get file-handler now that we have the logfile path
# from the config.
logger.setup()
if args.quiet:
log.setLevel(logging.ERROR)