Example #1
0
File: file.py Project: Jc2k/sashimi
def sibpath(path):
    d, f = os.path.split(__file__)
    return os.path.join(d, path)

class File(object):

    @classmethod
    def can_fuzz(cls, field):
        if field["type"] == "file":
            return True
        return False

    def fuzz(self, field, content_types):
        return open(sibpath("assets/test.mp3")).read()

registry.register(File)


class Image(object):

    @classmethod
    def can_fuzz(cls, field):
        if field["type"] == "image":
            return True
        return False

    def fuzz(self, field, content_types):
        return open(sibpath("assets/test.png")).read()

registry.register(Image)
Example #2
0

class StringFuzzer(object):

    @classmethod
    def can_fuzz(cls, field):
        if field["type"] == "string" and "vocabulary" in field:
            return True
        return False

    def fuzz(self, field, content_types):
        return random.choice(field["vocabulary"])


class LinesFuzzer(object):

    @classmethod
    def can_fuzz(cls, field):
        if field["type"] == "lines" and "vocabulary" in field:
            return True
        return False

    def fuzz(self, field, content_types):
        return random.choice(field["vocabulary"])


registry.register(TextFuzzer)
registry.register(StringFuzzer)
registry.register(LinesFuzzer)

Example #3
0
    tokenizer = Tokenizer()
    tokenizer.visit(regex, visitor)
    return visitor.root


class RegexFuzzer(object):

    """
    Allows a field with regex validation to have test data generated. This is
    calculated with a graph not simply brute force.

    This is a very thin wrapper around :py:class:`TreeGenerator` to make it
    follow the sashimi field generator interface.
    """

    @classmethod
    def can_fuzz(cls, field):
        if "regex" in field:
            return True
        return False

    def fuzz(self, field, content_types):
        """
        Returns a random string that satisfies the ``regex`` in field
        """
        return get_regex_tree(field['regex']).random()

registry.register(RegexFuzzer)


Example #4
0
class Reference(object):
    @classmethod
    def can_fuzz(cls, field):
        if field["type"] == "reference":
            return True
        return False

    def fuzz(self, field, content_types):
        if field["allowed_types"]:
            # Pick a random allowed_type
            pt = random.choice(field["allowed_types"])

            # Do we have one already?
            pc = getToolByName(content_types.portal, "portal_catalog")
            results = pc({"portal_type": pt})
            if results:
                return random.choice(results).UID

            # We dont have one, create one
            ct = random.choice(content_types.chains[pt])
            new_obj = ct.create_chain(content_types.portal, lazy=True)
            return new_obj.ob.UID()

        for pt, ct in content_types.portal.objectItems():
            if ct.portal_type in content_types.chains:
                return ct.UID()


registry.register(Reference)
Example #5
0
import random
from sashimi.generators.registry import registry

class Numbers(object):

    @classmethod
    def can_fuzz(cls, field):
        return False

    def fuzz(self, field, content_types):
        return random.randint(0, 9999999999999)


registry.register(Numbers)

Example #6
0
try:
    from DateTime import DateTime
except ImportError:
    pass

from sashimi.generators.registry import registry

class DatetimeFuzzer(object):

    @classmethod
    def can_fuzz(cls, field):
        if field["type"] == "datetime":
            return True
        return False

    def fuzz(self, field, content_types):
        return DateTime()

registry.register(DatetimeFuzzer)
Example #7
0
File: bool.py Project: Jc2k/sashimi
import random
from sashimi.generators.registry import registry

class Bool(object):

    @classmethod
    def can_fuzz(cls, field):
        if field["type"] == "boolean":
            return True
        return False

    def fuzz(self, field, content_types):
        return random.choice((True, False))

registry.register(Bool)