Files
Dennis Nemec 6134a47ff2
Some checks failed
CI / backend (push) Has been cancelled
CI / frontend (push) Has been cancelled
CI / ui (push) Has been cancelled
WP-30/31/32: backup targets, strategies and execution
SMB (smbclient) and FTP/FTPS (curl with netrc) targets with encrypted
credentials and connection test; strategies with cron schedule, retention,
optional openssl AES-256 encryption; sources: PVC hostpath tar, pg_dumpall
in the Postgres pod, namespace manifests, host directory. Backup job
collects, encrypts, uploads, verifies size, records sha256 and applies
retention on the target; scheduler starts due strategies. Backups page
with target/strategy forms, run now and history. Restore guide in docs.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-02 23:15:38 +02:00

110 lines
3.4 KiB
Rust

//! WP-02: /api/jobs (run history, manual run).
mod common;
use axum::http::StatusCode;
use common::{get, post, test_app_with_admin};
use serde_json::json;
const ADMIN: &str = "admin@example.com";
const PW: &str = "admin-password-123";
#[tokio::test]
async fn admin_runs_a_job_and_sees_it_in_the_list_with_log() {
let app = test_app_with_admin().await;
let token = common::login(&app, ADMIN, PW).await.access;
let res = post(
&app,
"/api/jobs/run",
json!({"kind": "package_refresh"}),
Some(&token),
)
.await;
assert_eq!(res.status, StatusCode::ACCEPTED, "{}", res.json);
let id = res.json["id"].as_str().unwrap().to_string();
assert_eq!(res.json["kind"], "package_refresh");
assert_eq!(res.json["triggered_by"], ADMIN);
// the test handler finishes quickly
let mut status = String::new();
for _ in 0..50 {
let run = get(&app, &format!("/api/jobs/{id}"), Some(&token)).await;
status = run.json["status"].as_str().unwrap().to_string();
if status != "running" {
assert!(run.json["log"].as_str().unwrap().contains("packages"));
break;
}
tokio::time::sleep(std::time::Duration::from_millis(20)).await;
}
assert_eq!(status, "success");
let list = get(&app, "/api/jobs?limit=10", Some(&token)).await;
assert_eq!(list.json.as_array().unwrap().len(), 1);
let kinds = get(&app, "/api/jobs/kinds", Some(&token)).await;
assert!(kinds
.json
.as_array()
.unwrap()
.contains(&json!("package_refresh")));
}
#[tokio::test]
async fn unknown_kind_is_404_and_run_is_admin_only() {
let app = test_app_with_admin().await;
let admin = common::login(&app, ADMIN, PW).await.access;
assert_eq!(
post(&app, "/api/jobs/run", json!({"kind": "nope"}), Some(&admin))
.await
.status,
StatusCode::UNPROCESSABLE_ENTITY
);
// every kind has a handler now; a backup without a strategy id starts and then fails
let run = post(
&app,
"/api/jobs/run",
json!({"kind": "backup"}),
Some(&admin),
)
.await;
assert_eq!(run.status, StatusCode::ACCEPTED);
let id = run.json["id"].as_str().unwrap().to_string();
for _ in 0..50 {
let r = get(&app, &format!("/api/jobs/{id}"), Some(&admin)).await;
if r.json["status"] != "running" {
assert_eq!(r.json["status"], "failed");
assert!(r.json["log"].as_str().unwrap().contains("strategy id"));
break;
}
tokio::time::sleep(std::time::Duration::from_millis(20)).await;
}
post(&app, "/api/users", json!({"email": "u@x.de", "display_name": "U", "password": "user-password-123", "role": "user"}), Some(&admin)).await;
let user = common::login(&app, "u@x.de", "user-password-123")
.await
.access;
assert_eq!(
post(
&app,
"/api/jobs/run",
json!({"kind": "package_refresh"}),
Some(&user)
)
.await
.status,
StatusCode::FORBIDDEN
);
assert_eq!(
get(&app, "/api/jobs", Some(&user)).await.status,
StatusCode::OK
);
assert_eq!(
get(
&app,
"/api/jobs/00000000-0000-0000-0000-000000000000",
Some(&user)
)
.await
.status,
StatusCode::NOT_FOUND
);
}