From: Ian Jackson Date: Mon, 3 May 2021 22:02:09 +0000 (+0100) Subject: bundles: Check that download link works X-Git-Tag: otter-0.6.0~395 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=e4ddbd8ef284349db8004087ff67bf6b8cc90f96;p=otter.git bundles: Check that download link works Signed-off-by: Ian Jackson --- diff --git a/apitest/apitest.rs b/apitest/apitest.rs index a71c24c0..e16d879a 100644 --- a/apitest/apitest.rs +++ b/apitest/apitest.rs @@ -19,6 +19,7 @@ pub use std::cell::{RefCell, RefMut}; pub use num_traits::NumCast; pub use serde_json::json; pub use structopt::StructOpt; +pub use reqwest; pub type JsV = serde_json::Value; pub type MC = MgmtCommand; diff --git a/wdriver/wdt-bundles.rs b/wdriver/wdt-bundles.rs index 48503561..9c4a0a36 100644 --- a/wdriver/wdt-bundles.rs +++ b/wdriver/wdt-bundles.rs @@ -23,6 +23,10 @@ fn tests(UsualSetup { su, alice, ..}: UsualSetup) { test!(c, "bundle", { let test_bundle = c.su.ds.example_bundle(); + let hash_exp = bundles::DigestWrite::of( + &mut File::open(&test_bundle).unwrap() + )?; + c.otter(&["upload-bundle"],&[&test_bundle])?; let mut w = c.su.w(&c.alice)?; @@ -32,6 +36,17 @@ fn tests(UsualSetup { su, alice, ..}: UsualSetup) { let bundle_id = bundle_link.find_element(By::ClassName("b_id"))?; let html = bundle_id.inner_html()?; assert_eq!(&html, "00000.zip"); + + let download = dbgc!(bundle_link.get_attribute("href")?).unwrap(); + let client = reqwest::blocking::Client::new(); + let download = Url::parse(&w.current_url()?)?.join(&download)?; + let mut resp = client.get(download).send()?; + let st = resp.status(); + assert!(st.is_success(), "{:?}", &st); + let mut digester = bundles::DigestWrite::sink(); + resp.copy_to(&mut digester)?; + let got = digester.finish().0; + assert_eq!(got, hash_exp); }); check(&mut w)?;