Fix missing pre-login Unix identity on installation and upgrades

This commit is contained in:
2026-12-01 08:32:45 +00:00
parent c3aa4688d8
commit e9d926434c
4 changed files with 56 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
import importlib.util, pathlib, tempfile, unittest, pwd
spec = importlib.util.spec_from_file_location('identity', pathlib.Path(__file__).resolve().parents[1] / 'packaging/ensure-default-identity.py')
m = importlib.util.module_from_spec(spec); spec.loader.exec_module(m)
class IdentityTest(unittest.TestCase):
def test_missing_and_idempotent(self):
with tempfile.TemporaryDirectory() as d:
p=pathlib.Path(d)/'nwserv.conf'; p.write_text('2 MARS\n')
self.assertTrue(m.repair(p)); content=p.read_text()
self.assertIn(f'11 {pwd.getpwnam("nobody").pw_uid}\n', content)
self.assertFalse(m.repair(p)); self.assertEqual(p.read_text(), content)
self.assertEqual(len(list(pathlib.Path(d).glob('*.pre-*'))), 1)
def test_preserve_existing(self):
with tempfile.TemporaryDirectory() as d:
p=pathlib.Path(d)/'nwserv.conf'; p.write_text('10 123\n11 456\n')
self.assertFalse(m.repair(p)); self.assertEqual(p.read_text(),'10 123\n11 456\n')
def test_partial(self):
with tempfile.TemporaryDirectory() as d:
p=pathlib.Path(d)/'nwserv.conf'; p.write_text('# 11 0\n10 123')
m.repair(p); self.assertIn('10 123\n',p.read_text()); self.assertIn('\n11 ',p.read_text())
if __name__ == '__main__': unittest.main()