|
1 | | -import ./make-test-python.nix ( |
2 | | - { pkgs, lib, ... }: |
3 | | - { |
4 | | - name = "dolibarr"; |
5 | | - meta.maintainers = [ ]; |
| 1 | +{ ... }: |
| 2 | +{ |
| 3 | + name = "dolibarr"; |
| 4 | + meta.maintainers = [ ]; |
6 | 5 |
|
7 | | - nodes.machine = |
8 | | - { ... }: |
9 | | - { |
10 | | - services.dolibarr = { |
11 | | - enable = true; |
12 | | - domain = "localhost"; |
13 | | - nginx = { |
14 | | - forceSSL = false; |
15 | | - enableACME = false; |
16 | | - }; |
| 6 | + nodes.machine = |
| 7 | + { ... }: |
| 8 | + { |
| 9 | + services.dolibarr = { |
| 10 | + enable = true; |
| 11 | + domain = "localhost"; |
| 12 | + nginx = { |
| 13 | + forceSSL = false; |
| 14 | + enableACME = false; |
17 | 15 | }; |
18 | | - |
19 | | - networking.firewall.allowedTCPPorts = [ 80 ]; |
20 | 16 | }; |
21 | 17 |
|
22 | | - testScript = '' |
23 | | - from html.parser import HTMLParser |
24 | | - start_all() |
| 18 | + networking.firewall.allowedTCPPorts = [ 80 ]; |
| 19 | + }; |
| 20 | + |
| 21 | + testScript = '' |
| 22 | + from html.parser import HTMLParser |
| 23 | + start_all() |
25 | 24 |
|
26 | | - csrf_token = None |
27 | | - class TokenParser(HTMLParser): |
28 | | - def handle_starttag(self, tag, attrs): |
29 | | - attrs = dict(attrs) # attrs is an assoc list originally |
30 | | - if tag == 'input' and attrs.get('name') == 'token': |
31 | | - csrf_token = attrs.get('value') |
32 | | - print(f'[+] Caught CSRF token: {csrf_token}') |
33 | | - def handle_endtag(self, tag): pass |
34 | | - def handle_data(self, data): pass |
| 25 | + csrf_token = None |
| 26 | + class TokenParser(HTMLParser): |
| 27 | + def handle_starttag(self, tag, attrs): |
| 28 | + attrs = dict(attrs) # attrs is an assoc list originally |
| 29 | + if tag == 'input' and attrs.get('name') == 'token': |
| 30 | + csrf_token = attrs.get('value') |
| 31 | + print(f'[+] Caught CSRF token: {csrf_token}') |
| 32 | + def handle_endtag(self, tag): pass |
| 33 | + def handle_data(self, data): pass |
35 | 34 |
|
36 | | - machine.wait_for_unit("phpfpm-dolibarr.service") |
37 | | - machine.wait_for_unit("nginx.service") |
38 | | - machine.wait_for_open_port(80) |
39 | | - # Sanity checks on URLs. |
40 | | - # machine.succeed("curl -fL http://localhost/index.php") |
41 | | - # machine.succeed("curl -fL http://localhost/") |
42 | | - # Perform installation. |
43 | | - machine.succeed('curl -fL -X POST http://localhost/install/check.php -F selectlang=auto') |
44 | | - machine.succeed('curl -fL -X POST http://localhost/install/fileconf.php -F selectlang=auto') |
45 | | - # First time is to write the configuration file correctly. |
46 | | - machine.succeed('curl -fL -X POST http://localhost/install/step1.php -F "testpost=ok" -F "action=set" -F "selectlang=auto"') |
47 | | - # Now, we have a proper conf.php in $stateDir. |
48 | | - assert 'nixos' in machine.succeed("cat /var/lib/dolibarr/conf.php") |
49 | | - machine.succeed('curl -fL -X POST http://localhost/install/step2.php --data "testpost=ok&action=set&dolibarr_main_db_character_set=utf8&dolibarr_main_db_collation=utf8_unicode_ci&selectlang=auto"') |
50 | | - machine.succeed('curl -fL -X POST http://localhost/install/step4.php --data "testpost=ok&action=set&selectlang=auto"') |
51 | | - machine.succeed('curl -fL -X POST http://localhost/install/step5.php --data "testpost=ok&action=set&login=root&pass=hunter2&pass_verif=hunter2&selectlang=auto"') |
52 | | - # Now, we have installed the machine, let's verify we still have the right configuration. |
53 | | - assert 'nixos' in machine.succeed("cat /var/lib/dolibarr/conf.php") |
54 | | - # We do not want any redirect now as we have installed the machine. |
55 | | - machine.succeed('curl -f -X GET http://localhost') |
56 | | - # Test authentication to the webservice. |
57 | | - parser = TokenParser() |
58 | | - parser.feed(machine.succeed('curl -f -X GET http://localhost/index.php?mainmenu=login&username=root')) |
59 | | - machine.succeed(f'curl -f -X POST http://localhost/index.php?mainmenu=login&token={csrf_token}&username=root&password=hunter2') |
60 | | - ''; |
61 | | - } |
62 | | -) |
| 35 | + machine.wait_for_unit("phpfpm-dolibarr.service") |
| 36 | + machine.wait_for_unit("nginx.service") |
| 37 | + machine.wait_for_open_port(80) |
| 38 | + # Sanity checks on URLs. |
| 39 | + # machine.succeed("curl -fL http://localhost/index.php") |
| 40 | + # machine.succeed("curl -fL http://localhost/") |
| 41 | + # Perform installation. |
| 42 | + machine.succeed('curl -fL -X POST http://localhost/install/check.php -F selectlang=auto') |
| 43 | + machine.succeed('curl -fL -X POST http://localhost/install/fileconf.php -F selectlang=auto') |
| 44 | + # First time is to write the configuration file correctly. |
| 45 | + machine.succeed('curl -fL -X POST http://localhost/install/step1.php -F "testpost=ok" -F "action=set" -F "selectlang=auto"') |
| 46 | + # Now, we have a proper conf.php in $stateDir. |
| 47 | + assert 'nixos' in machine.succeed("cat /var/lib/dolibarr/conf.php") |
| 48 | + machine.succeed('curl -fL -X POST http://localhost/install/step2.php --data "testpost=ok&action=set&dolibarr_main_db_character_set=utf8&dolibarr_main_db_collation=utf8_unicode_ci&selectlang=auto"') |
| 49 | + machine.succeed('curl -fL -X POST http://localhost/install/step4.php --data "testpost=ok&action=set&selectlang=auto"') |
| 50 | + machine.succeed('curl -fL -X POST http://localhost/install/step5.php --data "testpost=ok&action=set&login=root&pass=hunter2&pass_verif=hunter2&selectlang=auto"') |
| 51 | + # Now, we have installed the machine, let's verify we still have the right configuration. |
| 52 | + assert 'nixos' in machine.succeed("cat /var/lib/dolibarr/conf.php") |
| 53 | + # We do not want any redirect now as we have installed the machine. |
| 54 | + machine.succeed('curl -f -X GET http://localhost') |
| 55 | + # Test authentication to the webservice. |
| 56 | + parser = TokenParser() |
| 57 | + parser.feed(machine.succeed('curl -f -X GET http://localhost/index.php?mainmenu=login&username=root')) |
| 58 | + machine.succeed(f'curl -f -X POST http://localhost/index.php?mainmenu=login&token={csrf_token}&username=root&password=hunter2') |
| 59 | + ''; |
| 60 | +} |
0 commit comments