Add tests for invalid negative reports
This commit is contained in:
parent
fae8a9a74f
commit
684ba0a575
|
@ -57,7 +57,10 @@ mod tests {
|
|||
};
|
||||
use troll_patrol::{
|
||||
bridge_verification_info::BridgeVerificationInfo,
|
||||
negative_report::{NegativeReport, SerializableNegativeReport},
|
||||
negative_report::{
|
||||
HashOfBridgeLine, HashOfBucket, NegativeReport, ProofOfBridgeKnowledge,
|
||||
SerializableNegativeReport,
|
||||
},
|
||||
positive_report::{PositiveReport, SerializablePositiveReport},
|
||||
BridgeDistributor,
|
||||
};
|
||||
|
@ -306,33 +309,75 @@ mod tests {
|
|||
|
||||
let report_1 =
|
||||
NegativeReport::from_bridgeline(bridges[0], "ru".to_string(), BridgeDistributor::Lox);
|
||||
println!(
|
||||
"report_1: {}, count: {}",
|
||||
array_bytes::bytes2hex("", report_1.fingerprint),
|
||||
num_report_1
|
||||
);
|
||||
reports.insert(report_1.to_json(), num_report_1);
|
||||
|
||||
let report_2 =
|
||||
NegativeReport::from_lox_bucket(bridges[1].fingerprint, cred.bucket, "ru".to_string());
|
||||
println!(
|
||||
"report_2: {}, count: {}",
|
||||
array_bytes::bytes2hex("", report_2.fingerprint),
|
||||
num_report_2
|
||||
);
|
||||
reports.insert(report_2.to_json(), num_report_2);
|
||||
|
||||
let report_3 =
|
||||
NegativeReport::from_lox_credential(bridges[2].fingerprint, cred, "ru".to_string());
|
||||
println!(
|
||||
"report_3: {}, count: {}",
|
||||
array_bytes::bytes2hex("", report_3.fingerprint),
|
||||
num_report_3
|
||||
);
|
||||
reports.insert(report_3.to_json(), num_report_3);
|
||||
|
||||
// TODO: Check reports with invalid fields
|
||||
// TODO: Check well-formed reports with incorrect bridge data
|
||||
// Check that reports with invalid fields are not counted
|
||||
let num_invalid_report_1 = rng.next_u32() % 4 + 1;
|
||||
let num_invalid_report_2 = rng.next_u32() % 4 + 1;
|
||||
|
||||
// Date in the future
|
||||
let mut invalid_report_1 =
|
||||
NegativeReport::from_bridgeline(bridges[0], "ru".to_string(), BridgeDistributor::Lox)
|
||||
.to_serializable_report();
|
||||
invalid_report_1.date = invalid_report_1.date + 2;
|
||||
reports.insert(
|
||||
serde_json::to_string(&invalid_report_1).unwrap(),
|
||||
num_invalid_report_1,
|
||||
);
|
||||
|
||||
// Invalid country code
|
||||
let mut invalid_report_2 =
|
||||
NegativeReport::from_bridgeline(bridges[1], "ru".to_string(), BridgeDistributor::Lox)
|
||||
.to_serializable_report();
|
||||
invalid_report_2.country = "xx".to_string();
|
||||
reports.insert(
|
||||
serde_json::to_string(&invalid_report_2).unwrap(),
|
||||
num_invalid_report_2,
|
||||
);
|
||||
|
||||
// Check that well-formed reports with incorrect bridge data are not counted
|
||||
let num_invalid_report_3 = rng.next_u32() % 4 + 1;
|
||||
let num_invalid_report_4 = rng.next_u32() % 4 + 1;
|
||||
let num_invalid_report_5 = rng.next_u32() % 4 + 1;
|
||||
|
||||
let mut hasher = Sha1::new();
|
||||
hasher.update([0; 20]);
|
||||
let empty_bridgeline_fingerprint: [u8; 20] = hasher.finalize().into();
|
||||
|
||||
// Unknown bridge fingerprint
|
||||
let mut invalid_report_3 =
|
||||
NegativeReport::from_bridgeline(bridges[2], "ru".to_string(), BridgeDistributor::Lox);
|
||||
invalid_report_3.fingerprint = empty_bridgeline_fingerprint;
|
||||
reports.insert(invalid_report_3.to_json(), num_invalid_report_3);
|
||||
|
||||
// Incorrect BridgeLine hash
|
||||
let mut invalid_report_4 = NegativeReport::new(
|
||||
bridges[0].fingerprint,
|
||||
ProofOfBridgeKnowledge::HashOfBridgeLine(HashOfBridgeLine::new(&BridgeLine::default())),
|
||||
"ru".to_string(),
|
||||
BridgeDistributor::Lox,
|
||||
);
|
||||
reports.insert(invalid_report_4.to_json(), num_invalid_report_4);
|
||||
|
||||
// Incorrect bucket hash
|
||||
let invalid_report_5 = NegativeReport::new(
|
||||
bridges[1].fingerprint,
|
||||
ProofOfBridgeKnowledge::HashOfBucket(HashOfBucket::new(&Scalar::ZERO)),
|
||||
"ru".to_string(),
|
||||
BridgeDistributor::Lox,
|
||||
);
|
||||
reports.insert(invalid_report_5.to_json(), num_invalid_report_5);
|
||||
|
||||
// Ensure each negative report is distinct and added successfully
|
||||
assert_eq!(reports.keys().len(), 8);
|
||||
|
||||
let request = tpc.verifynegative(reports);
|
||||
let response = handle(th.context.clone(), &mut Htables, request)
|
||||
|
|
Loading…
Reference in New Issue