jet-pilot: init at 1.31.0 (#334500)
[NixPkgs.git] / nixos / tests / php / pcre.nix
blob438cc3a5e12efb4c962b67fa1ac1c1d998d9ba45
1 let
2   testString = "can-use-subgroups";
3 in
4 import ../make-test-python.nix (
5   {
6     pkgs,
7     lib,
8     php,
9     ...
10   }:
11   {
12     name = "php-${php.version}-httpd-pcre-jit-test";
13     meta.maintainers = lib.teams.php.members;
15     nodes.machine =
16       { lib, pkgs, ... }:
17       {
18         time.timeZone = "UTC";
19         services.httpd = {
20           enable = true;
21           adminAddr = "please@dont.contact";
22           phpPackage = php;
23           enablePHP = true;
24           phpOptions = "pcre.jit = true";
25           extraConfig =
26             let
27               testRoot = pkgs.writeText "index.php" ''
28                 <?php
29                 preg_match('/(${testString})/', '${testString}', $result);
30                 var_dump($result);
31               '';
32             in
33             ''
34               Alias / ${testRoot}/
36               <Directory ${testRoot}>
37                 Require all granted
38               </Directory>
39             '';
40         };
41       };
42     testScript =
43       let
44         # PCRE JIT SEAlloc feature does not play well with fork()
45         # The feature needs to either be disabled or PHP configured correctly
46         # More information in https://bugs.php.net/bug.php?id=78927 and https://bugs.php.net/bug.php?id=78630
47         pcreJitSeallocForkIssue = pkgs.writeText "pcre-jit-sealloc-issue.php" ''
48           <?php
49           preg_match('/nixos/', 'nixos');
50           $pid = pcntl_fork();
51           pcntl_wait($pid);
52         '';
53       in
54       ''
55         machine.wait_for_unit("httpd.service")
56         # Ensure php evaluation by matching on the var_dump syntax
57         response = machine.succeed("curl -fvvv -s http://127.0.0.1:80/index.php")
58         expected = 'string(${toString (builtins.stringLength testString)}) "${testString}"'
59         assert expected in response, "Does not appear to be able to use subgroups."
60         machine.succeed("${php}/bin/php -f ${pcreJitSeallocForkIssue}")
61       '';
62   }