Exemplo n.º 1
0
    def test_writing(self):
        desc = 'This is a basic description of a campaign'
        camp = Campaign(name='A Campaign', lang='en', description=desc)

        o = stixlangwrap(['th', 'en'], camp)

        # that an object w/o a translation object raise an error
        self.assertRaises(ValueError, o.setlangtext, 'description', 'th',
                          'foo')

        # that a translation object can be added
        o.addtranslationobject(ident=self.ident)

        # and that it can be fetched:
        transobj = o.gettranslationobject()

        # and that is is a properly formed object
        self.assertEqual(transobj.type, 'language-content')
        self.assertEqual(transobj.created_by_ref, self.ident.id)

        # and the English description is returned
        self.assertEqual(o.getlangtext('description'), ('en', desc))

        # that when a translation is set
        thdesc = 'a Thai description'
        o.setlangtext('description', 'th', thdesc)

        # that the translation is now returned
        self.assertEqual(o.getlangtext('description'), ('th', thdesc))

        transobj = o.gettranslationobject()

        # and the translation is in the correct location
        self.assertEqual(transobj.contents['th']['description'], thdesc)
def rel_mem_store():
    cam = Campaign(id=CAMPAIGN_ID, **CAMPAIGN_KWARGS)
    idy = Identity(id=IDENTITY_ID, **IDENTITY_KWARGS)
    ind = Indicator(id=INDICATOR_ID, **INDICATOR_KWARGS)
    mal = Malware(id=MALWARE_ID, **MALWARE_KWARGS)
    rel1 = Relationship(ind, 'indicates', mal, id=RELATIONSHIP_IDS[0])
    rel2 = Relationship(mal, 'targets', idy, id=RELATIONSHIP_IDS[1])
    rel3 = Relationship(cam, 'uses', mal, id=RELATIONSHIP_IDS[2])
    stix_objs = [cam, idy, ind, mal, rel1, rel2, rel3]
    yield MemoryStore(stix_objs)
Exemplo n.º 3
0
    def test_nolang(self):
        desc = 'This is a basic description of a campaign.'
        camp = Campaign(name='A Campaign',
                        description=desc,
                        created_by_ref=self.ident.id)

        o = stixlangwrap('th', camp)

        # that a campaign object w/o language, returns None as the
        # language
        self.assertEqual(o.getlangtext('description'), (None, desc))
Exemplo n.º 4
0
    def test_notfoundbundle(self):
        desc = 'This is a basic description of a campaign.'
        camp = Campaign(name='A Campaign',
                        lang='en',
                        description=desc,
                        created_by_ref=self.ident.id)

        o = stixlangwrap('en', camp)

        bundle = Bundle(objects=[camp, _BogusLC(object_ref=camp.id)])

        self.assertRaises(ValueError, o.addtranslationobject, bundle=bundle)
Exemplo n.º 5
0
    def test_failures(self):
        desc = 'This is a basic description of a campaign.'
        camp = Campaign(name='A Campaign',
                        lang='en',
                        description=desc,
                        created_by_ref=self.ident.id)

        o = stixlangwrap('en', camp)
        self.assertRaises(ValueError, o.addtranslationobject, camp)

        self.assertRaises(ValueError, o.addtranslationobject)
        self.assertRaises(ValueError, o.addtranslationobject, 1, 1)
def test_memory_store_object_with_custom_property(mem_store):
    camp = Campaign(
        name="Scipio Africanus",
        objective="Defeat the Carthaginians",
        x_empire="Roman",
        allow_custom=True,
    )

    mem_store.add(camp)

    camp_r = mem_store.get(camp.id)
    assert camp_r.id == camp.id
    assert camp_r.x_empire == camp.x_empire
def test_memory_store_object_creator_of_missing(mem_store):
    camp = Campaign(
        name="Scipio Africanus",
        objective="Defeat the Carthaginians",
        x_empire="Roman",
        allow_custom=True,
    )

    mem_store.add(camp)

    camp_r = mem_store.get(camp.id)
    assert camp_r.id == camp.id
    assert camp_r.x_empire == camp.x_empire
    assert mem_store.creator_of(camp) is None
