示例#1
0
def validate_xml(data):
    try:
        return {
            "xml": sdv.validate_xml(StringIO.StringIO(data)).as_dict(),
            "best_practices": sdv.validate_best_practices(StringIO.StringIO(data)).as_dict(),
            "result": "validated"
        }
    except sdv.errors.ValidationError as e:
        return {"result": "error", "message": str(e)}
示例#2
0
def best_practice_validate(fn, options):
    """Performs STIX Best Practice validation against the input filename.

    Args:
        validator: An instance of STIXBestPracticeValidator
        fn: A filename for a STIX document
        options: ValidationOptions instance with validation options for
            this validation run.

    Returns:
        A dictionary of validation results

    """
    info("Performing best practice validation on %s" % fn)

    results = sdv.validate_best_practices(doc=fn, version=options.lang_version)

    return results
示例#3
0
def best_practice_validate(fn, options):
    """Performs STIX Best Practice validation against the input filename.

    Args:
        validator: An instance of STIXBestPracticeValidator
        fn: A filename for a STIX document
        options: ValidationOptions instance with validation options for
            this validation run.

    Returns:
        A dictionary of validation results

    """
    info("Performing best practice validation on %s" % fn)

    results = sdv.validate_best_practices(
        doc=fn,
        version=options.lang_version
    )

    return results
示例#4
0
    except sdv.errors.InvalidSTIXVersionError, e:
        rdict['xml'] = "@version attribute is invalid: %s" % str(e)
    except sdv.errors.ValidationError, e:
        rdict['xml'] = "Schema directory not found or schemaloc is False: %s" % str(e)
    except sdv.errors.XMLSchemaImportError, e:
        rdict['xml'] = "Error while processing schemas for validation: %s" % str(e)
    except sdv.errors.XMLSchemaIncludeError, e:
        rdict['xml'] = "Error processing xs:include directives: %s" % str(e)
    except IOError, e:
        rdict['xml'] = "Not a valid XML document: %s" % str(e)
    except Exception, e:
        rdict['xml'] = str(e)

    f.seek(0)
    try:
        result = sdv.validate_best_practices(f)
        rdict['best_practices'] = result.as_dict()
    except sdv.errors.UnknownSTIXVersionError, e:
        rdict['best_practices'] = "Could not determine @version attribute: %s" % str(e)
    except sdv.errors.InvalidSTIXVersionError, e:
        rdict['best_practices'] = "@version attribute is invalid: %s" % str(e)
    except IOError, e:
        rdict['best_practices'] = "Not a valid XML document: %s" % str(e)
    except Exception, e:
        rdict['best_practices'] = str(e)

    #f.seek(0)
    #try:
    #    result = sdv.validate_profile(f)
    #    rdict['profile'] = result.as_dict()
    #except sdv.errors.ProfileParseError, e:
 def setUp(cls):
     sio = StringIO(BP_INVALID_XML)
     cls.results = sdv.validate_best_practices(sio)
示例#6
0
 def setUp(cls):
     sio = StringIO(BP_INVALID_XML)
     cls.results = sdv.validate_best_practices(sio)
示例#7
0
            'xml'] = "Schema directory not found or schemaloc is False: %s" % str(
                e)
    except sdv.errors.XMLSchemaImportError, e:
        rdict[
            'xml'] = "Error while processing schemas for validation: %s" % str(
                e)
    except sdv.errors.XMLSchemaIncludeError, e:
        rdict['xml'] = "Error processing xs:include directives: %s" % str(e)
    except IOError, e:
        rdict['xml'] = "Not a valid XML document: %s" % str(e)
    except Exception, e:
        rdict['xml'] = str(e)

    f.seek(0)
    try:
        result = sdv.validate_best_practices(f)
        rdict['best_practices'] = result.as_dict()
    except sdv.errors.UnknownSTIXVersionError, e:
        rdict[
            'best_practices'] = "Could not determine @version attribute: %s" % str(
                e)
    except sdv.errors.InvalidSTIXVersionError, e:
        rdict['best_practices'] = "@version attribute is invalid: %s" % str(e)
    except IOError, e:
        rdict['best_practices'] = "Not a valid XML document: %s" % str(e)
    except Exception, e:
        rdict['best_practices'] = str(e)

    #f.seek(0)
    #try:
    #    result = sdv.validate_profile(f)