2016-12-22 02:41:46 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2016-12-24 22:46:22 +01:00
|
|
|
import os
|
2017-03-15 00:53:23 +01:00
|
|
|
import shutil
|
2016-12-24 22:46:22 +01:00
|
|
|
|
2016-12-22 02:41:46 +01:00
|
|
|
import pytest
|
|
|
|
|
2016-12-24 22:46:22 +01:00
|
|
|
from tests.logging import save_logs
|
|
|
|
try:
|
|
|
|
from bin.filecheck import KittenGroomerFileCheck, File, main
|
|
|
|
NODEPS = False
|
|
|
|
except ImportError:
|
|
|
|
NODEPS = True
|
|
|
|
|
2017-04-10 13:18:51 +02:00
|
|
|
fixture = pytest.fixture
|
|
|
|
skip = pytest.mark.skip
|
2016-12-24 22:46:22 +01:00
|
|
|
skipif_nodeps = pytest.mark.skipif(NODEPS,
|
|
|
|
reason="Dependencies aren't installed")
|
|
|
|
|
|
|
|
|
|
|
|
@skipif_nodeps
|
2017-04-10 13:18:51 +02:00
|
|
|
class TestSystem:
|
2016-12-24 22:46:22 +01:00
|
|
|
|
2017-04-10 13:18:51 +02:00
|
|
|
@fixture
|
|
|
|
def valid_groomer(self):
|
|
|
|
src_path = os.path.join(os.getcwd(), 'tests/src_valid')
|
|
|
|
dst_path = self.make_dst_dir_path(src_path)
|
|
|
|
return KittenGroomerFileCheck(src_path, dst_path, debug=True)
|
2016-12-24 22:46:22 +01:00
|
|
|
|
2017-04-10 13:18:51 +02:00
|
|
|
@fixture
|
|
|
|
def invalid_groomer(self):
|
|
|
|
src_path = os.path.join(os.getcwd(), 'tests/src_invalid')
|
|
|
|
dst_path = self.make_dst_dir_path(src_path)
|
|
|
|
return KittenGroomerFileCheck(src_path, dst_path, debug=True)
|
2017-03-15 00:53:23 +01:00
|
|
|
|
|
|
|
def make_dst_dir_path(self, src_dir_path):
|
|
|
|
dst_path = src_dir_path + '_dst'
|
|
|
|
shutil.rmtree(dst_path, ignore_errors=True)
|
|
|
|
os.makedirs(dst_path, exist_ok=True)
|
|
|
|
return dst_path
|
|
|
|
|
2017-04-10 13:18:51 +02:00
|
|
|
def test_filecheck_src_valid(self, valid_groomer):
|
|
|
|
valid_groomer.run()
|
|
|
|
test_description = "filecheck_valid"
|
|
|
|
save_logs(valid_groomer, test_description)
|
|
|
|
|
|
|
|
def test_filecheck_src_invalid(self, invalid_groomer):
|
|
|
|
invalid_groomer.run()
|
|
|
|
test_description = "filecheck_invalid"
|
|
|
|
save_logs(invalid_groomer, test_description)
|
|
|
|
|
2016-12-22 02:41:46 +01:00
|
|
|
|
|
|
|
class TestFileHandling:
|
2017-02-23 22:49:29 +01:00
|
|
|
def test_autorun(self):
|
|
|
|
# Run on a single autorun file, confirm that it gets flagged as dangerous
|
2017-03-15 00:53:23 +01:00
|
|
|
# TODO: build out these and other methods for individual file cases
|
2017-02-23 22:49:29 +01:00
|
|
|
pass
|