コード例 #1
0
def test_convert_old_acl_group():
    rulestr = "( group x )"
    access_rules = convert_old_acl(rulestr)
    assert len(access_rules) == 1
    assert_access_rule_with_flags(access_rules[0],
                                  invert=False,
                                  blocking=False,
                                  group_ids=[99990000])
コード例 #2
0
def test_convert_old_acl_ip_with_netmask():
    rulestr = "( ip 1.2.3.0/24 )"
    access_rules = convert_old_acl(rulestr)
    assert len(access_rules) == 1
    assert_access_rule_with_flags(access_rules[0],
                                  invert=False,
                                  blocking=False,
                                  subnets=[IPv4Network("1.2.3.0/24")])
コード例 #3
0
def test_convert_old_acl_and_2not():
    rulestr = "( NOT ( group x ) ) AND ( NOT ( group y ) )"
    access_rules = convert_old_acl(rulestr)
    assert len(access_rules) == 1
    assert_access_rule_with_flags(access_rules[0],
                                  invert=True,
                                  blocking=True,
                                  group_ids=[99990000, 99990001])
コード例 #4
0
def test_convert_old_acl_not_group_rule():
    rulestr = "NOT ( group hanswurst )"
    access_rules = convert_old_acl(rulestr)
    assert len(access_rules) == 1
    assert_access_rule_with_flags(access_rules[0],
                                  invert=True,
                                  blocking=True,
                                  group_ids=[99990000])
コード例 #5
0
def test_convert_old_acl_group_and_ip():
    rulestr = "( group x ) AND ( ip 1.1.1.1 )"
    access_rules = convert_old_acl(rulestr)
    assert len(access_rules) == 1
    assert_access_rule_with_flags(access_rules[0],
                                  invert=False,
                                  blocking=False,
                                  group_ids=[99990000],
                                  subnets=[IPv4Network("1.1.1.1/32")])
コード例 #6
0
def test_convert_old_acl_group_and_iplist(some_iplist):
    iplist = some_iplist
    rulestr = "( group x ) AND ( iplist {} )".format(iplist.name)
    access_rules = convert_old_acl(rulestr)
    assert len(access_rules) == 1
    assert_access_rule_with_flags(access_rules[0],
                                  invert=False,
                                  blocking=False,
                                  group_ids=[99990000],
                                  subnets=iplist.subnets)
コード例 #7
0
def test_or_not_same_split():
    rulestr = "( NOT ( group x ) ) OR ( user y )"
    access_rules = convert_old_acl(rulestr)
    assert len(access_rules) == 2
    assert_access_rule_with_flags(access_rules[1],
                                  invert=True,
                                  blocking=True,
                                  group_ids=[99990001])
    assert_access_rule_with_flags(access_rules[0],
                                  invert=False,
                                  blocking=False,
                                  group_ids=[99990000])
コード例 #8
0
def test_or_not_mixed_split_2not():
    rulestr = "( NOT ( group x ) OR ( NOT (  ip 1.1.1.1 ) ) )"
    access_rules = convert_old_acl(rulestr)
    assert len(access_rules) == 2
    assert_access_rule_with_flags(access_rules[0],
                                  invert=True,
                                  blocking=True,
                                  group_ids=[99990000])
    assert_access_rule_with_flags(access_rules[1],
                                  invert=True,
                                  blocking=True,
                                  subnets=[IPv4Network("1.1.1.1/32")])
コード例 #9
0
def test_convert_old_acl_or_nested_and_not():
    rulestr = "( ( user test ) ) OR ( NOT ( group x ) AND ( NOT ( group y ) ) )"
    access_rules = convert_old_acl(rulestr)
    assert len(access_rules) == 2
    assert_access_rule_with_flags(access_rules[0],
                                  invert=True,
                                  blocking=True,
                                  group_ids=[99990001, 99990002])
    assert_access_rule_with_flags(access_rules[1],
                                  invert=False,
                                  blocking=False,
                                  group_ids=[99990000])
