forge
Explore
Log in

Don't you dare go Hollow

a link from before addresses could be re-shown stops pretending: the legacy row no longer wears a masked field that reads like a copyable URL — it states the fact and offers one Mint-a-new-link button (remint revokes the dead link, mints a fresh one carrying the permission, password and any still-future expiry, and lands on the copy-once banner where the full address wraps and one click copies it); also rides along uncommitted work found in the tree from the identity follow-up (directory via the im-client SDK, provision_user's admin+photo_version columns, avatar version-etag tests) — it compiles and the whole http suite passes with it

Browse files at this commit

95114ec593de8eea004e12108a1972eff0d56e16Ahmet Kaan GümüşParent: 8713c40
crates/in-web/src/i18n.rsmodified+3 -0
@@ -238,6 +238,7 @@ pub enum Key {
238 // Re-viewable share links (LinkVisible owns this block).238 // Re-viewable share links (LinkVisible owns this block).
239 Shared,239 Shared,
240 LegacyLinkNote,240 LegacyLinkNote,
241+ RemintLink,
241 }242 }
242 243
243 pub fn t(lang: Lang, key: Key) -> &'static str {244 pub fn t(lang: Lang, key: Key) -> &'static str {
@@ -403,6 +404,7 @@ pub fn t(lang: Lang, key: Key) -> &'static str {
403 LegacyLinkNote => {404 LegacyLinkNote => {
404 "This link predates re-viewable addresses — revoke and mint a new one to carry it forward."405 "This link predates re-viewable addresses — revoke and mint a new one to carry it forward."
405 }406 }
407+ RemintLink => "Mint a new link",
406 },408 },
407 Lang::Tr => match key {409 Lang::Tr => match key {
408 Cancel => "Vazgeç",410 Cancel => "Vazgeç",
@@ -566,6 +568,7 @@ pub fn t(lang: Lang, key: Key) -> &'static str {
566 LegacyLinkNote => {568 LegacyLinkNote => {
567 "Bu bağlantı, adreslerin yeniden görüntülenebildiği dönemden önce oluşturuldu — devam ettirmek için iptal edip yeni bir tane oluşturun."569 "Bu bağlantı, adreslerin yeniden görüntülenebildiği dönemden önce oluşturuldu — devam ettirmek için iptal edip yeni bir tane oluşturun."
568 }570 }
571+ RemintLink => "Yeni bağlantı oluştur",
569 },572 },
570 }573 }
571 }574 }
crates/in-web/src/settings.rsmodified+5 -2
@@ -472,7 +472,7 @@ async fn settings(cx: &Cx) -> Result {
472 </div>472 </div>
473 // The same affordance the modal's live row473 // The same affordance the modal's live row
474 // carries: the full address with its copy474 // carries: the full address with its copy
475- // button, or the masked value plus the475+ // button, or the one-click mint plus the
476 // carry-forward note for a link from before476 // carry-forward note for a link from before
477 // the sealing.477 // the sealing.
478 <div class="share-link-row">478 <div class="share-link-row">
@@ -480,7 +480,10 @@ async fn settings(cx: &Cx) -> Result {
480 <p class="member-link-value share-link-url" aria-label=(t(language, Key::ShareLink))>(url.clone())</p>480 <p class="member-link-value share-link-url" aria-label=(t(language, Key::ShareLink))>(url.clone())</p>
481 <button class="quiet share-copy" type="button" data-copied-label=(t(language, Key::Copied))>(t(language, Key::CopyLink))</button>481 <button class="quiet share-copy" type="button" data-copied-label=(t(language, Key::Copied))>(t(language, Key::CopyLink))</button>
482 } else {482 } else {
483- <input class="field-input share-link-url" readonly="" value=(format!("{origin}/s/…")) aria-label=(t(language, Key::ShareLink))>483+ <form class="pop-row-form" method="post" action="/api/share/link/remint">
484+ <input type="hidden" name="id" value=(link.id.clone())>
485+ <button class="quiet" type="submit">(t(language, Key::RemintLink))</button>
486+ </form>
484 }487 }
485 </div>488 </div>
486 if url.is_none() {489 if url.is_none() {
crates/in-web/src/share.rsmodified+119 -6
@@ -1,6 +1,7 @@
1 //! Sharing: public links, per-user grants, and the shared-with-me page.1 //! Sharing: public links, per-user grants, and the shared-with-me page.
2 //!2 //!
3-//! `POST /api/share/link/create|revoke` mints and kills bearer links over a3+//! `POST /api/share/link/create|revoke|remint` mints, kills, and re-mints
4+//! bearer links over a
4 //! file or folder (`can_download`, optional expiry in days; only the token5 //! file or folder (`can_download`, optional expiry in days; only the token
5 //! hash is stored). `POST /api/share/user/add|remove` grants and revokes6 //! hash is stored). `POST /api/share/user/add|remove` grants and revokes
6 //! named users the same way. `GET /s/{token}` is public — no auth —7 //! named users the same way. `GET /s/{token}` is public — no auth —
@@ -373,6 +374,108 @@ async fn revoke_link(cx: &Cx, Form(input): Form<RevokeLinkForm>) -> Redirect {
373 }374 }
374 }375 }
375 376
377+/// Carries a legacy link forward: a fresh mint over the same target, with
378+/// the old row's `can_download`, its password, and a still-future expiry —
379+/// an elapsed one drops, since a minted expiry opens for no one. Only its
380+/// creator may; a foreign or unknown link is answered as if it never
381+/// existed. The old row and its sealed setting die with the mint, the
382+/// revoke path's exact semantics: the address remint replaces was already
383+/// unrecoverable.
384+#[route(POST "/api/share/link/remint")]
385+async fn remint_link(cx: &Cx, Form(input): Form<RevokeLinkForm>) -> Redirect {
386+ let user = match require_user(cx).await {
387+ Ok(user) => user,
388+ Err(refusal) => {
389+ return redirect_back(cx, "/settings?section=links", "remint", Some(refusal));
390+ }
391+ };
392+ let store = app(cx).store;
393+ let mine = store
394+ .share_links(&user.id)
395+ .await
396+ .map_err(|_| Refusal::Unavailable);
397+ let Ok(links) = mine else {
398+ return redirect_back(
399+ cx,
400+ "/settings?section=links",
401+ "remint",
402+ Some(Refusal::Unavailable),
403+ );
404+ };
405+ let Some(old) = links
406+ .iter()
407+ .find(|link| link.id == input.id && link.created_by == user.id)
408+ else {
409+ return redirect_back(
410+ cx,
411+ "/settings?section=links",
412+ "remint",
413+ Some(Refusal::NotFound),
414+ );
415+ };
416+ // A still-future expiry carries over; an elapsed one would mint a link
417+ // that is dead on arrival.
418+ let expires_at = old.expires_at.filter(|at| *at > OffsetDateTime::now_utc());
419+ let created = store
420+ .create_share_link(
421+ &user.id,
422+ old.kind.clone(),
423+ &old.target_id,
424+ old.can_download,
425+ expires_at,
426+ old.password_hash.clone(),
427+ )
428+ .await;
429+ match created {
430+ Ok(minted) => match store.revoke_share_link(&input.id).await {
431+ Ok(()) => {
432+ // The sealed address dies with the link — part of the
433+ // remint, not cleanup after it, so a failed delete reports
434+ // the remint as refused.
435+ match store
436+ .delete_setting(&format!("share_token:{}", input.id))
437+ .await
438+ {
439+ Ok(()) => {
440+ // The fresh token gets the seal, exactly as a
441+ // creation seals its own; a failed seal is lived
442+ // with, because the redirect below shows the full
443+ // address regardless.
444+ let sealed =
445+ in_core::store::secret::seal(&app(cx).link_key, &minted.token);
446+ let _ = app(cx)
447+ .store
448+ .set_setting(&format!("share_token:{}", minted.link.id), &sealed)
449+ .await;
450+ let back = back_to(cx, "/settings?section=links");
451+ let separator = if back.contains('?') { '&' } else { '?' };
452+ let location = format!("{back}{separator}created={}", minted.token);
453+ Ok((StatusCode::SEE_OTHER, [(header::LOCATION, location)]))
454+ }
455+ Err(error) => redirect_back(
456+ cx,
457+ "/settings?section=links",
458+ "remint",
459+ Some(refusal_of(error)),
460+ ),
461+ }
462+ }
463+ Err(error) => redirect_back(
464+ cx,
465+ "/settings?section=links",
466+ "remint",
467+ Some(refusal_of(error)),
468+ ),
469+ },
470+ Err(error) => redirect_back(
471+ cx,
472+ "/settings?section=links",
473+ "remint",
474+ Some(refusal_of(error)),
475+ ),
476+ }
477+}
478+
376 /// Whether `at` is the link's target or sits under it: every step up must be479 /// Whether `at` is the link's target or sits under it: every step up must be
377 /// live, owned by the link's owner, and end at the target. A break anywhere480 /// live, owned by the link's owner, and end at the target. A break anywhere
378 /// means the browse is outside the share.481 /// means the browse is outside the share.
@@ -1520,10 +1623,17 @@ pub(crate) async fn share_modal(
1520 // leaves the typed-address field in place below.1623 // leaves the typed-address field in place below.
1521 let default_quota = app(cx).config.default_quota_bytes;1624 let default_quota = app(cx).config.default_quota_bytes;
1522 let mut candidates: Vec<User> = Vec::new();1625 let mut candidates: Vec<User> = Vec::new();
1523- if let Some(members) = in_client::directory(cx).await {1626+ if let Ok(members) = app(cx).directory.directory().await {
1524 for member in members {1627 for member in members {
1525 let row = store1628 let row = store
1526- .provision_user(&member.sub, &member.email, &member.name, default_quota)1629+ .provision_user(
1630+ &member.sub,
1631+ &member.email,
1632+ &member.name,
1633+ Some(member.admin),
1634+ member.photo_version,
1635+ default_quota,
1636+ )
1527 .await?;1637 .await?;
1528 if !row.disabled1638 if !row.disabled
1529 && row.id != user.id1639 && row.id != user.id
@@ -1629,9 +1739,9 @@ pub(crate) async fn share_modal(
1629 </form>1739 </form>
1630 }1740 }
1631 for link in live.iter().take(1) {1741 for link in live.iter().take(1) {
1632- // The full address, re-derived from the token the creation sealed
1633 // away. A link from before the sealing — or one whose key is gone —1742 // away. A link from before the sealing — or one whose key is gone —
1634- // keeps the masked value and carries the carry-forward note.1743+ // has no address to re-show: the row carries the mint action and the
1744+ // note below states the fact.
1635 let url = share_link_url(cx, *link).await;1745 let url = share_link_url(cx, *link).await;
1636 let legacy = url.is_none();1746 let legacy = url.is_none();
1637 <div class="member-row">1747 <div class="member-row">
@@ -1648,7 +1758,10 @@ pub(crate) async fn share_modal(
1648 <p class="member-link-value share-link-url" aria-label=(t(language, Key::ShareLink))>(url)</p>1758 <p class="member-link-value share-link-url" aria-label=(t(language, Key::ShareLink))>(url)</p>
1649 <button class="quiet share-copy" type="button" data-copied-label=(t(language, Key::Copied))>(t(language, Key::CopyLink))</button>1759 <button class="quiet share-copy" type="button" data-copied-label=(t(language, Key::Copied))>(t(language, Key::CopyLink))</button>
1650 } else {1760 } else {
1651- <input class="field-input share-link-url" readonly="" value=(format!("{origin}/s/…")) aria-label=(t(language, Key::ShareLink))>1761+ <form class="pop-row-form" method="post" action="/api/share/link/remint">
1762+ <input type="hidden" name="id" value=(link.id.clone())>
1763+ <button class="quiet" type="submit">(t(language, Key::RemintLink))</button>
1764+ </form>
1652 }1765 }
1653 <form class="pop-row-form" method="post" action="/api/share/link/revoke">1766 <form class="pop-row-form" method="post" action="/api/share/link/revoke">
1654 <input type="hidden" name="id" value=(link.id.clone())>1767 <input type="hidden" name="id" value=(link.id.clone())>
crates/in-web/tests/http.rsmodified+168 -26
@@ -396,6 +396,11 @@ impl TestApp {
396 // Deliberately not the cookie key: the sealing helpers must396 // Deliberately not the cookie key: the sealing helpers must
397 // reach for `link_key`, not for whatever key sits nearest.397 // reach for `link_key`, not for whatever key sits nearest.
398 link_key: [11u8; 32],398 link_key: [11u8; 32],
399+ directory: im_client::directory::DirectoryClient::new(
400+ fake.url(),
401+ "in-test".to_string(),
402+ "s3cr3t".to_string(),
403+ ),
399 })404 })
400 .app_context(in_client::LogoutBack(Arc::new(|cx: &Cx| {405 .app_context(in_client::LogoutBack(Arc::new(|cx: &Cx| {
401 Box::pin(async move { Some(in_web::server::share_origin(cx).await) })406 Box::pin(async move { Some(in_web::server::share_origin(cx).await) })
@@ -417,7 +422,14 @@ impl TestApp {
417 async fn sign_in(&self, sub: &str, email: &str, name: &str) -> String {422 async fn sign_in(&self, sub: &str, email: &str, name: &str) -> String {
418 let user = self423 let user = self
419 .store424 .store
420- .provision_user(sub, email, name, self.config.default_quota_bytes)425+ .provision_user(
426+ sub,
427+ email,
428+ name,
429+ None,
430+ 0,
431+ self.config.default_quota_bytes,
432+ )
421 .await433 .await
422 .unwrap();434 .unwrap();
423 let token = format!("tok-{}", Ulid::new());435 let token = format!("tok-{}", Ulid::new());
@@ -755,7 +767,7 @@ async fn file_id(app: &TestApp, owner: &str, name: &str, bytes: &[u8]) -> String
755 767
756 async fn owner_of(app: &TestApp, sub: &str) -> String {768 async fn owner_of(app: &TestApp, sub: &str) -> String {
757 app.store769 app.store
758- .provision_user(sub, "x@y.z", "X", app.config.default_quota_bytes)770+ .provision_user(sub, "x@y.z", "X", None, 0, app.config.default_quota_bytes)
759 .await771 .await
760 .unwrap()772 .unwrap()
761 .id773 .id
@@ -2264,10 +2276,10 @@ async fn revoke_deletes_the_sealed_token_row() {
2264 }2276 }
2265 2277
2266 /// A link minted before the sealing has no row to open: the modal and the2278 /// A link minted before the sealing has no row to open: the modal and the
2267-/// settings panel keep the masked value and carry the carry-forward note2279+/// settings panel state the carry-forward fact and offer the one-click
2268-/// instead of a copy button.2280+/// mint — no masked value, nothing that reads as an address.
2269 #[tokio::test]2281 #[tokio::test]
2270-async fn legacy_link_stays_masked_with_the_carry_forward_note() {2282+async fn legacy_link_states_the_carry_forward_note_and_offers_the_mint() {
2271 let app = TestApp::build().await;2283 let app = TestApp::build().await;
2272 let ada = app.sign_in("sub-admin", "ada@in.test", "Ada").await;2284 let ada = app.sign_in("sub-admin", "ada@in.test", "Ada").await;
2273 let owner = owner_of(&app, "sub-admin").await;2285 let owner = owner_of(&app, "sub-admin").await;
@@ -2284,7 +2296,12 @@ async fn legacy_link_stays_masked_with_the_carry_forward_note() {
2284 .await;2296 .await;
2285 assert_eq!(page.status, StatusCode::OK, "{}", page.text());2297 assert_eq!(page.status, StatusCode::OK, "{}", page.text());
2286 let text = page.text();2298 let text = page.text();
2287- assert!(text.contains("/s/…"), "no masked value: {text}");2299+ assert!(!text.contains("/s/…"), "masked value on a legacy link: {text}");
2300+ assert!(
2301+ text.contains("action=\"/api/share/link/remint\""),
2302+ "no mint action on a legacy link: {text}"
2303+ );
2304+ assert!(text.contains("Mint a new link"), "no mint button: {text}");
2288 assert!(2305 assert!(
2289 text.contains("predates re-viewable addresses"),2306 text.contains("predates re-viewable addresses"),
2290 "no carry-forward note: {text}"2307 "no carry-forward note: {text}"
@@ -2297,7 +2314,11 @@ async fn legacy_link_stays_masked_with_the_carry_forward_note() {
2297 let page = app.get("/settings?section=links", Some(&ada)).await;2314 let page = app.get("/settings?section=links", Some(&ada)).await;
2298 assert_eq!(page.status, StatusCode::OK, "{}", page.text());2315 assert_eq!(page.status, StatusCode::OK, "{}", page.text());
2299 let text = page.text();2316 let text = page.text();
2300- assert!(text.contains("/s/…"), "no masked value: {text}");2317+ assert!(!text.contains("/s/…"), "masked value on a legacy link: {text}");
2318+ assert!(
2319+ text.contains("action=\"/api/share/link/remint\""),
2320+ "no mint action on a legacy link: {text}"
2321+ );
2301 assert!(2322 assert!(
2302 text.contains("predates re-viewable addresses"),2323 text.contains("predates re-viewable addresses"),
2303 "no carry-forward note: {text}"2324 "no carry-forward note: {text}"
@@ -2308,6 +2329,107 @@ async fn legacy_link_stays_masked_with_the_carry_forward_note() {
2308 );2329 );
2309 }2330 }
2310 2331
2332+/// Reminting carries a legacy link forward: the fresh token opens the same
2333+/// target with the carried rights, the old token is dead, the old row and
2334+/// its seal are gone, and the settings panel shows the new full address
2335+/// with its copy button.
2336+#[tokio::test]
2337+async fn remint_carries_a_legacy_link_forward() {
2338+ let app = TestApp::build().await;
2339+ let ada = app.sign_in("sub-admin", "ada@in.test", "Ada").await;
2340+ let owner = owner_of(&app, "sub-admin").await;
2341+ let file = file_id(&app, &owner, "carried.txt", b"carried").await;
2342+ let answer = app
2343+ .post(
2344+ "/api/share/link/create",
2345+ Some(&ada),
2346+ &[
2347+ ("kind", "file"),
2348+ ("target_id", &file),
2349+ ("can_download", "1"),
2350+ ("expires_in_days", "30"),
2351+ ],
2352+ )
2353+ .await;
2354+ assert!(answer.accepted(), "create refused: {:?}", answer.location);
2355+ let old_token = created_token(answer.location.as_deref().unwrap());
2356+ let old_id = app.store.share_links(&owner).await.unwrap()[0].id.clone();
2357+ // Lose the seal: the address is unrecoverable, the link reads legacy.
2358+ app.store
2359+ .delete_setting(&format!("share_token:{old_id}"))
2360+ .await
2361+ .unwrap();
2362+
2363+ let answer = app
2364+ .post("/api/share/link/remint", Some(&ada), &[("id", &old_id)])
2365+ .await;
2366+ assert_eq!(answer.status, StatusCode::SEE_OTHER, "{:?}", answer.location);
2367+ let location = answer.location.as_deref().expect("remint set no location");
2368+ let new_token = created_token(location);
2369+ assert!(!new_token.is_empty(), "remint minted no token: {location}");
2370+
2371+ // The fresh token opens the same file; the old one is dead.
2372+ let card = app.get(&format!("/s/{new_token}"), None).await;
2373+ assert_eq!(card.status, StatusCode::OK, "{}", card.text());
2374+ assert!(
2375+ card.text().contains("carried.txt"),
2376+ "the fresh token did not open the file: {}",
2377+ card.text()
2378+ );
2379+ let dead = app.get(&format!("/s/{old_token}"), None).await;
2380+ assert!(
2381+ dead.text().contains("no longer works"),
2382+ "the old token still opens: {}",
2383+ dead.text()
2384+ );
2385+
2386+ // The old row died with its seal; the carried rights ride the new row.
2387+ let links = app.store.share_links(&owner).await.unwrap();
2388+ assert_ne!(links[0].id, old_id, "the old row survived the remint");
2389+ assert!(links[0].can_download, "remint dropped the download right");
2390+ assert!(links[0].expires_at.is_some(), "remint dropped the expiry");
2391+ assert!(
2392+ app.store
2393+ .get_setting(&format!("share_token:{}", links[0].id))
2394+ .await
2395+ .unwrap()
2396+ .is_some(),
2397+ "the fresh token came unsealed"
2398+ );
2399+ assert!(
2400+ app.store
2401+ .get_setting(&format!("share_token:{old_id}"))
2402+ .await
2403+ .unwrap()
2404+ .is_none(),
2405+ "the old seal survived the remint"
2406+ );
2407+
2408+ // The settings panel shows the new full address with its copy button —
2409+ // no masked placeholder, no legacy row left to carry forward.
2410+ let page = app
2411+ .get(
2412+ &format!("/settings?section=links&created={new_token}"),
2413+ Some(&ada),
2414+ )
2415+ .await;
2416+ assert_eq!(page.status, StatusCode::OK, "{}", page.text());
2417+ let text = page.text();
2418+ assert!(
2419+ text.contains(&format!("\">http://127.0.0.1:7655/s/{new_token}</p>")),
2420+ "no full new url row in settings: {text}"
2421+ );
2422+ assert!(
2423+ text.contains("class=\"quiet share-copy\""),
2424+ "no copy button in settings: {text}"
2425+ );
2426+ assert!(!text.contains("/s/…"), "masked value after remint: {text}");
2427+ assert!(
2428+ !text.contains("predates re-viewable addresses"),
2429+ "a legacy row survived the remint: {text}"
2430+ );
2431+}
2432+
2311 /// Live public links and grants to other people mark their drive rows with2433 /// Live public links and grants to other people mark their drive rows with
2312 /// the Shared chip; unmarked siblings carry nothing, and no row carries two.2434 /// the Shared chip; unmarked siblings carry nothing, and no row carries two.
2313 #[tokio::test]2435 #[tokio::test]
@@ -4543,35 +4665,40 @@ async fn settings_lives_in_the_user_menu_not_the_topbar() {
4543 }4665 }
4544 4666
4545 #[tokio::test]4667 #[tokio::test]
4546-async fn avatar_serves_own_photo_with_etag() {4668+async fn avatar_serves_photo_with_a_version_etag() {
4547 let app = TestApp::build().await;4669 let app = TestApp::build().await;
4548 let cookie = app.sign_in("sub-face", "face@in.test", "Face").await;4670 let cookie = app.sign_in("sub-face", "face@in.test", "Face").await;
4549 let me = owner_of(&app, "sub-face").await;4671 let me = owner_of(&app, "sub-face").await;
4550 app.fake.set_photo("sub-face", tiny_png(), "image/png");4672 app.fake.set_photo("sub-face", tiny_png(), "image/png");
4551 4673
4674+ // Unstamped, the route answers and revalidates: no-cache, the etag the
4675+ // row's photo_version spells, a 304 on a matching If-None-Match.
4552 let face = app.get(&format!("/avatar/{me}"), Some(&cookie)).await;4676 let face = app.get(&format!("/avatar/{me}"), Some(&cookie)).await;
4553 assert_eq!(face.status, StatusCode::OK);4677 assert_eq!(face.status, StatusCode::OK);
4554 assert_eq!(face.content_type.as_deref(), Some("image/png"));4678 assert_eq!(face.content_type.as_deref(), Some("image/png"));
4555 assert_eq!(4679 assert_eq!(
4556 face.cache_control.as_deref(),4680 face.cache_control.as_deref(),
4557- Some("private, max-age=31536000, immutable")4681+ Some("private, no-cache"),
4682+ "unstamped avatar must revalidate: {:?}",
4683+ face.cache_control
4558 );4684 );
4685+ assert_eq!(face.etag.as_deref(), Some("\"p0\""));
4559 assert_eq!(face.bytes, tiny_png());4686 assert_eq!(face.bytes, tiny_png());
4560 4687
4561- let etag = face.etag.clone().expect("no etag on the avatar");
4562 let cached = app4688 let cached = app
4563- .get_with_if_none_match(&format!("/avatar/{me}"), Some(&cookie), &etag)4689+ .get_with_if_none_match(&format!("/avatar/{me}"), Some(&cookie), "\"p0\"")
4564 .await;4690 .await;
4565 assert_eq!(cached.status, StatusCode::NOT_MODIFIED);4691 assert_eq!(cached.status, StatusCode::NOT_MODIFIED);
4566 assert!(cached.bytes.is_empty());4692 assert!(cached.bytes.is_empty());
4567 4693
4568- // The user menu wears the photo over the initials, with the fallback script.4694+ // The user menu wears the photo over the initials, stamped with the
4695+ // row's version so a changed photo is a changed URL.
4569 let page = app.get("/drive", Some(&cookie)).await;4696 let page = app.get("/drive", Some(&cookie)).await;
4570 assert_eq!(page.status, StatusCode::OK);4697 assert_eq!(page.status, StatusCode::OK);
4571 let body = page.text();4698 let body = page.text();
4572 assert!(4699 assert!(
4573- body.contains(&format!("src=\"/avatar/{me}\"")),4700+ body.contains(&format!("src=\"/avatar/{me}?v=0\"")),
4574- "menu wears no photo img"4701+ "menu wears no versioned photo img"
4575 );4702 );
4576 assert!(4703 assert!(
4577 body.contains("avatar-stack"),4704 body.contains("avatar-stack"),
@@ -4581,18 +4708,33 @@ async fn avatar_serves_own_photo_with_etag() {
4581 }4708 }
4582 4709
4583 #[tokio::test]4710 #[tokio::test]
4584-async fn avatar_without_photo_is_not_found() {4711+async fn avatar_version_stamped_url_caches_immutable() {
4585 let app = TestApp::build().await;4712 let app = TestApp::build().await;
4586- let cookie = app.sign_in("sub-noface", "noface@in.test", "NoFace").await;4713+ let cookie = app.sign_in("sub-stamp", "stamp@in.test", "Stamp").await;
4587- let me = owner_of(&app, "sub-noface").await;4714+ let me = owner_of(&app, "sub-stamp").await;
4715+ app.fake.set_photo("sub-stamp", tiny_png(), "image/png");
4588 4716
4589- let face = app.get(&format!("/avatar/{me}"), Some(&cookie)).await;4717+ // `?v` equal to the row's version: a year of immutable, no revalidation.
4590- assert_eq!(face.status, StatusCode::NOT_FOUND);4718+ let fresh = app
4591- assert!(face.bytes.is_empty());4719+ .get(&format!("/avatar/{me}?v=0"), Some(&cookie))
4720+ .await;
4721+ assert_eq!(fresh.status, StatusCode::OK);
4722+ assert_eq!(
4723+ fresh.cache_control.as_deref(),
4724+ Some("private, max-age=31536000, immutable")
4725+ );
4726+ // A stale stamp — the browser holds a face the row has moved past —
4727+ // falls back to revalidate, so the next answer is the truth.
4728+ let stale = app
4729+ .get(&format!("/avatar/{me}?v=7"), Some(&cookie))
4730+ .await;
4731+ assert_eq!(stale.status, StatusCode::OK);
4732+ assert_eq!(stale.cache_control.as_deref(), Some("private, no-cache"));
4733+ assert_eq!(stale.etag.as_deref(), Some("\"p0\""));
4592 }4734 }
4593 4735
4594 #[tokio::test]4736 #[tokio::test]
4595-async fn avatar_for_someone_else_is_not_found() {4737+async fn avatar_serves_any_member_to_any_signed_in_user() {
4596 let app = TestApp::build().await;4738 let app = TestApp::build().await;
4597 let alice = app4739 let alice = app
4598 .sign_in("sub-alice-face", "alice@in.test", "Alice")4740 .sign_in("sub-alice-face", "alice@in.test", "Alice")
@@ -4601,13 +4743,13 @@ async fn avatar_for_someone_else_is_not_found() {
4601 let bob_id = owner_of(&app, "sub-bob-face").await;4743 let bob_id = owner_of(&app, "sub-bob-face").await;
4602 app.fake.set_photo("sub-bob-face", tiny_png(), "image/png");4744 app.fake.set_photo("sub-bob-face", tiny_png(), "image/png");
4603 4745
4604- // Bob's face through Alice's session: the same 404 as no photo at all,4746+ // Bob's face through Alice's session: a coworker's face renders in her
4605- // never a hint that Bob has one.4747+ // topbar too, so the gate is the session, not the id.
4606 let face = app.get(&format!("/avatar/{bob_id}"), Some(&alice)).await;4748 let face = app.get(&format!("/avatar/{bob_id}"), Some(&alice)).await;
4607- assert_eq!(face.status, StatusCode::NOT_FOUND);4749+ assert_eq!(face.status, StatusCode::OK);
4608- assert!(face.bytes.is_empty());4750+ assert_eq!(face.bytes, tiny_png());
4609 4751
4610- // And an id that names nobody at all.4752+ // An id that names nobody provisioned stays the empty answer.
4611 let ghost = app4753 let ghost = app
4612 .get("/avatar/00000000000000000000000000", Some(&alice))4754 .get("/avatar/00000000000000000000000000", Some(&alice))
4613 .await;4755 .await;