Skip to content

Commit 2d4fc61

Browse files
committed
tests: init kratos
1 parent c9fedc5 commit 2d4fc61

3 files changed

Lines changed: 211 additions & 0 deletions

File tree

nixos/tests/all-tests.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,8 @@ in
807807
jitsi-meet = runTest ./jitsi-meet.nix;
808808
jool = import ./jool.nix { inherit pkgs runTest; };
809809
jotta-cli = runTest ./jotta-cli.nix;
810+
kratos = runTest ./kratos.nix;
811+
kratos-abstractions = runTest ./kratos-abstractions.nix;
810812
k3s = import ./rancher {
811813
inherit pkgs runTest;
812814
inherit (pkgs) lib;
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
{ lib, pkgs, ... }:
2+
3+
{
4+
name = "kratos-abstractions";
5+
meta.maintainers = with lib.maintainers; [ philocalyst ];
6+
7+
nodes.machine =
8+
{ ... }:
9+
let
10+
identitySchema = pkgs.writeText "kratos-identity.schema.json" ''
11+
{
12+
"$id": "https://example.com/schemas/identity.schema.json",
13+
"$schema": "http://json-schema.org/draft-07/schema#",
14+
"title": "Identity",
15+
"type": "object",
16+
"properties": {
17+
"traits": {
18+
"type": "object",
19+
"properties": {
20+
"email": {
21+
"type": "string",
22+
"format": "email",
23+
"ory.sh/kratos": {
24+
"credentials": {
25+
"password": {
26+
"identifier": true
27+
}
28+
}
29+
}
30+
}
31+
},
32+
"required": [ "email" ],
33+
"additionalProperties": false
34+
}
35+
}
36+
}
37+
'';
38+
39+
defaultSecret = pkgs.writeText "kratos-default-secret" "abcdefghijklmnopqrstuvwxyz123456";
40+
cookieSecret = pkgs.writeText "kratos-cookie-secret" "bcdefghijklmnopqrstuvwxyz1234567";
41+
cipherSecret = pkgs.writeText "kratos-cipher-secret" "0123456789abcdef0123456789abcdef";
42+
smtpConnectionURI = pkgs.writeText "kratos-smtp-connection-uri" "smtps://test:test@localhost:1025/?skip_ssl_verify=true";
43+
in
44+
{
45+
services.kratos = {
46+
enable = true;
47+
database.createLocally = true;
48+
identitySchemas = [
49+
{
50+
id = "default";
51+
path = identitySchema;
52+
}
53+
];
54+
urls = {
55+
public = "https://id.example.test/";
56+
admin = "http://kratos.internal.test:4434/";
57+
selfService = "https://auth.example.test";
58+
defaultReturnTo = "https://app.example.test/";
59+
allowedReturnUrls = [
60+
"https://app.example.test/"
61+
"https://auth.example.test/"
62+
];
63+
};
64+
secretFiles = {
65+
default = [ defaultSecret ];
66+
cookie = [ cookieSecret ];
67+
cipher = [ cipherSecret ];
68+
courierSmtpConnectionURI = smtpConnectionURI;
69+
};
70+
settings = {
71+
selfservice.methods.password.enabled = true;
72+
};
73+
};
74+
};
75+
76+
testScript =
77+
{ nodes, ... }:
78+
let
79+
settings = nodes.machine.services.kratos.settings;
80+
in
81+
''
82+
machine.wait_for_unit("postgresql.service")
83+
machine.wait_for_unit("kratos-postgresql-init.service")
84+
machine.wait_for_unit("kratos-migrate.service")
85+
machine.wait_for_unit("kratos.service")
86+
machine.wait_for_open_port(4433)
87+
machine.wait_for_open_port(4434)
88+
89+
machine.succeed("curl --fail http://127.0.0.1:4433/health/ready")
90+
machine.succeed("curl --fail http://127.0.0.1:4434/health/ready")
91+
machine.succeed("su - postgres -c \"psql -tAc \\\"SELECT 1 FROM pg_database WHERE datname = 'kratos'\\\"\" | grep 1")
92+
93+
assert "${settings.serve.public.base_url}" == "https://id.example.test/"
94+
assert "${settings.serve.admin.base_url}" == "http://kratos.internal.test:4434/"
95+
assert "${settings.selfservice.default_browser_return_url}" == "https://app.example.test/"
96+
assert "${settings.selfservice.flows.login.ui_url}" == "https://auth.example.test/login"
97+
assert "${settings.selfservice.flows.registration.ui_url}" == "https://auth.example.test/registration"
98+
assert "${settings.selfservice.flows.settings.ui_url}" == "https://auth.example.test/settings"
99+
assert "${settings.selfservice.flows.error.ui_url}" == "https://auth.example.test/error"
100+
assert "${settings.selfservice.flows.recovery.ui_url}" == "https://auth.example.test/recovery"
101+
assert "${settings.selfservice.flows.verification.ui_url}" == "https://auth.example.test/verification"
102+
assert "${settings.selfservice.flows.logout.after.default_browser_return_url}" == "https://auth.example.test/login"
103+
'';
104+
}

nixos/tests/kratos.nix

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
{ lib, ... }:
2+
3+
{
4+
name = "kratos";
5+
meta.maintainers = with lib.maintainers; [ philocalyst ];
6+
7+
nodes.machine =
8+
{ config, ... }:
9+
let
10+
identitySchema = config.node.pkgs.writeText "kratos-identity.schema.json" ''
11+
{
12+
"$id": "https://example.com/schemas/identity.schema.json",
13+
"$schema": "http://json-schema.org/draft-07/schema#",
14+
"title": "Identity",
15+
"type": "object",
16+
"properties": {
17+
"traits": {
18+
"type": "object",
19+
"properties": {
20+
"email": {
21+
"type": "string",
22+
"format": "email",
23+
"ory.sh/kratos": {
24+
"credentials": {
25+
"password": {
26+
"identifier": true
27+
}
28+
},
29+
"recovery": {
30+
"via": "email"
31+
},
32+
"verification": {
33+
"via": "email"
34+
}
35+
}
36+
}
37+
},
38+
"required": [ "email" ],
39+
"additionalProperties": false
40+
}
41+
}
42+
}
43+
'';
44+
in
45+
{
46+
services.kratos = {
47+
enable = true;
48+
identitySchemas = [
49+
{
50+
id = "default";
51+
path = identitySchema;
52+
}
53+
];
54+
settings = {
55+
selfservice = {
56+
default_browser_return_url = "http://127.0.0.1:4455/";
57+
allowed_return_urls = [ "http://127.0.0.1:4455/" ];
58+
methods.password.enabled = true;
59+
flows = {
60+
error.ui_url = "http://127.0.0.1:4455/error";
61+
settings = {
62+
ui_url = "http://127.0.0.1:4455/settings";
63+
privileged_session_max_age = "15m";
64+
};
65+
recovery = {
66+
enabled = true;
67+
ui_url = "http://127.0.0.1:4455/recovery";
68+
};
69+
verification = {
70+
enabled = true;
71+
ui_url = "http://127.0.0.1:4455/verification";
72+
};
73+
logout.after.default_browser_return_url = "http://127.0.0.1:4455/login";
74+
login = {
75+
ui_url = "http://127.0.0.1:4455/login";
76+
lifespan = "10m";
77+
};
78+
registration = {
79+
ui_url = "http://127.0.0.1:4455/registration";
80+
lifespan = "10m";
81+
after.password.hooks = [ { hook = "session"; } ];
82+
};
83+
};
84+
};
85+
secrets = {
86+
cookie = [ "abcdefghijklmnopqrstuvwxyz123456" ];
87+
cipher = [ "0123456789abcdef0123456789abcdef" ];
88+
default = [ "abcdefghijklmnopqrstuvwxyz123456" ];
89+
};
90+
courier.smtp.connection_uri = "smtps://test:test@localhost:1025/?skip_ssl_verify=true";
91+
};
92+
};
93+
};
94+
95+
testScript = ''
96+
machine.wait_for_unit("kratos-migrate.service")
97+
machine.wait_for_unit("kratos.service")
98+
machine.wait_for_open_port(4433)
99+
machine.wait_for_open_port(4434)
100+
101+
machine.succeed("curl --fail http://127.0.0.1:4433/health/ready")
102+
machine.succeed("curl --fail http://127.0.0.1:4434/health/ready")
103+
machine.succeed("test -f /var/lib/kratos/db.sqlite")
104+
'';
105+
}

0 commit comments

Comments
 (0)