Skip to content

Commit

Permalink
Test to ensure standard decoder accepts urlsafe, and vice-versa
Browse files Browse the repository at this point in the history
  • Loading branch information
dantreiman committed Jun 11, 2024
1 parent 74b4a08 commit b5bc9d6
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion google-apis-common/src/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,14 +355,28 @@ mod test {
assert_eq!(Some(b"hello world".as_slice()), wrapper.bytes.as_deref());
}

#[test]
fn urlsafe_base64_de_standard_success_cases() {
let wrapper: Base64URLSafeWrapper = // Expect URL-safe base64 accepts standard encoding
serde_json::from_reader(r#"{"bytes": "REE/P0V+Nz4oIWtH"}"#.as_bytes()).unwrap();
assert_eq!(Some(b"DA??E~7>(!kG".as_slice()), wrapper.bytes.as_deref());
}

#[test]
fn urlsafe_base64_de_failure_cases() {
assert!(
serde_json::from_str::<Base64URLSafeWrapper>(r#"{"bytes": "aGVsbG8gd29ybG+Q"}"#)
serde_json::from_str::<Base64URLSafeWrapper>(r#"{"bytes": "aGVsbG8gd29ybG&Q"}"#)
.is_err()
);
}

#[test]
fn standard_base64_de_urlsafe_success_cases() {
let wrapper: Base64URLSafeWrapper = // Expect standard base64 accepts url-safe encoding
serde_json::from_reader(r#"{"bytes": "REE_P0V-Nz4oIWtH"}"#.as_bytes()).unwrap();
assert_eq!(Some(b"DA??E~7>(!kG".as_slice()), wrapper.bytes.as_deref());
}

#[test]
fn standard_base64_de_failure_cases() {
assert!(serde_json::from_str::<Base64StandardWrapper>(r#"{"bytes": "%"}"#).is_err());
Expand Down

0 comments on commit b5bc9d6

Please sign in to comment.