fix: various fixes and additions
This commit is contained in:
30 files changed
+462
-127
No files matched your search
+148
-2
@@ -68,11 +68,71 @@ let
|
||||
in
|
||||
{
|
||||
assertions = [
|
||||
# Detours are resolved at start, once subscription entries exist; without any, nothing is added.
|
||||
# Detours are resolved at start, once subscription and runtime entries exist.
|
||||
(
|
||||
assert pkgs.lib.hasInfix ''{"outbounds":{"exit":"primary"},"subscriptions":{"sub":"primary"}}'' (startScript chained);
|
||||
assert pkgs.lib.hasInfix "proxy-suite-outbound-detours" (startScript chained);
|
||||
assert !(pkgs.lib.hasInfix "outbound chaining" (startScript (evalProxySuite [ baseModule ])));
|
||||
assert pkgs.lib.hasInfix ''/var/lib/proxy-suite/outbounds.d/$RUNTIME_OB_TAG.detour'' (startScript chained);
|
||||
true
|
||||
)
|
||||
|
||||
# Selection leaves proxy.selectionExclude alone; the inventory says so.
|
||||
(
|
||||
let
|
||||
script = startScript (evalProxySuite [
|
||||
baseModule
|
||||
{ services.proxy-suite.proxy.selectionExclude = [ "primary" ]; }
|
||||
]);
|
||||
in
|
||||
assert pkgs.lib.hasInfix ''--argjson ex '["primary"]' '' script;
|
||||
assert pkgs.lib.hasInfix ''excluded: ($tags - $selectable)'' script;
|
||||
true
|
||||
)
|
||||
|
||||
# An inbound pinned to a chained outbound gets the whole chain.
|
||||
(
|
||||
let
|
||||
script = generated.readDerivation
|
||||
(evalProxySuite [
|
||||
{
|
||||
system.stateVersion = "26.05";
|
||||
services.proxy-suite = {
|
||||
enable = true;
|
||||
proxy = {
|
||||
enable = true;
|
||||
outbounds = [
|
||||
{
|
||||
tag = "hop";
|
||||
url = "http://hop.example.com:8080";
|
||||
}
|
||||
{
|
||||
tag = "exit";
|
||||
url = "http://exit.example.com:8080";
|
||||
detour = "hop";
|
||||
}
|
||||
];
|
||||
};
|
||||
inbounds = {
|
||||
enable = true;
|
||||
serverAddress = "203.0.113.1";
|
||||
listeners.main = {
|
||||
type = "socks";
|
||||
port = 1081;
|
||||
via = "exit";
|
||||
users = [
|
||||
{
|
||||
name = "a";
|
||||
password = "b";
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
]).config.systemd.services."proxy-suite-inbounds".serviceConfig.ExecStart;
|
||||
in
|
||||
assert pkgs.lib.hasInfix "# via outbound: hop" script;
|
||||
assert pkgs.lib.hasInfix "--arg hop hop '.streamSettings.sockopt.dialerProxy = $hop'" script;
|
||||
true
|
||||
)
|
||||
|
||||
@@ -89,9 +149,66 @@ in
|
||||
assert tunDns.strategy == "ipv4_only";
|
||||
true
|
||||
)
|
||||
# Fake addresses survive a restart, one cache per TUN config.
|
||||
(
|
||||
assert (mkTunConfig dnsFixture).experimental.cache_file.path == "/var/lib/proxy-suite/fakeip/tun.db";
|
||||
assert (mkTunConfig dnsFixture).experimental.cache_file.store_fakeip;
|
||||
true
|
||||
)
|
||||
# DNS follows the routing: proxied names through remote, direct ones local, in its order.
|
||||
(
|
||||
let
|
||||
routed = evalProxySuite [
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite.proxy.routing = {
|
||||
proxy = {
|
||||
domains = [ "blocked.example" ];
|
||||
geosites = [ "google" ];
|
||||
};
|
||||
rules = [
|
||||
{
|
||||
outbound = "direct";
|
||||
domains = [ "bank.example" ];
|
||||
}
|
||||
{
|
||||
outbound = "block";
|
||||
domains = [ "ads.example" ];
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
||||
];
|
||||
rules = map (r: {
|
||||
inherit (r) server;
|
||||
match = r.domain_suffix or r.rule_set;
|
||||
}) (mkTProxyConfig routed).dns.rules;
|
||||
in
|
||||
assert
|
||||
rules == [
|
||||
{
|
||||
server = "local";
|
||||
match = [ "bank.example" ];
|
||||
}
|
||||
{
|
||||
server = "remote";
|
||||
match = [ "blocked.example" ];
|
||||
}
|
||||
{
|
||||
server = "local";
|
||||
match = [ "geosite-category-ru" ];
|
||||
}
|
||||
{
|
||||
server = "remote";
|
||||
match = [ "geosite-google" ];
|
||||
}
|
||||
];
|
||||
true
|
||||
)
|
||||
# TProxy has no TUN to hand fake addresses to.
|
||||
(
|
||||
assert !(builtins.any (s: s.tag == "fakeip") tproxyDns.servers);
|
||||
assert !((mkTProxyConfig dnsFixture).experimental ? cache_file);
|
||||
assert builtins.head tproxyDns.rules == { domain_suffix = [ "corp.example" ]; server = "corp"; };
|
||||
true
|
||||
)
|
||||
@@ -125,6 +242,35 @@ in
|
||||
];
|
||||
};
|
||||
}
|
||||
# An inbound cannot chain through what the inbound service does not run.
|
||||
{
|
||||
enable = true;
|
||||
proxy = {
|
||||
enable = true;
|
||||
outbounds = [
|
||||
{
|
||||
tag = "exit";
|
||||
url = "http://exit.example.com:8080";
|
||||
detour = "warp";
|
||||
}
|
||||
];
|
||||
};
|
||||
inbounds = {
|
||||
enable = true;
|
||||
serverAddress = "203.0.113.1";
|
||||
listeners.main = {
|
||||
type = "socks";
|
||||
port = 1081;
|
||||
via = "exit";
|
||||
users = [
|
||||
{
|
||||
name = "a";
|
||||
password = "b";
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
||||
# The sing-box DNS options need sing-box.
|
||||
{
|
||||
enable = true;
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
hasRuleSet,
|
||||
dnsHasRuleSet,
|
||||
dnsServerByTag,
|
||||
mkBadFixtureRaw,
|
||||
mkFailingAssertions,
|
||||
}:
|
||||
|
||||
let
|
||||
@@ -21,8 +19,6 @@ let
|
||||
minimal
|
||||
mkRoutingRules
|
||||
mkTProxyConfig
|
||||
mkBadFixtureRaw
|
||||
mkFailingAssertions
|
||||
;
|
||||
};
|
||||
inherit (fixtures)
|
||||
@@ -38,7 +34,6 @@ let
|
||||
proxyDirectConfig
|
||||
urlTestCustomStartScript
|
||||
noProxyBackendDefaultFixture
|
||||
invalidCoreProxyAssertions
|
||||
blockGeoRules
|
||||
routingOrDomainRules
|
||||
routingOrGeoIPRules
|
||||
@@ -71,7 +66,6 @@ let
|
||||
ruDefaultConfig
|
||||
urlTestCustomStartScript
|
||||
noProxyBackendDefaultFixture
|
||||
invalidCoreProxyAssertions
|
||||
;
|
||||
};
|
||||
in
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
minimal,
|
||||
mkRoutingRules,
|
||||
mkTProxyConfig,
|
||||
mkBadFixtureRaw,
|
||||
mkFailingAssertions,
|
||||
}:
|
||||
|
||||
let
|
||||
@@ -138,21 +136,6 @@ let
|
||||
}
|
||||
];
|
||||
|
||||
invalidCoreProxyAssertions = mkFailingAssertions mkBadFixtureRaw [
|
||||
[
|
||||
{
|
||||
system.stateVersion = "26.05";
|
||||
services.proxy-suite = {
|
||||
enable = true;
|
||||
proxy = {
|
||||
enable = true;
|
||||
backend = "sing-box";
|
||||
};
|
||||
};
|
||||
}
|
||||
]
|
||||
];
|
||||
|
||||
blockGeoRules = mkRoutingRules (evalProxySuite [
|
||||
baseModule
|
||||
{
|
||||
@@ -188,7 +171,6 @@ in
|
||||
urlTestCustomFixture
|
||||
urlTestCustomStartScript
|
||||
noProxyBackendDefaultFixture
|
||||
invalidCoreProxyAssertions
|
||||
blockGeoRules
|
||||
routingOrDomainRules
|
||||
routingOrGeoIPRules
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
ruDefaultConfig,
|
||||
urlTestCustomStartScript,
|
||||
noProxyBackendDefaultFixture,
|
||||
invalidCoreProxyAssertions,
|
||||
}:
|
||||
|
||||
{
|
||||
@@ -53,6 +52,5 @@
|
||||
assert !(noProxyBackendDefaultFixture.config.systemd.services ? "proxy-suite-socks");
|
||||
true
|
||||
)
|
||||
]
|
||||
++ invalidCoreProxyAssertions;
|
||||
];
|
||||
}
|
||||
+21
-10
@@ -176,21 +176,33 @@ let
|
||||
};
|
||||
};
|
||||
};
|
||||
mkFixture =
|
||||
# A bad fixture must fail on its own merits. Without a root file system and with a boot
|
||||
# loader, NixOS's own assertions fail every system, so any case passed as bad.
|
||||
mkBootableToplevel =
|
||||
modules:
|
||||
forceEval
|
||||
(evalProxySuite (
|
||||
[
|
||||
{
|
||||
fileSystems."/" = {
|
||||
device = "none";
|
||||
fsType = "tmpfs";
|
||||
};
|
||||
boot.loader.grub.enable = false;
|
||||
}
|
||||
]
|
||||
++ modules
|
||||
)).config.system.build.toplevel.drvPath;
|
||||
mkBadFixture = modules: mkBootableToplevel ([ baseModule ] ++ modules);
|
||||
mkBadFixtureRaw = mkBootableToplevel;
|
||||
mkBadProxySuiteFixture =
|
||||
proxySuiteConfig:
|
||||
evalProxySuite [
|
||||
mkBootableToplevel [
|
||||
{
|
||||
system.stateVersion = "26.05";
|
||||
services.proxy-suite = proxySuiteConfig;
|
||||
}
|
||||
];
|
||||
mkBadFixture =
|
||||
modules:
|
||||
forceEval ((evalProxySuite ([ baseModule ] ++ modules)).config.system.build.toplevel.drvPath);
|
||||
mkBadFixtureRaw =
|
||||
modules: forceEval ((evalProxySuite modules).config.system.build.toplevel.drvPath);
|
||||
mkBadProxySuiteFixture =
|
||||
proxySuiteConfig: forceEval ((mkFixture proxySuiteConfig).config.system.build.toplevel.drvPath);
|
||||
mkFailingAssertions =
|
||||
evaluate: cases:
|
||||
map (
|
||||
@@ -247,7 +259,6 @@ in
|
||||
lineContaining
|
||||
shellValueByPrefix
|
||||
baseModule
|
||||
mkFixture
|
||||
mkBadFixture
|
||||
mkBadFixtureRaw
|
||||
mkBadProxySuiteFixture
|
||||
|
||||
@@ -56,8 +56,6 @@ let
|
||||
hasRuleSet
|
||||
dnsHasRuleSet
|
||||
dnsServerByTag
|
||||
mkBadFixtureRaw
|
||||
mkFailingAssertions
|
||||
;
|
||||
};
|
||||
inherit (coreProxyChecks) ruDefaultConfig;
|
||||
|
||||
+14
-2
@@ -122,7 +122,8 @@
|
||||
printf '%s\n' '["community"]' > tags.json
|
||||
jq -n '{tags:["own-vps","community-de"],
|
||||
sources:{"own-vps":"static","community-de":"sub:community"},
|
||||
pinned:"community-de", selection:"urltest"}' > inventory.json
|
||||
pinned:"community-de", selection:"urltest",
|
||||
detours:{"community-de":"own-vps"}, excluded:["own-vps"]}' > inventory.json
|
||||
|
||||
run() {
|
||||
env \
|
||||
@@ -153,6 +154,9 @@
|
||||
grep -q 'Pinned: community-de' listing
|
||||
grep -q '\*community-de' listing
|
||||
grep -q 'own-vps *static' listing
|
||||
# What each one chains through, and what selection leaves alone.
|
||||
grep -q 'community-de *sub:community, via own-vps$' listing
|
||||
grep -q 'own-vps *static, never picked$' listing
|
||||
# The old spelling still dispatches.
|
||||
run outbounds | cmp - listing
|
||||
|
||||
@@ -184,6 +188,14 @@
|
||||
run proxy outbounds rm spool-one | grep -q 'Removed outbound: spool-one'
|
||||
[ ! -e obd/spool-one.url ]
|
||||
|
||||
# --detour leaves the hop next to the entry, and only names an outbound that exists.
|
||||
! run proxy outbounds add bad-hop http://example.com:1 --detour nope 2>/dev/null
|
||||
[ ! -e obd/bad-hop.url ]
|
||||
run proxy outbounds add chained http://example.com:1 --detour own-vps | grep -q 'Added outbound: chained'
|
||||
[ "$(cat obd/chained.detour)" = own-vps ]
|
||||
run proxy outbounds rm chained > /dev/null
|
||||
[ ! -e obd/chained.detour ]
|
||||
|
||||
# JSON, as `link --json` prints it, lands as <tag>.json without its own tag; stdin too.
|
||||
run proxy outbounds add from-json '{"type":"trojan","tag":"x","server":"t.test","server_port":443,"password":"p"}' \
|
||||
| grep -q 'Added outbound: from-json'
|
||||
@@ -631,7 +643,7 @@
|
||||
and .outbounds[0].detour == null and .outbounds[2].detour == "x1"' <<<"$r" > /dev/null
|
||||
r="$(d '{"outbounds":{"x1":"sb"},"subscriptions":{}}' '{"x1":"static","sb":"static"}' hybrid \
|
||||
'{"outbounds":[{"tag":"x1"},{"tag":"sb"}],"xray":[{"tag":"x1"}]}')"
|
||||
jq -e '.errors == ["outbound '"'x1'"' runs on XRay and can only chain through another XRay outbound, not '"'sb'"'"]' <<<"$r" > /dev/null
|
||||
jq -e '[.errors[].message] == ["outbound '"'x1'"' runs on XRay and can only chain through another XRay outbound, not '"'sb'"'"]' <<<"$r" > /dev/null
|
||||
# A missing hop and a loop are errors, and nothing is rewritten.
|
||||
r="$(d '{"outbounds":{"a":"b","b":"a","c":"gone"},"subscriptions":{}}' '{"a":"static","b":"static","c":"static"}' sing-box \
|
||||
'{"outbounds":[{"tag":"a"},{"tag":"b"},{"tag":"c"}],"xray":[]}')"
|
||||
|
||||
@@ -95,7 +95,8 @@ in
|
||||
assert pkgs.lib.hasInfix "all-bypass)" routeModeStartScript;
|
||||
assert pkgs.lib.hasInfix ".route.rules = (sing_box_preserved_rules + $route_rules)"
|
||||
routeModeBackendJqFilter;
|
||||
assert pkgs.lib.hasInfix ".dns.rules = []" routeModeBackendJqFilter;
|
||||
# all-proxy and all-bypass keep proxy.dns.singBox.rules and fake IP.
|
||||
assert pkgs.lib.hasInfix ".dns.rules = .dns.rules[:0]" routeModeBackendJqFilter;
|
||||
true
|
||||
)
|
||||
|
||||
@@ -153,7 +154,7 @@ in
|
||||
shellValueByPrefix minimalProxyCtlWrapper "export RUNTIME_SUBS_DIR="
|
||||
== "/var/lib/proxy-suite/subscriptions.d";
|
||||
assert pkgs.lib.hasInfix "proxy pin [tag]" minimalProxyCtlScript;
|
||||
assert pkgs.lib.hasInfix "proxy outbounds add <tag> <url>" minimalProxyCtlScript;
|
||||
assert pkgs.lib.hasInfix "proxy outbounds add <tag> <url|json|->" minimalProxyCtlScript;
|
||||
true
|
||||
)
|
||||
];
|
||||
|
||||
@@ -78,7 +78,7 @@ in
|
||||
(
|
||||
assert pkgs.lib.hasInfix ''PROXY_TAG="$PINNED_OUTBOUND"'' subscriptionFirstSelectionStartScript;
|
||||
assert
|
||||
pkgs.lib.hasInfix ''map(if .tag == $t then .tag = "proxy" else . end)''
|
||||
pkgs.lib.hasInfix ''map(if .tag == $t then .tag = "proxy" else . end''
|
||||
subscriptionFirstSelectionStartScript;
|
||||
true
|
||||
)
|
||||
@@ -147,8 +147,8 @@ in
|
||||
|
||||
# The fetcher's output must land in the cache, not after a stray newline.
|
||||
(
|
||||
assert pkgs.lib.hasInfix ''--tag-prefix "$tag" > "$cache.tmp"'' subscriptionOnlyStartScript;
|
||||
assert pkgs.lib.hasInfix ''--tag-prefix "$tag" > "$cache.tmp"'' subscriptionOnlyUpdateScript;
|
||||
assert pkgs.lib.hasInfix ''--tag-prefix "$tag" --links-out "$links.tmp" > "$cache.tmp"'' subscriptionOnlyStartScript;
|
||||
assert pkgs.lib.hasInfix ''--tag-prefix "$tag" --links-out "$links.tmp" > "$cache.tmp"'' subscriptionOnlyUpdateScript;
|
||||
true
|
||||
)
|
||||
|
||||
|
||||
@@ -131,6 +131,8 @@ let
|
||||
services.proxy-suite.tgWsProxy = {
|
||||
enable = true;
|
||||
secretFile = "/run/secrets/tg-ws-proxy";
|
||||
# Only read when there is a log file to rotate.
|
||||
log.file = "/var/log/proxy-suite-tg-ws-proxy/tg-ws-proxy.log";
|
||||
log.keep = 0;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -16,6 +16,9 @@ let
|
||||
singBoxCfg = null;
|
||||
proxyCfg = null;
|
||||
sshProxyCfg = null;
|
||||
warpCfg = null;
|
||||
awgOutbounds = null;
|
||||
constants = null;
|
||||
hybridEnabled = null;
|
||||
collapseNamedOutbounds = null;
|
||||
selectionMode = null;
|
||||
@@ -136,18 +139,6 @@ let
|
||||
];
|
||||
};
|
||||
}
|
||||
{
|
||||
enable = true;
|
||||
proxy = {
|
||||
enable = true;
|
||||
outbounds = [
|
||||
{
|
||||
tag = "primary";
|
||||
url = "http://proxy.example.com:8080";
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
||||
{
|
||||
enable = true;
|
||||
proxy = {
|
||||
|
||||
Reference in new issue
Block a user