mirror of
https://github.com/mii443/RustySecrets.git
synced 2025-08-22 16:25:32 +00:00
Tests & CI.
This commit is contained in:
22
tests/generation-errors.rs
Normal file
22
tests/generation-errors.rs
Normal file
@ -0,0 +1,22 @@
|
||||
extern crate rusty_secrets;
|
||||
|
||||
use rusty_secrets::custom_error::{pie2io};
|
||||
use rusty_secrets::generate_shares;
|
||||
use std::error::Error;
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "Threshold K can not be larger than N")]
|
||||
fn test_generate_invalid_k() {
|
||||
let share1 = "2-1-1YAYwmOHqZ69jA".to_string().into_bytes();
|
||||
|
||||
generate_shares(10, 5, &share1).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_errors() {
|
||||
let nan = "2a".to_string();
|
||||
match nan.parse::<u8>().map_err(pie2io) {
|
||||
Ok(_) => assert!(false),
|
||||
Err(x) => assert_eq!("Integer parsing error", x.description()),
|
||||
}
|
||||
}
|
@ -2,7 +2,6 @@ extern crate rusty_secrets;
|
||||
|
||||
use rusty_secrets::{recover_secret, generate_shares};
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_reasonable_splits() {
|
||||
let max_shares = 50;
|
||||
|
107
tests/recovery-errors.rs
Normal file
107
tests/recovery-errors.rs
Normal file
@ -0,0 +1,107 @@
|
||||
extern crate rusty_secrets;
|
||||
|
||||
use rusty_secrets::{recover_secret};
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "Not enough shares provided!")]
|
||||
fn test_recover_sellibitze_missing_share() {
|
||||
let share1 = "2-1-1YAYwmOHqZ69jA".to_string();
|
||||
let shares = vec![share1];
|
||||
|
||||
recover_secret(shares).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "Not enough shares provided!")]
|
||||
fn test_recover_sellibitze_no_shares() {
|
||||
let shares = vec![];
|
||||
recover_secret(shares).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "Share parse error: Expected 3 parts separated by a minus sign")]
|
||||
fn test_recover_2_parts_share() {
|
||||
let share1 = "2-1-1YAYwmOHqZ69jA".to_string();
|
||||
let share2 = "2-F7rAjX3UOa53KA".to_string();
|
||||
|
||||
let shares = vec![share1, share2];
|
||||
|
||||
recover_secret(shares).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "Integer parsing error")]
|
||||
fn test_recover_incorrect_share_num() {
|
||||
let share1 = "2-1-1YAYwmOHqZ69jA".to_string();
|
||||
let share2 = "2-DEFINITLY_NAN-YJZQDGm22Y77Gw".to_string();
|
||||
|
||||
let shares = vec![share1, share2];
|
||||
|
||||
recover_secret(shares).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "Share parse error: Illegal K,N parameters")]
|
||||
fn test_recover_0_share_num() {
|
||||
let share1 = "2-0-1YAYwmOHqZ69jA".to_string();
|
||||
let share2 = "2-1-YJZQDGm22Y77Gw".to_string();
|
||||
|
||||
let shares = vec![share1, share2];
|
||||
|
||||
recover_secret(shares).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "Share parse error: Base64 decoding of data block failed")]
|
||||
fn test_recover_invalid_b64() {
|
||||
let share1 = "2-5-j0P4PHsw4lW+rg".to_string();
|
||||
let share2 = "2-1-YJZQDG((((m22Y)))77Gw".to_string();
|
||||
|
||||
let shares = vec![share1, share2];
|
||||
|
||||
recover_secret(shares).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "Incompatible shares")]
|
||||
fn test_recover_invalid_b64_size() {
|
||||
let share1 = "2-5-j0P4PHsw4lW+rg".to_string();
|
||||
let share2 = "2-1-YJZQDGm22Y77GwZ69jA".to_string();
|
||||
|
||||
let shares = vec![share1, share2];
|
||||
|
||||
recover_secret(shares).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "Duplicate Share Number")]
|
||||
fn test_recover_duplicate_shares_number() {
|
||||
let share1 = "2-1-1YAYwmOHqZ69jA".to_string();
|
||||
let share2 = "2-1-j0P4PHsw4lW+rg".to_string();
|
||||
|
||||
let shares = vec![share1, share2];
|
||||
|
||||
recover_secret(shares).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "Duplicate Share Data")]
|
||||
fn test_recover_duplicate_shares_data() {
|
||||
let share1 = "2-2-YJZQDGm22Y77Gw".to_string();
|
||||
let share2 = "2-3-YJZQDGm22Y77Gw".to_string();
|
||||
|
||||
let shares = vec![share1, share2];
|
||||
|
||||
recover_secret(shares).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "Not enough shares provided!")]
|
||||
fn test_recover_too_few_shares() {
|
||||
let share1 = "5-1-DbuicpLQiCf7bVWiAz8eCpQGpdZmYQ7z2j2+g351tWFLOQPTZkXY8BYfwGGGjkOoz1g9x0ScmLFcWk+2tign".to_string();
|
||||
let share2 = "5-2-nShdfkY5+SlfybMyqjHXCZ01bq5N/0Lkf0nQZw5x3bnHIEVfa0RA4YcJ4SjG/UdpgO/gOcyLRkSp2Dwf8bvw".to_string();
|
||||
|
||||
let shares = vec![share1, share2];
|
||||
|
||||
recover_secret(shares).unwrap();
|
||||
}
|
@ -42,96 +42,3 @@ fn test_recover_sellibitze_more_than_threshold_shars() {
|
||||
secret.push(10);
|
||||
assert_eq!(recover_secret(shares).unwrap(), secret);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_recover_sellibitze_missing_share() {
|
||||
let share1 = "2-1-1YAYwmOHqZ69jA".to_string();
|
||||
let shares = vec![share1];
|
||||
|
||||
recover_secret(shares).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_recover_sellibitze_no_shares() {
|
||||
let shares = vec![];
|
||||
recover_secret(shares).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_recover_2_parts_share() {
|
||||
let share1 = "2-1-1YAYwmOHqZ69jA".to_string();
|
||||
let share2 = "2-F7rAjX3UOa53KA".to_string();
|
||||
|
||||
let shares = vec![share1, share2];
|
||||
|
||||
recover_secret(shares).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_recover_incorrect_share_num() {
|
||||
let share1 = "2-1-1YAYwmOHqZ69jA".to_string();
|
||||
let share2 = "2-DEFINITLY_NAN-YJZQDGm22Y77Gw".to_string();
|
||||
|
||||
let shares = vec![share1, share2];
|
||||
|
||||
recover_secret(shares).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_recover_0_share_num() {
|
||||
let share1 = "2-0-1YAYwmOHqZ69jA".to_string();
|
||||
let share2 = "2-1-YJZQDGm22Y77Gw".to_string();
|
||||
|
||||
let shares = vec![share1, share2];
|
||||
|
||||
recover_secret(shares).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_recover_invalid_b64() {
|
||||
let share1 = "2-0-1YAYwmOHqZ69jA".to_string();
|
||||
let share2 = "2-1-YJZQDG((((m22Y)))77Gw".to_string();
|
||||
|
||||
let shares = vec![share1, share2];
|
||||
|
||||
recover_secret(shares).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_recover_invalid_b64_size() {
|
||||
let share1 = "2-0-1YAYwmOHqZ69jA".to_string();
|
||||
let share2 = "2-1-YJZQDGm22Y77GwZ69jA".to_string();
|
||||
|
||||
let shares = vec![share1, share2];
|
||||
|
||||
recover_secret(shares).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_recover_duplicate_shares() {
|
||||
let share1 = "2-0-1YAYwmOHqZ69jA".to_string();
|
||||
let share2 = "2-0-1YAYwmOHqZ69jA".to_string();
|
||||
|
||||
let shares = vec![share1, share2];
|
||||
|
||||
recover_secret(shares).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_recover_too_few_shares() {
|
||||
let share1 = "5-1-DbuicpLQiCf7bVWiAz8eCpQGpdZmYQ7z2j2+g351tWFLOQPTZkXY8BYfwGGGjkOoz1g9x0ScmLFcWk+2tign".to_string();
|
||||
let share2 = "5-2-nShdfkY5+SlfybMyqjHXCZ01bq5N/0Lkf0nQZw5x3bnHIEVfa0RA4YcJ4SjG/UdpgO/gOcyLRkSp2Dwf8bvw".to_string();
|
||||
|
||||
let shares = vec![share1, share2];
|
||||
|
||||
recover_secret(shares).unwrap();
|
||||
}
|
||||
|
Reference in New Issue
Block a user