重构error code
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use rpki::data_model::tal::{Tal, TalDecodeError};
|
||||
use rpki::data_model::tal::{Tal, TalDecodeError, TalParseError, TalProfileError};
|
||||
|
||||
fn mk_tal(uris: &[&str], b64_lines: &[&str]) -> String {
|
||||
let mut out = String::new();
|
||||
@@ -20,14 +20,19 @@ fn tal_rejects_missing_separator() {
|
||||
let s = "# c\nhttps://example.invalid/ta.cer\nAAAA\n";
|
||||
assert!(matches!(
|
||||
Tal::decode_bytes(s.as_bytes()),
|
||||
Err(TalDecodeError::MissingSeparatorEmptyLine)
|
||||
Err(TalDecodeError::Validate(
|
||||
TalProfileError::MissingSeparatorEmptyLine
|
||||
))
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tal_rejects_missing_uris() {
|
||||
let s = "# c\n\nAAAA\n";
|
||||
assert!(matches!(Tal::decode_bytes(s.as_bytes()), Err(TalDecodeError::MissingTaUris)));
|
||||
assert!(matches!(
|
||||
Tal::decode_bytes(s.as_bytes()),
|
||||
Err(TalDecodeError::Validate(TalProfileError::MissingTaUris))
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -35,7 +40,9 @@ fn tal_rejects_unsupported_scheme() {
|
||||
let s = mk_tal(&["ftp://example.invalid/ta.cer"], &["AAAA"]);
|
||||
assert!(matches!(
|
||||
Tal::decode_bytes(s.as_bytes()),
|
||||
Err(TalDecodeError::UnsupportedUriScheme(_))
|
||||
Err(TalDecodeError::Validate(
|
||||
TalProfileError::UnsupportedUriScheme(_)
|
||||
))
|
||||
));
|
||||
}
|
||||
|
||||
@@ -44,14 +51,19 @@ fn tal_rejects_directory_uri() {
|
||||
let s = mk_tal(&["https://example.invalid/dir/"], &["AAAA"]);
|
||||
assert!(matches!(
|
||||
Tal::decode_bytes(s.as_bytes()),
|
||||
Err(TalDecodeError::UriIsDirectory(_))
|
||||
Err(TalDecodeError::Validate(TalProfileError::UriIsDirectory(_)))
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tal_rejects_comment_after_header() {
|
||||
let s = "# c\nhttps://example.invalid/ta.cer\n# late\n\nAAAA\n";
|
||||
assert!(matches!(Tal::decode_bytes(s.as_bytes()), Err(TalDecodeError::CommentAfterHeader)));
|
||||
assert!(matches!(
|
||||
Tal::decode_bytes(s.as_bytes()),
|
||||
Err(TalDecodeError::Validate(
|
||||
TalProfileError::CommentAfterHeader
|
||||
))
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -59,13 +71,15 @@ fn tal_rejects_invalid_base64() {
|
||||
let s = mk_tal(&["https://example.invalid/ta.cer"], &["not-base64!!!"]);
|
||||
assert!(matches!(
|
||||
Tal::decode_bytes(s.as_bytes()),
|
||||
Err(TalDecodeError::SpkiBase64Decode)
|
||||
Err(TalDecodeError::Validate(TalProfileError::SpkiBase64Decode))
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tal_rejects_invalid_utf8() {
|
||||
let bytes = [0xFFu8, 0xFEu8];
|
||||
assert!(matches!(Tal::decode_bytes(&bytes), Err(TalDecodeError::InvalidUtf8)));
|
||||
assert!(matches!(
|
||||
Tal::decode_bytes(&bytes),
|
||||
Err(TalDecodeError::Parse(TalParseError::InvalidUtf8))
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user