message: rpm-ostree: improve input validation
  This adds some more input validation on input releases/nodes coming
  from the Cincinnati server, with relevant tests too.
diff: @@ -22,6 +22,8 @@ pub struct Release {
  impl Release {
  /// Builds a `Release` object from a Cincinnati node.
  pub fn from_cincinnati(node: Node) -> Fallible<Self> {
  + ensure!(!node.version.is_empty(), "empty version field");
  + ensure!(!node.payload.is_empty(), "empty payload field (checksum)");
  let scheme = node
  .metadata
  .get(SCHEME_KEY)
  @@ -40,3 +42,49 @@ impl Release {
  Ok(rel)
  }
  }
  +
  +#[cfg(test)]
  +mod tests {
  + use super::*;
  + use maplit::hashmap;
  +
  + #[test]
  + fn release_from_cincinnati() {
  + let input = Node {
  + version: "mock-version".to_string(),
  + payload: "mock-payload".to_string(),
  + metadata: hashmap! {
  + SCHEME_KEY.to_string() => CHECKSUM_SCHEME.to_string(),
  + },
  + };
  + Release::from_cincinnati(input).unwrap();
  + }
  +
  + #[test]
  + fn invalid_node() {
  + let node1 = Node {
  + version: "".to_string(),
  + payload: "mock-payload".to_string(),
  + metadata: hashmap! {
  + SCHEME_KEY.to_string() => CHECKSUM_SCHEME.to_string(),
  + },
  + };
  + Release::from_cincinnati(node1).unwrap_err();
  +
  + let node2 = Node {
  + version: "mock-version".to_string(),
  + payload: "".to_string(),
  + metadata: hashmap! {
  + SCHEME_KEY.to_string() => CHECKSUM_SCHEME.to_string(),
  + },
  + };
  + Release::from_cincinnati(node2).unwrap_err();
  +
  + let node3 = Node {
  + version: "mock-version".to_string(),
  + payload: "mock-payload".to_string(),
  + metadata: hashmap! {},
  + };
  + Release::from_cincinnati(node3).unwrap_err();
  + }
  +}
  