mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-10 03:23:29 +03:00
nixosTests.draupnir: init
Co-authored-by: emilylange <git@emilylange.de> Co-authored-by: Martin Weinelt <hexa@darmstadt.ccc.de> Co-authored-by: teutat3s <10206665+teutat3s@users.noreply.github.com>
This commit is contained in:
parent
4b153aad5d
commit
d6413ba436
3 changed files with 156 additions and 1 deletions
|
@ -409,6 +409,7 @@ in
|
||||||
domination = runTest ./domination.nix;
|
domination = runTest ./domination.nix;
|
||||||
dovecot = handleTest ./dovecot.nix { };
|
dovecot = handleTest ./dovecot.nix { };
|
||||||
drawterm = discoverTests (import ./drawterm.nix);
|
drawterm = discoverTests (import ./drawterm.nix);
|
||||||
|
draupnir = runTest ./matrix/draupnir.nix;
|
||||||
drbd = runTest ./drbd.nix;
|
drbd = runTest ./drbd.nix;
|
||||||
druid = handleTestOn [ "x86_64-linux" ] ./druid { };
|
druid = handleTestOn [ "x86_64-linux" ] ./druid { };
|
||||||
drupal = runTest ./drupal.nix;
|
drupal = runTest ./drupal.nix;
|
||||||
|
|
150
nixos/tests/matrix/draupnir.nix
Normal file
150
nixos/tests/matrix/draupnir.nix
Normal file
|
@ -0,0 +1,150 @@
|
||||||
|
{
|
||||||
|
lib,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
|
||||||
|
{
|
||||||
|
name = "draupnir";
|
||||||
|
meta.maintainers = with lib.maintainers; [
|
||||||
|
RorySys
|
||||||
|
emilylange
|
||||||
|
];
|
||||||
|
|
||||||
|
nodes = {
|
||||||
|
homeserver =
|
||||||
|
{ pkgs, ... }:
|
||||||
|
{
|
||||||
|
services.matrix-synapse = {
|
||||||
|
enable = true;
|
||||||
|
log.root.level = "WARNING";
|
||||||
|
settings = {
|
||||||
|
database.name = "sqlite3";
|
||||||
|
registration_shared_secret = "supersecret-registration";
|
||||||
|
|
||||||
|
listeners = [
|
||||||
|
{
|
||||||
|
bind_addresses = [
|
||||||
|
"::"
|
||||||
|
];
|
||||||
|
port = 8008;
|
||||||
|
resources = [
|
||||||
|
{
|
||||||
|
compress = true;
|
||||||
|
names = [ "client" ];
|
||||||
|
}
|
||||||
|
{
|
||||||
|
compress = false;
|
||||||
|
names = [ "federation" ];
|
||||||
|
}
|
||||||
|
];
|
||||||
|
tls = false;
|
||||||
|
type = "http";
|
||||||
|
x_forwarded = false;
|
||||||
|
}
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
specialisation.draupnir = {
|
||||||
|
inheritParentConfig = true;
|
||||||
|
|
||||||
|
configuration.services.draupnir = {
|
||||||
|
enable = true;
|
||||||
|
settings = {
|
||||||
|
homeserverUrl = "http://localhost:8008";
|
||||||
|
managementRoom = "#moderators:homeserver";
|
||||||
|
};
|
||||||
|
secrets = {
|
||||||
|
accessToken = "/tmp/draupnir-access-token";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
environment.systemPackages = with pkgs; [
|
||||||
|
curl
|
||||||
|
jq
|
||||||
|
(writers.writePython3Bin "test_draupnir_in_matrix"
|
||||||
|
{
|
||||||
|
libraries = [ python3Packages.matrix-nio ];
|
||||||
|
flakeIgnore = [ "E501" ];
|
||||||
|
}
|
||||||
|
''
|
||||||
|
import asyncio
|
||||||
|
from nio import AsyncClient, MatrixRoom, RoomMemberEvent, RoomMessageNotice
|
||||||
|
|
||||||
|
|
||||||
|
async def main() -> None:
|
||||||
|
client = AsyncClient("http://localhost:8008", "moderator")
|
||||||
|
|
||||||
|
async def member_callback(room: MatrixRoom, event: RoomMemberEvent) -> None:
|
||||||
|
if event.membership == "join" and event.sender == "@draupnir:homeserver":
|
||||||
|
await client.room_send(
|
||||||
|
room_id=room.room_id,
|
||||||
|
message_type="m.room.message",
|
||||||
|
content={
|
||||||
|
"msgtype": "m.text",
|
||||||
|
"body": "!draupnir status"
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
async def message_callback(room: MatrixRoom, event: RoomMessageNotice) -> None:
|
||||||
|
print(f"{event.sender}: {event.body}")
|
||||||
|
if event.sender == "@draupnir:homeserver":
|
||||||
|
await client.close()
|
||||||
|
exit(0)
|
||||||
|
|
||||||
|
client.add_event_callback(member_callback, RoomMemberEvent)
|
||||||
|
client.add_event_callback(message_callback, RoomMessageNotice)
|
||||||
|
|
||||||
|
print(await client.login("password"))
|
||||||
|
|
||||||
|
room = await client.room_create(
|
||||||
|
name="Moderators",
|
||||||
|
alias="moderators",
|
||||||
|
invite=["@draupnir:homeserver"],
|
||||||
|
power_level_override={
|
||||||
|
"users": {
|
||||||
|
"@draupnir:homeserver": 100,
|
||||||
|
"@moderator:homeserver": 100,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
print(room)
|
||||||
|
|
||||||
|
print(await client.join(room.room_id))
|
||||||
|
|
||||||
|
await client.sync_forever(timeout=30000)
|
||||||
|
|
||||||
|
|
||||||
|
asyncio.run(main())
|
||||||
|
''
|
||||||
|
)
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
testScript =
|
||||||
|
{ nodes, ... }:
|
||||||
|
''
|
||||||
|
import json
|
||||||
|
|
||||||
|
homeserver.wait_for_unit("matrix-synapse.service")
|
||||||
|
homeserver.wait_until_succeeds("curl --fail -L http://localhost:8008/")
|
||||||
|
|
||||||
|
homeserver.succeed("matrix-synapse-register_new_matrix_user -u draupnir -p password --no-admin")
|
||||||
|
homeserver.succeed("matrix-synapse-register_new_matrix_user -u moderator -p password --no-admin")
|
||||||
|
|
||||||
|
# get draupnir access token
|
||||||
|
payload = json.dumps({ "type": "m.login.password", "user": "draupnir", "password": "password" })
|
||||||
|
homeserver.succeed(
|
||||||
|
f"curl --fail --json '{payload}' http://localhost:8008/_matrix/client/v3/login"
|
||||||
|
+ " | jq -r .access_token"
|
||||||
|
+ " | tee /tmp/draupnir-access-token"
|
||||||
|
)
|
||||||
|
|
||||||
|
homeserver.succeed("${nodes.homeserver.system.build.toplevel}/specialisation/draupnir/bin/switch-to-configuration test")
|
||||||
|
homeserver.wait_for_unit("draupnir.service")
|
||||||
|
|
||||||
|
print(homeserver.succeed("test_draupnir_in_matrix >&2", timeout=60))
|
||||||
|
'';
|
||||||
|
}
|
|
@ -12,6 +12,7 @@
|
||||||
fetchYarnDeps,
|
fetchYarnDeps,
|
||||||
stdenv,
|
stdenv,
|
||||||
cctools,
|
cctools,
|
||||||
|
nixosTests,
|
||||||
}:
|
}:
|
||||||
|
|
||||||
# docs: https://github.com/NixOS/nixpkgs/blob/master/doc/languages-frameworks/javascript.section.md#yarn2nix-javascript-yarn2nix
|
# docs: https://github.com/NixOS/nixpkgs/blob/master/doc/languages-frameworks/javascript.section.md#yarn2nix-javascript-yarn2nix
|
||||||
|
@ -95,7 +96,10 @@ mkYarnPackage rec {
|
||||||
|
|
||||||
distPhase = "true";
|
distPhase = "true";
|
||||||
|
|
||||||
passthru.updateScript = ./update.sh;
|
passthru = {
|
||||||
|
tests = { inherit (nixosTests) draupnir; };
|
||||||
|
updateScript = ./update.sh;
|
||||||
|
};
|
||||||
|
|
||||||
meta = with lib; {
|
meta = with lib; {
|
||||||
description = "A moderation tool for Matrix";
|
description = "A moderation tool for Matrix";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue