1 import ./make-test-python.nix ({ pkgs, lib, ... }: {
3 meta.maintainers = [ ];
17 networking.firewall.allowedTCPPorts = [ 80 ];
21 from html.parser import HTMLParser
25 class TokenParser(HTMLParser):
26 def handle_starttag(self, tag, attrs):
27 attrs = dict(attrs) # attrs is an assoc list originally
28 if tag == 'input' and attrs.get('name') == 'token':
29 csrf_token = attrs.get('value')
30 print(f'[+] Caught CSRF token: {csrf_token}')
31 def handle_endtag(self, tag): pass
32 def handle_data(self, data): pass
34 machine.wait_for_unit("phpfpm-dolibarr.service")
35 machine.wait_for_unit("nginx.service")
36 machine.wait_for_open_port(80)
37 # Sanity checks on URLs.
38 # machine.succeed("curl -fL http://localhost/index.php")
39 # machine.succeed("curl -fL http://localhost/")
40 # Perform installation.
41 machine.succeed('curl -fL -X POST http://localhost/install/check.php -F selectlang=auto')
42 machine.succeed('curl -fL -X POST http://localhost/install/fileconf.php -F selectlang=auto')
43 # First time is to write the configuration file correctly.
44 machine.succeed('curl -fL -X POST http://localhost/install/step1.php -F "testpost=ok" -F "action=set" -F "selectlang=auto"')
45 # Now, we have a proper conf.php in $stateDir.
46 assert 'nixos' in machine.succeed("cat /var/lib/dolibarr/conf.php")
47 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"')
48 machine.succeed('curl -fL -X POST http://localhost/install/step4.php --data "testpost=ok&action=set&selectlang=auto"')
49 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"')
50 # Now, we have installed the machine, let's verify we still have the right configuration.
51 assert 'nixos' in machine.succeed("cat /var/lib/dolibarr/conf.php")
52 # We do not want any redirect now as we have installed the machine.
53 machine.succeed('curl -f -X GET http://localhost')
54 # Test authentication to the webservice.
55 parser = TokenParser()
56 parser.feed(machine.succeed('curl -f -X GET http://localhost/index.php?mainmenu=login&username=root'))
57 machine.succeed(f'curl -f -X POST http://localhost/index.php?mainmenu=login&token={csrf_token}&username=root&password=hunter2')