2021-10-24 13:10:25 +02:00
|
|
|
#! /usr/bin/python3
|
|
|
|
# ------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Copyright (C) 2021 Christian Boltz <apparmor@cboltz.de>
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of version 2 of the GNU General Public
|
|
|
|
# License published by the Free Software Foundation.
|
|
|
|
#
|
|
|
|
# ------------------------------------------------------------------
|
|
|
|
|
|
|
|
import unittest
|
|
|
|
|
2021-10-24 15:26:26 +02:00
|
|
|
from apparmor.common import AppArmorBug
|
2021-10-24 15:29:25 +02:00
|
|
|
from apparmor.notify import get_last_login_timestamp, sane_timestamp
|
2022-08-07 20:32:07 -04:00
|
|
|
from common_test import AATest, setup_all_loops
|
2021-10-24 15:29:25 +02:00
|
|
|
|
2022-08-07 12:26:24 -04:00
|
|
|
|
2021-10-24 15:29:25 +02:00
|
|
|
class TestSane_timestamp(AATest):
|
2022-06-18 14:30:49 -04:00
|
|
|
tests = (
|
2022-08-07 12:26:24 -04:00
|
|
|
(2524704400, False), # Sun Jan 2 03:46:40 CET 2050
|
|
|
|
(944780400, False), # Fri Dec 10 00:00:00 CET 1999
|
|
|
|
(1635026400, True), # Sun Oct 24 00:00:00 CEST 2021
|
2022-06-18 14:30:49 -04:00
|
|
|
)
|
2021-10-24 15:29:25 +02:00
|
|
|
|
|
|
|
def _run_test(self, params, expected):
|
|
|
|
self.assertEqual(sane_timestamp(params), expected)
|
2021-10-24 13:10:25 +02:00
|
|
|
|
2022-08-07 12:26:24 -04:00
|
|
|
|
2021-10-24 13:10:25 +02:00
|
|
|
class TestGet_last_login_timestamp(AATest):
|
2022-06-18 14:30:49 -04:00
|
|
|
tests = (
|
2022-08-07 12:26:24 -04:00
|
|
|
(('wtmp-x86_64', 'root'), 1635070346), # Sun Oct 24 12:12:26 CEST 2021
|
|
|
|
(('wtmp-x86_64', 'whoever'), 0),
|
|
|
|
(('wtmp-s390x', 'root'), 1626368763), # Thu Jul 15 19:06:03 CEST 2021
|
|
|
|
(('wtmp-s390x', 'linux1'), 1626368772), # Thu Jul 15 19:06:12 CEST 2021
|
|
|
|
(('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),
|
2022-06-18 14:30:49 -04:00
|
|
|
)
|
2021-10-24 13:10:25 +02:00
|
|
|
|
|
|
|
def _run_test(self, params, expected):
|
|
|
|
filename, user = params
|
2023-02-19 16:26:14 -05:00
|
|
|
filename = 'wtmp-examples/' + filename
|
2021-10-24 13:10:25 +02:00
|
|
|
self.assertEqual(get_last_login_timestamp(user, filename), expected)
|
|
|
|
|
2021-10-24 15:26:26 +02:00
|
|
|
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')
|
|
|
|
|
2021-10-24 13:10:25 +02:00
|
|
|
|
|
|
|
setup_all_loops(__name__)
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main(verbosity=1)
|