nixosTests.dolibarr: migrate to runTest

Part of #386873
This commit is contained in:
Piotr Kwiecinski 2025-03-30 01:05:50 +01:00
parent 1c2f1b30b5
commit 48e6184ddf
No known key found for this signature in database
GPG key ID: EC0DE1CB9D5258B4
2 changed files with 55 additions and 57 deletions

View file

@ -342,7 +342,7 @@ in {
documentation = pkgs.callPackage ../modules/misc/documentation/test.nix { inherit nixosLib; }; documentation = pkgs.callPackage ../modules/misc/documentation/test.nix { inherit nixosLib; };
doh-proxy-rust = handleTest ./doh-proxy-rust.nix {}; doh-proxy-rust = handleTest ./doh-proxy-rust.nix {};
dokuwiki = runTest ./dokuwiki.nix; dokuwiki = runTest ./dokuwiki.nix;
dolibarr = handleTest ./dolibarr.nix {}; dolibarr = runTest ./dolibarr.nix;
domination = handleTest ./domination.nix {}; domination = handleTest ./domination.nix {};
dovecot = handleTest ./dovecot.nix {}; dovecot = handleTest ./dovecot.nix {};
drawterm = discoverTests (import ./drawterm.nix); drawterm = discoverTests (import ./drawterm.nix);

View file

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