test_unbound.py 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import os
  2. import infra.basetest
  3. class TestUnbound(infra.basetest.BRTest):
  4. rootfs_overlay = \
  5. infra.filepath("tests/package/test_unbound/rootfs-overlay")
  6. config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
  7. f"""
  8. BR2_PACKAGE_UNBOUND=y
  9. BR2_ROOTFS_OVERLAY="{rootfs_overlay}"
  10. BR2_TARGET_ROOTFS_CPIO=y
  11. # BR2_TARGET_ROOTFS_TAR is not set
  12. """
  13. def test_run(self):
  14. cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio")
  15. self.emulator.boot(arch="armv5",
  16. kernel="builtin",
  17. options=["-initrd", cpio_file])
  18. self.emulator.login()
  19. # Check the program can execute.
  20. self.assertRunOk("unbound -V")
  21. # Verify that the configuration checker validates our file.
  22. self.assertRunOk("unbound-checkconf")
  23. # Our test configuration enabled the unbound remote
  24. # control. The unbound server is supposed to be started by the
  25. # sysv initscript. We should see the already running server.
  26. out, ret = self.emulator.run("unbound-control status")
  27. self.assertEqual(ret, 0)
  28. self.assertRegex("\n".join(out), r"unbound \(pid \d+\) is running")
  29. # We check the "unbound-host" program is working with a simple
  30. # query. Note: this local query succeed even if the unbound
  31. # server is not running. We are only testing this program
  32. # here. The server side will be tested with the BusyBox
  33. # "nslookup" applet.
  34. out, ret = self.emulator.run("unbound-host -t A localhost.")
  35. self.assertEqual(ret, 0)
  36. self.assertEqual(out[0], "localhost. has address 127.0.0.1")
  37. # We test few other "unbound-control" commands.
  38. self.assertRunOk("unbound-control stats")
  39. self.assertRunOk("unbound-control list_local_zones")
  40. # We check we see our test IPv4 address record.
  41. cmd = "nslookup -type=A somehost.buildroot.test."
  42. out, ret = self.emulator.run(cmd)
  43. self.assertEqual(ret, 0)
  44. self.assertIn("Address: 10.20.30.40", out)
  45. # We also check we see our reverse record.
  46. cmd = "nslookup 10.20.30.40"
  47. out, ret = self.emulator.run(cmd)
  48. self.assertEqual(ret, 0)
  49. expected = "40.30.20.10.in-addr.arpa\tname = somehost.buildroot.test"
  50. self.assertIn(expected, out)
  51. # We check we see our test text record.
  52. cmd = "nslookup -type=TXT sometext.buildroot.test."
  53. out, ret = self.emulator.run(cmd)
  54. self.assertEqual(ret, 0)
  55. expected = "sometext.buildroot.test\ttext = \"Hello Buildroot TXT\""
  56. self.assertIn(expected, out)
  57. # We add a new record with unbound-control.
  58. record_data = "someotherhost.buildroot.test. IN A 10.99.99.99"
  59. cmd = f"unbound-control local_data \"{record_data}\""
  60. self.assertRunOk(cmd)
  61. # We check we see our new IPv4 address record.
  62. cmd = "nslookup -type=A someotherhost.buildroot.test."
  63. out, ret = self.emulator.run(cmd)
  64. self.assertEqual(ret, 0)
  65. self.assertIn("Address: 10.99.99.99", out)