Exemplo n.º 1
0
def test_set_marking_mark_another_property_same_marking():
    before = Malware(
        granular_markings=[
            {
                "selectors": ["description"],
                "marking_ref": MARKING_IDS[0],
            },
        ],
        **MALWARE_KWARGS
    )
    after = Malware(
        granular_markings=[
            {
                "selectors": ["description"],
                "marking_ref": MARKING_IDS[1],
            },
            {
                "selectors": ["description"],
                "marking_ref": MARKING_IDS[2],
            },
        ],
        **MALWARE_KWARGS
    )
    before = markings.set_markings(before, [MARKING_IDS[1], MARKING_IDS[2]], ["description"])

    for m in before["granular_markings"]:
        assert m in after["granular_markings"]
Exemplo n.º 2
0
def test_set_marking_bad_input(data):
    before = Malware(object_marking_refs=[MARKING_IDS[0]], **MALWARE_KWARGS)
    after = Malware(object_marking_refs=[MARKING_IDS[0]], **MALWARE_KWARGS)
    with pytest.raises(exceptions.InvalidValueError):
        before = markings.set_markings(before, data, None)

    assert before == after
Exemplo n.º 3
0
def test_set_marking_mark_multiple_mixed_markings():
    before = Malware(
        granular_markings=[
            {
                "selectors": ["description", "modified"],
                "marking_ref": MARKING_IDS[1],
            },
            {
                "selectors": ["description", "modified"],
                "lang": MARKING_LANGS[2],
            },
        ],
        **MALWARE_KWARGS
    )
    after = Malware(
        granular_markings=[
            {
                "selectors": ["description", "modified"],
                "marking_ref": MARKING_IDS[2],
            },
            {
                "selectors": ["description", "modified"],
                "lang": MARKING_LANGS[3],
            },
        ],
        **MALWARE_KWARGS
    )
    before = markings.set_markings(before, [MARKING_IDS[2], MARKING_LANGS[3]], ["description", "modified"])
    for m in before["granular_markings"]:
        assert m in after["granular_markings"]
def test_set_marking_mark_multiple_selector_multiple_refs_from_none():
    before = Malware(**MALWARE_KWARGS)
    after = Malware(granular_markings=[{
        "selectors": ["description", "modified"],
        "marking_ref": MARKING_IDS[0]
    }, {
        "selectors": ["description", "modified"],
        "marking_ref": MARKING_IDS[1]
    }],
                    **MALWARE_KWARGS)
    before = markings.set_markings(before, [MARKING_IDS[0], MARKING_IDS[1]],
                                   ["description", "modified"])
    for m in before["granular_markings"]:
        assert m in after["granular_markings"]
def test_set_marking_bad_selector(marking):
    before = Malware(granular_markings=[{
        "selectors": ["description"],
        "marking_ref": MARKING_IDS[0]
    }],
                     **MALWARE_KWARGS)
    after = Malware(granular_markings=[{
        "selectors": ["description"],
        "marking_ref": MARKING_IDS[0]
    }],
                    **MALWARE_KWARGS)

    with pytest.raises(AssertionError):
        before = markings.set_markings(before, marking[0], marking[1])

    assert before == after
Exemplo n.º 6
0
def test_set_marking():
    before = Malware(
        object_marking_refs=[MARKING_IDS[0], MARKING_IDS[1], MARKING_IDS[2]],
        **MALWARE_KWARGS)
    after = Malware(object_marking_refs=[MARKING_IDS[4], MARKING_IDS[5]],
                    **MALWARE_KWARGS)

    before = markings.set_markings(before, [MARKING_IDS[4], MARKING_IDS[5]],
                                   None)

    for m in before["object_marking_refs"]:
        assert m in [MARKING_IDS[4], MARKING_IDS[5]]

    assert [MARKING_IDS[0], MARKING_IDS[1],
            MARKING_IDS[2]] not in before["object_marking_refs"]

    for x in before["object_marking_refs"]:
        assert x in after["object_marking_refs"]
def test_set_marking_mark_one_selector_multiple_lang_refs():
    before = Malware(**MALWARE_KWARGS)
    after = Malware(granular_markings=[
        {
            "selectors": ["description"],
            "lang": MARKING_LANGS[0],
        },
        {
            "selectors": ["description"],
            "lang": MARKING_LANGS[1],
        },
    ],
                    **MALWARE_KWARGS)
    before = markings.set_markings(before,
                                   [MARKING_LANGS[0], MARKING_LANGS[1]],
                                   ["description"])
    for m in before["granular_markings"]:
        assert m in after["granular_markings"]