예제 #1
0
def test_getlocation_term_fail_invalid_op():
    term = get_getlocation_term()
    term.left.op = 'invalid'
    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'HTTP_DYNAMIC'], '')

    assert excinfo.value.message == '左表达式>>(invalid)不是正确的操作符'
예제 #2
0
def test_getlocation_term_fail_invalid_location_value():
    term = get_getlocation_term()
    term.left.location_value = ['not_exist']
    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'HTTP_DYNAMIC'], '')

    assert excinfo.value.message == '左表达式>>事件(HTTP_DYNAMIC)不包含字段(not_exist)'
예제 #3
0
def test_event_term_fail_invalid_event():
    term = get_event_term()
    term.left.event = ['nebula', 'not_exsit']

    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'ACCOUNT_LOGIN'], '')
    assert excinfo.value.message == '左表达式>>事件(not_exsit)定义配置不存在'
예제 #4
0
def test_getlocation_term_fail_inconsistent_trigger():
    term = get_getlocation_term()
    term.left.source_event_field = 'nebula.ACCOUNT_LOGIN.c_ip'
    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'HTTP_DYNAMIC'], '')

    assert excinfo.value.message == '左表达式>>getlocation的来源事件(ACCOUNT_LOGIN)与触发事件(HTTP_DYNAMIC)不一致'
예제 #5
0
def test_getlocation_term_fail_invalid_field_type():
    term = get_getlocation_term()
    term.left.source_event_field = 'nebula.HTTP_DYNAMIC.status'
    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'HTTP_DYNAMIC'], '')

    assert excinfo.value.message == '左表达式>>getlocation的来源字段(status)不是字符串类型'
예제 #6
0
def test_general_term_fail_wrong_scope():
    term = get_general_term()
    term.scope = 'invalid'

    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'ACCOUNT_LOGIN'], '')
    assert excinfo.value.message == '条款的适用类型错误'
예제 #7
0
def test_general_term_fail_null_remark():
    term = get_general_term()
    term.remark = None

    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'ACCOUNT_LOGIN'], '')
    assert excinfo.value.message == '条款描述为空'
예제 #8
0
def test_count_term_fail_null_operand():
    term = get_count_term()
    term.left.operand = []

    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'HTTP_DYNAMIC'], '')
    assert excinfo.value.message == '左表达式>>算法(count)缺少统计对象'
예제 #9
0
def test_event_term_fail_invalid_field():
    term = get_event_term()
    term.left.field = 'not_exsit'

    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'ACCOUNT_LOGIN'], '')
    assert excinfo.value.message == '左表达式>>事件(ACCOUNT_LOGIN)不包含字段(not_exsit)'
예제 #10
0
def test_general_term_fail_wrong_number():
    term = get_general_term()
    term.op = '=='
    term.right.value = 'a'
    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'ACCOUNT_LOGIN'], '')
    assert excinfo.value.message == '(a)不是合理的数字'
예제 #11
0
def test_getlocation_term_fail_invalid_field():
    term = get_getlocation_term()
    term.left.source_event_field = 'nebula.HTTP_DYNAMIC.not_exist'
    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'HTTP_DYNAMIC'], '')

    assert excinfo.value.message == '左表达式>>事件(HTTP_DYNAMIC)不包含字段(not_exist)'
예제 #12
0
def test_getvariable_term_fail_invalid_variable():
    term = get_getvariable_term()
    term.left.variable = ['nebula', 'not_exist']

    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'ACCOUNT_LOGIN'], '')
    assert excinfo.value.message == '左表达式>>变量(not_exist)定义配置不存在'
예제 #13
0
def test_sbl_term_fail_invalid_ttl():
    term = get_sbl_term()

    term.left.ttl = -1
    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'HTTP_DYNAMIC'], '')

    assert excinfo.value.message == '左表达式>>(-1)不是正确的ttl值'
예제 #14
0
def test_sbl_term_fail_invalid_check_type():
    term = get_sbl_term()

    term.left.check_type = 'invalid'
    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'HTTP_DYNAMIC'], '')

    assert excinfo.value.message == '左表达式>>(invalid)不是正确的值类型'
예제 #15
0
def test_count_term_fail_invalid_algorithm():
    # algorithm
    term = get_count_term()
    term.left.algorithm = 'max'

    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'HTTP_DYNAMIC'], '')
    assert excinfo.value.message == '左表达式>>不支持算法(max)'
예제 #16
0
def test_count_term_fail_invalid_interval():
    # interval
    term = get_count_term()
    term.left.interval = -1

    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'HTTP_DYNAMIC'], '')
    assert excinfo.value.message == '左表达式>>(-1)不是正确的时间窗口值'
예제 #17
0
def test_general_term_fail_wrong_regex():
    term = get_event_term()
    term.left.field = 'uri_stem'
    term.op = 'regex'
    term.right.value = '('
    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'ACCOUNT_LOGIN'], '')
    assert excinfo.value.message == '(()不是合理的正则表达式'
예제 #18
0
def test_getlocation_term_fail_multiple_location_value():
    term = get_getlocation_term()
    term.left.op = '='
    term.left.location_value = ['c_ip', 'did']
    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'HTTP_DYNAMIC'], '')

    assert excinfo.value.message == '左表达式>>等于操作只支持一个变量'
