python310Packages.pydeconz: 104 -> 105
[NixPkgs.git] / nixos / tests / gitea.nix
blob68a2566c11911af14776c4335a12f636e44afe67
1 { system ? builtins.currentSystem,
2   config ? {},
3   pkgs ? import ../.. { inherit system config; }
4 }:
6 with import ../lib/testing-python.nix { inherit system pkgs; };
7 with pkgs.lib;
9 let
10   supportedDbTypes = [ "mysql" "postgres" "sqlite3" ];
11   makeGiteaTest = type: nameValuePair type (makeTest {
12     name = "gitea-${type}";
13     meta.maintainers = with maintainers; [ aanderse kolaente ma27 ];
15     nodes = {
16       server = { config, pkgs, ... }: {
17         virtualisation.memorySize = 2048;
18         services.gitea = {
19           enable = true;
20           database = { inherit type; };
21           settings.service.DISABLE_REGISTRATION = true;
22         };
23         environment.systemPackages = [ pkgs.gitea pkgs.jq ];
24         services.openssh.enable = true;
25       };
26       client1 = { config, pkgs, ... }: {
27         environment.systemPackages = [ pkgs.git ];
28       };
29       client2 = { config, pkgs, ... }: {
30         environment.systemPackages = [ pkgs.git ];
31       };
32     };
34     testScript = let
35       inherit (import ./ssh-keys.nix pkgs) snakeOilPrivateKey snakeOilPublicKey;
36     in ''
37       GIT_SSH_COMMAND = "ssh -i $HOME/.ssh/privk -o StrictHostKeyChecking=no"
38       REPO = "gitea@server:test/repo"
39       PRIVK = "${snakeOilPrivateKey}"
41       start_all()
43       client1.succeed("mkdir /tmp/repo")
44       client1.succeed("mkdir -p $HOME/.ssh")
45       client1.succeed(f"cat {PRIVK} > $HOME/.ssh/privk")
46       client1.succeed("chmod 0400 $HOME/.ssh/privk")
47       client1.succeed("git -C /tmp/repo init")
48       client1.succeed("echo hello world > /tmp/repo/testfile")
49       client1.succeed("git -C /tmp/repo add .")
50       client1.succeed("git config --global user.email test@localhost")
51       client1.succeed("git config --global user.name test")
52       client1.succeed("git -C /tmp/repo commit -m 'Initial import'")
53       client1.succeed(f"git -C /tmp/repo remote add origin {REPO}")
55       server.wait_for_unit("gitea.service")
56       server.wait_for_open_port(3000)
57       server.succeed("curl --fail http://localhost:3000/")
59       server.succeed(
60           "curl --fail http://localhost:3000/user/sign_up | grep 'Registration is disabled. "
61           + "Please contact your site administrator.'"
62       )
63       server.succeed(
64           "su -l gitea -c 'GITEA_WORK_DIR=/var/lib/gitea gitea admin user create "
65           + "--username test --password totallysafe --email test@localhost'"
66       )
68       api_token = server.succeed(
69           "curl --fail -X POST http://test:totallysafe@localhost:3000/api/v1/users/test/tokens "
70           + "-H 'Accept: application/json' -H 'Content-Type: application/json' -d "
71           + "'{\"name\":\"token\"}' | jq '.sha1' | xargs echo -n"
72       )
74       server.succeed(
75           "curl --fail -X POST http://localhost:3000/api/v1/user/repos "
76           + "-H 'Accept: application/json' -H 'Content-Type: application/json' "
77           + f"-H 'Authorization: token {api_token}'"
78           + ' -d \'{"auto_init":false, "description":"string", "license":"mit", "name":"repo", "private":false}\'''
79       )
81       server.succeed(
82           "curl --fail -X POST http://localhost:3000/api/v1/user/keys "
83           + "-H 'Accept: application/json' -H 'Content-Type: application/json' "
84           + f"-H 'Authorization: token {api_token}'"
85           + ' -d \'{"key":"${snakeOilPublicKey}","read_only":true,"title":"SSH"}\'''
86       )
88       client1.succeed(
89           f"GIT_SSH_COMMAND='{GIT_SSH_COMMAND}' git -C /tmp/repo push origin master"
90       )
92       client2.succeed("mkdir -p $HOME/.ssh")
93       client2.succeed(f"cat {PRIVK} > $HOME/.ssh/privk")
94       client2.succeed("chmod 0400 $HOME/.ssh/privk")
95       client2.succeed(f"GIT_SSH_COMMAND='{GIT_SSH_COMMAND}' git clone {REPO}")
96       client2.succeed('test "$(cat repo/testfile | xargs echo -n)" = "hello world"')
98       server.succeed(
99           'test "$(curl http://localhost:3000/api/v1/repos/test/repo/commits '
100           + '-H "Accept: application/json" | jq length)" = "1"'
101       )
103       client1.shutdown()
104       client2.shutdown()
105       server.shutdown()
106     '';
107   });
110 listToAttrs (map makeGiteaTest supportedDbTypes)