test_oath_toolkit.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import os
  2. import infra.basetest
  3. class TestOathToolKit(infra.basetest.BRTest):
  4. config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
  5. """
  6. BR2_PACKAGE_OATH_TOOLKIT=y
  7. BR2_TARGET_ROOTFS_CPIO=y
  8. # BR2_TARGET_ROOTFS_TAR is not set
  9. """
  10. def test_run(self):
  11. cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio")
  12. self.emulator.boot(arch="armv5",
  13. kernel="builtin",
  14. options=["-initrd", cpio_file])
  15. self.emulator.login()
  16. self.assertRunOk("oathtool --version")
  17. # Test commands and expected results are coming from examples
  18. # producing stable/reproducible outputs given in the oathtool
  19. # manual page. See:
  20. # https://www.nongnu.org/oath-toolkit/oathtool.1.html
  21. tests = [
  22. ("echo 00 | oathtool -", "328482"),
  23. ("oathtool -c 5 3132333435363738393031323334353637383930", "254676"),
  24. ("oathtool -w 10 3132333435363738393031323334353637383930 969429", "3"),
  25. ("oathtool --totp --now \"2008-04-23 17:42:17 UTC\" 00", "974945")
  26. ]
  27. for cmd, expected_out in tests:
  28. out, ret = self.emulator.run(cmd)
  29. self.assertEqual(ret, 0, f"Failed to run '{cmd}'")
  30. self.assertEqual(expected_out, out[0])