From 8851a2583e09fcd3b9c3c84c9245cdfb68ddd958 Mon Sep 17 00:00:00 2001 From: Julien Olivain Date: Sun, 6 Oct 2024 00:58:08 +0200 Subject: [PATCH] support/testing: add oath-toolkit runtime test Signed-off-by: Julien Olivain Signed-off-by: Thomas Petazzoni --- DEVELOPERS | 1 + .../tests/package/test_oath_toolkit.py | 38 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 support/testing/tests/package/test_oath_toolkit.py diff --git a/DEVELOPERS b/DEVELOPERS index d606caa179..fc3e4bdf25 100644 --- a/DEVELOPERS +++ b/DEVELOPERS @@ -1944,6 +1944,7 @@ F: support/testing/tests/package/test_ntp.py F: support/testing/tests/package/test_ntp/ F: support/testing/tests/package/test_numactl.py F: support/testing/tests/package/test_numactl/ +F: support/testing/tests/package/test_oath_toolkit.py F: support/testing/tests/package/test_octave.py F: support/testing/tests/package/test_ola.py F: support/testing/tests/package/test_ola/ diff --git a/support/testing/tests/package/test_oath_toolkit.py b/support/testing/tests/package/test_oath_toolkit.py new file mode 100644 index 0000000000..92c0845614 --- /dev/null +++ b/support/testing/tests/package/test_oath_toolkit.py @@ -0,0 +1,38 @@ +import os + +import infra.basetest + + +class TestOathToolKit(infra.basetest.BRTest): + config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \ + """ + BR2_PACKAGE_OATH_TOOLKIT=y + BR2_TARGET_ROOTFS_CPIO=y + # BR2_TARGET_ROOTFS_TAR is not set + """ + + def test_run(self): + cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio") + self.emulator.boot(arch="armv5", + kernel="builtin", + options=["-initrd", cpio_file]) + self.emulator.login() + + self.assertRunOk("oathtool --version") + + # Test commands and expected results are coming from examples + # producing stable/reproducible outputs given in the oathtool + # manual page. See: + # https://www.nongnu.org/oath-toolkit/oathtool.1.html + + tests = [ + ("echo 00 | oathtool -", "328482"), + ("oathtool -c 5 3132333435363738393031323334353637383930", "254676"), + ("oathtool -w 10 3132333435363738393031323334353637383930 969429", "3"), + ("oathtool --totp --now \"2008-04-23 17:42:17 UTC\" 00", "974945") + ] + + for cmd, expected_out in tests: + out, ret = self.emulator.run(cmd) + self.assertEqual(ret, 0, f"Failed to run '{cmd}'") + self.assertEqual(expected_out, out[0])