Skip to content

Commit 015baae

Browse files
authored
nixosTests.dolibarr: migrate to runTest (#394482)
2 parents a2cd41e + 48e6184 commit 015baae

File tree

2 files changed

+55
-57
lines changed

2 files changed

+55
-57
lines changed

nixos/tests/all-tests.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ in {
342342
documentation = pkgs.callPackage ../modules/misc/documentation/test.nix { inherit nixosLib; };
343343
doh-proxy-rust = handleTest ./doh-proxy-rust.nix {};
344344
dokuwiki = runTest ./dokuwiki.nix;
345-
dolibarr = handleTest ./dolibarr.nix {};
345+
dolibarr = runTest ./dolibarr.nix;
346346
domination = handleTest ./domination.nix {};
347347
dovecot = handleTest ./dovecot.nix {};
348348
drawterm = discoverTests (import ./drawterm.nix);

nixos/tests/dolibarr.nix

Lines changed: 54 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,60 @@
1-
import ./make-test-python.nix (
2-
{ pkgs, lib, ... }:
3-
{
4-
name = "dolibarr";
5-
meta.maintainers = [ ];
1+
{ ... }:
2+
{
3+
name = "dolibarr";
4+
meta.maintainers = [ ];
65

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;
1715
};
18-
19-
networking.firewall.allowedTCPPorts = [ 80 ];
2016
};
2117

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()
2524
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
3534
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

Comments
 (0)