Skip to content

Commit

Permalink
Add test with non-UTF-8 data
Browse files Browse the repository at this point in the history
  • Loading branch information
djc committed Aug 1, 2022
1 parent bc3131c commit 0f22b64
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
15 changes: 15 additions & 0 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,21 @@ mod unit {
);
}

#[test]
fn skips_non_utf8_junk() {
assert_eq!(
check(
b"\x00\x00\n\
-----BEGIN RSA PRIVATE KEY-----\n\
qw\n\
-----END RSA PRIVATE KEY-----\n
\x00\x00"
)
.unwrap(),
vec![crate::Item::RSAKey(vec![0xab])]
);
}

#[test]
fn rejects_invalid_base64() {
assert_eq!(
Expand Down
Binary file added tests/data/gunk.pem
Binary file not shown.
18 changes: 9 additions & 9 deletions tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ fn test_rsa_private_keys() {
let mut reader = BufReader::new(&data[..]);

assert_eq!(
rustls_pemfile::rsa_private_keys(&mut reader)
.unwrap()
.len(),
rustls_pemfile::rsa_private_keys(&mut reader).unwrap().len(),
2
);
}
Expand All @@ -19,12 +17,14 @@ fn test_certs() {
let data = include_bytes!("data/certificate.chain.pem");
let mut reader = BufReader::new(&data[..]);

assert_eq!(
rustls_pemfile::certs(&mut reader)
.unwrap()
.len(),
3
);
assert_eq!(rustls_pemfile::certs(&mut reader).unwrap().len(), 3);
}

#[test]
fn test_certs_with_binary() {
let data = include_bytes!("data/gunk.pem");
let mut reader = BufReader::new(&data[..]);
assert_eq!(rustls_pemfile::certs(&mut reader).unwrap().len(), 2);
}

#[test]
Expand Down

0 comments on commit 0f22b64

Please sign in to comment.