Пример #1
0
  def validate(self, full=True):
    """
    Checks if the attributes of the class are valid

    :returns: Boolean
    """
    ObjectValidator.validateDigits(self, 'def_attribute_id')
    # validate attribute value
    value_obj = self.__get_value_obj()
    # TODO: encoding error
    ObjectValidator.validateRegex(value_obj,
                                  'value',
                                  getattr(self.definition, 'regex'),
                                  u'The value "{0}" does not match {1} for definition {2}'.format(value_obj.value,
                                                                                                  getattr(self.definition, 'regex'),
                                                                                                  getattr(self.definition, 'name')).encode('utf-8'),
                                  True)
    errors = not getattr(value_obj, 'validate')()
    if errors:
      return False

    if full:
      ObjectValidator.validateDigits(self, 'object_id')
      ObjectValidator.validateDigits(self, 'creator_id')
      ObjectValidator.validateDigits(self, 'modifier_id')
    ObjectValidator.validateDateTime(self, 'created')
    ObjectValidator.validateDateTime(self, 'modified')
    return ObjectValidator.isObjectValid(self)
Пример #2
0
  def validate(self):
    """
    Checks if the attributes of the class are valid

    :returns: Boolean
    """
    # TODO: Edit cannot change username!
    # TODO: Verify validation of User Object
    if not (self.password or self.username):
      return False
    ObjectValidator.validateAlNum(self,
                                  'username',
                                  minLength=3,
                                  maxLength=254)
    # Don't update if the password is already a hash
    if not (self.password == 'EXTERNALAUTH') and re.match('^[0-9a-f]{40}$',
                                                          self.password) is None:
      ObjectValidator.validateRegex(self,
                                    'password',
                                    r'(?=^.{8,}$)(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[\W_])(?=^.*[^\s].*$).*$',
                                    'Password has to be set and contain Upper and Lower cases, symbols and numbers and have at least a length of 8'
                                    )

    ObjectValidator.validateEmailAddress(self, 'email')
    ObjectValidator.validateAlNum(self, 'name', minLength=3, withSymbols=True)
    ObjectValidator.validateAlNum(self, 'sirname', minLength=3, withSymbols=True)

    # if self.gpg_key:
    #  ObjectValidator.validateRegex(self,
    #                                'gpg_key',
    #                                '-----BEGIN PGP PUBLIC KEY BLOCK-----(.*?)-----END PGP PUBLIC KEY BLOCK-----',
    #                                'GPG Key not under the right format')
    if self.last_login is not None:
      ObjectValidator.validateDateTime(self, 'last_login')
    return ObjectValidator.isObjectValid(self)
Пример #3
0
    def validate(self):
        """
    Checks if the attributes of the class are valid

    :returns: Boolean
    """
        return ObjectValidator.validateDateTime(self, 'value')
Пример #4
0
  def validate(self):
    """
    Checks if the attributes of the class are valid

    :returns: Boolean
    """
    ObjectValidator.validateAlNum(self, 'title', withSpaces=True, minLength=3,
                                  withSymbols=True)
    ObjectValidator.validateAlNum(self,
                                  'description',
                                  withNonPrintableCharacters=True,
                                  withSpaces=True,
                                  minLength=3,
                                  withSymbols=True)
    ObjectValidator.validateDigits(self, 'tlp_level_id', minimal=0, maximal=3)
    ObjectValidator.validateDigits(self, 'status_id', minimal=0, maximal=3)
    ObjectValidator.validateDigits(self, 'published', minimal=0, maximal=1)
    ObjectValidator.validateDigits(self, 'risk_id', minimal=0, maximal=4)
    ObjectValidator.validateDigits(self, 'analysis_status_id', minimal=0, maximal=4)
    ObjectValidator.validateDigits(self, 'creator_id')
    ObjectValidator.validateDigits(self, 'modifier_id')
    ObjectValidator.validateDateTime(self, 'created')
    ObjectValidator.validateDateTime(self, 'modified')
    if self.first_seen is not None:
      ObjectValidator.validateDateTime(self, 'first_seen')
    if self.last_seen is not None:
      ObjectValidator.validateDateTime(self, 'last_seen')
    if ((self.first_seen is not None and self.last_seen is not None) and not isinstance(self.first_seen, FailedValidation) and not isinstance(self.last_seen, FailedValidation)):
      # check if date is time zone avare
      if not self.first_seen.tzinfo:
        self.first_seen = self.__create_tzaware_datetime(self.first_seen)
      if not self.last_seen.tzinfo:
        self.last_seen = self.__create_tzaware_datetime(self.last_seen)

      if self.first_seen > self.last_seen:
        setattr(self, 'first_seen',
                FailedValidation(self.first_seen,
                                 'First seen is after last seen.'))
        setattr(self, 'last_seen',
                FailedValidation(self.last_seen,
                                 'Last seen is before last seen.'))
    if self.first_seen is None and self.last_seen is not None:
      setattr(self, 'first_seen',
              FailedValidation(self.first_seen,
                               'First seen cannot be empty when last seen is'
                               + ' set.'))
      setattr(self, 'last_seen',
              FailedValidation(self.last_seen,
                               'Last seen cannot be set when first seen is'
                               + ' empty.'))
    return ObjectValidator.isObjectValid(self)
Пример #5
0
  def validate(self, ignore_attribtues=False):
    """
    Checks if the attributes of the class are valid

    :returns: Boolean
    """
    if not ignore_attribtues:
      for attribute in self.attributes:
        result = attribute.validate()
        if not result:
          return False
    function = getattr(self.definition, 'validate')
    if not function():
      return False
    ObjectValidator.validateDigits(self, 'creator_id')
    ObjectValidator.validateDateTime(self, 'created')
    ObjectValidator.validateDigits(self, 'def_object_id')
    if self.parent_object_id is not None:
      ObjectValidator.validateDigits(self, 'parent_object_id')
    ObjectValidator.validateDateTime(self, 'created')
    return ObjectValidator.isObjectValid(self)
Пример #6
0
  def validateDateTime(string):
    """
      Validates if the attribute is a date or date time under the
      specified formats address.

      Note: The actual object is changed internally

      :param string: Text to be analyzed
      :type string: String


      :return Boolean
    """
    obj = Container(string)
    return ObjectValidator.validateDateTime(obj, 'value',
                                            changeAttribute=False)
Пример #7
0
    def validateDateTime(string):
        """
      Validates if the attribute is a date or date time under the
      specified formats address.

      Note: The actual object is changed internally

      :param string: Text to be analyzed
      :type string: String


      :return Boolean
    """
        obj = Container(string)
        return ObjectValidator.validateDateTime(obj,
                                                'value',
                                                changeAttribute=False)
Пример #8
0
  def validate(self):
    """
    Checks if the attributes of the class are valid

    :returns: Boolean
    """
    ObjectValidator.validateDateTime(self, 'created')
    ObjectValidator.validateDigits(self, 'creator_id')
    ObjectValidator.validateDigits(self, 'modifier_id')
    ObjectValidator.validateDigits(self, 'event_id')
    ObjectValidator.validateAlNum(self,
                                  'comment',
                                  minLength=5,
                                  withSpaces=True,
                                  withNonPrintableCharacters=True,
                                  withSymbols=True)
    ObjectValidator.validateDateTime(self, 'created')
    ObjectValidator.validateDateTime(self, 'modified')
    return ObjectValidator.isObjectValid(self)