mirror of
https://gitlab.com/apparmor/apparmor.git
synced 2025-03-04 08:24:42 +01:00
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:
parent
255716b90a
commit
63f1a58bef
4 changed files with 11 additions and 0 deletions
|
@ -12,6 +12,7 @@
|
||||||
import unittest
|
import unittest
|
||||||
from common_test import AATest, setup_all_loops
|
from common_test import AATest, setup_all_loops
|
||||||
|
|
||||||
|
from apparmor.common import AppArmorBug
|
||||||
from apparmor.notify import get_last_login_timestamp
|
from apparmor.notify import get_last_login_timestamp
|
||||||
|
|
||||||
class TestGet_last_login_timestamp(AATest):
|
class TestGet_last_login_timestamp(AATest):
|
||||||
|
@ -23,6 +24,8 @@ class TestGet_last_login_timestamp(AATest):
|
||||||
(['wtmp-s390x', 'whoever' ], 0),
|
(['wtmp-s390x', 'whoever' ], 0),
|
||||||
(['wtmp-aarch64', 'guillaume' ], 1611562789), # Mon Jan 25 09:19:49 CET 2021
|
(['wtmp-aarch64', 'guillaume' ], 1611562789), # Mon Jan 25 09:19:49 CET 2021
|
||||||
(['wtmp-aarch64', 'whoever' ], 0),
|
(['wtmp-aarch64', 'whoever' ], 0),
|
||||||
|
(['wtmp-truncated', 'root' ], 0),
|
||||||
|
(['wtmp-truncated', 'whoever' ], 0),
|
||||||
]
|
]
|
||||||
|
|
||||||
def _run_test(self, params, expected):
|
def _run_test(self, params, expected):
|
||||||
|
@ -30,6 +33,11 @@ class TestGet_last_login_timestamp(AATest):
|
||||||
filename = 'wtmp-examples/%s' % filename
|
filename = 'wtmp-examples/%s' % filename
|
||||||
self.assertEqual(get_last_login_timestamp(user, filename), expected)
|
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__)
|
setup_all_loops(__name__)
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
BIN
utils/test/wtmp-examples/wtmp-truncated
Normal file
BIN
utils/test/wtmp-examples/wtmp-truncated
Normal file
Binary file not shown.
BIN
utils/test/wtmp-examples/wtmp-x86_64-past
Normal file
BIN
utils/test/wtmp-examples/wtmp-x86_64-past
Normal file
Binary file not shown.
3
utils/test/wtmp-examples/wtmp-x86_64-past-expected
Normal file
3
utils/test/wtmp-examples/wtmp-x86_64-past-expected
Normal 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
|
Loading…
Add table
Reference in a new issue