1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
import ./make-test-python.nix ({ pkgs, lib, ...} : {
name = "wiki-js";
meta = with pkgs.lib.maintainers; {
maintainers = [ ma27 ];
};
nodes.machine = { pkgs, ... }: {
virtualisation.memorySize = 2047;
services.wiki-js = {
enable = true;
settings.db.host = "/run/postgresql";
settings.db.user = "wiki-js";
settings.db.db = "wiki-js";
settings.logLevel = "debug";
};
services.postgresql = {
enable = true;
ensureDatabases = [ "wiki-js" ];
ensureUsers = [
{ name = "wiki-js";
ensureDBOwnership = true;
}
];
};
systemd.services.wiki-js = {
requires = [ "postgresql.service" ];
after = [ "postgresql.service" ];
};
environment.systemPackages = with pkgs; [ jq ];
};
testScript = let
payloads.finalize = pkgs.writeText "finalize.json" (builtins.toJSON {
adminEmail = "webmaster@example.com";
adminPassword = "notapassword";
adminPasswordConfirm = "notapassword";
siteUrl = "http://localhost:3000";
telemetry = false;
});
payloads.login = pkgs.writeText "login.json" (builtins.toJSON [{
operationName = null;
extensions = {};
query = ''
mutation ($username: String!, $password: String!, $strategy: String!) {
authentication {
login(username: $username, password: $password, strategy: $strategy) {
responseResult {
succeeded
errorCode
slug
message
__typename
}
jwt
mustChangePwd
mustProvideTFA
mustSetupTFA
continuationToken
redirect
tfaQRImage
__typename
}
__typename
}
}
'';
variables = {
password = "notapassword";
strategy = "local";
username = "webmaster@example.com";
};
}]);
payloads.content = pkgs.writeText "content.json" (builtins.toJSON [{
extensions = {};
operationName = null;
query = ''
mutation ($content: String!, $description: String!, $editor: String!, $isPrivate: Boolean!, $isPublished: Boolean!, $locale: String!, $path: String!, $publishEndDate: Date, $publishStartDate: Date, $scriptCss: String, $scriptJs: String, $tags: [String]!, $title: String!) {
pages {
create(content: $content, description: $description, editor: $editor, isPrivate: $isPrivate, isPublished: $isPublished, locale: $locale, path: $path, publishEndDate: $publishEndDate, publishStartDate: $publishStartDate, scriptCss: $scriptCss, scriptJs: $scriptJs, tags: $tags, title: $title) {
responseResult {
succeeded
errorCode
slug
message
__typename
}
page {
id
updatedAt
__typename
}
__typename
}
__typename
}
}
'';
variables = {
content = "# Header\n\nHello world!";
description = "";
editor = "markdown";
isPrivate = false;
isPublished = true;
locale = "en";
path = "home";
publishEndDate = "";
publishStartDate = "";
scriptCss = "";
scriptJs = "";
tags = [];
title = "Hello world";
};
}]);
in ''
machine.start()
machine.wait_for_unit("multi-user.target")
machine.wait_for_open_port(3000)
machine.succeed("curl -sSf localhost:3000")
with subtest("Setup"):
result = machine.succeed(
"curl -sSf localhost:3000/finalize -X POST -d "
+ "@${payloads.finalize} -H 'Content-Type: application/json' "
+ "| jq .ok | xargs echo"
)
assert result.strip() == "true", f"Expected true, got {result}"
# During the setup the service gets restarted, so we use this
# to check if the setup is done.
machine.wait_until_fails("curl -sSf localhost:3000")
machine.wait_until_succeeds("curl -sSf localhost:3000")
with subtest("Base functionality"):
auth = machine.succeed(
"curl -sSf localhost:3000/graphql -X POST "
+ "-d @${payloads.login} -H 'Content-Type: application/json' "
+ "| jq '.[0].data.authentication.login.jwt' | xargs echo"
).strip()
assert auth
create = machine.succeed(
"curl -sSf localhost:3000/graphql -X POST "
+ "-d @${payloads.content} -H 'Content-Type: application/json' "
+ f"-H 'Authorization: Bearer {auth}' "
+ "| jq '.[0].data.pages.create.responseResult.succeeded'|xargs echo"
)
assert create.strip() == "true", f"Expected true, got {create}"
machine.shutdown()
'';
})
|