Add truncated and ancient wtmp example to tests

A too-small file can't contain something useful.

Also, a wtmp file with a timestamp from pre-2000 is beyond what you'd
expect on a 2021 system.
This commit is contained in:
Christian Boltz 2021-10-24 15:26:26 +02:00
parent 255716b90a
commit 63f1a58bef
Failed to generate hash of commit
4 changed files with 11 additions and 0 deletions

View file

@ -12,6 +12,7 @@
import unittest
from common_test import AATest, setup_all_loops
from apparmor.common import AppArmorBug
from apparmor.notify import get_last_login_timestamp
class TestGet_last_login_timestamp(AATest):
@ -23,6 +24,8 @@ class TestGet_last_login_timestamp(AATest):
(['wtmp-s390x', 'whoever' ], 0),
(['wtmp-aarch64', 'guillaume' ], 1611562789), # Mon Jan 25 09:19:49 CET 2021
(['wtmp-aarch64', 'whoever' ], 0),
(['wtmp-truncated', 'root' ], 0),
(['wtmp-truncated', 'whoever' ], 0),
]
def _run_test(self, params, expected):
@ -30,6 +33,11 @@ class TestGet_last_login_timestamp(AATest):
filename = 'wtmp-examples/%s' % filename
self.assertEqual(get_last_login_timestamp(user, filename), expected)
def test_date_1999(self):
with self.assertRaises(AppArmorBug):
# wtmp-x86_64-past is hand-edited to Thu Dec 30 00:00:00 CET 1999, which is outside the expected data range
get_last_login_timestamp('root', 'wtmp-examples/wtmp-x86_64-past')
setup_all_loops(__name__)
if __name__ == '__main__':

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,3 @@
root pts/0 blast.from.the.p Thu Dec 30 00:00 gone - no logout
wtmp-x86_64-past begins Thu Dec 30 00:00:00 1999