diff options
| author | Nsable-sh <nsable-sh@noreply.git.bitflash.network> | 2026-08-11 15:38:31 -0300 |
|---|---|---|
| committer | Nsable-sh <nsable-sh@noreply.git.bitflash.network> | 2026-08-11 15:38:31 -0300 |
| commit | ff3829b28fd2ddc85a9a3bb4424cd5b4719854ab (patch) | |
| tree | 2351d19d9695b3a7c32498b23d8d23dde3e28309 /src/selftest.cpp | |
| parent | a83fae37099cb102beb5a4c174a4abe6ef3f24a4 (diff) | |
net: add optional SOCKS5 outbound proxy
Diffstat (limited to 'src/selftest.cpp')
| -rw-r--r-- | src/selftest.cpp | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/src/selftest.cpp b/src/selftest.cpp index dcb9192..5b36b9d 100644 --- a/src/selftest.cpp +++ b/src/selftest.cpp | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | 7 | ||
| 8 | #include "headers_core.h" | 8 | #include "headers_core.h" |
| 9 | #include "bip32.h" | 9 | #include "bip32.h" |
| 10 | #include "proxy.h" | ||
| 10 | #include "selftest.h" | 11 | #include "selftest.h" |
| 11 | #include "walletcmd.h" | 12 | #include "walletcmd.h" |
| 12 | 13 | ||
| @@ -1253,6 +1254,43 @@ static int RunParseMoneySelfTest() | |||
| 1253 | return nFail == 0 ? 0 : 1; | 1254 | return nFail == 0 ? 0 : 1; |
| 1254 | } | 1255 | } |
| 1255 | 1256 | ||
| 1257 | static int RunSocks5ProxySelfTest() | ||
| 1258 | { | ||
| 1259 | printf("socks5-proxy self-test\n"); | ||
| 1260 | int nFail = 0; | ||
| 1261 | std::string host, err; | ||
| 1262 | unsigned short port = 0; | ||
| 1263 | |||
| 1264 | nFail += Check(BtfParseSocks5Proxy("127.0.0.1:9050", host, port, err) && | ||
| 1265 | host == "127.0.0.1" && port == 9050, | ||
| 1266 | "parses local Tor proxy endpoint") ? 0 : 1; | ||
| 1267 | nFail += Check(BtfParseSocks5Proxy("localhost:9050", host, port, err) && | ||
| 1268 | host == "localhost" && port == 9050, | ||
| 1269 | "parses hostname proxy endpoint") ? 0 : 1; | ||
| 1270 | nFail += Check(!BtfParseSocks5Proxy("localhost", host, port, err), | ||
| 1271 | "rejects missing port") ? 0 : 1; | ||
| 1272 | nFail += Check(!BtfParseSocks5Proxy("localhost:0", host, port, err), | ||
| 1273 | "rejects zero port") ? 0 : 1; | ||
| 1274 | nFail += Check(!BtfParseSocks5Proxy("localhost:70000", host, port, err), | ||
| 1275 | "rejects out-of-range port") ? 0 : 1; | ||
| 1276 | nFail += Check(!BtfParseSocks5Proxy("user:pass@localhost:9050", host, port, err), | ||
| 1277 | "rejects unsupported authenticated proxy syntax") ? 0 : 1; | ||
| 1278 | |||
| 1279 | BtfClearSocks5Proxy(); | ||
| 1280 | nFail += Check(!BtfSocks5ProxyEnabled(), "starts disabled after clear") ? 0 : 1; | ||
| 1281 | nFail += Check(BtfSetSocks5Proxy("127.0.0.1:9050", err) && | ||
| 1282 | BtfSocks5ProxyEnabled() && | ||
| 1283 | BtfSocks5ProxyName() == "127.0.0.1:9050", | ||
| 1284 | "enables parsed SOCKS5 proxy") ? 0 : 1; | ||
| 1285 | BtfClearSocks5Proxy(); | ||
| 1286 | nFail += Check(!BtfSocks5ProxyEnabled(), "clear disables proxy") ? 0 : 1; | ||
| 1287 | |||
| 1288 | printf("%s (%d failure%s)\n", nFail == 0 ? "ALL TESTS PASSED" : "TESTS FAILED", | ||
| 1289 | nFail, nFail == 1 ? "" : "s"); | ||
| 1290 | fflush(stdout); | ||
| 1291 | return nFail == 0 ? 0 : 1; | ||
| 1292 | } | ||
| 1293 | |||
| 1256 | int RunSelfTest(const std::string& name) | 1294 | int RunSelfTest(const std::string& name) |
| 1257 | { | 1295 | { |
| 1258 | AttachTerminal(); | 1296 | AttachTerminal(); |
| @@ -1275,8 +1313,10 @@ int RunSelfTest(const std::string& name) | |||
| 1275 | return RunPoolStratumSelfTest(); | 1313 | return RunPoolStratumSelfTest(); |
| 1276 | if (name == "parse-money") | 1314 | if (name == "parse-money") |
| 1277 | return RunParseMoneySelfTest(); | 1315 | return RunParseMoneySelfTest(); |
| 1316 | if (name == "socks5-proxy") | ||
| 1317 | return RunSocks5ProxySelfTest(); | ||
| 1278 | 1318 | ||
| 1279 | printf("Unknown self-test '%s'\n", name.c_str()); | 1319 | printf("Unknown self-test '%s'\n", name.c_str()); |
| 1280 | printf("Known self-tests: wallet-keypool, wallet-hd, wallet-format, wallet-crypto, wallet-encrypt, net-message, consensus-limits, pool-stratum\n"); | 1320 | printf("Known self-tests: wallet-keypool, wallet-hd, wallet-format, wallet-crypto, wallet-encrypt, net-message, consensus-limits, pool-stratum, parse-money, socks5-proxy\n"); |
| 1281 | return 1; | 1321 | return 1; |
| 1282 | } | 1322 | } |