nixos/dolibarr: add h2o+postgres setup as an extra test machine

This commit is contained in:
·𐑑𐑴𐑕𐑑𐑩𐑤
2025-10-06 18:55:56 +07:00
parent 3fdabe09a5
commit 401e2b5e84

View File

@@ -3,58 +3,84 @@
name = "dolibarr"; name = "dolibarr";
meta.maintainers = [ ]; meta.maintainers = [ ];
nodes.machine = nodes = {
{ ... }: nginx_mysql =
{ { ... }:
services.dolibarr = { {
enable = true; services.dolibarr = {
domain = "localhost"; enable = true;
nginx = { domain = "localhost";
forceSSL = false; nginx = {
enableACME = false; forceSSL = false;
enableACME = false;
};
database.type = "mysql";
}; };
networking.firewall.allowedTCPPorts = [ 80 ];
}; };
h2o_postgresql =
{ ... }:
{
services.dolibarr = {
enable = true;
domain = "localhost";
h2o = {
acme.enable = false;
};
database.type = "postgresql";
};
networking.firewall.allowedTCPPorts = [ 80 ]; networking.firewall.allowedTCPPorts = [ 80 ];
}; };
};
testScript = '' testScript = # python
from html.parser import HTMLParser ''
start_all() from html.parser import HTMLParser
start_all()
csrf_token = None csrf_token = None
class TokenParser(HTMLParser): class TokenParser(HTMLParser):
def handle_starttag(self, tag, attrs): def handle_starttag(self, tag, attrs):
attrs = dict(attrs) # attrs is an assoc list originally attrs = dict(attrs) # attrs is an assoc list originally
if tag == 'input' and attrs.get('name') == 'token': if tag == 'input' and attrs.get('name') == 'token':
csrf_token = attrs.get('value') csrf_token = attrs.get('value')
print(f'[+] Caught CSRF token: {csrf_token}') print(f'[+] Caught CSRF token: {csrf_token}')
def handle_endtag(self, tag): pass def handle_endtag(self, tag): pass
def handle_data(self, data): pass def handle_data(self, data): pass
machine.wait_for_unit("phpfpm-dolibarr.service") # wait for app
machine.wait_for_unit("nginx.service") for machine in (nginx_mysql, h2o_postgresql):
machine.wait_for_open_port(80) machine.wait_for_unit("phpfpm-dolibarr.service")
# Sanity checks on URLs.
# machine.succeed("curl -fL http://localhost/index.php") # wait for web servers
# machine.succeed("curl -fL http://localhost/") nginx_mysql.wait_for_unit("nginx.service")
# Perform installation. nginx_mysql.wait_for_open_port(80)
machine.succeed('curl -fL -X POST http://localhost/install/check.php -F selectlang=auto') h2o_postgresql.wait_for_unit("h2o.service")
machine.succeed('curl -fL -X POST http://localhost/install/fileconf.php -F selectlang=auto') h2o_postgresql.wait_for_open_port(80)
# First time is to write the configuration file correctly.
machine.succeed('curl -fL -X POST http://localhost/install/step1.php -F "testpost=ok" -F "action=set" -F "selectlang=auto"') for machine in (nginx_mysql, h2o_postgresql):
# Now, we have a proper conf.php in $stateDir. # Sanity checks on URLs.
assert 'nixos' in machine.succeed("cat /var/lib/dolibarr/conf.php") machine.succeed("curl -fL http://localhost/index.php")
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"') machine.succeed("curl -fL http://localhost/")
machine.succeed('curl -fL -X POST http://localhost/install/step4.php --data "testpost=ok&action=set&selectlang=auto"') # Perform installation.
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"') machine.succeed('curl -fL -X POST http://localhost/install/check.php -F selectlang=auto')
# Now, we have installed the machine, let's verify we still have the right configuration. machine.succeed('curl -fL -X POST http://localhost/install/fileconf.php -F selectlang=auto')
assert 'nixos' in machine.succeed("cat /var/lib/dolibarr/conf.php") # First time is to write the configuration file correctly.
# We do not want any redirect now as we have installed the machine. machine.succeed('curl -fL -X POST http://localhost/install/step1.php -F "testpost=ok" -F "action=set" -F "selectlang=auto"')
machine.succeed('curl -f -X GET http://localhost') # Now, we have a proper conf.php in $stateDir.
# Test authentication to the webservice. assert 'nixos' in machine.succeed("cat /var/lib/dolibarr/conf.php")
parser = TokenParser() 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"')
parser.feed(machine.succeed('curl -f -X GET http://localhost/index.php?mainmenu=login&username=root')) machine.succeed('curl -fL -X POST http://localhost/install/step4.php --data "testpost=ok&action=set&selectlang=auto"')
machine.succeed(f'curl -f -X POST http://localhost/index.php?mainmenu=login&token={csrf_token}&username=root&password=hunter2') 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"')
''; # Now, we have installed the machine, let's verify we still have the right configuration.
assert 'nixos' in machine.succeed("cat /var/lib/dolibarr/conf.php")
# We do not want any redirect now as we have installed the machine.
machine.succeed('curl -f -X GET http://localhost')
# Test authentication to the webservice.
parser = TokenParser()
parser.feed(machine.succeed('curl -f -X GET http://localhost/index.php?mainmenu=login&username=root'))
machine.succeed(f'curl -f -X POST http://localhost/index.php?mainmenu=login&token={csrf_token}&username=root&password=hunter2')
'';
} }