summaryrefslogtreecommitdiffstats
path: root/nixos/tests/kubo/kubo.nix
blob: 41627e6c4c5017a727e1c2bba6c5f5defecea371 (plain)
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
{ lib, ... }:
{
  name = "kubo";
  meta = with lib.maintainers; {
    maintainers = [
      mguentner
      Luflosi
    ];
  };

  nodes.machine =
    { config, ... }:
    {
      services.kubo = {
        enable = true;
        # Also will add a unix domain socket socket API address, see module.
        startWhenNeeded = true;
        settings.Addresses.API = "/ip4/127.0.0.1/tcp/2324";
        dataDir = "/mnt/ipfs";
      };
      users.users.alice = {
        isNormalUser = true;
        extraGroups = [ config.services.kubo.group ];
      };
    };

  testScript = ''
    start_all()

    with subtest("Automatic socket activation"):
        ipfs_hash = machine.succeed(
            "echo fnord0 | su alice -l -c 'ipfs add --quieter'"
        )
        machine.succeed(f"ipfs cat /ipfs/{ipfs_hash.strip()} | grep fnord0")

    machine.stop_job("ipfs")

    with subtest("IPv4 socket activation"):
        machine.succeed("ipfs --api /ip4/127.0.0.1/tcp/2324 id")
        ipfs_hash = machine.succeed(
            "echo fnord | ipfs --api /ip4/127.0.0.1/tcp/2324 add --quieter"
        )
        machine.succeed(f"ipfs cat /ipfs/{ipfs_hash.strip()} | grep fnord")

    machine.stop_job("ipfs")

    with subtest("Unix domain socket activation"):
        ipfs_hash = machine.succeed(
            "echo fnord2 | ipfs --api /unix/run/ipfs.sock add --quieter"
        )
        machine.succeed(
            f"ipfs --api /unix/run/ipfs.sock cat /ipfs/{ipfs_hash.strip()} | grep fnord2"
        )

    machine.stop_job("ipfs")

    with subtest("Socket activation for the Gateway"):
        machine.succeed(
            f"curl -s 'http://127.0.0.1:8080/ipfs/{ipfs_hash.strip()}' | grep fnord2"
        )

    with subtest("Setting dataDir works properly with the hardened systemd unit"):
        machine.succeed("test -e /mnt/ipfs/config")
        machine.succeed("test ! -e /var/lib/ipfs/")
  '';
}