forked from Cisco-Talos/clamav-bytecode-compiler
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added runtime unit test and fixed broken unit tests
Broken unit tests were moved to a directory 'broken' until they can be fixed, and a runtime unit test was added. Made Dockerfile pass the ctest call.
- Loading branch information
Showing
10 changed files
with
148 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
VIRUSNAME_PREFIX("Clamav-Unit-Test-Signature.02") | ||
VIRUSNAMES("") | ||
TARGET(0) | ||
|
||
FUNCTIONALITY_LEVEL_MIN(FUNC_LEVEL_096_4) | ||
|
||
SIGNATURES_DECL_BEGIN | ||
DECLARE_SIGNATURE(test_string) | ||
SIGNATURES_DECL_END | ||
|
||
SIGNATURES_DEF_BEGIN | ||
/* matches "CLAMAV-TEST-STRING-NOT-EICAR" */ | ||
DEFINE_SIGNATURE(test_string, "0:434c414d41562d544553542d535452494e472d4e4f542d4549434152") | ||
SIGNATURES_DEF_END | ||
|
||
bool logical_trigger() | ||
{ | ||
/***Will return true if signature matches ***/ | ||
return matches(Signatures.test_string); | ||
} | ||
|
||
/***bytecode function that executes if the logical signature matched ***/ | ||
int entrypoint(void) | ||
{ | ||
foundVirus(""); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Copyright (C) 2021 Cisco Systems, Inc. and/or its affiliates. All rights reserved. | ||
|
||
""" | ||
The tests in this file check that clambcc is able to compile the example | ||
bytecode signatures. | ||
""" | ||
|
||
import os | ||
from pathlib import Path | ||
import platform | ||
import shutil | ||
import subprocess | ||
import sys | ||
import time | ||
import unittest | ||
|
||
import testcase | ||
|
||
|
||
os_platform = platform.platform() | ||
operating_system = os_platform.split('-')[0].lower() | ||
|
||
|
||
class TC(testcase.TestCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
super(TC, cls).setUpClass() | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
super(TC, cls).tearDownClass() | ||
|
||
def setUp(self): | ||
super(TC, self).setUp() | ||
|
||
def tearDown(self): | ||
super(TC, self).tearDown() | ||
self.verify_valgrind_log() | ||
|
||
def test_00_run_test(self): | ||
self.step_name('Test that clamscan can run a specific signature.') | ||
|
||
testPath = os.path.join(TC.path_source , 'test' , '02' , 'Sig.c') | ||
|
||
SIGDIR = 'sigs' | ||
os.mkdir(SIGDIR) | ||
|
||
self.execute_command(f'{TC.clambcc} {testPath} -o {SIGDIR} {TC.headers}') | ||
|
||
SAMPLEDIR = 'samples' | ||
os.mkdir (SAMPLEDIR) | ||
|
||
SIGSTRING='CLAMAV-TEST-STRING-NOT-EICAR' | ||
outFile = os.path.join(SAMPLEDIR, 'file') | ||
self.execute_command (f'echo {SIGSTRING} > {outFile}') | ||
|
||
command = f'clamscan --bytecode-unsigned -d {SIGDIR} {SAMPLEDIR}' | ||
output = self.execute_command (command) | ||
|
||
self.verify_output(output.out, expected='Clamav-Unit-Test-Signature.02 FOUND') | ||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.