예제 #1
0
    def test_completion_rate_not_running(self):
        rule = ScannerQueryRule(state=NEW, task_count=10000)
        assert rule.completion_rate() is None

        rule.state = SCHEDULED
        assert rule.completion_rate() is None

        rule.state = ABORTING
        assert rule.completion_rate() is None

        rule.state = ABORTED
        assert rule.completion_rate() is None
예제 #2
0
def test_query_rule_change_state_to_invalid(current_state, target_state):
    rule = ScannerQueryRule(name='some_rule', scanner=YARA)
    rule.state = current_state
    with pytest.raises(ImproperScannerQueryRuleStateError):
        rule.change_state_to(target_state)
    # Manually changing state doesn't affect 'completed' property, and since
    # changing through change_state_to() failed before it should always be
    # None in this test.
    assert rule.completed is None
예제 #3
0
def test_query_rule_change_state_to_valid(current_state, target_state):
    rule = ScannerQueryRule(name='some_rule', scanner=YARA)
    rule.state = current_state
    with freeze_time('2020-04-08 15:16:23.42') as frozen_time:
        rule.change_state_to(target_state)
    if target_state == COMPLETED:
        assert rule.completed == frozen_time()
    else:
        assert rule.completed is None
예제 #4
0
def test_query_rule_change_state_to_invalid(current_state, target_state):
    rule = ScannerQueryRule(name='some_rule', scanner=YARA)
    rule.state = current_state
    with pytest.raises(ImproperScannerQueryRuleStateError):
        rule.change_state_to(target_state)
예제 #5
0
def test_query_rule_change_state_to_valid(current_state, target_state):
    rule = ScannerQueryRule(name='some_rule', scanner=YARA)
    rule.state = current_state
    rule.change_state_to(target_state)