Пример #1
0
def test_apply_diff_merge_detetion_points():
    original_root = RootAnalysis()
    original_observable = original_root.add_observable("test", "test")

    modified_root = original_root.copy()
    modified_observable = modified_root.get_observable(original_observable)
    modified_observable.add_detection_point("test")

    target_root = original_root.copy()
    target_observable = target_root.get_observable(original_observable)

    assert not target_observable.has_detection_points()
    target_observable.apply_diff_merge(original_observable,
                                       modified_observable)
    assert target_observable.has_detection_points

    # exists before but not after
    original_root = RootAnalysis()
    original_observable = original_root.add_observable("test", "test")

    modified_root = original_root.copy()
    modified_observable = modified_root.get_observable(original_observable)

    target_root = original_root.copy()
    target_observable = target_root.get_observable(original_observable)

    original_observable.add_detection_point("test")

    assert not target_observable.has_detection_points()
    target_observable.apply_diff_merge(original_observable,
                                       modified_observable)
    assert not target_observable.has_detection_points()
Пример #2
0
def test_apply_diff_merge_tags():
    original_root = RootAnalysis()
    original_observable = original_root.add_observable("test", "test")
    modified_root = original_root.copy()
    modified_observable = modified_root.get_observable(original_observable)
    modified_observable.add_tag("test")

    target_root = original_root.copy()
    target_observable = target_root.add_observable("test", "test")

    assert not target_observable.tags
    target_observable.apply_diff_merge(original_observable,
                                       modified_observable)
    assert target_observable.tags
    assert target_observable.tags[0] == "test"

    # exists before but not after
    original_root = RootAnalysis()
    original_observable = original_root.add_observable("test", "test")
    modified_root = original_root.copy()
    modified_observable = modified_root.get_observable(original_observable)

    target_root = original_root.copy()
    target_observable = target_root.add_observable("test", "test")

    original_observable.add_tag("test")

    assert not target_observable.tags
    target_observable.apply_diff_merge(original_observable,
                                       modified_observable)
    assert not target_observable.tags
Пример #3
0
def test_root_eq():
    # two different uuids
    assert RootAnalysis() != RootAnalysis()
    root = RootAnalysis()
    # same uuids
    assert root == root.copy()
    # invalid compare
    assert root != object()
    # same uuid different version
    root = RootAnalysis()
    modified_root = root.copy()
    modified_root.version = str(uuid.uuid4())
    assert root != modified_root
    # same uuid same version
    root.version = modified_root.version
    assert root == modified_root
Пример #4
0
def test_root_copy():
    root = RootAnalysis()
    observable = root.add_observable("test", "test")
    amt = AnalysisModuleType("test", "")
    analysis = observable.add_analysis(type=amt, details={"test": "test"})

    root_copy = root.copy()
    observable_copy = root_copy.get_observable(observable)
    assert observable_copy == observable
    assert not (observable_copy is observable)
    analysis_copy = observable_copy.get_analysis(amt)
    assert analysis_copy == analysis
    assert not (analysis_copy is analysis)
Пример #5
0
def test_root_diff_merge():
    target = RootAnalysis()
    before = RootAnalysis()
    after = before.copy()
    after.analysis_mode = "test"
    after.queue = "test"
    after.description = "test"
    after.analysis_cancelled = True
    after.analysis_cancelled_reason = "test"

    target.apply_diff_merge(before, after)
    assert target.analysis_mode == "test"
    assert target.queue == "test"
    assert target.description == "test"
    assert target.analysis_cancelled
    assert target.analysis_cancelled_reason == "test"