feat: readable download names and PUT /capture-profiles/:id

- downloads are named <orbit>_<time>_<engine>_<id8>.<ext> (schedule zone or UTC), orbit names are
  reduced to [a-z0-9_-], and the header carries filename and filename*
- operators can change a profile's schedule and retention (absent = keep, null = clear), validated
  like registration, audited, and a changed schedule never replays slots that already passed

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-15 12:19:32 +07:00
parent 1bff2ab234
commit fb277249f7
11 changed files with 602 additions and 10 deletions

View File

@@ -1395,3 +1395,126 @@ async fn someone_who_may_only_refresh_gets_into_the_app_but_sees_nothing_else()
StatusCode::OK
);
}
// ---- capture profile updates (shares this file's lab: a real profile with a real Outpost)
#[tokio::test]
async fn an_operator_can_change_a_profiles_schedule_and_retention_and_nothing_else() {
let lab = fresh().await;
let admin = lab.admin();
let uri = format!("/api/v1/capture-profiles/{}", lab.application);
let (status, profile) = lab
.send(
&admin,
"PUT",
&uri,
Some(json!({"schedule": {"hour": 2, "minute": 30, "timezone": "Asia/Jakarta"}, "retention": {"mode": "count"}})),
)
.await;
assert_eq!(status, StatusCode::OK, "{profile}");
assert_eq!(profile["schedule"]["minute"], 30);
assert_eq!(profile["application_id"], lab.application.to_string());
let (_, listed) = lab
.send(&admin, "GET", "/api/v1/capture-profiles", None)
.await;
assert_eq!(listed[0]["schedule"]["hour"], 2);
// null clears the schedule; the retention override stays because it was not mentioned
let (status, profile) = lab
.send(&admin, "PUT", &uri, Some(json!({"schedule": null})))
.await;
assert_eq!(status, StatusCode::OK);
assert!(
profile["schedule"].is_null() && !profile["retention"].is_null(),
"{profile}"
);
let audited = lab.state.db.audit_log_events();
assert!(
audited
.iter()
.any(|(event, detail)| event == "capture.profile_updated"
&& detail.contains(&lab.application.to_string())),
"{audited:?}"
);
}
#[tokio::test]
async fn a_profile_update_is_validated_like_a_registration() {
let lab = fresh().await;
let admin = lab.admin();
let uri = format!("/api/v1/capture-profiles/{}", lab.application);
for (body, expected) in [
(
json!({"schedule": {"hour": 24, "minute": 0, "timezone": "Asia/Jakarta"}}),
StatusCode::BAD_REQUEST,
),
(
json!({"schedule": {"hour": 2, "minute": 0, "timezone": "Mars/Olympus"}}),
StatusCode::BAD_REQUEST,
),
(
json!({"retention": {"mode": "count", "keep": 0}}),
StatusCode::BAD_REQUEST,
),
// identity and wiring are not editable here
(
json!({"format": "postgres_sql"}),
StatusCode::UNPROCESSABLE_ENTITY,
),
(
json!({"outpost_id": Uuid::new_v4()}),
StatusCode::UNPROCESSABLE_ENTITY,
),
] {
assert_eq!(
lab.send(&admin, "PUT", &uri, Some(body.clone())).await.0,
expected,
"{body}"
);
}
let unknown = format!("/api/v1/capture-profiles/{}", Uuid::new_v4());
assert_eq!(
lab.send(&admin, "PUT", &unknown, Some(json!({"schedule": null})))
.await
.0,
StatusCode::NOT_FOUND
);
// nothing above changed the profile
let (_, listed) = lab
.send(&admin, "GET", "/api/v1/capture-profiles", None)
.await;
assert!(listed[0]["schedule"].is_null());
}
#[tokio::test]
async fn only_an_administrator_can_change_a_profile() {
let lab = fresh().await;
let (qa, _) = lab.refresher("qa");
let stranger = lab.person("stranger");
let uri = format!("/api/v1/capture-profiles/{}", lab.application);
for caller in [&qa, &stranger] {
let status = lab
.send(caller, "PUT", &uri, Some(json!({"schedule": null})))
.await
.0;
assert!(
status == StatusCode::FORBIDDEN || status == StatusCode::NOT_FOUND,
"{status}"
);
}
assert_eq!(
lab.send(
&Caller {
cookie: None,
csrf: None,
admin_token: false,
user_id: None
},
"PUT",
&uri,
Some(json!({"schedule": null}))
)
.await
.0,
StatusCode::UNAUTHORIZED
);
}