|
| 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 | +} |
0 commit comments