Fit larger Linux package inventories within bounded snapshots
Rust development slice / linux (push) Failing after 8s
Rust development slice / linux (push) Failing after 8s
This commit is contained in:
@@ -4,6 +4,7 @@ use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
|
||||
pub const SOFTWARE_OBSERVATION_MAX_BYTES: usize = 128 * 1024;
|
||||
pub const LINUX_SOFTWARE_OBSERVATION_MAX_BYTES: usize = 256 * 1024;
|
||||
|
||||
pub fn firmware_identifier(value: &str) -> Option<String> {
|
||||
let value = value.trim_matches(|c: char| c == '\0' || c.is_whitespace());
|
||||
@@ -167,8 +168,8 @@ pub fn validate_for_scope(
|
||||
let mut scopes = std::collections::BTreeSet::new();
|
||||
for item in observations {
|
||||
let max_bytes = match (scope, item["scope"].as_str()) {
|
||||
("linux.base", Some("linux.software")) | ("windows.base", Some("windows.software")) =>
|
||||
SOFTWARE_OBSERVATION_MAX_BYTES,
|
||||
("linux.base", Some("linux.software")) => LINUX_SOFTWARE_OBSERVATION_MAX_BYTES,
|
||||
("windows.base", Some("windows.software")) => SOFTWARE_OBSERVATION_MAX_BYTES,
|
||||
_ => 32768,
|
||||
};
|
||||
if serde_json::to_vec(item)
|
||||
@@ -269,6 +270,23 @@ mod tests {
|
||||
assert!(validate(&serde_json::to_vec(&unknown).unwrap(), now).is_err());
|
||||
}
|
||||
#[test]
|
||||
fn larger_linux_package_lists_fit_the_software_scope() {
|
||||
let now = Utc::now();
|
||||
let mut v = base();
|
||||
let package = json!({"name":"some-package","version":"1.0","architecture":"amd64"});
|
||||
v["collection_started_at"] = json!(now);
|
||||
v["collection_completed_at"] = json!(now);
|
||||
v["observations"] = json!([{"scope":"linux.software","source_id":"dpkg-query","observed_at":now,"quality":"valid","completeness":"complete","truncated":false,"error_code":null,"data":vec![package; 2200]}]);
|
||||
let bytes = serde_json::to_vec(&v).unwrap();
|
||||
assert!(bytes.len() > SOFTWARE_OBSERVATION_MAX_BYTES);
|
||||
assert!(validate(&bytes, now).is_ok());
|
||||
v["observations"][0]["scope"] = json!("linux.hardware");
|
||||
assert_eq!(
|
||||
validate(&serde_json::to_vec(&v).unwrap(), now).unwrap_err(),
|
||||
"OBSERVATION_SIZE"
|
||||
);
|
||||
}
|
||||
#[test]
|
||||
fn windows_scope_does_not_weaken_linux_or_accept_platform_spoofing() {
|
||||
let now = Utc::now();
|
||||
let mut v = base();
|
||||
|
||||
Reference in New Issue
Block a user