コード例 #10
0
def test_convert_old_acl_date_later():
    rulestr = "( date > 01.01.2015 )"
    access_rules = convert_old_acl(rulestr)
    assert len(access_rules) == 1
    assert_access_rule_with_flags(access_rules[0],
                                  invert=False,
                                  blocking=False,
                                  dateranges=[
                                      DateRange(datetime.date(2015, 1, 1),
                                                datetime.date(9999, 12, 31),
                                                '()')
                                  ])
コード例 #11
0
def test_convert_nid_to_rulestr(import_node_with_non_dnf_ruleset):
    nid_to_rulestr = {1: "{ NOT ( group z ) }",
                      2: "{ group x },{ group y }",
                      3: ""}

    nid_to_access_rules = acl_migration.convert_nid_to_rulestr(nid_to_rulestr)
    assert len(nid_to_access_rules) == 3
    assert len(nid_to_access_rules[1]) == 1
    assert len(nid_to_access_rules[2]) == 1
    assert len(nid_to_access_rules[3]) == 0
    assert_access_rule_with_flags(nid_to_access_rules[1][0], group_ids=[99990000], invert=True, blocking=True)
    assert_access_rule_with_flags(nid_to_access_rules[2][0], group_ids=[99990001, 99990002], invert=False, blocking=False)
コード例 #12
0
def test_convert_old_acl_date_earlier_inc():
    rulestr = "( date <= 01.01.2015 )"
    access_rules = convert_old_acl(rulestr)
    assert len(access_rules) == 1
    assert_access_rule_with_flags(access_rules[0],
                                  invert=False,
                                  blocking=False,
                                  dateranges=[
                                      DateRange(datetime.date(1, 1, 1),
                                                datetime.date(2015, 1, 1),
                                                '(]')
                                  ])
コード例 #13
0
def test_convert_old_acl_group_and_date():
    rulestr = "( group x ) AND ( date > 01.01.2015 )"
    access_rules = convert_old_acl(rulestr)
    assert len(access_rules) == 1
    assert_access_rule_with_flags(access_rules[0],
                                  invert=False,
                                  blocking=False,
                                  group_ids=[99990000],
                                  dateranges=[
                                      DateRange(datetime.date(2015, 1, 1),
                                                datetime.date(9999, 12, 31),
                                                '()')
                                  ])
コード例 #14
0
def test_convert_nid_to_rulestr(import_node_with_non_dnf_ruleset):
    nid_to_rulestr = {
        1: "{ NOT ( group z ) }",
        2: "{ group x },{ group y }",
        3: ""
    }

    nid_to_access_rules = acl_migration.convert_nid_to_rulestr(nid_to_rulestr)
    assert len(nid_to_access_rules) == 3
    assert len(nid_to_access_rules[1]) == 1
    assert len(nid_to_access_rules[2]) == 1
    assert len(nid_to_access_rules[3]) == 0
    assert_access_rule_with_flags(nid_to_access_rules[1][0],
                                  group_ids=[99990000],
                                  invert=True,
                                  blocking=True)
    assert_access_rule_with_flags(nid_to_access_rules[2][0],
                                  group_ids=[99990001, 99990002],
                                  invert=False,
                                  blocking=False)
コード例 #15
0
def test_convert_old_acl_and_2not():
    rulestr = "( NOT ( group x ) ) AND ( NOT ( group y ) )"
    access_rules = convert_old_acl(rulestr)
    assert len(access_rules) == 1
    assert_access_rule_with_flags(access_rules[0], invert=True, blocking=True, group_ids=[99990000, 99990001])
コード例 #16
0
def test_convert_old_acl_not_group_rule():
    rulestr = "NOT ( group hanswurst )"
    access_rules = convert_old_acl(rulestr)
    assert len(access_rules) == 1
    assert_access_rule_with_flags(access_rules[0], invert=True, blocking=True, group_ids=[99990000])
コード例 #17
0
def test_convert_old_acl_nobody_rule():
    rulestr = "NOT ( true )"
    access_rules = convert_old_acl(rulestr)
    assert len(access_rules) == 1
    assert_access_rule_with_flags(access_rules[0], invert=True, blocking=True)
コード例 #18
0
def test_or_not_same_split():
    rulestr = "( NOT ( group x ) ) OR ( user y )"
    access_rules = convert_old_acl(rulestr)
    assert len(access_rules) == 2
    assert_access_rule_with_flags(access_rules[1], invert=True, blocking=True, group_ids=[99990001])
    assert_access_rule_with_flags(access_rules[0], invert=False, blocking=False, group_ids=[99990000])
