Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1f3beb5786 | ||
|
|
a9ea12651f |
No files matched your search
@@ -17,7 +17,7 @@ use crate::pipeline::csaf_match::{AdvisoryIndex, Wanted};
|
||||
use compliance_core::csaf_ingest::Advisory;
|
||||
use compliance_core::device_check::{DeviceCheck, DeviceLookup};
|
||||
use compliance_core::models::plc_device::normalised_order_number;
|
||||
use compliance_core::models::{PlcDevice, TargetDevice};
|
||||
use compliance_core::models::PlcDevice;
|
||||
use compliance_core::tenant_ctx::TenantCtx;
|
||||
|
||||
/// The provider whose advisories name devices by order number.
|
||||
@@ -44,14 +44,10 @@ async fn advisories_naming(
|
||||
}
|
||||
|
||||
/// Each of `devices` against `advisories`.
|
||||
/// An exported device keeps the export it comes from (#1090, #1097).
|
||||
fn checks(devices: Vec<TargetDevice>, advisories: &[Advisory]) -> Vec<DeviceCheck> {
|
||||
fn checks(devices: Vec<PlcDevice>, advisories: &[Advisory]) -> Vec<DeviceCheck> {
|
||||
devices
|
||||
.into_iter()
|
||||
.map(|d| DeviceCheck {
|
||||
exported_in: d.exported_in,
|
||||
..DeviceCheck::new(d.device, advisories)
|
||||
})
|
||||
.map(|device| DeviceCheck::new(device, advisories))
|
||||
.collect()
|
||||
}
|
||||
|
||||
@@ -85,13 +81,16 @@ pub async fn list_devices(
|
||||
.await
|
||||
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?
|
||||
.ok_or(StatusCode::NOT_FOUND)?;
|
||||
// Entered and exported alike (#1090, #1097): a TIA export's devices are
|
||||
// listed under their names in the project, saying which export they are
|
||||
// from, so a client edits only the entered ones.
|
||||
let target_devices = target.target_devices();
|
||||
// Entered and exported alike (#1090): a TIA export's devices are listed
|
||||
// under their names in the project.
|
||||
let target_devices: Vec<_> = target
|
||||
.target_devices()
|
||||
.into_iter()
|
||||
.map(|d| d.device)
|
||||
.collect();
|
||||
let mut order_numbers: Vec<String> = target_devices
|
||||
.iter()
|
||||
.map(|d| d.device.order_number.clone())
|
||||
.map(|d| d.order_number.clone())
|
||||
.collect();
|
||||
order_numbers.sort();
|
||||
order_numbers.dedup();
|
||||
@@ -205,15 +204,9 @@ mod tests {
|
||||
assert_eq!(advisories.len(), 1);
|
||||
let devices = checks(
|
||||
vec![
|
||||
PlcDevice::new("6ES7511-1AK02-0AB0", "3.1.4", None)
|
||||
.unwrap()
|
||||
.into(),
|
||||
PlcDevice::new("6ES7511-1AK02-0AB0", "3.1.5", None)
|
||||
.unwrap()
|
||||
.into(),
|
||||
PlcDevice::new("6ES7516-3AN02-0AB0", "3.0", None)
|
||||
.unwrap()
|
||||
.into(),
|
||||
PlcDevice::new("6ES7511-1AK02-0AB0", "3.1.4", None).unwrap(),
|
||||
PlcDevice::new("6ES7511-1AK02-0AB0", "3.1.5", None).unwrap(),
|
||||
PlcDevice::new("6ES7516-3AN02-0AB0", "3.0", None).unwrap(),
|
||||
],
|
||||
&advisories,
|
||||
);
|
||||
|
||||
@@ -125,7 +125,6 @@ pub async fn require_entitlement(
|
||||
// carry no tenant context here): the registry also says whether this
|
||||
// member is blocked in the tenant.
|
||||
let user = Some(ctx.user_id.as_str()).filter(|u| !u.is_empty());
|
||||
let open = open_when_not_entitled(&request);
|
||||
match registry.check_entitlement(&ctx.tenant_id, None, user).await {
|
||||
Ok(check) if check.allowed => {
|
||||
let mut ctx = ctx;
|
||||
@@ -138,15 +137,6 @@ pub async fn require_entitlement(
|
||||
request.extensions_mut().insert(ctx);
|
||||
next.run(request).await
|
||||
}
|
||||
// The registry knows the workspace but refuses it (expired, blocked):
|
||||
// its branding is still read, so the screen that says so keeps the
|
||||
// workspace's frame and logo. Read-only, and nothing else.
|
||||
Ok(_) if open => {
|
||||
let mut ctx = ctx;
|
||||
ctx.status = TenantStatus::Restricted;
|
||||
request.extensions_mut().insert(ctx);
|
||||
next.run(request).await
|
||||
}
|
||||
Ok(check) if check.member_blocked() => (
|
||||
StatusCode::FORBIDDEN,
|
||||
Json(serde_json::json!({
|
||||
@@ -176,17 +166,6 @@ pub async fn require_entitlement(
|
||||
}
|
||||
}
|
||||
|
||||
/// The routes a workspace the registry refuses still reads: its branding
|
||||
/// (#1087), so a lockout screen keeps its frame and logo. GET only; the
|
||||
/// acknowledgement and everything else stay refused.
|
||||
const OPEN_WHEN_NOT_ENTITLED: [&str; 2] = ["/api/v1/branding", "/api/v1/branding/logo"];
|
||||
|
||||
/// Whether `request` reads one of [`OPEN_WHEN_NOT_ENTITLED`].
|
||||
fn open_when_not_entitled(request: &Request) -> bool {
|
||||
request.method() == axum::http::Method::GET
|
||||
&& OPEN_WHEN_NOT_ENTITLED.contains(&request.uri().path())
|
||||
}
|
||||
|
||||
/// 503 when the registry cannot answer: access is never widened on doubt.
|
||||
fn entitlement_unavailable() -> Response {
|
||||
(
|
||||
|
||||
@@ -710,9 +710,6 @@ async fn a_tia_export_brings_its_devices_and_replaces_the_last_one() {
|
||||
let devices = body["data"].as_array().unwrap();
|
||||
assert_eq!(devices.len(), 1, "{body}");
|
||||
assert_eq!(devices[0]["label"], "PLC_1", "{body}");
|
||||
// It says which export it comes from, so the page saves and edits only
|
||||
// the devices entered with the target, never this one.
|
||||
assert_eq!(devices[0]["exported_in"], "linie1.tia-export.zip", "{body}");
|
||||
|
||||
server.cleanup().await;
|
||||
}
|
||||
@@ -34,13 +34,9 @@ async fn fake_registry(seen: Seen) -> String {
|
||||
"/v1/internal/entitlements/check",
|
||||
post(|State(seen): State<Seen>, Json(body): Json<serde_json::Value>| async move {
|
||||
let blocked = body["user_id"].as_str() == Some("u-blocked");
|
||||
let expired = body["user_id"].as_str() == Some("u-expired");
|
||||
seen.lock().unwrap().push(body);
|
||||
Json(if blocked {
|
||||
serde_json::json!({ "allowed": false, "status": "active", "reason": "member_blocked" })
|
||||
} else if expired {
|
||||
serde_json::json!({ "allowed": false, "status": "expired", "reason": "entitlement_expired",
|
||||
"branding": { "color": "#0082c9" } })
|
||||
} else {
|
||||
serde_json::json!({ "allowed": true, "status": "active" })
|
||||
})
|
||||
@@ -88,17 +84,6 @@ async fn agent(registry: &str) -> Option<Arc<ComplianceAgent>> {
|
||||
|
||||
/// GET /r as `ctx` through the entitlement middleware.
|
||||
async fn call(agent: Arc<ComplianceAgent>, ctx: TenantContext) -> (StatusCode, serde_json::Value) {
|
||||
call_at(agent, ctx, "GET", "/r").await
|
||||
}
|
||||
|
||||
/// `method` `path` as `ctx` through the entitlement middleware; every route
|
||||
/// answers "ok".
|
||||
async fn call_at(
|
||||
agent: Arc<ComplianceAgent>,
|
||||
ctx: TenantContext,
|
||||
method: &str,
|
||||
path: &str,
|
||||
) -> (StatusCode, serde_json::Value) {
|
||||
let inject = move |mut req: Request, next: Next| {
|
||||
let ctx = ctx.clone();
|
||||
async move {
|
||||
@@ -108,19 +93,10 @@ async fn call_at(
|
||||
};
|
||||
let app = Router::new()
|
||||
.route("/r", get(|| async { "ok" }))
|
||||
.route("/api/v1/branding", get(|| async { "ok" }))
|
||||
.route("/api/v1/branding/logo", get(|| async { "ok" }))
|
||||
.route("/api/v1/branding/ack", post(|| async { "ok" }))
|
||||
.layer(from_fn_with_state(agent, require_entitlement))
|
||||
.layer(from_fn(inject));
|
||||
let resp = app
|
||||
.oneshot(
|
||||
Request::builder()
|
||||
.method(method)
|
||||
.uri(path)
|
||||
.body(Body::empty())
|
||||
.unwrap(),
|
||||
)
|
||||
.oneshot(Request::builder().uri("/r").body(Body::empty()).unwrap())
|
||||
.await
|
||||
.unwrap();
|
||||
let status = resp.status();
|
||||
@@ -162,41 +138,6 @@ async fn a_blocked_member_is_refused_and_others_are_not() {
|
||||
assert_eq!(seen.lock().unwrap().len(), calls);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn a_refused_workspace_still_reads_its_branding_and_nothing_else() {
|
||||
let seen: Seen = Arc::default();
|
||||
let base = fake_registry(seen).await;
|
||||
let Some(agent) = agent(&base).await else {
|
||||
return;
|
||||
};
|
||||
// Its frame and logo, for the screen that says it is refused.
|
||||
for path in ["/api/v1/branding", "/api/v1/branding/logo"] {
|
||||
let (status, _) = call_at(agent.clone(), member("u-expired"), "GET", path).await;
|
||||
assert_eq!(status, StatusCode::OK, "{path}");
|
||||
}
|
||||
// Everything else, the acknowledgement included, stays refused.
|
||||
let (status, body) = call(agent.clone(), member("u-expired")).await;
|
||||
assert_eq!(status, StatusCode::FORBIDDEN);
|
||||
assert_eq!(body["error"], "not_entitled");
|
||||
let (status, _) = call_at(
|
||||
agent.clone(),
|
||||
member("u-expired"),
|
||||
"POST",
|
||||
"/api/v1/branding/ack",
|
||||
)
|
||||
.await;
|
||||
assert_eq!(status, StatusCode::FORBIDDEN);
|
||||
// A blocked member sees the frame too, and nothing else.
|
||||
let (status, _) = call_at(
|
||||
agent.clone(),
|
||||
member("u-blocked"),
|
||||
"GET",
|
||||
"/api/v1/branding",
|
||||
)
|
||||
.await;
|
||||
assert_eq!(status, StatusCode::OK);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn an_unreachable_registry_still_refuses_as_before() {
|
||||
// Not a block decision: the entitlement check itself fails closed when
|
||||
|
||||
@@ -114,10 +114,6 @@ pub struct DeviceCheck {
|
||||
pub product: Option<DeviceName>,
|
||||
/// The advisories naming it: affecting it first, then by severity.
|
||||
pub advisories: Vec<DeviceAdvisory>,
|
||||
/// The TIA export that declares it (its file name, #1090/#1097); none for
|
||||
/// a device entered with the target. Only an entered one is edited.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub exported_in: Option<String>,
|
||||
}
|
||||
|
||||
impl DeviceCheck {
|
||||
@@ -151,7 +147,6 @@ impl DeviceCheck {
|
||||
device,
|
||||
product,
|
||||
advisories: rows,
|
||||
exported_in: None,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9919,7 +9919,6 @@ div.offer-option { flex-direction: column; align-items: flex-start; justify-cont
|
||||
.dev-detail-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; align-items: flex-start; }
|
||||
.dev-detail-head > div:first-child { display: flex; flex-direction: column; gap: 4px; }
|
||||
.dev-detail-label { font-size: 14px; color: var(--text-tertiary); }
|
||||
.dev-detail-source { display: block; margin-top: 2px; }
|
||||
.dev-detail-actions { display: flex; gap: 8px; }
|
||||
.dev-detail-actions .btn { min-height: 44px; }
|
||||
.btn-danger-ghost { color: var(--danger); border-color: var(--danger-bg); }
|
||||
|
||||
@@ -9057,15 +9057,6 @@ pub mod devices {
|
||||
de: "Firmware",
|
||||
en: "Firmware",
|
||||
};
|
||||
/// Where an exported device comes from, instead of its edit buttons: it
|
||||
/// changes with the next export, not here.
|
||||
pub fn exported_from(file: &str, lang: Lang) -> String {
|
||||
match lang {
|
||||
Lang::De => format!("Aus dem TIA-Export {file}; ändert sich mit dem nächsten Export."),
|
||||
Lang::En => format!("From the TIA export {file}; changes with the next export."),
|
||||
}
|
||||
}
|
||||
|
||||
pub const CHANGE_FIRMWARE: Text = Text {
|
||||
de: "Firmware ändern",
|
||||
en: "Change firmware",
|
||||
|
||||
@@ -104,14 +104,7 @@ pub fn TargetDevicesPage(id: String) -> Element {
|
||||
}
|
||||
None => return rsx! { div { class: "loading", {tx::LOADING.get(lang)} } },
|
||||
};
|
||||
// The devices entered with the target: the only ones saved. Exported ones
|
||||
// (#1090, #1097) are listed after them and change with their export, so
|
||||
// a selected entered device has the same index in both lists.
|
||||
let devices: Vec<PlcDevice> = listed
|
||||
.iter()
|
||||
.filter(|c| c.exported_in.is_none())
|
||||
.map(|c| c.device.clone())
|
||||
.collect();
|
||||
let devices: Vec<PlcDevice> = listed.iter().map(|c| c.device.clone()).collect();
|
||||
// A first device is added from the empty rail's form.
|
||||
let show_form = can_write && (adding() || listed.is_empty());
|
||||
let chosen = (!show_form)
|
||||
@@ -369,11 +362,8 @@ fn DeviceDetail(
|
||||
div {
|
||||
h2 { "{name}" }
|
||||
span { class: "dev-detail-label", "{label}" }
|
||||
if let Some(file) = &check.exported_in {
|
||||
span { class: "dev-detail-label dev-detail-source", {tx::exported_from(file, lang)} }
|
||||
}
|
||||
}
|
||||
if can_write && check.exported_in.is_none() {
|
||||
if can_write {
|
||||
div { class: "dev-detail-actions",
|
||||
if !editing() {
|
||||
button {
|
||||
|
||||
Reference in new issue
Block a user