v0.41.0
This commit is contained in:
1 parent
aa27866531
commit
54b2ac0838
3 files changed
-155
No files matched your search
@@ -1,60 +0,0 @@
|
|||||||
#!/usr/bin/env node
|
|
||||||
"use strict";
|
|
||||||
// Checks that the panel's consistent-hash simulator (src/admin/web/vhosts/balancing.js)
|
|
||||||
// ranks backends exactly like the proxy (src/balance/model.rs). The reference
|
|
||||||
// vectors come from the Rust test `rendezvous_reference_vectors`.
|
|
||||||
const fs = require("node:fs");
|
|
||||||
const path = require("node:path");
|
|
||||||
const vm = require("node:vm");
|
|
||||||
const crypto = require("node:crypto");
|
|
||||||
const assert = require("node:assert/strict");
|
|
||||||
|
|
||||||
const root = path.resolve(__dirname, "../..");
|
|
||||||
const source = fs.readFileSync(path.join(root, "src/admin/web/vhosts/balancing.js"), "utf8");
|
|
||||||
const sandbox = { window: {}, TextEncoder, BigInt, Math, Number, Uint8Array, Uint32Array, DataView };
|
|
||||||
vm.runInNewContext(source, sandbox, { filename: "balancing.js" });
|
|
||||||
const core = sandbox.window.rustProxyBalancingCore;
|
|
||||||
assert.equal(typeof core?.score, "function");
|
|
||||||
|
|
||||||
for (const input of ["", "abc", "a".repeat(55), "a".repeat(56), "a".repeat(64), "zażółć|/music/ü.mp3|s1", "x".repeat(1000)]) {
|
|
||||||
const expected = crypto.createHash("sha256").update(input, "utf8").digest("hex");
|
|
||||||
const actual = Buffer.from(core.sha256(new TextEncoder().encode(input))).toString("hex");
|
|
||||||
assert.equal(actual, expected, `sha256 mismatch for length ${input.length}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const members = [{ id: "s1", weight: 1 }, { id: "s2", weight: 1 }, { id: "s3", weight: 2 }];
|
|
||||||
const rendered = ["/a.mp3", "/music/b.mp3", "/c", "tenant-42", "192.0.2.10"]
|
|
||||||
.map(key => `${key}=${core.rank("files", key, members).map(m => m.id).join(",")}`).join(";");
|
|
||||||
const expected = fs.readFileSync(path.join(root, "tests/fixtures/balance_rendezvous_vectors.txt"), "utf8").trim();
|
|
||||||
assert.equal(rendered, expected, "simulator ranking differs from the proxy");
|
|
||||||
|
|
||||||
const key = (settings, line) => core.hashKey(settings, line);
|
|
||||||
assert.equal(key({ source: "path" }, "/music/Album/track.MP3?user=42&x"), "/music/Album/track.MP3");
|
|
||||||
assert.equal(key({ source: "path", ignore_case: true }, "/music/Album/track.MP3"), "/music/album/track.mp3");
|
|
||||||
assert.equal(key({ source: "path", path_depth: 1 }, "/music/Album/track.MP3"), "/music");
|
|
||||||
assert.equal(key({ source: "path", path_depth: 2 }, "https://cdn.example.com/music/Album/track.MP3"), "/music/Album");
|
|
||||||
assert.equal(key({ source: "uri" }, "/music/a.mp3?user=42&x"), "/music/a.mp3?user=42&x");
|
|
||||||
assert.equal(key({ source: "host" }, "https://Files.Example.com:8443/x"), "files.example.com");
|
|
||||||
assert.equal(key({ source: "host" }, "https://[2001:db8::1]:443/x"), "2001:db8::1");
|
|
||||||
assert.equal(key({ source: "query", name: "user" }, "/x?user=42&x"), "42");
|
|
||||||
assert.equal(key({ source: "query", name: "x" }, "/x?user=42&x"), null);
|
|
||||||
assert.equal(key({ source: "query", name: "user" }, "/x"), null);
|
|
||||||
assert.equal(key({ source: "cookie", name: "sid" }, "ABC"), "ABC");
|
|
||||||
assert.equal(key({ source: "ip" }, " 203.0.113.9 "), "203.0.113.9");
|
|
||||||
|
|
||||||
// Removing a backend moves only its own keys.
|
|
||||||
const pool = [
|
|
||||||
{ id: "a", weight: 1, enabled: true, drain: false, backup: false, pool_eligible: false },
|
|
||||||
{ id: "b", weight: 1, enabled: true, drain: false, backup: false, pool_eligible: false },
|
|
||||||
{ id: "c", weight: 1, enabled: true, drain: false, backup: false, pool_eligible: false },
|
|
||||||
];
|
|
||||||
const samples = Array.from({ length: 300 }, (_, n) => `/f/${n}`);
|
|
||||||
assert.equal(core.simulate({ poolId: "v", settings: { source: "path" }, members: pool, samples }).filter(r => r.member).length, 0,
|
|
||||||
"location-only members are not used by the vhost pool");
|
|
||||||
const rows = core.simulate({ poolId: "v", settings: { source: "path" }, members: pool, explicit: true, samples, down: new Set(["b"]) });
|
|
||||||
for (const row of rows) {
|
|
||||||
if (row.previous === "b") assert.notEqual(row.member, "b");
|
|
||||||
else assert.equal(row.member, row.previous);
|
|
||||||
}
|
|
||||||
assert.ok(rows.some(row => row.previous === "b"));
|
|
||||||
console.log("balance simulator: ok");
|
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
#!/usr/bin/env node
|
|
||||||
"use strict";
|
|
||||||
// Small dependency-free smoke test for the cache-rule editor's VCL output.
|
|
||||||
const fs = require("node:fs");
|
|
||||||
const path = require("node:path");
|
|
||||||
const vm = require("node:vm");
|
|
||||||
const assert = require("node:assert/strict");
|
|
||||||
|
|
||||||
const root = path.resolve(__dirname, "../..");
|
|
||||||
const source = fs.readFileSync(path.join(root, "src/admin/web/cache-rules.js"), "utf8");
|
|
||||||
const sandbox = { window: {} };
|
|
||||||
vm.runInNewContext(source, sandbox, { filename: "cache-rules.js" });
|
|
||||||
const editor = sandbox.window.rustProxyCacheRules;
|
|
||||||
assert.equal(typeof editor?.exportVcl, "function");
|
|
||||||
const vcl = editor.exportVcl([
|
|
||||||
{ id: "r1", stage: "request", conditions: [], actions: [
|
|
||||||
{ type: "remove_request_header", name: "X-Tracking" },
|
|
||||||
{ type: "set_request_header", name: "X-Device", value: "mobile" },
|
|
||||||
{ type: "lookup" },
|
|
||||||
], stop: true },
|
|
||||||
{ id: "r2", stage: "request", hash_stage: true, conditions: [], actions: [
|
|
||||||
{ type: "hash_header", name: "X-Device" },
|
|
||||||
] },
|
|
||||||
{ id: "r3", stage: "response", conditions: [], actions: [
|
|
||||||
{ type: "no_store" }, { type: "allow_store" },
|
|
||||||
{ type: "set_backend_header", name: "Vary", value: "Accept-Language" },
|
|
||||||
] },
|
|
||||||
{ id: "r4", stage: "deliver", conditions: [], actions: [], stop: true },
|
|
||||||
]);
|
|
||||||
for (const statement of [
|
|
||||||
"sub vcl_recv {", "unset req.http.X-Tracking;",
|
|
||||||
'set req.http.X-Device = "mobile";', "return (hash);",
|
|
||||||
"sub vcl_hash {", "hash_data(req.http.X-Device);",
|
|
||||||
"sub vcl_backend_response {", "set beresp.uncacheable = true;",
|
|
||||||
"set beresp.uncacheable = false;", 'set beresp.http.Vary = "Accept-Language";',
|
|
||||||
"sub vcl_deliver {", "return (deliver);",
|
|
||||||
]) assert.ok(vcl.includes(statement), `missing in VCL export: ${statement}`);
|
|
||||||
assert.ok(!vcl.includes("return (lookup);"), "should not generate lookup in recv");
|
|
||||||
assert.equal((vcl.match(/return \(deliver\);/g) || []).length, 1, "single terminal deliver");
|
|
||||||
// Cookie/session guards: templates emit cookie_pass, explicit guards keep pass.
|
|
||||||
sandbox.t = key => key;
|
|
||||||
const actionsOf = key => JSON.parse(JSON.stringify(editor.TEMPLATES[key]().map(rule => rule.actions.map(a => a.type).join(","))));
|
|
||||||
for (const key of ["cookiepass", "sessioncookies", "django", "laravel", "authjs", "aspnet", "drupal"])
|
|
||||||
assert.deepEqual(actionsOf(key), ["cookie_pass"], key);
|
|
||||||
assert.deepEqual(actionsOf("wordpress"), ["pass", "cookie_pass"]);
|
|
||||||
assert.deepEqual(actionsOf("woocommerce"), ["pass", "cookie_pass"]);
|
|
||||||
assert.deepEqual(actionsOf("cdn"), ["pass", "pass", "pass", "strip_cookies", "cookie_pass"]);
|
|
||||||
for (const key of ["safemethods", "authbypass", "checkout", "preview", "webhooks", "graphql", "signedurls"])
|
|
||||||
assert.deepEqual(actionsOf(key), ["pass"], key);
|
|
||||||
for (const key of ["privateroutes", "privateapi"])
|
|
||||||
assert.equal(actionsOf(key)[0], "pass", key);
|
|
||||||
// Every cookie_pass template rule has a non-negated Cookie condition (server validation).
|
|
||||||
for (const key of Object.keys(editor.TEMPLATES)) for (const rule of editor.TEMPLATES[key]())
|
|
||||||
if (rule.actions.some(a => a.type === "cookie_pass"))
|
|
||||||
assert.ok(rule.conditions.some(c => !c.negate && (c.field === "cookie" || (c.field === "header" && String(c.name).toLowerCase() === "cookie"))), key);
|
|
||||||
const guardVcl = editor.exportVcl([{ id: "g", stage: "request", match: "all", conditions: [{ field: "header", name: "Cookie", operator: "exists", values: [] }], actions: [{ type: "cookie_pass" }], stop: true }]);
|
|
||||||
assert.ok(guardVcl.includes("return (cookie_pass);"), guardVcl);
|
|
||||||
assert.ok(guardVcl.includes("RustProxy extension (Cookie guard)"), guardVcl);
|
|
||||||
console.log("PASS: cache rules JS export, request headers, store override, vcl_hash and terminal deliver");
|
|
||||||
console.log("PASS: cookie_pass templates and VCL export");
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
#!/usr/bin/env node
|
|
||||||
"use strict";
|
|
||||||
// Checks that the panel routing tester (src/admin/web/vhosts/routing.js) selects the
|
|
||||||
// same location as the proxy for tests/fixtures/routing_conditions_cases.json, which
|
|
||||||
// the Rust test `fixture_cases_select_the_expected_location` also uses.
|
|
||||||
const fs = require("node:fs");
|
|
||||||
const path = require("node:path");
|
|
||||||
const vm = require("node:vm");
|
|
||||||
const assert = require("node:assert/strict");
|
|
||||||
|
|
||||||
const root = path.resolve(__dirname, "../..");
|
|
||||||
const sandbox = { window: {}, BigInt, RegExp, Math, Number, String, Array, Boolean };
|
|
||||||
vm.runInNewContext(fs.readFileSync(path.join(root, "src/admin/web/vhosts/routing.js"), "utf8"), sandbox, { filename: "routing.js" });
|
|
||||||
const core = sandbox.window.rustProxyRoutingCore;
|
|
||||||
assert.equal(typeof core?.evaluate, "function");
|
|
||||||
|
|
||||||
const fixture = JSON.parse(fs.readFileSync(path.join(root, "tests/fixtures/routing_conditions_cases.json"), "utf8"));
|
|
||||||
for (const item of fixture.cases) {
|
|
||||||
const request = {
|
|
||||||
method: item.method || "GET", path: item.path, query: item.query ?? null, host: item.host || "site.test",
|
|
||||||
client_ip: item.client_ip || "203.0.113.5", country: item.country || null,
|
|
||||||
headers: Object.entries(item.headers || {}),
|
|
||||||
};
|
|
||||||
const { winner } = core.evaluate(fixture.vhost.routes, request);
|
|
||||||
assert.equal(winner ? winner.route.id : "main", item.expect, item.name);
|
|
||||||
}
|
|
||||||
|
|
||||||
const cidr = core.cidrContains;
|
|
||||||
assert.ok(cidr("10.0.0.0/8", "10.200.1.1"));
|
|
||||||
assert.ok(!cidr("10.0.0.0/8", "11.0.0.1"));
|
|
||||||
assert.ok(cidr("2001:db8::/32", "2001:db8:1::5"));
|
|
||||||
assert.ok(!cidr("2001:db8::/32", "2001:db9::1"));
|
|
||||||
assert.ok(cidr("192.0.2.7", "::ffff:192.0.2.7"), "IPv4-mapped addresses are compared as IPv4");
|
|
||||||
assert.ok(cidr("::1", "::1"));
|
|
||||||
console.log(`routing tester: ok (${fixture.cases.length} cases)`);
|
|
||||||
Reference in new issue
Block a user