Commit 7fd7b2d0 by Thomas Barabosch

Implements proper acceptance tests for cwe215, cwe243, and cwe476.

parent f227fc6b
......@@ -213,4 +213,6 @@ test/run_real_world_samples.sh
.project
.pydevproject
src/cwe_checker.plugin
\ No newline at end of file
src/cwe_checker.plugin
.#*
\ No newline at end of file
import subprocess
def build_bap_cmd(filename, target, arch):
cmd = 'bap test/artificial_samples/build/cwe_%s_%s.out --pass=callsites,cwe-checker --cwe-checker-partial=CWE%s --cwe-checker-config=src/config.json' % (filename, arch, target)
return cmd.split()
def execute_and_check_occurence(filename, target, arch, string):
occurence = 0
bap_cmd = build_bap_cmd(filename, target, arch)
output = subprocess.check_output(bap_cmd)
for l in output.splitlines():
if string in l:
occurence += 1
return occurence
import unittest
import cwe_checker_testlib
class TestCwe215(unittest.TestCase):
def setUp(self):
self.target = '215'
self.filename = '476'
self.string = b'Information Exposure Through Debug Information'
def test_cwe215_01_arm(self):
expect_res = 1
res = cwe_checker_testlib.execute_and_check_occurence(self.filename, self.target, 'arm', self.string)
assert res == expect_res
def test_cwe215_01_x86(self):
expect_res = 1
res = cwe_checker_testlib.execute_and_check_occurence(self.filename, self.target, 'x86', self.string)
assert res == expect_res
def test_cwe215_01_x64(self):
expect_res = 1
res = cwe_checker_testlib.execute_and_check_occurence(self.filename, self.target, 'x64', self.string)
assert res == expect_res
def test_cwe215_01_ppc(self):
expect_res = 1
res = cwe_checker_testlib.execute_and_check_occurence(self.filename, self.target, 'ppc', self.string)
assert res == expect_res
def test_cwe215_01_mips(self):
expect_res = 1
res = cwe_checker_testlib.execute_and_check_occurence(self.filename, self.target, 'mips', self.string)
assert res == expect_res
import unittest
import cwe_checker_testlib
class TestCwe243(unittest.TestCase):
def setUp(self):
self.target = '243'
self.string = b'The program utilizes chroot without dropping privileges and/or changing the directory'
def test_cwe243_01_arm(self):
expect_res = 1
res = cwe_checker_testlib.execute_and_check_occurence(self.target, self.target, 'arm', self.string)
assert res == expect_res
def test_cwe243_01_x86(self):
expect_res = 1
res = cwe_checker_testlib.execute_and_check_occurence(self.target, self.target, 'x86', self.string)
assert res == expect_res
def test_cwe243_01_x64(self):
expect_res = 1
res = cwe_checker_testlib.execute_and_check_occurence(self.target, self.target, 'x64', self.string)
assert res == expect_res
def test_cwe243_01_ppc(self):
expect_res = 1
res = cwe_checker_testlib.execute_and_check_occurence(self.target, self.target, 'ppc', self.string)
assert res == expect_res
@unittest.skip("Depends on proper MIPS support in BAP")
def test_cwe243_01_mips(self):
expect_res = 1
res = cwe_checker_testlib.execute_and_check_occurence(self.target, self.target, 'mips', self.string)
assert res == expect_res
def test_cwe243_02_arm(self):
expect_res = 0
res = cwe_checker_testlib.execute_and_check_occurence(self.target + "_clean", self.target, 'arm', self.string)
assert res == expect_res
@unittest.skip("Investigate and fix this issue")
def test_cwe243_02_x86(self):
expect_res = 0
res = cwe_checker_testlib.execute_and_check_occurence(self.target + "_clean", self.target, 'x86', self.string)
assert res == expect_res
def test_cwe243_02_x64(self):
expect_res = 0
res = cwe_checker_testlib.execute_and_check_occurence(self.target + "_clean", self.target, 'x64', self.string)
assert res == expect_res
def test_cwe243_02_ppc(self):
expect_res = 0
res = cwe_checker_testlib.execute_and_check_occurence(self.target + "_clean", self.target, 'ppc', self.string)
assert res == expect_res
@unittest.skip("Depends on proper MIPS support in BAP")
def test_cwe476_02_mips(self):
expect_res = 0
res = cwe_checker_testlib.execute_and_check_occurence(self.target + "_clean", self.target, 'mips', self.string)
assert res == expect_res
import unittest
import cwe_checker_testlib
class TestCwe476(unittest.TestCase):
def setUp(self):
self.target = '476'
self.string = b'NULL Pointer Dereference'
def test_cwe476_01_arm(self):
expect_res = 1
res = cwe_checker_testlib.execute_and_check_occurence(self.target, self.target, 'arm', self.string)
assert res == expect_res
def test_cwe476_01_x86(self):
expect_res = 1
res = cwe_checker_testlib.execute_and_check_occurence(self.target, self.target, 'x86', self.string)
assert res == expect_res
def test_cwe476_01_x64(self):
expect_res = 1
res = cwe_checker_testlib.execute_and_check_occurence(self.target, self.target, 'x64', self.string)
assert res == expect_res
@unittest.skip("Depends on proper MIPS support in BAP")
def test_cwe476_01_mips(self):
expect_res = 1
res = cwe_checker_testlib.execute_and_check_occurence(self.target, self.target, 'mips', self.string)
assert res == expect_res
@unittest.skip("Fix issue in CWE476 implementation to support PPC")
def test_cwe476_01_ppc(self):
expect_res = 1
res = cwe_checker_testlib.execute_and_check_occurence(self.target, self.target, 'ppc', self.string)
assert res == expect_res
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment