Skip to content

Commit

Permalink
Add test and fix bug when querying and using bad hash on .has()
Browse files Browse the repository at this point in the history
  • Loading branch information
allada committed Dec 27, 2020
1 parent 42d4c8d commit 9adbe81
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
7 changes: 4 additions & 3 deletions cas/grpc_service/cas_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ impl ContentAddressableStorage for CasServer {
missing_blob_digests: vec![],
};
for digest in request_data.blob_digests.into_iter() {
// BUG!!!!
if !self.store.has(&digest.hash, digest.hash.len()).await? {
response.missing_blob_digests.push(digest);
let result_status = self.store.has(&digest.hash, digest.hash.len()).await;
if !result_status.unwrap_or(false) {
// TODO(allada) We should log somewhere in the event result_status.is_err() (like bad hash).
response.missing_blob_digests.push(digest.clone());
}
}
Ok(Response::new(response))
Expand Down
37 changes: 37 additions & 0 deletions cas/grpc_service/tests/cas_server_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const INSTANCE_NAME: &str = "foo";
const HASH1: &str = "0123456789abcdef000000000000000000000000000000000123456789abcdef";
const HASH2: &str = "9993456789abcdef000000000000000000000000000000000123456789abc999";
const HASH3: &str = "7773456789abcdef000000000000000000000000000000000123456789abc777";
const BAD_HASH: &str = "BAD_HASH";

#[cfg(test)]
mod find_missing_blobs {
Expand Down Expand Up @@ -65,6 +66,42 @@ mod find_missing_blobs {
assert_eq!(response.missing_blob_digests.len(), 0); // All items should have been found.
Ok(())
}

#[tokio::test]
async fn has_three_requests_one_bad_hash() -> Result<(), Error> {
let cas_server = CasServer::new(create_store(&StoreType::Memory));

const VALUE: &str = "1";

cas_server
.store
.update(&HASH1, VALUE.len(), Box::new(Cursor::new(VALUE)))
.await?;
let raw_response = cas_server
.find_missing_blobs(Request::new(FindMissingBlobsRequest {
instance_name: INSTANCE_NAME.to_string(),
blob_digests: vec![Digest {
hash: HASH1.to_string(),
size_bytes: VALUE.len() as i64,
}, Digest {
hash: BAD_HASH.to_string(),
size_bytes: VALUE.len() as i64,
}, Digest {
hash: HASH1.to_string(),
size_bytes: VALUE.len() as i64,
}],
}))
.await;
assert!(raw_response.is_ok());
let response = raw_response.unwrap().into_inner();
assert_eq!(response.missing_blob_digests, vec![
Digest {
hash: BAD_HASH.to_string(),
size_bytes: VALUE.len() as i64,
}
]); // All items should have been found.
Ok(())
}
}

#[cfg(test)]
Expand Down

0 comments on commit 9adbe81

Please sign in to comment.