diff --git a/crates/forge-web/src/pages/profile.rs b/crates/forge-web/src/pages/profile.rs
index a494876..42b3609 100644
--- a/crates/forge-web/src/pages/profile.rs
+++ b/crates/forge-web/src/pages/profile.rs
@@ -686,103 +686,91 @@ mod tests {
site
}
+ /// One seeded site covers the repo list for each kind of viewer, the about text, the
+ /// edit button, the unknown-user 404 and the fixed routes. Each signed-in viewer gets its
+ /// own session token.
#[tokio::test]
- async fn about_is_rendered_and_sanitized() {
+ async fn profile_visibility_routing_and_edit_button() {
let site = seeded().await;
- let (status, body) = get(&site.router, "/tahinli", None).await;
- assert_eq!(status, 200);
- assert!(body.contains("
bold"));
- assert!(!body.contains(""#;
let (content_type, body) = multipart(&[
("csrf", None, CSRF.as_bytes()),
@@ -835,34 +862,36 @@ pub(crate) mod tests {
body,
)
.await;
- assert_eq!(reply.status, 200);
- assert!(reply.text().contains(r#"role="alert""#));
- assert!(fx.store.avatar_hash(&fx.user.id).await.unwrap().is_none());
- }
-
- #[tokio::test]
- async fn avatar_upload_then_remove_is_served_correctly() {
- let fx = fixture().await;
- let png = png_bytes();
+ assert_eq!(reply.status, 200, "svg: status");
+ assert!(reply.text().contains(r#"role="alert""#), "svg: alert");
+ assert!(
+ fx.store.avatar_hash(&fx.user.id).await.unwrap().is_none(),
+ "svg: nothing stored"
+ );
+ // A PNG upload is stored, shown and served with its hash as the version.
let reply = upload_avatar(&fx.router, CSRF, &png).await;
- assert_eq!(reply.status, 303);
+ assert_eq!(reply.status, 303, "upload: status");
assert_eq!(
reply.header("location").as_deref(),
- Some("/settings/profile?saved=avatar")
+ Some("/settings/profile?saved=avatar"),
+ "upload: location"
);
let stored_hash = fx.store.avatar_hash(&fx.user.id).await.unwrap().unwrap();
- assert_eq!(stored_hash.len(), 16);
+ assert_eq!(stored_hash.len(), 16, "upload: hash length");
// The page shows the new avatar with the hash as its version.
let (_, _, body) = send(&fx.router, "GET", "/settings/profile", true, None).await;
- assert!(body.contains(&format!("?v={stored_hash}")), "{body}");
- assert!(body.contains("Remove photo"), "{body}");
+ assert!(
+ body.contains(&format!("?v={stored_hash}")),
+ "page: version {body}"
+ );
+ assert!(body.contains("Remove photo"), "page: remove item {body}");
// The top-nav avatar uses the real hash too, not the default URL.
let (_, _, body) = send(&fx.router, "GET", "/", true, None).await;
let nav_src = format!(r#"src="/avatars/tahinli?v={stored_hash}""#);
- assert!(body.contains(&nav_src), "{body}");
+ assert!(body.contains(&nav_src), "nav: avatar url {body}");
// Served as a stored PNG with a hash ETag, and 304 on a match.
let served = send_full(
@@ -874,26 +903,39 @@ pub(crate) mod tests {
Vec::new(),
)
.await;
- assert_eq!(served.status, 200);
- assert_eq!(served.header("content-type").as_deref(), Some("image/png"));
- assert_eq!(served.header("etag"), Some(format!("\"{stored_hash}\"")));
+ assert_eq!(served.status, 200, "served: status");
+ assert_eq!(
+ served.header("content-type").as_deref(),
+ Some("image/png"),
+ "served: type"
+ );
+ assert_eq!(
+ served.header("etag"),
+ Some(format!("\"{stored_hash}\"")),
+ "served: etag"
+ );
assert_eq!(
served.header("x-content-type-options").as_deref(),
- Some("nosniff")
+ Some("nosniff"),
+ "served: nosniff"
+ );
+ assert!(
+ served.body.starts_with(&[0x89, b'P', b'N', b'G']),
+ "served: png bytes"
);
- assert!(served.body.starts_with(&[0x89, b'P', b'N', b'G']));
let uri = format!("/avatars/tahinli?v={stored_hash}");
let immutable = send_full(&fx.router, "GET", &uri, false, None, Vec::new()).await;
assert_eq!(
immutable.header("cache-control").as_deref(),
- Some("public, max-age=31536000, immutable")
+ Some("public, max-age=31536000, immutable"),
+ "versioned: cache-control"
);
let etag = format!("\"{stored_hash}\"");
let mut request = Request::builder().method("GET").uri(&uri);
request = request.header("if-none-match", etag.as_str());
let not_modified = fx.router.handle(request.body(Body::empty()).unwrap()).await;
- assert_eq!(not_modified.status().as_u16(), 304);
+ assert_eq!(not_modified.status().as_u16(), 304, "versioned: 304");
// Removing gives the generated default SVG.
let form = format!("csrf={CSRF}");
@@ -905,20 +947,27 @@ pub(crate) mod tests {
Some(&form),
)
.await;
- assert_eq!(status, 303);
+ assert_eq!(status, 303, "remove: status");
assert_eq!(
location.as_deref(),
- Some("/settings/profile?saved=avatar-removed")
+ Some("/settings/profile?saved=avatar-removed"),
+ "remove: location"
+ );
+ assert!(
+ fx.store.avatar_hash(&fx.user.id).await.unwrap().is_none(),
+ "remove: cleared"
);
- assert!(fx.store.avatar_hash(&fx.user.id).await.unwrap().is_none());
let (_, _, body) = send(&fx.router, "GET", "/", true, None).await;
assert!(
body.contains(r#"src="/avatars/tahinli?v=default""#),
- "{body}"
+ "remove: nav default {body}"
);
// With no photo there is nothing to remove, so the menu leaves that item out.
let (_, _, body) = send(&fx.router, "GET", "/settings/profile", true, None).await;
- assert!(!body.contains("Remove photo"), "{body}");
+ assert!(
+ !body.contains("Remove photo"),
+ "remove: no remove item {body}"
+ );
let default = send_full(
&fx.router,
@@ -929,15 +978,21 @@ pub(crate) mod tests {
Vec::new(),
)
.await;
- assert_eq!(default.status, 200);
+ assert_eq!(default.status, 200, "default: status");
assert_eq!(
default.header("content-type").as_deref(),
- Some("image/svg+xml")
+ Some("image/svg+xml"),
+ "default: type"
);
assert_eq!(
default.header("x-content-type-options").as_deref(),
- Some("nosniff")
+ Some("nosniff"),
+ "default: nosniff"
+ );
+ assert!(
+ default.text().starts_with("