def test_write_manually(self):
        obj = PtraceRule('read', '/foo', allow_keyword=True)

        expected = '    allow ptrace read peer=/foo,'

        self.assertEqual(expected, obj.get_clean(2), 'unexpected clean rule')
        self.assertEqual(expected, obj.get_raw(2), 'unexpected raw rule')
    def test_ptrace_from_log(self):
        parser = ReadLog('', '', '', '')
        event = 'type=AVC msg=audit(1409700683.304:547661): apparmor="DENIED" operation="ptrace" profile="/home/ubuntu/bzr/apparmor/tests/regression/apparmor/ptrace" pid=22465 comm="ptrace" requested_mask="tracedby" denied_mask="tracedby" peer="/home/ubuntu/bzr/apparmor/tests/regression/apparmor/ptrace"'

        parsed_event = parser.parse_event(event)

        self.assertEqual(
            parsed_event, {
                'request_mask': 'tracedby',
                'denied_mask': 'tracedby',
                'error_code': 0,
                'magic_token': 0,
                'parent': 0,
                'profile':
                '/home/ubuntu/bzr/apparmor/tests/regression/apparmor/ptrace',
                'peer':
                '/home/ubuntu/bzr/apparmor/tests/regression/apparmor/ptrace',
                'operation': 'ptrace',
                'resource': None,
                'info': None,
                'aamode': 'REJECTING',
                'time': 1409700683,
                'active_hat': None,
                'pid': 22465,
                'task': 0,
                'attr': None,
                'name2': None,
                'name': None,
                'family': None,
                'protocol': None,
                'sock_type': None,
            })

        obj = PtraceRule(parsed_event['denied_mask'],
                         parsed_event['peer'],
                         log_event=parsed_event)

        #              audit  allow  deny   comment    access        all?   peer                                                           all?
        expected = exp(
            False, False, False, '', {'tracedby'}, False,
            '/home/ubuntu/bzr/apparmor/tests/regression/apparmor/ptrace',
            False)

        self._compare_obj(obj, expected)

        self.assertEqual(
            obj.get_raw(1),
            '  ptrace tracedby peer=/home/ubuntu/bzr/apparmor/tests/regression/apparmor/ptrace,'
        )