[core] Share links and repo layout: HMAC tokens with epoch, prefix check, exact hosts/<hostname>.toml, error codes; edge config v2
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": 1,
|
||||
"version": 2,
|
||||
"http_listen": "0.0.0.0:80",
|
||||
"https_listen": "0.0.0.0:443",
|
||||
"https_port": 443,
|
||||
@@ -82,7 +82,8 @@
|
||||
"path": "/api/v1/status",
|
||||
"interval_secs": 15
|
||||
},
|
||||
"access_log": true
|
||||
"access_log": true,
|
||||
"share_links": false
|
||||
},
|
||||
{
|
||||
"hostname": "status.example.org",
|
||||
@@ -101,7 +102,8 @@
|
||||
"request_headers": [],
|
||||
"response_headers": [],
|
||||
"health_check": null,
|
||||
"access_log": false
|
||||
"access_log": false,
|
||||
"share_links": false
|
||||
},
|
||||
{
|
||||
"hostname": "wiki.home.test",
|
||||
@@ -131,7 +133,8 @@
|
||||
],
|
||||
"response_headers": [],
|
||||
"health_check": null,
|
||||
"access_log": false
|
||||
"access_log": false,
|
||||
"share_links": false
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -145,7 +145,11 @@ fn errors_have_codes_fields_and_params_for_the_ui() {
|
||||
"host.hostname.missing",
|
||||
Some("hostname"),
|
||||
),
|
||||
("hostname = \"app.test\"\n", "host.upstreams.missing", Some("upstreams")),
|
||||
(
|
||||
"hostname = \"app.test\"\n",
|
||||
"host.upstreams.missing",
|
||||
Some("upstreams"),
|
||||
),
|
||||
(
|
||||
"hostname = \"App.test\"\nupstreams = [\"http://127.0.0.1:1\"]\n",
|
||||
"host.hostname.uppercase",
|
||||
@@ -227,7 +231,10 @@ fn params_carry_suggestions() {
|
||||
.unwrap();
|
||||
assert_eq!(e.params()["suggestion"], "app.test");
|
||||
let errs = errors_for("hostname = \"app.test\"\nupstreams = [\"http://10.0.0.2:3000/app\"]\n");
|
||||
let e = errs.iter().find(|e| e.code() == "host.upstream.path").unwrap();
|
||||
let e = errs
|
||||
.iter()
|
||||
.find(|e| e.code() == "host.upstream.path")
|
||||
.unwrap();
|
||||
assert_eq!(e.params()["suggestion"], "http://10.0.0.2:3000");
|
||||
assert_eq!(e.params()["url"], "http://10.0.0.2:3000/app");
|
||||
}
|
||||
|
||||
@@ -90,7 +90,12 @@ fn an_expired_token_is_refused_as_expired() {
|
||||
#[test]
|
||||
fn a_token_for_another_host_is_refused() {
|
||||
let t = token("/", None);
|
||||
for host in ["other.home.test", "PHOTOS.home.test", "photos.home.test.", "photos.home"] {
|
||||
for host in [
|
||||
"other.home.test",
|
||||
"PHOTOS.home.test",
|
||||
"photos.home.test.",
|
||||
"photos.home",
|
||||
] {
|
||||
assert_eq!(
|
||||
verify_link(&key(), host, &t, None, NOW, &none()),
|
||||
Err(Rejection::Invalid),
|
||||
@@ -111,7 +116,9 @@ fn a_token_made_with_another_key_is_refused() {
|
||||
#[test]
|
||||
fn every_single_bit_flip_is_refused() {
|
||||
let t = token("/albums", None);
|
||||
let raw = URL_SAFE_NO_PAD.decode(t.strip_prefix("ish1.").unwrap()).unwrap();
|
||||
let raw = URL_SAFE_NO_PAD
|
||||
.decode(t.strip_prefix("ish1.").unwrap())
|
||||
.unwrap();
|
||||
for i in 0..raw.len() {
|
||||
for bit in 0..8 {
|
||||
let mut r = raw.clone();
|
||||
@@ -132,7 +139,9 @@ fn every_single_bit_flip_is_refused() {
|
||||
#[test]
|
||||
fn a_longer_expiry_or_wider_prefix_cannot_be_spliced_in() {
|
||||
let t = token("/albums/summer", None);
|
||||
let raw = URL_SAFE_NO_PAD.decode(t.strip_prefix("ish1.").unwrap()).unwrap();
|
||||
let raw = URL_SAFE_NO_PAD
|
||||
.decode(t.strip_prefix("ish1.").unwrap())
|
||||
.unwrap();
|
||||
let (payload, mac) = raw.split_at(raw.len() - 32);
|
||||
// Same MAC, prefix cut down to "/albums".
|
||||
let mut p = payload[..30].to_vec();
|
||||
@@ -198,8 +207,12 @@ fn the_token_carries_no_password_hash() {
|
||||
// Two links that differ only in the password have the same payload; only the MAC differs.
|
||||
let a = token("/", Some("password-one"));
|
||||
let b = token("/", Some("password-two"));
|
||||
let ra = URL_SAFE_NO_PAD.decode(a.strip_prefix("ish1.").unwrap()).unwrap();
|
||||
let rb = URL_SAFE_NO_PAD.decode(b.strip_prefix("ish1.").unwrap()).unwrap();
|
||||
let ra = URL_SAFE_NO_PAD
|
||||
.decode(a.strip_prefix("ish1.").unwrap())
|
||||
.unwrap();
|
||||
let rb = URL_SAFE_NO_PAD
|
||||
.decode(b.strip_prefix("ish1.").unwrap())
|
||||
.unwrap();
|
||||
assert_eq!(ra.len(), rb.len());
|
||||
assert_eq!(ra[..ra.len() - 32], rb[..rb.len() - 32]);
|
||||
assert_ne!(ra[ra.len() - 32..], rb[rb.len() - 32..]);
|
||||
@@ -208,7 +221,9 @@ fn the_token_carries_no_password_hash() {
|
||||
#[test]
|
||||
fn a_dropped_password_flag_does_not_open_the_link() {
|
||||
let t = token("/", Some("correct horse"));
|
||||
let mut raw = URL_SAFE_NO_PAD.decode(t.strip_prefix("ish1.").unwrap()).unwrap();
|
||||
let mut raw = URL_SAFE_NO_PAD
|
||||
.decode(t.strip_prefix("ish1.").unwrap())
|
||||
.unwrap();
|
||||
raw[29] = 0;
|
||||
let forged = format!("ish1.{}", URL_SAFE_NO_PAD.encode(&raw));
|
||||
assert_eq!(
|
||||
@@ -290,7 +305,10 @@ fn short_keys_are_refused() {
|
||||
fn prefixes_are_normalised_or_refused() {
|
||||
assert_eq!(check_prefix("/").unwrap(), "/");
|
||||
assert_eq!(check_prefix("/a/").unwrap(), "/a");
|
||||
assert_eq!(check_prefix("/albums/summer-2026").unwrap(), "/albums/summer-2026");
|
||||
assert_eq!(
|
||||
check_prefix("/albums/summer-2026").unwrap(),
|
||||
"/albums/summer-2026"
|
||||
);
|
||||
for bad in [
|
||||
"", "a", "//", "/a//b", "/a/../b", "/..", "/.", "/a/./b", "/a%2fb", "/a\\b", "/a b",
|
||||
"/a;b", "/ä", "/a?b", "/a#b",
|
||||
@@ -307,7 +325,13 @@ fn ids_round_trip_as_hex() {
|
||||
let i = ShareId([0xab; 16]);
|
||||
assert_eq!(i.to_hex(), "ab".repeat(16));
|
||||
assert_eq!(ShareId::from_hex(&i.to_hex()), Some(i));
|
||||
for bad in ["", "ab", &"AB".repeat(16), &"zz".repeat(16), &"a".repeat(33)] {
|
||||
for bad in [
|
||||
"",
|
||||
"ab",
|
||||
&"AB".repeat(16),
|
||||
&"zz".repeat(16),
|
||||
&"a".repeat(33),
|
||||
] {
|
||||
assert_eq!(ShareId::from_hex(bad), None, "{bad:?}");
|
||||
}
|
||||
}
|
||||
@@ -373,6 +397,9 @@ fn no_path_trick_escapes_the_prefix() {
|
||||
("/", "/%2e%2e/x"),
|
||||
];
|
||||
for (prefix, path) in cases {
|
||||
assert!(!path_within(prefix, path), "{prefix} must not cover {path:?}");
|
||||
assert!(
|
||||
!path_within(prefix, path),
|
||||
"{prefix} must not cover {path:?}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user