import unittest from samsara.collectors.linux_schedules import cron_rows, enrich_timers class ScheduleTests(unittest.TestCase): def test_cron_schedules_and_scripts_without_sensitive_arguments(self): text = '# ignored\nMAILTO=secret@example.test\n0 2 * * * app /usr/bin/python3 /opt/jobs/report.py --password=SECRET\n@daily root /opt/jobs/backup.sh --token=SECRET\n' rows = cron_rows(text, '/etc/cron.d/example', system_file=True) self.assertEqual(len(rows), 2) self.assertIn('report.py', rows[0]['name']) self.assertIn('0 2 * * *', rows[0]['triggers']) self.assertEqual(rows[0]['account'], 'app') self.assertIn('@daily', rows[1]['triggers']) self.assertNotIn('SECRET', str(rows)) self.assertNotIn('secret@example.test', str(rows)) self.assertNotIn('arguments', rows[0]) def test_timer_metadata_and_missing_next_run(self): rows = [{'name': 'report.timer'}, {'name': 'other.timer'}] def command(args): self.assertIn('--', args) return 'Id=report.timer\nTimersCalendar={ OnCalendar=*-*-* 02:00:00 ; next_elapse=... }\nTriggers=report.service\nNextElapseUSecRealtime=Mon 2026-11-02 02:00:00 UTC\n\nId=other.timer\nTimersCalendar=\n' enrich_timers(rows, command) self.assertIn('02:00:00', rows[0]['triggers']) self.assertEqual(rows[0]['associated_unit'], 'report.service') self.assertNotIn('triggers', rows[1]) def test_inline_shell_not_exposed(self): rows = cron_rows("@hourly bash -c 'echo SECRET'", 'current-user') self.assertNotIn('SECRET', str(rows))