//! OTA release publishing. // ── The publisher's sequence ── // // Four authenticated calls in a fixed order (create, register, upload, confirm) // plus one public check. Each writes to a URL the SDK builds itself out of the // session's app id and the release id the server handed back, so the exact path // is the contract: a release created at the wrong URL is a 404 the publisher // only finds out about at release time. use crate::common::*; use uuid::Uuid; const APP: &str = "6ba7b810-9dad-11d1-80b4-00c04fd430c8"; const RELEASE: &str = "11111111-2222-3333-4444-555555555555"; fn release_id() -> Uuid { Uuid::parse_str(RELEASE).unwrap() } fn releases_path() -> String { format!("/api/v1/sync/ota/apps/{APP}/releases") } fn artifacts_path() -> String { format!("{}/{RELEASE}/artifacts", releases_path()) } fn confirm_path() -> String { format!("{}/confirm", artifacts_path()) } #[tokio::test] async fn create_release_posts_to_the_app_releases_url() { let kit = MockKit::start().await; let client = kit.authed(); kit.post(&releases_path()) .json(json!({ "id": RELEASE, "version": "0.4.1", "notes": "Bug fixes", })) .await; let release = client .ota_create_release("0.4.1", "Bug fixes") .await .unwrap(); assert_eq!(release.id, release_id()); assert_eq!(release.version, "0.4.1"); assert_eq!(release.notes, "Bug fixes"); // The app id comes from the session, not from the caller, so the path is // the only place a wrong session would show. assert_eq!(kit.hits(&releases_path()).await, 1); let body = kit.body(&releases_path()).await; assert_eq!(body["version"], "0.4.1"); assert_eq!(body["notes"], "Bug fixes"); let req = &kit.requests_to(&releases_path()).await[0]; assert!( req.headers .get("authorization") .expect("the publisher call is authenticated") .to_str() .unwrap() .starts_with("Bearer "), ); } #[tokio::test] async fn register_artifact_posts_under_its_release_and_returns_the_upload_target() { let kit = MockKit::start().await; let client = kit.authed(); kit.post(&artifacts_path()) .json(json!({ "upload_url": "https://s3.example/put?sig=abc", "s3_key": "ota/app/0.4.1/darwin/aarch64/artifact", })) .await; let upload = client .ota_register_artifact(release_id(), "darwin", "aarch64", 12_345, "RWS...==") .await .unwrap(); assert_eq!(upload.upload_url, "https://s3.example/put?sig=abc"); assert_eq!(upload.s3_key, "ota/app/0.4.1/darwin/aarch64/artifact"); assert_eq!(kit.hits(&artifacts_path()).await, 1); let body = kit.body(&artifacts_path()).await; assert_eq!(body["target"], "darwin"); assert_eq!(body["arch"], "aarch64"); assert_eq!(body["file_size"], 12_345); assert_eq!(body["signature"], "RWS...=="); } #[tokio::test] async fn confirm_artifact_posts_to_the_confirm_url_under_its_release() { let kit = MockKit::start().await; let client = kit.authed(); // Both routes are mounted so a confirm that went to the register URL would // still get a 200 and be caught by the hit counts rather than by an error. kit.post(&artifacts_path()).json(json!({})).await; kit.post(&confirm_path()).code(204).empty().await; client .ota_confirm_artifact(release_id(), "linux", "x86_64") .await .unwrap(); assert_eq!(kit.hits(&confirm_path()).await, 1); assert_eq!(kit.hits(&artifacts_path()).await, 0); let body = kit.body(&confirm_path()).await; assert_eq!(body["target"], "linux"); assert_eq!(body["arch"], "x86_64"); } #[tokio::test] async fn upload_artifact_puts_the_bytes_unencrypted_to_the_presigned_url() { let kit = MockKit::start().await; let client = kit.authed(); const PRESIGNED: &str = "/s3/ota-artifact"; kit.put(PRESIGNED).code(200).empty().await; let bytes = b"a tauri bundle, signed elsewhere".to_vec(); client .ota_upload_artifact(&kit.url(PRESIGNED), bytes.clone()) .await .unwrap(); let req = &kit.requests_to(PRESIGNED).await[0]; // OTA artifacts are public downloads, so the bytes go up as they are: an // encrypted one would fail Tauri's signature check on every installed app. assert_eq!(req.body, bytes); assert_eq!( req.headers.get("content-type").unwrap().to_str().unwrap(), "application/octet-stream" ); } #[tokio::test] async fn updater_check_reads_the_public_slug_url_and_maps_204_to_no_update() { let kit = MockKit::start().await; let client = kit.client(); let up_to_date = "/api/v1/sync/ota/goingson/darwin/aarch64/0.4.1"; let behind = "/api/v1/sync/ota/goingson/darwin/aarch64/0.4.0"; kit.get(up_to_date).code(204).empty().await; kit.get(behind) .json(json!({ "version": "0.4.1", "url": "https://makenot.work/api/v1/sync/ota/download/abc", "signature": "RWS=", "notes": "Bug fixes", "pub_date": "2026-06-07T00:00:00+00:00", })) .await; // The updater endpoint is unauthenticated, so this runs on a client with no // session at all: the version in the path is what selects the answer. let manifest = client .ota_updater_check("goingson", "darwin", "aarch64", "0.4.0") .await .unwrap() .expect("a newer version is offered"); assert_eq!(manifest.version, "0.4.1"); assert_eq!(manifest.signature, "RWS="); assert_eq!(manifest.notes, "Bug fixes"); assert_eq!(manifest.pub_date, "2026-06-07T00:00:00+00:00"); assert!( client .ota_updater_check("goingson", "darwin", "aarch64", "0.4.1") .await .unwrap() .is_none(), "204 means the caller is current" ); assert_eq!(kit.hits(behind).await, 1); assert_eq!(kit.hits(up_to_date).await, 1); } #[tokio::test] async fn a_publisher_call_without_a_session_never_reaches_the_wire() { let kit = MockKit::start().await; let client = kit.client(); kit.post(&releases_path()).json(json!({})).await; let err = client.ota_create_release("0.4.1", "").await.unwrap_err(); assert!(matches!(err, SyncKitError::NotAuthenticated), "got {err:?}"); assert_eq!( kit.requests().await.len(), 0, "the session check happens before the URL is built" ); }