agent: Add test to random::reseed_rng()

Introduced an unit test for the random::reseed_rng() function.

Fixes #291
Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
This commit is contained in:
Wainer dos Santos Moschetta 2021-04-08 14:34:35 -04:00 committed by Eduardo Lima (Etrunko)
parent d8f39fb269
commit 39a35b693a

View File

@ -46,3 +46,24 @@ pub fn reseed_rng(data: &[u8]) -> Result<()> {
Ok(())
}
#[cfg(test)]
mod tests {
use super::*;
use crate::skip_if_not_root;
use std::fs::File;
use std::io::prelude::*;
#[test]
fn test_reseed_rng() {
skip_if_not_root!();
const POOL_SIZE: usize = 512;
let mut f = File::open("/dev/urandom").unwrap();
let mut seed = [0; POOL_SIZE];
let n = f.read(&mut seed).unwrap();
// Ensure the buffer was filled.
assert!(n == POOL_SIZE);
let ret = reseed_rng(&seed);
assert!(ret.is_ok());
}
}