Ejemplo n.º 1
0
 def test_to_xml_utf16_encoded(self):
     encoding = 'utf-16'
     s = STIXHeader()
     s.title = UNICODE_STR
     xml = s.to_xml(encoding=encoding)
     print(xml)
     self.assertTrue(UNICODE_STR in xml.decode(encoding))
Ejemplo n.º 2
0
 def test_to_xml_utf16_encoded(self):
     encoding = 'utf-16'
     s = STIXHeader()
     s.title = UNICODE_STR
     xml = s.to_xml(encoding=encoding)
     print(xml)
     self.assertTrue(UNICODE_STR in xml.decode(encoding))
Ejemplo n.º 3
0
def main():
    # Adding a Package_Intent field to a STIX_Header.
    from stix.core import STIXHeader
    from stix.common.vocabs import PackageIntent

    # Create STIXHeader instance
    header = STIXHeader()
    header.package_intents.append(PackageIntent.TERM_INDICATORS)

    # To add a Package_Intent value that exists outside of the
    # PackageIntentVocab controlled vocabulary, we pass in an
    # instance of VocabString.
    #
    # This will create a new Package_Intent field without an
    # xsi:type and will not perform any validation of input terms.
    #
    # Passing in an instance of VocabString works for every
    # ControlledVocabularyStringType field (or in python-stix,
    # every VocabString field).

    non_default_value = VocabString("NON STANDARD PACKAGE INTENT")
    header.package_intents.append(non_default_value)

    print header.to_xml()

    # NOTE: Passing in a str value that is not included in the list
    # of default CV terms will raise a ValueError. This is why we pass
    # in a VocabString instance.
    #
    # Example:
    try:
        print(
            "[-] Attempting to add an str instance that does not exist "
            "in the PackageIntent ALLOWED_VALUES list")
        header.package_intents.append("THIS WILL THROW A VALUEERROR")
    except Exception as ex:
        print "[!] As expected, that failed. Here's the Exception message:"
        print "[!]", str(ex)
Ejemplo n.º 4
0
def main():
    # Create STIXHeader instance
    header = STIXHeader()
    header.package_intents.append(PackageIntent.TERM_INDICATORS)

    # To add a Package_Intent value that exists outside of the
    # PackageIntentVocab controlled vocabulary, we pass in an
    # instance of VocabString.
    #
    # This will create a new Package_Intent field without an
    # xsi:type and will not perform any validation of input terms.
    #
    # Passing in an instance of VocabString works for every
    # ControlledVocabularyStringType field (or in python-stix,
    # every VocabString field).

    non_default_value = VocabString("NON STANDARD PACKAGE INTENT")
    header.package_intents.append(non_default_value)

    # Print XML!
    print header.to_xml()

    # NOTE: Passing in a str value that is not included in the list
    # of default CV terms will raise a ValueError. This is why we pass
    # in a VocabString instance.
    #
    # Example:
    try:
        msg = (
            "[-] Attempting to add an str instance that does not exist "
            "in the PackageIntent ALLOWED_VALUES list"
        )
        print(msg)

        header.package_intents.append("THIS WILL THROW A VALUEERROR")
    except Exception as ex:
        print "[!] As expected, that failed. Here's the Exception message:"
        print "[!]", str(ex)
Ejemplo n.º 5
0
 def test_to_xml_no_encoding(self):
     s = STIXHeader()
     s.title = UNICODE_STR
     xml = s.to_xml(encoding=None)
     self.assertTrue(isinstance(xml, unicode))
     self.assertTrue(UNICODE_STR in xml)
Ejemplo n.º 6
0
 def test_to_xml_default_encoded(self):
     s = STIXHeader()
     s.title = UNICODE_STR
     xml = s.to_xml()
     self.assertTrue(UNICODE_STR in xml.decode('utf-8'))
Ejemplo n.º 7
0
 def test_to_xml_no_encoding(self):
     s = STIXHeader()
     s.title = UNICODE_STR
     xml = s.to_xml(encoding=None)
     self.assertTrue(isinstance(xml, unicode))
     self.assertTrue(UNICODE_STR in xml)
Ejemplo n.º 8
0
 def test_to_xml_default_encoded(self):
     s = STIXHeader()
     s.title = UNICODE_STR
     xml = s.to_xml()
     self.assertTrue(UNICODE_STR in xml.decode("utf-8"))