コード例 #19
0
def test_or_not_mixed_split_2not():
    rulestr = "( NOT ( group x ) OR ( NOT (  ip 1.1.1.1 ) ) )"
    access_rules = convert_old_acl(rulestr)
    assert len(access_rules) == 2
    assert_access_rule_with_flags(access_rules[0], invert=True, blocking=True, group_ids=[99990000])
    assert_access_rule_with_flags(access_rules[1], invert=True, blocking=True, subnets=[IPv4Network("1.1.1.1/32")])
コード例 #20
0
def test_convert_old_acl_or_nested_and_not():
    rulestr = "( ( user test ) ) OR ( NOT ( group x ) AND ( NOT ( group y ) ) )"
    access_rules = convert_old_acl(rulestr)
    assert len(access_rules) == 2
    assert_access_rule_with_flags(access_rules[0], invert=True, blocking=True, group_ids=[99990001, 99990002])
    assert_access_rule_with_flags(access_rules[1], invert=False, blocking=False, group_ids=[99990000])
コード例 #21
0
def test_convert_old_acl_group_and_ip():
    rulestr = "( group x ) AND ( ip 1.1.1.1 )"
    access_rules = convert_old_acl(rulestr)
    assert len(access_rules) == 1
    assert_access_rule_with_flags(access_rules[0], invert=False, blocking=False, group_ids=[99990000],
                                  subnets=[IPv4Network("1.1.1.1/32")])
コード例 #22
0
def test_convert_old_acl_group_and_iplist(some_iplist):
    iplist = some_iplist
    rulestr = "( group x ) AND ( iplist {} )".format(iplist.name)
    access_rules = convert_old_acl(rulestr)
    assert len(access_rules) == 1
    assert_access_rule_with_flags(access_rules[0], invert=False, blocking=False, group_ids=[99990000], subnets=iplist.subnets)
コード例 #23
0
def test_convert_old_acl_group_and_date():
    rulestr = "( group x ) AND ( date > 01.01.2015 )"
    access_rules = convert_old_acl(rulestr)
    assert len(access_rules) == 1
    assert_access_rule_with_flags(access_rules[0], invert=False, blocking=False, group_ids=[99990000],
                                  dateranges=[DateRange(datetime.date(2015, 1, 1), datetime.date(9999, 12, 31), '()')])
コード例 #24
0
def test_convert_old_acl_date_earlier_inc():
    rulestr = "( date <= 01.01.2015 )"
    access_rules = convert_old_acl(rulestr)
    assert len(access_rules) == 1
    assert_access_rule_with_flags(access_rules[0], invert=False, blocking=False,
                                  dateranges=[DateRange(datetime.date(1, 1, 1), datetime.date(2015, 1, 1), '(]')])
コード例 #25
0
def test_convert_old_acl_group():
    rulestr = "( group x )"
    access_rules = convert_old_acl(rulestr)
    assert len(access_rules) == 1
    assert_access_rule_with_flags(access_rules[0], invert=False, blocking=False, group_ids=[99990000])
コード例 #26
0
def test_convert_old_acl_nobody_rule():
    rulestr = "NOT ( true )"
    access_rules = convert_old_acl(rulestr)
    assert len(access_rules) == 1
    assert_access_rule_with_flags(access_rules[0], invert=True, blocking=True)
コード例 #27
0
def test_convert_old_acl_ip():
    rulestr = "( ip 1.2.3.4 )"
    access_rules = convert_old_acl(rulestr)
    assert len(access_rules) == 1
    assert_access_rule_with_flags(access_rules[0], invert=False, blocking=False, subnets=[IPv4Network("1.2.3.4/32")])
コード例 #28
0
def test_convert_old_acl_date_later():
    rulestr = "( date > 01.01.2015 )"
    access_rules = convert_old_acl(rulestr)
    assert len(access_rules) == 1
    assert_access_rule_with_flags(access_rules[0], invert=False, blocking=False,
                                  dateranges=[DateRange(datetime.date(2015, 1, 1), datetime.date(9999, 12, 31), '()')])