Beispiel #1
0
 def test_fuzzable_same_as_string_field_null(self):
     '''
     Verify that the number of mutations is the same as for a StringField with value 'null'
     '''
     t = warp_with_template(kjson.JsonNull(name='null', fuzzable=True))
     st = Template(name='reference template', fields=String('null', name='snull'))
     self.assertEqual(t.num_mutations(), st.num_mutations())
     while t.mutate():
         st.mutate()
         self.assertEqual(t.render().bytes, st.render().bytes)
Beispiel #2
0
 def test_fuzzable_same_as_quoted_string_field(self):
     '''
     Verify that the number of mutations is the same as for a quoted StringField with the same default value
     '''
     value = 'kitty'
     t = warp_with_template(kjson.JsonString(name='test', value=value, fuzzable=True))
     st = Template(name='reference template', fields=String(name='reference', value=value))
     self.assertEqual(t.num_mutations(), st.num_mutations())
     while t.mutate():
         st.mutate()
         self.assertEqual(t.render().bytes, '"%s"' % st.render().bytes)
Beispiel #3
0
        if content:
            content_name = '%s_content' + name
            if isinstance(content, StringTypes):
                fields.append(String(content, fuzzable=fuzz_content, name=content_name))
            elif isinstance(content, IntType):
                fields.append(SInt32(content, encoder=ENC_INT_DEC, fuzzable=fuzz_content, name=content_name))
            elif isinstance(content, ListType):
                fields.append(Static(delimiter))
                for elem in content:
                    _check_type(elem, XmlElement, 'element inside the content list')
                    fields.append(elem)
        fields.append(Static('</'))
        fields.append(Clone(value_field))
        fields.append(Static('>' + delimiter))
        super(XmlElement, self).__init__(fields, name=name)


if __name__ == '__main__':
    # name, attribute, value, fuzz_attribute=False, fuzz_value=True
    attributes = [
        XmlAttribute(name='attr1', attribute='boom', value='attr1 value'),
        XmlAttribute(name='attr2', attribute='box', value=2),
    ]
    inner_elements = [
        XmlElement(name='inner element', element_name='an_inner_element', content=1, delimiter='\n'),
        XmlElement(name='inner element 2', element_name='an_inner_element', content='brrr', delimiter='\n')
    ]
    element = XmlElement(name='element1', element_name='an_element', attributes=attributes, content=inner_elements, delimiter='\n')
    t = Template(element, name='test')
    print(t.render().tobytes())