[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:
@@ -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