1 { system ? builtins.currentSystem,
3 pkgs ? import ../.. { inherit system config; }
6 with import ../lib/testing-python.nix { inherit system pkgs; };
10 supportedDbTypes = [ "mysql" "postgres" "sqlite3" ];
11 makeGiteaTest = type: nameValuePair type (makeTest {
12 name = "gitea-${type}";
13 meta.maintainers = with maintainers; [ aanderse kolaente ma27 ];
16 server = { config, pkgs, ... }: {
17 virtualisation.memorySize = 2048;
20 database = { inherit type; };
21 settings.service.DISABLE_REGISTRATION = true;
23 environment.systemPackages = [ pkgs.gitea pkgs.jq ];
24 services.openssh.enable = true;
26 client1 = { config, pkgs, ... }: {
27 environment.systemPackages = [ pkgs.git ];
29 client2 = { config, pkgs, ... }: {
30 environment.systemPackages = [ pkgs.git ];
35 inherit (import ./ssh-keys.nix pkgs) snakeOilPrivateKey snakeOilPublicKey;
37 GIT_SSH_COMMAND = "ssh -i $HOME/.ssh/privk -o StrictHostKeyChecking=no"
38 REPO = "gitea@server:test/repo"
39 PRIVK = "${snakeOilPrivateKey}"
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/")
60 "curl --fail http://localhost:3000/user/sign_up | grep 'Registration is disabled. "
61 + "Please contact your site administrator.'"
64 "su -l gitea -c 'GITEA_WORK_DIR=/var/lib/gitea gitea admin user create "
65 + "--username test --password totallysafe --email test@localhost'"
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"
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}\'''
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"}\'''
89 f"GIT_SSH_COMMAND='{GIT_SSH_COMMAND}' git -C /tmp/repo push origin master"
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"')
99 'test "$(curl http://localhost:3000/api/v1/repos/test/repo/commits '
100 + '-H "Accept: application/json" | jq length)" = "1"'
110 listToAttrs (map makeGiteaTest supportedDbTypes)