1 import ./make-test-python.nix ({ lib, pkgs, ... }:
4 # Note: For some reason Privoxy can't issue valid
5 # certificates if the CA is generated using gnutls :(
6 certs = pkgs.runCommand "example-certs"
7 { buildInputs = [ pkgs.openssl ]; }
12 openssl req -new -nodes -x509 \
13 -extensions v3_ca -keyout $out/ca.key \
14 -out $out/ca.crt -days 365 \
15 -subj "/O=Privoxy CA/CN=Privoxy CA"
17 # generate server key/signing request
18 openssl genrsa -out $out/server.key 3072
19 openssl req -new -key $out/server.key \
20 -out server.csr -sha256 \
21 -subj "/O=An unhappy server./CN=example.com"
23 # sign the request/generate the certificate
24 openssl x509 -req -in server.csr -CA $out/ca.crt \
25 -CAkey $out/ca.key -CAcreateserial -out $out/server.crt \
32 meta = with lib.maintainers; {
33 maintainers = [ rnhmjoj ];
36 nodes.machine = { ... }: {
37 services.nginx.enable = true;
38 services.nginx.virtualHosts."example.com" = {
40 sslCertificate = "${certs}/server.crt";
41 sslCertificateKey = "${certs}/server.key";
42 locations."/".root = pkgs.writeTextFile
44 destination = "/how-are-you/index.html";
45 text = "I've had a bad day!\n";
47 locations."/ads".extraConfig = ''
48 return 200 "Hot Nixpkgs PRs in your area. Click here!\n";
56 ca-cert-file = "${certs}/ca.crt";
57 ca-key-file = "${certs}/ca.key";
68 FILTER: positive This is a filter example.
73 security.pki.certificateFiles = [ "${certs}/ca.crt" ];
75 networking.hosts."::1" = [ "example.com" ];
76 networking.proxy.httpProxy = "http://localhost:8118";
77 networking.proxy.httpsProxy = "http://localhost:8118";
80 nodes.machine_socks4 = { ... }: { services.privoxy = { enable = true; settings.forward-socks4 = "/ 127.0.0.1:9050 ."; }; };
81 nodes.machine_socks4a = { ... }: { services.privoxy = { enable = true; settings.forward-socks4a = "/ 127.0.0.1:9050 ."; }; };
82 nodes.machine_socks5 = { ... }: { services.privoxy = { enable = true; settings.forward-socks5 = "/ 127.0.0.1:9050 ."; }; };
83 nodes.machine_socks5t = { ... }: { services.privoxy = { enable = true; settings.forward-socks5t = "/ 127.0.0.1:9050 ."; }; };
87 with subtest("Privoxy is running"):
88 machine.wait_for_unit("privoxy")
89 machine.wait_for_open_port(8118)
90 machine.succeed("curl -f http://config.privoxy.org")
92 with subtest("Privoxy can filter http requests"):
93 machine.wait_for_open_port(80)
94 assert "great day" in machine.succeed(
95 "curl -sfL http://example.com/how-are-you? | tee /dev/stderr"
98 with subtest("Privoxy can filter https requests"):
99 machine.wait_for_open_port(443)
100 assert "great day" in machine.succeed(
101 "curl -sfL https://example.com/how-are-you? | tee /dev/stderr"
104 with subtest("Blocks are working"):
105 machine.wait_for_open_port(443)
106 machine.fail("curl -f https://example.com/ads 1>&2")
107 machine.succeed("curl -f https://example.com/PRIVOXY-FORCE/ads 1>&2")
109 with subtest("Temporary certificates are cleaned"):
110 # Count current certificates
111 machine.succeed("test $(ls /run/privoxy/certs | wc -l) -gt 0")
112 # Forward in time 12 days, trigger the timer..
113 machine.succeed("date -s \"$(date --date '12 days')\"")
114 machine.systemctl("start systemd-tmpfiles-clean")
116 machine.succeed("test $(ls /run/privoxy/certs | wc -l) -eq 0")
118 with subtest("Privoxy supports socks upstream proxies"):
119 for m in [machine_socks4, machine_socks4a, machine_socks5, machine_socks5t]:
120 m.wait_for_unit("privoxy")
121 m.wait_for_open_port(8118)
122 # We expect a 503 error because the dummy upstream proxy is not reachable.
123 # In issue #265654, instead privoxy segfaulted causing curl to exit with "Empty reply from server".
124 m.succeed("http_proxy=http://localhost:8118 curl -v http://does-not-exist/ 2>&1 | grep 'HTTP/1.1 503'")