Ejemplo n.º 1
0
    def from_cflow(cls, cflow_line, granularity=Granularity.FUNC):
        """Instantiate Call by parsing a line from cflow call graph.

        Parameters
        ----------
        cflow_line : str
            A line of string from the cflow call graph.
        granularity : str
            The granularity of the call graph into which the instance of Call
            will be added to. See attacksurfacemeter.granularity.Granularity
            for available choices.

        Returns
        -------
        new_instance : Call
            An instance of Call.
        """
        cflow_line_parser = CflowLineParser.get_instance(cflow_line)

        new_instance = cls(cflow_line_parser.get_function_name(),
                           cflow_line_parser.get_function_signature(),
                           Environments.C, granularity)
        new_instance.level = cflow_line_parser.get_level()

        return new_instance
Ejemplo n.º 2
0
    def test_get_function_signature_name_only(self):
        # Arrange
        test_line_parser = CflowLineParser.get_instance("            printf()")

        # Act
        test_function_signature = test_line_parser.get_function_signature()

        # Assert
        self.assertEqual("", test_function_signature)
Ejemplo n.º 3
0
    def from_cflow(cls, cflow_line):
        cflow_line_parser = CflowLineParser.get_instance(cflow_line)

        new_instance = cls(cflow_line_parser.get_function_name(),
                           cflow_line_parser.get_function_signature(),
                           Environments.C)
        new_instance.level = cflow_line_parser.get_level()

        return new_instance
    def test_get_function_name(self):
        # Arrange
        test_line_parser = CflowLineParser.get_instance("GreeterSayHi() <void GreeterSayHi () at ./src/helloworld.c:48>:")

        # Act
        test_function_name = test_line_parser.get_function_name()

        # Assert
        self.assertEqual("GreeterSayHi", test_function_name)
    def test_get_level_2(self):
        # Arrange
        test_line_parser = CflowLineParser.get_instance("        recursive_b() <void recursive_b (int i) at ./src/greetings.c:32> (R):")

        # Act
        test_level = test_line_parser.get_level()

        # Assert
        self.assertEqual(2, test_level)
    def test_get_level_0(self):
        # Arrange
        test_line_parser = CflowLineParser.get_instance("GreeterSayHi() <void GreeterSayHi () at ./src/helloworld.c:48>:")

        # Act
        test_level = test_line_parser.get_level()

        # Assert
        self.assertEqual(0, test_level)
    def test_get_function_signature_name_only(self):
        # Arrange
        test_line_parser = CflowLineParser.get_instance("            printf()")

        # Act
        test_function_signature = test_line_parser.get_function_signature()

        # Assert
        self.assertEqual("", test_function_signature)
Ejemplo n.º 8
0
    def test_get_function_name(self):
        # Arrange
        test_line_parser = CflowLineParser.get_instance(
            "GreeterSayHi() <void GreeterSayHi () at ./src/helloworld.c:48>:")

        # Act
        test_function_name = test_line_parser.get_function_name()

        # Assert
        self.assertEqual("GreeterSayHi", test_function_name)
Ejemplo n.º 9
0
    def test_get_level_0(self):
        # Arrange
        test_line_parser = CflowLineParser.get_instance(
            "GreeterSayHi() <void GreeterSayHi () at ./src/helloworld.c:48>:")

        # Act
        test_level = test_line_parser.get_level()

        # Assert
        self.assertEqual(0, test_level)
    def test_issue_41(self):
        '''Unit test to test the fix for issue #41.
        
        Specifics:
            https://github.com/andymeneely/attack-surface-metrics/issues/41
        '''

        # Arrange
        test_line_parser = CflowLineParser.get_instance(
            "mp_msg() <void mp_msg (int mod, int lev, const char *format, "
                "...) at ./libavfilter/vf_mp.c:353>: [see 20795]"
        )

        # Act
        test_function_signature = test_line_parser.get_function_signature()

        # Assert
        self.assertEqual("./libavfilter/vf_mp.c", test_function_signature)

        # Arrange
        test_line_parser = CflowLineParser.get_instance(
            "    mp_msg() <void mp_msg (int mod, int lev, const char "
                "*format, ...) at ./libavfilter/vf_mp.c:353>:"
        )

        # Act
        test_function_signature = test_line_parser.get_function_signature()

        # Assert
        self.assertEqual("./libavfilter/vf_mp.c", test_function_signature)

        # Arrange
        test_line_parser = CflowLineParser.get_instance(
            "    mp_msg() <void mp_msg (int mod, int lev, const char "
                "*format, ...) at ./libavfilter/vf_mp.c:353>: [see 20795]"
        )

        # Act
        test_function_signature = test_line_parser.get_function_signature()

        # Assert
        self.assertEqual("./libavfilter/vf_mp.c", test_function_signature)
Ejemplo n.º 11
0
    def test_get_level_2(self):
        # Arrange
        test_line_parser = CflowLineParser.get_instance(
            "        recursive_b() <void recursive_b (int i) at ./src/greetings.c:32> (R):"
        )

        # Act
        test_level = test_line_parser.get_level()

        # Assert
        self.assertEqual(2, test_level)
Ejemplo n.º 12
0
    def test_issue_41(self):
        '''Unit test to test the fix for issue #41.
        
        Specifics:
            https://github.com/andymeneely/attack-surface-metrics/issues/41
        '''

        # Arrange
        test_line_parser = CflowLineParser.get_instance(
            "mp_msg() <void mp_msg (int mod, int lev, const char *format, "
            "...) at ./libavfilter/vf_mp.c:353>: [see 20795]")

        # Act
        test_function_signature = test_line_parser.get_function_signature()

        # Assert
        self.assertEqual("./libavfilter/vf_mp.c", test_function_signature)

        # Arrange
        test_line_parser = CflowLineParser.get_instance(
            "    mp_msg() <void mp_msg (int mod, int lev, const char "
            "*format, ...) at ./libavfilter/vf_mp.c:353>:")

        # Act
        test_function_signature = test_line_parser.get_function_signature()

        # Assert
        self.assertEqual("./libavfilter/vf_mp.c", test_function_signature)

        # Arrange
        test_line_parser = CflowLineParser.get_instance(
            "    mp_msg() <void mp_msg (int mod, int lev, const char "
            "*format, ...) at ./libavfilter/vf_mp.c:353>: [see 20795]")

        # Act
        test_function_signature = test_line_parser.get_function_signature()

        # Assert
        self.assertEqual("./libavfilter/vf_mp.c", test_function_signature)