def test_memory_store_object_creator_of_present(mem_store):
    camp = Campaign(
        name="Scipio Africanus",
        objective="Defeat the Carthaginians",
        created_by_ref=IDENTITY_ID,
        x_empire="Roman",
        allow_custom=True,
    )

    iden = Identity(
        id=IDENTITY_ID,
        name="Foo Corp.",
        identity_class="corporation",
    )

    mem_store.add(camp)
    mem_store.add(iden)

    camp_r = mem_store.get(camp.id)
    assert camp_r.id == camp.id
    assert camp_r.x_empire == camp.x_empire
    assert mem_store.creator_of(camp_r) == iden
Exemplo n.º 9
0
attack_pattern2 = AttackPattern(
    type="attack-pattern",
    spec_version="2.1",
    id="attack-pattern--f6050ea6-a9a3-4524-93ed-c27858d6cb3c",
    created="2016-08-08T15:50:10.983Z",
    modified="2017-01-30T21:15:04.127Z",
    name="HTTP Flood",
    external_references=[ref_capec2])

campaign1 = Campaign(
    type="campaign",
    spec_version="2.1",
    id="campaign--e5268b6e-4931-42f1-b379-87f48eb41b1e",
    created="2016-08-08T15:50:10.983Z",
    modified="2016-08-08T15:50:10.983Z",
    name="Operation Bran Flakes",
    description=
    "A concerted effort to insert false information into the BPP's web pages.",
    aliases=["OBF"],
    first_seen="2016-01-08T12:50:40.123Z",
    objective="Hack www.bpp.bn")

campaign2 = Campaign(type="campaign",
                     spec_version="2.1",
                     id="campaign--1d8897a7-fdc2-4e59-afc9-becbe04df727",
                     created="2016-08-08T15:50:10.983Z",
                     modified="2016-08-08T15:50:10.983Z",
                     name="Operation Raisin Bran",
                     description="A DDOS campaign to flood BPP web servers.",
                     aliases=["ORB"],
                     first_seen="2016-02-07T19:45:32.126Z",
Exemplo n.º 10
0
    def test_reading(self):
        name = 'A Campaign'
        desc = 'This is a basic description of a campaign.'
        camp = Campaign(name=name,
                        lang='en',
                        description=desc,
                        created_by_ref=self.ident.id)

        # that a simple language wrapper
        o = stixlangwrap('en', camp)

        # returns the parent descrption
        self.assertEqual(o.description, desc)

        # and the correct language
        self.assertEqual(o.getlangtext('description'), ('en', desc))

        o = stixlangwrap(['th', 'en'], camp)

        # that when a translaction object
        thdesc = 'A description in Thai.'
        transobj = LanguageContent(object_ref=camp.id,
                                   object_modified=camp.modified,
                                   contents={'th': {
                                       'description': thdesc
                                   }},
                                   created_by_ref=self.ident.id)

        # is added to a language wrapper w/ Thai as the priority
        o.addtranslationobject(transobj)

        # that the Thai description is returned
        self.assertEqual(o.description, thdesc)
        self.assertEqual(o.getlangtext('description'), ('th', thdesc))

        # that then a translation object does not have a translation for a
        # property, that it falls back to what is available
        self.assertEqual(o.getlangtext('name'), ('en', name))

        # That a Thai language wrapper
        o = stixlangwrap('th', camp)

        # with no translation, returns the English text
        self.assertEqual(o.description, desc)
        self.assertEqual(o.getlangtext('description'), ('en', desc))

        # That a Thai language wrapper, that does not want defaults
        o = stixlangwrap('th', camp, no_default=True)

        # w/o a translation

        # raises errors
        self.assertRaises(AttributeError, getattr, o, 'description')
        self.assertRaises(AttributeError, o.getlangtext, 'description')

        o = stixlangwrap(['th', 'en'], camp)

        # that when a translaction object
        thdesc = 'A description in Thai.'
        transobj = LanguageContent(object_ref=camp.id,
                                   object_modified=camp.modified,
                                   contents={'th': {
                                       'description': thdesc
                                   }},
                                   created_by_ref=self.ident.id)

        # is added to a language wrapper w/ Thai as the priority
        o.addtranslationobject(transobj)

        # and a second translaction object
        thname = 'A name in Thai.'
        transobj2 = LanguageContent(object_ref=camp.id,
                                    object_modified=camp.modified,
                                    contents={'th': {
                                        'name': thname
                                    }},
                                    created_by_ref=self.ident.id)

        # is added to a language wrapper w/ Thai as the priority
        o.addtranslationobject(transobj2)

        # that both translations are returned
        self.assertEqual(o.getlangtext('description'), ('th', thdesc))
        self.assertEqual(o.getlangtext('name'), ('th', thname))