at master 2.7 kB view raw
1{ ... }: 2{ 3 name = "dolibarr"; 4 meta.maintainers = [ ]; 5 6 nodes.machine = 7 { ... }: 8 { 9 services.dolibarr = { 10 enable = true; 11 domain = "localhost"; 12 nginx = { 13 forceSSL = false; 14 enableACME = false; 15 }; 16 }; 17 18 networking.firewall.allowedTCPPorts = [ 80 ]; 19 }; 20 21 testScript = '' 22 from html.parser import HTMLParser 23 start_all() 24 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 34 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}