test_nginx_modsecurity.py 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. import os
  2. import infra.basetest
  3. class TestNginxModsecurity(infra.basetest.BRTest):
  4. overlay = infra.filepath("tests/package/test_nginx_modsecurity/overlay")
  5. config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
  6. f"""
  7. BR2_PACKAGE_NGINX=y
  8. BR2_PACKAGE_NGINX_HTTP=y
  9. BR2_PACKAGE_NGINX_MODSECURITY=y
  10. BR2_ROOTFS_OVERLAY="{overlay}"
  11. BR2_TARGET_ROOTFS_CPIO=y
  12. BR2_TARGET_ROOTFS_CPIO_GZIP=y
  13. """
  14. def test_run(self):
  15. cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio")
  16. self.emulator.boot(arch="armv5",
  17. kernel="builtin",
  18. options=["-initrd", cpio_file])
  19. self.emulator.login()
  20. self.assertRunOk("nginx -V")
  21. self.assertRunOk("wget http://localhost/index.html")
  22. self.assertRunOk("grep -F 'Welcome to nginx!' index.html")
  23. cmd = "wget -q -O /dev/null --server-response 2>&1 " \
  24. "http://localhost/blockme/ 2>&1 | awk '/^ HTTP/{print $2}'"
  25. out, ret = self.emulator.run(cmd)
  26. self.assertEqual(ret, 0)
  27. # Check for HTTP 403 Unauthorized:
  28. self.assertEqual(out[0], "403")