use crate::common::{ PW, TAHINLI_CMD, attr_values, boot_forge, element_texts, git, head_sha, input_value, ok, open_stream, path_str, set_identity, temp_dir, tool_on_path, }; use std::fs; use std::path::Path; use std::time::Duration; use reqwest::header::{ CONTENT_DISPOSITION, CONTENT_SECURITY_POLICY, CONTENT_TYPE, COOKIE, HeaderMap, HeaderName, LOCATION, SET_COOKIE, X_CONTENT_TYPE_OPTIONS, }; const PNG: &[u8] = b"\x89PNG\r\n\x1a\n\x00\x00\x00\x00IEND\xaeB`\x82"; struct Resp { status: u16, headers: HeaderMap, bytes: Vec, } impl Resp { fn body(&self) -> String { String::from_utf8_lossy(&self.bytes).into_owned() } fn header(&self, name: HeaderName) -> Option { self.headers .get(name) .and_then(|v| v.to_str().ok()) .map(str::to_owned) } fn set_cookies(&self) -> Vec { self.headers .get_all(SET_COOKIE) .iter() .filter_map(|v| v.to_str().ok().map(str::to_owned)) .collect() } } struct Http { client: reqwest::Client, base: String, } impl Http { fn new(port: u16) -> Self { let client = reqwest::Client::builder() .redirect(reqwest::redirect::Policy::none()) .timeout(Duration::from_secs(60)) .build() .expect("http client"); Self { client, base: format!("http://127.0.0.1:{port}"), } } async fn get(&self, path: &str, cookie: Option<&str>) -> Resp { self.send(self.client.get(format!("{}{path}", self.base)), cookie) .await } async fn post_form(&self, path: &str, form: &[(&str, &str)], cookie: Option<&str>) -> Resp { self.send( self.client.post(format!("{}{path}", self.base)).form(form), cookie, ) .await } async fn stream(&self, path: &str, cookie: Option<&str>) -> reqwest::Response { open_stream(&self.client, &format!("{}{path}", self.base), cookie).await } async fn send(&self, req: reqwest::RequestBuilder, cookie: Option<&str>) -> Resp { let req = match cookie { Some(cookie) => req.header(COOKIE, cookie), None => req, }; let res = req.send().await.expect("http request"); let status = res.status().as_u16(); let headers = res.headers().clone(); let bytes = res.bytes().await.expect("read body").to_vec(); Resp { status, headers, bytes, } } } fn cookie_named(resp: &Resp, suffix: &str) -> Option { resp.set_cookies().iter().find_map(|set| { let pair = set.split(';').next()?; let (name, value) = pair.split_once('=')?; (name.ends_with(suffix) && !value.is_empty()).then(|| format!("{name}={value}")) }) } fn assert_latest_bar(body: &str, what: &str, subject: &str, oid: &str, count: &str) { assert_eq!( element_texts(body, ".head-sub").len(), 1, "{what}: one head line" ); let shas = element_texts(body, ".head-sub a.mono"); assert_eq!(shas.len(), 1, "{what}: the head line must show the sha"); assert_eq!(shas[0].trim(), &oid[..7], "{what}: short sha"); let links = element_texts(body, ".head-sub a[href*=\"/commit/\"]"); assert!( !links.iter().any(|l| l.trim() == subject), "{what}: the head line must not show the subject {subject:?}, got {links:?}" ); let parts = element_texts(body, ".head-sub span"); assert!( parts.iter().any(|c| c.trim() == count), "{what}: the head line must show {count:?}, got {parts:?}" ); } fn write_fixtures(work: &Path) { fs::create_dir_all(work.join("src")).expect("create src"); fs::write( work.join("README.md"), "# Browse Test\n\nSee [the code](src/main.rs).\n\n![logo](img.png)\n", ) .expect("write README.md"); fs::write(work.join("src/main.rs"), "fn main() {}\n").expect("write main.rs"); fs::write(work.join("img.png"), PNG).expect("write img.png"); fs::write(work.join("evil.html"), "\n").expect("write evil.html"); fs::write( work.join("weights.bin"), "version https://git-lfs.github.com/spec/v1\noid sha256:4d7a214614ab2935c943f9e0ff69d22eadbb8f32b1258daaa5e2ca24d17e2393\nsize 1234\n", ) .expect("write weights.bin"); } fn commit_all(repo: &Path, message: &str) { set_identity(repo); ok(&git(repo, &["add", "-A"]), "git add"); ok( &git( repo, &["-c", "commit.gpgsign=false", "commit", "-q", "-m", message], ), "git commit", ); } fn push_fixtures(dir: &Path, url: &str, work: &Path) -> String { ok(&git(dir, &["clone", url, path_str(work)]), "https clone"); write_fixtures(work); commit_all(work, "browse fixtures"); ok(&git(work, &["push", "origin", "HEAD:main"]), "push main"); let main_oid = head_sha(work); ok( &git(work, &["checkout", "-q", "-b", "feature/x"]), "create feature/x", ); fs::write(work.join("feature.txt"), "on a branch\n").expect("write feature.txt"); commit_all(work, "feature commit"); ok( &git(work, &["push", "origin", "feature/x"]), "push feature/x", ); main_oid } async fn login(http: &Http, username: &str, password: &str) -> String { let page = http.get("/login", None).await; assert_eq!(page.status, 200, "GET /login"); let precsrf_cookie = cookie_named(&page, "forge_precsrf").expect("precsrf cookie"); let precsrf = input_value(&page.body(), "precsrf"); let res = http .post_form( "/login", &[ ("username", username), ("password", password), ("next", "/"), ("precsrf", &precsrf), ], Some(&precsrf_cookie), ) .await; assert_eq!(res.status, 303, "login as {username}: {}", res.body()); cookie_named(&res, "forge_session").expect("session cookie after login") } async fn create_token(http: &Http, session: &str, name: &str) -> String { let page = http.get("/settings/keys", Some(session)).await; assert_eq!(page.status, 200, "GET /settings/keys"); let csrf = input_value(&page.body(), "csrf"); let res = http .post_form( "/settings/tokens", &[("csrf", &csrf), ("name", name), ("expires", "30")], Some(session), ) .await; assert_eq!(res.status, 200, "create token: {}", res.body()); let token = element_texts(&res.body(), "pre.code code") .into_iter() .next() .expect("token shown after creation"); let token = token.trim().to_owned(); assert!(token.starts_with("forge_"), "unexpected token shape"); token } async fn create_repo(http: &Http, session: &str, name: &str, visibility: &str) { let page = http.get("/new", Some(session)).await; assert_eq!(page.status, 200, "GET /new"); let csrf = input_value(&page.body(), "csrf"); let res = http .post_form( "/new", &[ ("csrf", &csrf), ("name", name), ("description", ""), ("visibility", visibility), ("default_branch", "main"), ], Some(session), ) .await; assert_eq!(res.status, 303, "create repo {name}: {}", res.body()); assert_eq!( res.header(LOCATION).as_deref(), Some(format!("/tahinli/{name}").as_str()) ); } fn assert_no_cookie(resp: &Resp, what: &str) { assert!( resp.set_cookies().is_empty(), "{what} must not set a cookie: {:?}", resp.set_cookies() ); } #[tokio::test] async fn browse_end_to_end() { if !tool_on_path("git") { eprintln!("SKIP browse_e2e: `git` was not found on PATH, so the browse test is skipped"); return; } let root = temp_dir("fbrw"); let (_server, ports) = boot_forge(root.path(), "", &[TAHINLI_CMD]).await; let dir = root.path().to_path_buf(); let http = Http::new(ports.http); let raw = Http::new(ports.content); let raw_base = raw.base.clone(); let tahinli = login(&http, "tahinli", PW).await; let token = create_token(&http, &tahinli, "browse-token").await; create_repo(&http, &tahinli, "pub", "public").await; create_repo(&http, &tahinli, "priv", "private").await; let pub_url = format!( "http://tahinli:{token}@127.0.0.1:{}/tahinli/pub.git", ports.http ); let priv_url = format!( "http://tahinli:{token}@127.0.0.1:{}/tahinli/priv.git", ports.http ); let pub_main = push_fixtures(&dir, &pub_url, &dir.join("pub-work")); push_fixtures(&dir, &priv_url, &dir.join("priv-work")); let pub_work = dir.join("pub-work"); ok( &git( &pub_work, &["checkout", "-q", "-b", "media", pub_main.as_str()], ), "create media branch", ); fs::write(pub_work.join("README.md"), "# On a media branch\n").expect("write media README"); commit_all(&pub_work, "media branch"); ok(&git(&pub_work, &["push", "origin", "media"]), "push media"); let home = http.get("/tahinli/pub", None).await; assert_eq!(home.status, 200, "anonymous home of public repo"); let csp = home .header(CONTENT_SECURITY_POLICY) .expect("CSP on app page"); let img_src = csp .split(';') .map(str::trim) .find(|d| d.starts_with("img-src")) .unwrap_or(""); assert!( img_src.contains(&raw_base), "app CSP img-src must include the raw origin: {csp}" ); let home_body = home.body(); assert!( element_texts(&home_body, "h1") .iter() .any(|t| t.contains("Browse Test")), "README heading missing on home" ); assert!( attr_values(&home_body, "a", "href") .iter() .any(|h| h == "/tahinli/pub/blob/main/src/main.rs"), "relative README link must point at the blob page" ); let image_srcs = attr_values(&home_body, "img", "src"); assert!( image_srcs .iter() .any(|s| s.starts_with(&format!("{raw_base}/tahinli/pub/main/")) && s.ends_with("img.png")), "README image must point at the raw origin: {image_srcs:?}" ); assert_latest_bar( &home_body, "repo home", "browse fixtures", &pub_main, "1 commit", ); let tree = http.get("/tahinli/pub/tree/main/src", None).await; assert_eq!(tree.status, 200, "tree of src"); assert!(tree.body().contains("main.rs"), "tree must list main.rs"); assert_latest_bar( &tree.body(), "tree of src", "browse fixtures", &pub_main, "1 commit", ); let blob = http.get("/tahinli/pub/blob/main/src/main.rs", None).await; assert_eq!(blob.status, 200, "blob of main.rs"); let blob_body = blob.body(); assert!(blob_body.contains("id=\"L1\""), "blob needs L1 anchors"); assert!( blob_body.contains("hl-"), "blob needs hl- highlight classes" ); let pointer = http.get("/tahinli/pub/blob/main/weights.bin", None).await; assert_eq!(pointer.status, 200, "blob of an LFS pointer"); assert!( pointer.body().contains("Stored with Git LFS ("), "pointer blob must say it is stored with Git LFS" ); assert!( pointer .body() .contains("this forge does not have the object"), "pointer without a stored object must say so" ); let commits = http.get("/tahinli/pub/commits/main", None).await; assert_eq!(commits.status, 200, "commits of main"); assert!( commits.body().contains("browse fixtures"), "commit list must show the commit" ); let commit = http .get(&format!("/tahinli/pub/commit/{pub_main}"), None) .await; assert_eq!(commit.status, 200, "commit page"); assert!( commit.body().contains("src/main.rs"), "commit page must show the diff of main.rs" ); let branches = http.get("/tahinli/pub/branches", None).await; assert_eq!(branches.status, 200, "branches"); assert!( branches.body().contains("feature/x"), "branches must list feature/x" ); let feature_head = String::from_utf8_lossy(&git(&pub_work, &["rev-parse", "feature/x"]).stdout) .trim() .to_owned(); let feature_tree = http.get("/tahinli/pub/tree/feature/x", None).await; assert_eq!(feature_tree.status, 200, "tree of feature/x"); assert!( feature_tree.body().contains("feature.txt"), "feature/x tree must list feature.txt" ); assert_latest_bar( &feature_tree.body(), "tree of feature/x", "feature commit", &feature_head, "2 commits", ); let archive = http.get("/tahinli/pub/archive/main.tar.gz", None).await; assert_eq!(archive.status, 200, "tar.gz archive"); assert!( archive.bytes.starts_with(&[0x1f, 0x8b]), "archive must start with gzip magic bytes" ); for path in [ "/tahinli/priv", "/tahinli/priv/tree/main/src", "/tahinli/priv/blob/main/src/main.rs", ] { let res = http.get(path, None).await; assert_eq!(res.status, 404, "anonymous {path} on private repo"); } let priv_img = http .get("/tahinli/priv/blob/main/img.png", Some(&tahinli)) .await; assert_eq!(priv_img.status, 200, "owner's blob page of img.png"); let priv_img_src = attr_values(&priv_img.body(), "img[src*=\"?token=\"]", "src") .into_iter() .next() .expect("img.png page must embed a raw URL with ?token="); assert!( priv_img_src.starts_with(&format!("{raw_base}/tahinli/priv/main/img.png?token=")), "signed raw URL shape: {priv_img_src}" ); let media = raw.get("/tahinli/pub/-/media/main/weights.bin", None).await; assert_eq!(media.status, 404, "media of an unstored LFS object"); let media_branch = raw.get("/tahinli/pub/media/README.md", None).await; assert_eq!( media_branch.status, 200, "raw README.md on the media branch" ); assert_eq!(media_branch.body(), "# On a media branch\n"); let dash = raw.get("/tahinli/pub/-/README.md", None).await; assert_eq!(dash.status, 404, "raw path with a `-` ref"); let main_rs = raw.get("/tahinli/pub/main/src/main.rs", None).await; assert_eq!(main_rs.status, 200, "raw public main.rs"); assert_eq!( main_rs.header(CONTENT_TYPE).as_deref(), Some("text/plain; charset=utf-8") ); assert_eq!( main_rs.header(X_CONTENT_TYPE_OPTIONS).as_deref(), Some("nosniff") ); let raw_csp = main_rs .header(CONTENT_SECURITY_POLICY) .expect("CSP on raw page"); assert!( raw_csp.contains("sandbox"), "raw CSP must sandbox: {raw_csp}" ); assert_no_cookie(&main_rs, "raw public main.rs"); let evil = raw.get("/tahinli/pub/main/evil.html", None).await; assert_eq!(evil.status, 200, "raw evil.html"); assert!( evil.header(CONTENT_DISPOSITION) .is_some_and(|v| v.starts_with("attachment")), "evil.html must be Content-Disposition: attachment" ); assert_no_cookie(&evil, "raw evil.html"); let img = raw.get("/tahinli/pub/main/img.png", None).await; assert_eq!(img.status, 200, "raw img.png"); assert_eq!(img.header(CONTENT_TYPE).as_deref(), Some("image/png")); assert_no_cookie(&img, "raw img.png"); let priv_no_token = raw.get("/tahinli/priv/main/img.png", None).await; assert_eq!(priv_no_token.status, 404, "private raw without token"); assert_no_cookie(&priv_no_token, "raw private without token"); let priv_path = priv_img_src .strip_prefix(&raw_base) .expect("raw base prefix"); let priv_ok = raw.get(priv_path, None).await; assert_eq!(priv_ok.status, 200, "private raw with the scraped token"); assert_no_cookie(&priv_ok, "raw private with token"); let (file_part, query) = priv_path.split_once("?token=").expect("token query"); let (expires, sig) = query.split_once('.').expect("token shape"); let flipped = if sig.starts_with('A') { 'B' } else { 'A' }; let tampered_sig = format!("{flipped}{}", &sig[1..]); let tampered = raw .get(&format!("{file_part}?token={expires}.{tampered_sig}"), None) .await; assert_eq!( tampered.status, 404, "tampered token must be rejected: the first base64 char carries six bits, so the flip always changes the signature" ); assert_no_cookie(&tampered, "raw tampered token"); let login_page = raw.get("/login", None).await; assert_eq!( login_page.status, 404, "/login must not exist on raw origin" ); assert_no_cookie(&login_page, "raw /login"); } async fn next_chunk(res: &mut reqwest::Response) -> Option { let chunk = tokio::time::timeout(Duration::from_secs(2), res.chunk()) .await .ok()? .expect("stream chunk")?; Some(String::from_utf8_lossy(&chunk).into_owned()) } #[tokio::test] async fn code_view_stream_follows_pushes() { if !tool_on_path("git") { eprintln!("SKIP browse_e2e: `git` was not found on PATH, so the stream test is skipped"); return; } let root = temp_dir("fliv"); let (_server, ports) = boot_forge(root.path(), "", &[TAHINLI_CMD]).await; let dir = root.path().to_path_buf(); let http = Http::new(ports.http); let tahinli = login(&http, "tahinli", PW).await; let token = create_token(&http, &tahinli, "live-token").await; create_repo(&http, &tahinli, "pub", "public").await; create_repo(&http, &tahinli, "priv", "private").await; let pub_url = format!( "http://tahinli:{token}@127.0.0.1:{}/tahinli/pub.git", ports.http ); let priv_url = format!( "http://tahinli:{token}@127.0.0.1:{}/tahinli/priv.git", ports.http ); let pub_main = push_fixtures(&dir, &pub_url, &dir.join("pub-live")); push_fixtures(&dir, &priv_url, &dir.join("priv-live")); let work = dir.join("pub-live"); let branch_page = http.get("/tahinli/pub/tree/main/", None).await; assert_eq!(branch_page.status, 200); assert!( branch_page .body() .contains(r#"data-live="/tahinli/pub/events?ref_name=main""#), "branch page follows main" ); let commit_page = http .get(&format!("/tahinli/pub/tree/{pub_main}/"), None) .await; assert_eq!(commit_page.status, 200); assert!( commit_page .body() .contains(r#"data-live="/tahinli/pub/events""#), "a commit page follows the repo header" ); assert!( !commit_page.body().contains("events?ref_name="), "a commit page does not follow a branch" ); let mut stream = http.stream("/tahinli/pub/events?ref_name=main", None).await; assert_eq!(stream.status().as_u16(), 200); assert_eq!( stream.headers().get(CONTENT_TYPE).unwrap(), "text/event-stream" ); ok( &git(&work, &["checkout", "-q", "feature/x"]), "checkout feature/x", ); fs::write(work.join("other.txt"), "other\n").expect("write other.txt"); commit_all(&work, "other branch commit"); ok( &git(&work, &["push", "-q", "origin", "feature/x"]), "push feature/x", ); assert!(next_chunk(&mut stream).await.is_none(), "other branch sent"); ok(&git(&work, &["checkout", "-q", "main"]), "checkout main"); fs::write(work.join("README.md"), "# Live\n\nChanged by a push.\n").expect("write README"); commit_all(&work, "change the README"); ok(&git(&work, &["push", "-q", "origin", "main"]), "push main"); let event = next_chunk(&mut stream).await.expect("event for main"); assert!(event.contains("event: changed"), "{event}"); ok( &git(&work, &["checkout", "-q", "-b", "topic"]), "create topic", ); ok( &git(&work, &["push", "-q", "origin", "topic"]), "push topic", ); let created = next_chunk(&mut stream) .await .expect("event for a new branch"); assert!(created.contains("event: changed"), "{created}"); ok( &git(&work, &["push", "-q", "origin", "--delete", "topic"]), "delete topic", ); let deleted = next_chunk(&mut stream) .await .expect("event for a deleted branch"); assert!(deleted.contains("event: changed"), "{deleted}"); let private = "/tahinli/priv/events?ref_name=main"; let anonymous = http.stream(private, None).await; assert_eq!( anonymous.status().as_u16(), 404, "private stream without a session" ); let member = http.stream(private, Some(tahinli.as_str())).await; assert_eq!( member.status().as_u16(), 200, "private stream for its owner" ); } async fn assert_changed(stream: &mut reqwest::Response, what: &str) { let event = next_chunk(stream) .await .unwrap_or_else(|| panic!("no event after {what}")); assert!(event.contains("event: changed"), "{what}: {event}"); } async fn post_redirect(http: &Http, path: &str, form: &[(&str, &str)], session: &str) { let res = http.post_form(path, form, Some(session)).await; assert_eq!(res.status, 303, "POST {path}: {}", res.body()); } #[tokio::test] async fn issue_streams_follow_writes() { if !tool_on_path("git") { eprintln!("SKIP browse_e2e: `git` was not found on PATH, so the stream test is skipped"); return; } let _root = temp_dir("filive"); let (_server, ports) = boot_forge(_root.path(), "", &[TAHINLI_CMD]).await; let http = Http::new(ports.http); let tahinli = login(&http, "tahinli", PW).await; create_repo(&http, &tahinli, "pub", "public").await; create_repo(&http, &tahinli, "priv", "private").await; let list_page = http.get("/tahinli/pub/issues", None).await; assert!( list_page .body() .contains(r#"data-live="/tahinli/pub/issues/live""#), "the list follows the repo" ); let mut list = http.stream("/tahinli/pub/issues/live", None).await; assert_eq!(list.status().as_u16(), 200); let new_page = http.get("/tahinli/pub/issues/new", Some(&tahinli)).await; let csrf = input_value(&new_page.body(), "csrf"); post_redirect( &http, "/tahinli/pub/issues/new", &[("csrf", &csrf), ("title", "First issue"), ("body", "Hello")], &tahinli, ) .await; assert_changed(&mut list, "creating an issue").await; let mut issue = http.stream("/tahinli/pub/issues/1/live", None).await; assert_eq!(issue.status().as_u16(), 200); let view = http.get("/tahinli/pub/issues/1", Some(&tahinli)).await; assert!( view.body() .contains(r#"data-live="/tahinli/pub/issues/1/live""#), "the issue page follows the issue" ); let target = input_value(&view.body(), "target_id"); type Write<'a> = (&'a str, &'a [(&'a str, &'a str)], &'a str); let writes: [Write; 8] = [ ( "/tahinli/pub/issues/1/comment", &[ ("csrf", &csrf), ("action", "comment"), ("body", "A comment"), ], "a comment", ), ( "/tahinli/pub/issues/1/edit", &[ ("csrf", &csrf), ("title", "First issue, edited"), ("body", "Hello again"), ], "an edit of the issue", ), ( "/tahinli/pub/issues/1/comment", &[("csrf", &csrf), ("action", "close_completed"), ("body", "")], "closing the issue", ), ( "/tahinli/pub/issues/1/comment", &[("csrf", &csrf), ("action", "reopen"), ("body", "")], "reopening the issue", ), ( "/tahinli/pub/issues/1/pin", &[("csrf", &csrf), ("pinned", "1")], "pinning the issue", ), ( "/tahinli/pub/issues/1/reactions", &[ ("csrf", &csrf), ("target_kind", "issue"), ("target_id", &target), ("reaction", "heart"), ], "a reaction", ), ( "/tahinli/pub/labels", &[("csrf", &csrf), ("name", "bug"), ("color", "#d73a4a")], "a new label", ), ( "/tahinli/pub/milestones", &[("csrf", &csrf), ("title", "v1")], "a new milestone", ), ]; for (path, form, what) in writes { post_redirect(&http, path, form, &tahinli).await; assert_changed(&mut list, what).await; assert_changed(&mut issue, what).await; } let anonymous = http.stream("/tahinli/priv/issues/live", None).await; assert_eq!( anonymous.status().as_u16(), 404, "private list without a session" ); let anonymous_issue = http.stream("/tahinli/priv/issues/1/live", None).await; assert_eq!( anonymous_issue.status().as_u16(), 404, "private issue without a session" ); let member = http .stream("/tahinli/priv/issues/live", Some(tahinli.as_str())) .await; assert_eq!(member.status().as_u16(), 200, "private list for its owner"); } #[tokio::test] async fn browsing_pages_stream_their_changes() { if !tool_on_path("git") { eprintln!("SKIP browse_e2e: `git` was not found on PATH, so the stream test is skipped"); return; } let root = temp_dir("flive"); let (_server, ports) = boot_forge(root.path(), "", &[TAHINLI_CMD]).await; let dir = root.path().to_path_buf(); let http = Http::new(ports.http); let tahinli = login(&http, "tahinli", PW).await; let token = create_token(&http, &tahinli, "live-pages-token").await; create_repo(&http, &tahinli, "pub", "public").await; let pub_url = format!( "http://tahinli:{token}@127.0.0.1:{}/tahinli/pub.git", ports.http ); let pushed = push_fixtures(&dir, &pub_url, &dir.join("pub-pages")); for path in [ "/notifications/events", "/notifications/events?all=1&user=tahinli", ] { let anonymous = http.stream(path, None).await; assert_eq!(anonymous.status().as_u16(), 401, "anonymous {path}"); } let inbox = http .stream("/notifications/events", Some(tahinli.as_str())) .await; assert_eq!(inbox.status().as_u16(), 200, "inbox stream for its owner"); let mut header = http.stream("/tahinli/pub/events", None).await; assert_eq!(header.status().as_u16(), 200); let page = http.get("/tahinli/pub", Some(&tahinli)).await; let csrf = input_value(&page.body(), "csrf"); let star = http .post_form("/tahinli/pub/star", &[("csrf", &csrf)], Some(&tahinli)) .await; assert_eq!(star.status, 303, "star: {}", star.body()); let event = next_chunk(&mut header).await.expect("event for a star"); assert!(event.contains("event: changed"), "{event}"); let shown = http.get("/tahinli/pub", None).await; assert!( shown.body().contains("\u{2605} 1"), "the header shows the star" ); let work = dir.join("pub-pages"); ok(&git(&work, &["checkout", "-q", "main"]), "checkout main"); fs::write(work.join("PUSH.txt"), "pushed again\n").expect("write PUSH.txt"); commit_all(&work, "a second push"); ok(&git(&work, &["push", "-q", "origin", "main"]), "push main"); assert_ne!(pushed, head_sha(&work), "the second push moved main"); let mut explore = http.stream("/explore/events", None).await; assert_eq!(explore.status().as_u16(), 200); create_repo(&http, &tahinli, "lib", "public").await; let listed = next_chunk(&mut explore) .await .expect("event for a new public repo"); assert!(listed.contains("event: changed"), "{listed}"); let mut profile = http.stream("/users/tahinli/events", None).await; assert_eq!(profile.status().as_u16(), 200); create_repo(&http, &tahinli, "tools", "public").await; let changed = next_chunk(&mut profile) .await .expect("event for a new repo of the profile"); assert!(changed.contains("event: changed"), "{changed}"); let missing = http.stream("/users/nobody/events", None).await; assert_eq!(missing.status().as_u16(), 404, "profile of an unknown user"); }