def test_walktree(self): # Construct a small tree h = refpolicy.Headers() a = refpolicy.AVRule() a.src_types.add("foo_t") a.tgt_types.add("bar_t") a.obj_classes.add("file") a.perms.add("read") ifcall = refpolicy.InterfaceCall(ifname="allow_foobar") ifcall.args.append("foo_t") ifcall.args.append("{ file dir }") i = refpolicy.Interface(name="foo") i.children.append(a) i.children.append(ifcall) h.children.append(i) a = refpolicy.AVRule() a.rule_type = a.DONTAUDIT a.src_types.add("user_t") a.tgt_types.add("user_home_t") a.obj_classes.add("lnk_file") a.perms.add("write") i = refpolicy.Interface(name="bar") i.children.append(a) h.children.append(i)
def test_iter(self): h = refpolicy.Headers() h.children.append(refpolicy.Interface(name="foo")) h.children.append(refpolicy.Interface(name="bar")) h.children.append(refpolicy.ClassMap("file", "read write")) i = 0 for node in h: i += 1 self.assertEqual(i, 3) i = 0 for node in h.interfaces(): i += 1 self.assertEqual(i, 2)