Skip to content

Commit

Permalink
nixosTests.privatebin: init
Browse files Browse the repository at this point in the history
  • Loading branch information
e1mo committed Sep 6, 2023
1 parent 39510fd commit 49b7af8
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 0 deletions.
1 change: 1 addition & 0 deletions nixos/tests/all-tests.nix
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,7 @@ in {
printing-socket = handleTest ./printing.nix { socket = true; };
printing-service = handleTest ./printing.nix { socket = false; };
privacyidea = handleTest ./privacyidea.nix {};
privatebin = handleTest ./privatebin.nix {};
privoxy = handleTest ./privoxy.nix {};
prometheus = handleTest ./prometheus.nix {};
prometheus-exporters = handleTest ./prometheus-exporters.nix {};
Expand Down
100 changes: 100 additions & 0 deletions nixos/tests/privatebin.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import ./make-test-python.nix ({ pkgs, lib, ... }:

let
titleEnvFile = pkgs.writeText "pbin.env" ''
PRIVATEBIN_NAME=NixOS Bin
'';
mkNode = extraConfig: { ... }: {
environment.systemPackages = [
pkgs.pbincli
];
services.privatebin = lib.recursiveUpdate
{
enable = true;
environmentFiles = [ titleEnvFile ];
settings = {
main.name._env = "PRIVATEBIN_NAME";
traffic.limit = 300;
};
}
extraConfig;
networking.firewall.allowedTCPPorts = [ 80 ];
};
in
{
name = "privatebin";
meta.maintainers = with lib.maintainers; [ e1mo ];

nodes = {
pgsql = mkNode {
databaseSetup = {
enable = true;
kind = "pgsql";
};
};
mysql = mkNode {
databaseSetup = {
enable = true;
kind = "mysql";
};
};
sqlite = mkNode {
databaseSetup = {
enable = true;
kind = "sqlite";
};
};
filesystem = mkNode {
settings = {
model.class = "Filesystem";
model_options.dir = "/var/lib/privatebin/data";
};
};
};

testScript = ''
start_all()
def get_id_links(output):
lines=paste_output.split("\n")
id=lines[3].split("\t")[1].strip()
link=lines[7].split("\t\t")[1].strip()
delete_link=lines[8].split("\t")[1].strip()
return (id,link,delete_link)
for machine in [pgsql,mysql,sqlite,filesystem]:
machine.wait_for_unit("phpfpm-privatebin.service")
machine.succeed("timedatectl set-time '2023-05-26 10:00'")
with subtest("Basic operations"):
machine.wait_until_succeeds("curl --fail --insecure -L http://localhost/", timeout=10)
assert "NixOS Bin" in machine.succeed("curl --fail --insecure -L http://localhost/")
paste_output=machine.succeed('pbincli send -s "http://localhost" -t "Hello, NixOS!"')
(id,link,delete_link) = get_id_links(paste_output)
machine.succeed(f'pbincli get -s "http://localhost" "{link}"')
machine.succeed(f'grep "Hello, NixOS!" paste-{id}.txt')
machine.succeed(f'pbincli delete -s "http://localhost" "{delete_link}"')
machine.fail(f'pbincli get -s "http://localhost" "{link}"')
machine.succeed("timedatectl set-time '2023-05-26 11:00:00'")
with subtest("Expiry"):
paste_output=machine.succeed('pbincli send -s "http://localhost" -t "This will expire soon" -E 5min')
(id,link,delete_link) = get_id_links(paste_output)
machine.succeed(f'pbincli get -s "http://localhost" "{link}"')
machine.succeed("timedatectl set-time '2023-05-26 11:05:30'")
machine.fail(f'pbincli get -s "http://localhost" "{link}"')
machine.succeed("timedatectl set-time '2023-05-26 12:00'")
with subtest("Burn after reading"):
paste_output=machine.succeed('pbincli send -s "http://localhost" -t "This will be burned" -B')
(id,link,delete_link) = get_id_links(paste_output)
machine.succeed(f'pbincli get -s "http://localhost" "{link}"')
machine.fail(f'pbincli get -s "http://localhost" "{link}"')
machine.succeed("timedatectl set-time '2023-05-26 13:00'")
with subtest("Ratelimit"):
machine.succeed('pbincli send -s "http://localhost" -t "This will be accepted"')
machine.fail('pbincli send -s "http://localhost" -t "This will get ratelimited"')
machine.shutdown()
'';
})
5 changes: 5 additions & 0 deletions pkgs/servers/web-apps/privatebin/default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{ lib
, stdenv
, fetchFromGitHub
, nixosTests
}:

stdenv.mkDerivation rec {
Expand All @@ -23,6 +24,10 @@ stdenv.mkDerivation rec {
runHook postInstall
'';

passthru.tests = {
inherit (nixosTests) privatebin;
};

meta = with lib; {
description = "Minimalist, open source online pastebin where the server has zero knowledge of pasted data";
changelog = "https://github.com/PrivateBin/PrivateBin/blob/${version}/CHANGELOG.md";
Expand Down

0 comments on commit 49b7af8

Please sign in to comment.