|
| 1 | +# |
| 2 | +# LAPluginTestCase.py - Test cases for License Checker plugin, part of ISA FW |
| 3 | +# |
| 4 | +# Copyright (c) 2015, Intel Corporation |
| 5 | +# |
| 6 | +# Redistribution and use in source and binary forms, with or without |
| 7 | +# modification, are permitted provided that the following conditions are met: |
| 8 | +# |
| 9 | +# * Redistributions of source code must retain the above copyright notice, |
| 10 | +# this list of conditions and the following disclaimer. |
| 11 | +# * Redistributions in binary form must reproduce the above copyright |
| 12 | +# notice, this list of conditions and the following disclaimer in the |
| 13 | +# documentation and/or other materials provided with the distribution. |
| 14 | +# * Neither the name of Intel Corporation nor the names of its contributors |
| 15 | +# may be used to endorse or promote products derived from this software |
| 16 | +# without specific prior written permission. |
| 17 | +# |
| 18 | +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 19 | +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 20 | +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 21 | +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE |
| 22 | +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 23 | +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 24 | +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 25 | +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 26 | +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 27 | +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE |
| 28 | + |
| 29 | +import unittest |
| 30 | +import sys |
| 31 | +sys.path.append("../isafw") |
| 32 | +import isafw |
| 33 | +import shutil |
| 34 | +import os |
| 35 | + |
| 36 | + |
| 37 | +reportdir = "./la_plugin/output" |
| 38 | + |
| 39 | +class TestLAPlugin(unittest.TestCase): |
| 40 | + |
| 41 | + def setUp(self): |
| 42 | + # cleaning up the report dir and creating it if needed |
| 43 | + if os.path.exists(os.path.dirname(reportdir+"/internal/test")): |
| 44 | + shutil.rmtree(reportdir) |
| 45 | + os.makedirs(os.path.dirname(reportdir+"/internal/test")) |
| 46 | + # fetching proxy info |
| 47 | + proxy = "" |
| 48 | + if "http_proxy" in os.environ: |
| 49 | + proxy = os.environ['http_proxy'] |
| 50 | + if "https_proxy" in os.environ: |
| 51 | + proxy = os.environ['https_proxy'] |
| 52 | + # creating ISA FW class |
| 53 | + self.imageSecurityAnalyser = isafw.ISA(proxy, reportdir) |
| 54 | + |
| 55 | + def test_package_with_licenses_OK(self): |
| 56 | + pkg = isafw.ISA_package() |
| 57 | + pkg.name = "bash" |
| 58 | + pkg.version = "4.3" |
| 59 | + pkg.licenses = ["Apache-1.1"] |
| 60 | + self.imageSecurityAnalyser.process_package(pkg) |
| 61 | + badLicExist = os.path.isfile (reportdir + "/license_report") |
| 62 | + # if no bad licenses exist no report is created |
| 63 | + self.assertFalse(badLicExist) |
| 64 | + |
| 65 | + def test_package_with_licenses_NotOK(self): |
| 66 | + pkg = isafw.ISA_package() |
| 67 | + pkg.name = "bash" |
| 68 | + pkg.version = "4.3" |
| 69 | + pkg.licenses = ["BadLicense-1.1"] |
| 70 | + self.imageSecurityAnalyser.process_package(pkg) |
| 71 | + with open(reportdir + "/license_report", 'r') as freport: |
| 72 | + output = freport.readline() |
| 73 | + print(output) |
| 74 | + # if bad licenses exist a report listing them is created |
| 75 | + self.assertEqual(output, |
| 76 | + "bash: BadLicense-1.1\n", |
| 77 | + 'Output does not match') |
| 78 | + |
| 79 | + |
| 80 | +if __name__ == '__main__': |
| 81 | + unittest.main() |
| 82 | + |
0 commit comments