at 25.11-pre 4.2 kB view raw
1import ../make-test-python.nix ( 2 { pkgs, lib, ... }: 3 let 4 domain = "sourcehut.localdomain"; 5 in 6 { 7 name = "sourcehut"; 8 9 meta.maintainers = with pkgs.lib.maintainers; [ 10 tomberek 11 nessdoor 12 ]; 13 14 nodes.machine = 15 { 16 config, 17 pkgs, 18 nodes, 19 ... 20 }: 21 { 22 imports = [ 23 ./nodes/common.nix 24 ]; 25 26 networking.domain = domain; 27 networking.extraHosts = '' 28 ${config.networking.primaryIPAddress} git.${domain} 29 ${config.networking.primaryIPAddress} meta.${domain} 30 ''; 31 32 services.sourcehut = { 33 git.enable = true; 34 settings."git.sr.ht" = { 35 oauth-client-secret = pkgs.writeText "gitsrht-oauth-client-secret" "3597288dc2c716e567db5384f493b09d"; 36 oauth-client-id = "d07cb713d920702e"; 37 }; 38 }; 39 40 environment.systemPackages = with pkgs; [ 41 git 42 ]; 43 }; 44 45 testScript = 46 let 47 userName = "nixos-test"; 48 userPass = "AutoNixosTestPwd"; 49 hutConfig = pkgs.writeText "hut-config" '' 50 instance "${domain}" { 51 # Will be replaced at runtime with the generated token 52 access-token "OAUTH-TOKEN" 53 } 54 ''; 55 sshConfig = pkgs.writeText "ssh-config" '' 56 Host git.${domain} 57 IdentityFile = ~/.ssh/id_rsa 58 ''; 59 in 60 '' 61 start_all() 62 machine.wait_for_unit("multi-user.target") 63 machine.wait_for_unit("sshd.service") 64 65 with subtest("Check whether meta comes up"): 66 machine.wait_for_unit("metasrht-api.service") 67 machine.wait_for_unit("metasrht.service") 68 machine.wait_for_unit("metasrht-webhooks.service") 69 machine.wait_for_open_port(5000) 70 machine.succeed("curl -sL http://localhost:5000 | grep meta.${domain}") 71 machine.succeed("curl -sL http://meta.${domain} | grep meta.${domain}") 72 73 with subtest("Create a new user account and OAuth access key"): 74 machine.succeed("echo ${userPass} | metasrht-manageuser -ps -e ${userName}@${domain}\ 75 -t active_paying ${userName}"); 76 (_, token) = machine.execute("srht-gen-oauth-tok -i ${domain} -q ${userName} ${userPass}") 77 token = token.strip().replace("/", r"\\/") # Escape slashes in token before passing it to sed 78 machine.execute("mkdir -p ~/.config/hut/") 79 machine.execute("sed s/OAUTH-TOKEN/" + token + "/ ${hutConfig} > ~/.config/hut/config") 80 81 with subtest("Check whether git comes up"): 82 machine.wait_for_unit("gitsrht-api.service") 83 machine.wait_for_unit("gitsrht.service") 84 machine.wait_for_unit("gitsrht-webhooks.service") 85 machine.succeed("curl -sL http://git.${domain} | grep git.${domain}") 86 87 with subtest("Add an SSH key for Git access"): 88 machine.execute("ssh-keygen -q -N \"\" -t rsa -f ~/.ssh/id_rsa") 89 machine.execute("cat ${sshConfig} > ~/.ssh/config") 90 machine.succeed("hut meta ssh-key create ~/.ssh/id_rsa.pub") 91 92 with subtest("Create a new repo and push contents to it"): 93 machine.execute("git init test") 94 machine.execute("echo \"Hello world!\" > test/hello.txt") 95 machine.execute("cd test && git add .") 96 machine.execute("cd test && git commit -m \"Initial commit\"") 97 machine.execute("cd test && git tag v0.1") 98 machine.succeed("cd test && git remote add origin gitsrht@git.${domain}:~${userName}/test") 99 machine.execute("( echo -n 'git.${domain} '; cat /etc/ssh/ssh_host_ed25519_key.pub ) > ~/.ssh/known_hosts") 100 machine.succeed("hut git create test") 101 machine.succeed("cd test && git push --tags --set-upstream origin master") 102 103 with subtest("Verify that the repo is downloadable and its contents match the original"): 104 machine.succeed("curl https://git.${domain}/~${userName}/test/archive/v0.1.tar.gz | tar -xz") 105 machine.succeed("diff test-v0.1/hello.txt test/hello.txt") 106 ''; 107 } 108)