filter certs with one trust
@@ -244,6 +244,9 @@ impl TrustGraph {
auths.iter().map(|auth| auth.trust.clone()).rev().collect();
Certificate::new_unverified(trusts)
})
+ // Certificates with one trust could appear if a trust will be issued from one root to another.
+ // But certificate with one trust doesn't make sense, so filter such certificates
+ .filter(|c| c.chain.len() > 1)
.collect(),
None => Vec::new(),
}
@@ -507,6 +510,28 @@ mod tests {
assert_eq!(certs[0], cert);
}
+ #[test]
+ fn test_chain_from_root_to_another_root() {
+ use std::str::FromStr;
+ let c = Certificate::from_str("11\n1111\nCt8ewXqEzSUvLR9CVtW39tHEDu3iBRsj21DzBZMc8LB4\n3PjbNp21wtJ91fKdMRnqx9mj5t3gGw2KMz3NfsjLknxF3zXPePWwD3hqw4szCBj2GGhjEK5tEw3MArVye2VBp1Si\n158981172690500\n1593768779352\n6aYjUmaYTgZpPefm3aEZXxaHrk72ujErEBFCJxp9uv8H\n3APg4AisAaUUzdp9QcsmxQde8V8Ft4GhzCzT6GJrSj5tjiwRmA4t8qrWDxyYEiJi2ym6qRdrew9awSnsz1xxZuid\n1593855179352\n1593768779352\n9mw5qRU2ty78iLDz45JETdiVPr89hAASRtmxS7wrLaZF\nqPbY4qpgMS77kdmDrdKD4TQMVUo4g4uqGGwm3s5EA4DTBhDofZQfBxTQsu1LgXqVwUBXfDz8mTTCuNopRPwQH7m\n1596448844131\n1593770444131").unwrap();
+
+ let mut graph = TrustGraph::default();
+ // add first and last trusts as roots
+ graph
+ .root_weights
+ .insert(c.chain[0].clone().issued_for.into(), 1);
+ graph
+ .root_weights
+ .insert(c.chain[2].clone().issued_for.into(), 1);
+
+ graph.add(c.clone(), current_time()).unwrap();
+
+ let t = c.chain[2].clone();
+ let certs = graph.get_all_certs(t.issued_for, &[]);
+
+ assert_eq!(certs.len(), 1);
+ }
+
#[test]
fn test_find_certs() {
let key_pair1 = KeyPair::generate();
