Ejemplo n.º 1
0
    def test_process_attributes_prevent_duplicates(self):
        a = AttrFactory.create(name="a")
        a_a = AttrFactory.create(name="a")
        b = AttrFactory.create(name="b")
        obj = ClassFactory.create(attrs=[a, a_a, b])

        generator.process_attributes(obj, [])
        self.assertEqual([a, b], obj.attrs)
Ejemplo n.º 2
0
    def test_process_attributes_prevent_duplicates_after_process(self, *args):
        obj = ClassFactory.create(attrs=[
            AttrFactory.create(name="a."),
            AttrFactory.create(name="a-"),
            AttrFactory.create(name="a*"),
        ])

        generator.process_attributes(obj, [])
        actual = [(attr.name, attr.local_name) for attr in obj.attrs]
        expected = [("ys4", "a."), ("ys0", "a-"), ("yso", "a*")]
        self.assertEqual(expected, actual)
Ejemplo n.º 3
0
    def test_process_attributes_with_exploit_names(
        self,
        mock_process_attribute,
        mock_has_duplicate_attrs,
        mock_sanitize_attribute_names,
        mock_hash_attributes_names,
        mock_unset_attributes_local_names,
    ):
        obj = ClassFactory.elements(3)
        mock_has_duplicate_attrs.return_value = True
        generator.process_attributes(obj, ["a", "b"])
        mock_process_attribute.assert_has_calls(
            [mock.call(obj, attr, ["a", "b"]) for attr in obj.attrs])

        mock_sanitize_attribute_names.assert_called_once_with(obj)
        mock_unset_attributes_local_names.assert_called_once_with(obj)
        mock_hash_attributes_names.assert_called_once_with(obj)
Ejemplo n.º 4
0
    def test_process_attributes_with_duplicate_names(
        self,
        mock_process_attribute,
        mock_has_duplicate_attrs,
        mock_sanitize_attribute_names,
        mock_hash_attributes_names,
        mock_unset_attributes_local_names,
    ):
        obj = ClassFactory.elements(3)
        mock_has_duplicate_attrs.side_effect = [True, False]
        generator.process_attributes(obj, ["a", "b"])
        mock_process_attribute.assert_has_calls(
            [mock.call(obj, attr, ["a", "b"]) for attr in obj.attrs])

        mock_sanitize_attribute_names.assert_called_once_with(obj)
        mock_unset_attributes_local_names.assert_called_once_with(obj)
        self.assertEqual(0, mock_hash_attributes_names.call_count)
Ejemplo n.º 5
0
 def test_process_attributes(self, mock_process_attribute):
     obj = ClassFactory.elements(3)
     generator.process_attributes(obj, ["a", "b"])
     mock_process_attribute.assert_has_calls(
         [mock.call(obj, attr, ["a", "b"]) for attr in obj.attrs])