예제 #19
0
def test_general_term_fail_wrong_op():
    term = get_general_term()
    term.op = 'regex'

    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'ACCOUNT_LOGIN'], '')
    print excinfo.value.message
    assert excinfo.value.message == '类型(long)不支持操作(匹配正则)'
예제 #20
0
def test_only_support_one_dimension_now():
    # groupby
    term = get_count_term()
    term.left.groupby = ['c_ip', 'uid']

    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'HTTP_DYNAMIC'], '')
    assert excinfo.value.message == '左表达式>>目前只支持单字段触发'

    term = get_count_term()
    term.left.trigger_fields = ['c_ip', 'uid']
    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'HTTP_DYNAMIC'], '')
    assert excinfo.value.message == '左表达式>>目前只支持单字段触发'
예제 #21
0
def test_count_term_fail_invalid_field():
    # trigger fields
    term = get_count_term()
    term.left.trigger_fields = ['not_exsit']

    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'HTTP_DYNAMIC'], '')
    assert excinfo.value.message == '左表达式>>事件(HTTP_DYNAMIC)不包含字段(not_exsit)'

    term = get_count_term()
    term.left.operand = ['not_exist']

    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'HTTP_DYNAMIC'], '')
    assert excinfo.value.message == '左表达式>>事件(HTTP_DYNAMIC)不包含字段(not_exist)'
예제 #22
0
def test_getlocation_term_fail_null_location_value():
    # trigger event
    term = get_getlocation_term()

    term.left.location_value = []
    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'HTTP_DYNAMIC'], '')

    assert excinfo.value.message == '左表达式>>getlocation缺乏参数配置'

    term = get_getlocation_term()
    term.left.location_value = [None]
    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'HTTP_DYNAMIC'], '')

    assert excinfo.value.message == '左表达式>>getlocation缺乏参数配置'
예제 #23
0
def test_count_term_fail_invalid_event():
    # trigger event
    term = get_count_term()
    term.left.source_event = ['nebula', 'not_exsit']

    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'HTTP_DYNAMIC'], '')
    assert excinfo.value.message == '左表达式>>事件(not_exsit)定义配置不存在'

    # source event
    term = get_count_term()
    term.left.source_event = ['nebula', 'not_exsit']

    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'HTTP_DYNAMIC'], '')
    assert excinfo.value.message == '左表达式>>事件(not_exsit)定义配置不存在'
예제 #24
0
def test_count_term_fail_invalid_groupby():
    # groupby
    term = get_count_term()
    term.left.groupby = ['not_exist']

    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'HTTP_DYNAMIC'], '')
    assert excinfo.value.message == '左表达式>>事件(HTTP_DYNAMIC)不包含字段(not_exist)'

    # groupby != trigger
    term = get_count_term()
    term.left.groupby = ['c_ip']
    term.left.trigger_fields = ['c_ip', 'uid']

    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'HTTP_DYNAMIC'], '')
    assert excinfo.value.message == '左表达式>>目前只支持单字段触发'
예제 #25
0
def test_count_term_fail_invalid_condition():
    # condition
    term = get_count_term()
    term.left.condition.append({'left': 'not_exist', 'op': '==', 'right': '0'})

    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'HTTP_DYNAMIC'], '')
    assert excinfo.value.message == '左表达式>>事件(HTTP_DYNAMIC)不包含字段(not_exist)'

    term = get_count_term()
    term.left.condition.append({'left': 'c_ip', 'op': '>', 'right': '0'})

    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'HTTP_DYNAMIC'], '')
    assert excinfo.value.message == '左表达式>>类型(string)不支持操作(大于)'

    term = get_count_term()
    term.left.condition.append({'left': 'status', 'op': '>', 'right': 'a'})

    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'HTTP_DYNAMIC'], '')
    assert excinfo.value.message == '左表达式>>(a)不是合理的数字'

    term = get_count_term()
    term.left.condition.append({
        'left': 'uri_stem',
        'op': 'regex',
        'right': '('
    })

    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'HTTP_DYNAMIC'], '')
    assert excinfo.value.message == '左表达式>>(()不是合理的正则表达式'

    term = get_count_term()
    term.left.condition.append({
        'left': 'status',
        'op': 'between',
        'right': '1'
    })

    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'HTTP_DYNAMIC'], '')
    assert excinfo.value.message == '左表达式>>介于需要逗号分隔的两个数字'

    term = get_count_term()
    term.left.condition.append({
        'left': 'status',
        'op': 'between',
        'right': '1,a'
    })

    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'HTTP_DYNAMIC'], '')
    assert excinfo.value.message == '左表达式>>(a)不是合理的数字'
예제 #26
0
def test_general_term_success():
    check_term(get_general_term(), ['nebula', 'ACCOUNT_LOGIN'], '')
예제 #27
0
def test_count_term_fail_inconsistent_trigger():
    term = get_count_term()
    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'ACCOUNT_LOGIN'], '')
    assert excinfo.value.message == '左表达式>>触发事件不一致'
예제 #28
0
def test_count_term_fail_null_trigger_field():
    term = get_count_term()
    term.left.trigger_fields = []
    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'HTTP_DYNAMIC'], '')
    assert excinfo.value.message == '左表达式>>触发字段为空'
예제 #29
0
def test_sbl_term_success():
    check_term(get_sbl_term(), ['nebula', 'HTTP_DYNAMIC'], '')
예제 #30
0
def test_getlocation_term_success():
    check_term(get_getlocation_term(), ['nebula', 'HTTP_DYNAMIC'], '')