Migrate to encodify
This commit is contained in:
@@ -7,8 +7,7 @@
|
||||
use std::io;
|
||||
use std::time::Duration;
|
||||
|
||||
use base64::Engine;
|
||||
use base64::engine::general_purpose::STANDARD as B64;
|
||||
use encodify::base64::STANDARD as B64;
|
||||
use ureq::Agent;
|
||||
use ureq::http::{Method, Request};
|
||||
|
||||
|
||||
@@ -8,8 +8,7 @@ use std::io::{BufRead, BufReader, Read, Write};
|
||||
use std::net::TcpStream;
|
||||
use std::time::Duration;
|
||||
|
||||
use base64::Engine;
|
||||
use base64::engine::general_purpose::STANDARD as B64;
|
||||
use encodify::base64::STANDARD as B64;
|
||||
|
||||
use super::error::{ContainerError, ContainerResult};
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ use std::process::Command;
|
||||
use std::sync::{Arc, OnceLock};
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use base64::Engine;
|
||||
use encodify::base64::STANDARD;
|
||||
use serde_json::Value;
|
||||
use testcontainers::core::{IntoContainerPort, WaitFor};
|
||||
use testcontainers::runners::SyncRunner;
|
||||
@@ -183,8 +183,7 @@ fn basic(user: &str, password: &str) -> String {
|
||||
raw.push_str(user);
|
||||
raw.push(':');
|
||||
raw.push_str(password);
|
||||
format!(
|
||||
"Basic {}",
|
||||
base64::engine::general_purpose::STANDARD.encode(raw.as_bytes())
|
||||
)
|
||||
let mut header = String::from("Basic ");
|
||||
STANDARD.encode_append(raw, &mut header);
|
||||
header
|
||||
}
|
||||
|
||||
@@ -6,8 +6,7 @@
|
||||
|
||||
use std::time::Duration;
|
||||
|
||||
use base64::Engine;
|
||||
use base64::engine::general_purpose::STANDARD as B64;
|
||||
use encodify::base64::STANDARD as B64;
|
||||
use testcontainers::core::{IntoContainerPort, WaitFor};
|
||||
use testcontainers::runners::{SyncBuilder, SyncRunner};
|
||||
use testcontainers::{Container, GenericBuildableImage, GenericImage, ImageExt};
|
||||
|
||||
+1
-2
@@ -1448,8 +1448,7 @@ fn dry_run_writes_nothing_but_emits_per_collection_counts() {
|
||||
|
||||
#[test]
|
||||
fn dav_source_change_protection_fires_across_users_on_same_root() {
|
||||
use base64::Engine;
|
||||
use base64::engine::general_purpose::STANDARD;
|
||||
use encodify::base64::STANDARD;
|
||||
use std::path::PathBuf;
|
||||
use vandelay::logging::Logger;
|
||||
use vandelay::sync::CommonConfig;
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*/
|
||||
|
||||
use encodify::base64::{LENIENT, STANDARD};
|
||||
use mockito::Matcher;
|
||||
use vandelay::exchange_ews::EwsClient;
|
||||
use vandelay::exchange_ews::autodiscover::{DiscoverySource, discover};
|
||||
@@ -300,8 +301,7 @@ fn http_401_surfaces_as_auth_error() {
|
||||
#[test]
|
||||
fn mime_content_round_trips_through_base64_decode() {
|
||||
let original = b"From: alice@x\r\nSubject: hi\r\n\r\nbody";
|
||||
use base64::Engine;
|
||||
let encoded = base64::engine::general_purpose::STANDARD.encode(original);
|
||||
let encoded = STANDARD.encode(original);
|
||||
let body = envelope(&format!(
|
||||
"<m:GetItemResponse{NS}><m:ResponseMessages>\
|
||||
<m:GetItemResponseMessage ResponseClass=\"Success\">\
|
||||
@@ -315,10 +315,7 @@ fn mime_content_round_trips_through_base64_decode() {
|
||||
let r = parse_response_messages(body.as_bytes(), b"GetItemResponseMessage").unwrap();
|
||||
let item = vandelay::exchange_ews::parse::parse_message_item(&r[0].inner_xml).unwrap();
|
||||
let s = item.mime_content.unwrap();
|
||||
let cleaned: String = s.chars().filter(|c| !c.is_whitespace()).collect();
|
||||
let bytes = base64::engine::general_purpose::STANDARD
|
||||
.decode(cleaned.as_bytes())
|
||||
.unwrap();
|
||||
let bytes = LENIENT.decode(&s).unwrap();
|
||||
assert_eq!(bytes, original);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
use std::sync::Once;
|
||||
|
||||
use base64::Engine;
|
||||
use encodify::base64::URL_SAFE_NO_PAD;
|
||||
use mockito::{Matcher, Server};
|
||||
use serde_json::json;
|
||||
use vandelay::exchange_graph::api::{Endpoints, collect_all_ids, paged_collect};
|
||||
@@ -36,7 +36,6 @@ fn url_message_collection(server_url: &str, folder: &str, top: usize) -> String
|
||||
}
|
||||
|
||||
fn make_jwt(exp: u64, upn: &str) -> String {
|
||||
use base64::engine::general_purpose::URL_SAFE_NO_PAD;
|
||||
let header = URL_SAFE_NO_PAD.encode(b"{\"alg\":\"none\"}");
|
||||
let claims = format!(r#"{{"tid":"tenant-1","upn":"{upn}","exp":{exp}}}"#);
|
||||
let payload = URL_SAFE_NO_PAD.encode(claims.as_bytes());
|
||||
|
||||
+28
-19
@@ -12,6 +12,7 @@ use std::sync::atomic::{AtomicU32, Ordering};
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
|
||||
use encodify::base64::STANDARD;
|
||||
use rusqlite::Connection;
|
||||
use vandelay::db;
|
||||
use vandelay::imap::client::{ConnectMode, ImapClient};
|
||||
@@ -230,7 +231,6 @@ fn authenticate_oauthbearer_sasl_ir() {
|
||||
|
||||
#[test]
|
||||
fn authenticate_oauthbearer_continuation_payload_uses_gs2_header() {
|
||||
use base64::Engine;
|
||||
let server = MockImap::start(|conn| {
|
||||
conn.write_line("* OK Hello")?;
|
||||
let (tag, _) = conn.read_command()?;
|
||||
@@ -242,9 +242,7 @@ fn authenticate_oauthbearer_continuation_payload_uses_gs2_header() {
|
||||
let mut line = String::new();
|
||||
conn.reader.read_line(&mut line)?;
|
||||
let payload = line.trim_end_matches(['\r', '\n']).to_owned();
|
||||
let decoded = base64::engine::general_purpose::STANDARD
|
||||
.decode(&payload)
|
||||
.expect("base64");
|
||||
let decoded = STANDARD.decode(&payload).expect("base64");
|
||||
let text = std::str::from_utf8(&decoded).unwrap_or("");
|
||||
assert!(
|
||||
text.starts_with("n,[email protected],"),
|
||||
@@ -1871,22 +1869,33 @@ fn mutf7_server_gets_the_folder_name_back_as_mutf7() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn utf8_name_from_a_server_that_never_enabled_utf8_falls_back_on_select() {
|
||||
let control: Script = Box::new(|conn: &mut MockConn| -> std::io::Result<()> {
|
||||
fn utf8_name_from_a_server_that_never_enabled_utf8_is_selected_as_listed() {
|
||||
assert_name_selected_as_listed(FRENCH_SENT_UTF8, FRENCH_SENT_UTF8, "utf8_no_enable");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn raw_ampersand_name_is_selected_as_listed_not_reencoded() {
|
||||
assert_name_selected_as_listed("R&D", "R&D", "raw_ampersand");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn modified_utf7_name_is_selected_as_listed() {
|
||||
assert_name_selected_as_listed(FRENCH_SENT_MUTF7, FRENCH_SENT_UTF8, "mutf7_as_listed");
|
||||
}
|
||||
|
||||
fn assert_name_selected_as_listed(listed: &'static str, stored: &str, archive_name: &str) {
|
||||
let control: Script = Box::new(move |conn: &mut MockConn| -> std::io::Result<()> {
|
||||
auth_preamble(conn, "IMAP4rev2 LITERAL+ AUTH=PLAIN")?;
|
||||
let (tag, cmd) = conn.read_command()?;
|
||||
assert_eq!(cmd, "LIST \"\" \"*\"");
|
||||
conn.write_line(&format!("* LIST () \"/\" \"{FRENCH_SENT_UTF8}\""))?;
|
||||
conn.write_line(&format!("* LIST () \"/\" \"{listed}\""))?;
|
||||
conn.write_line(&format!("{tag} OK LIST done"))?;
|
||||
let (tag, _) = conn.read_command()?;
|
||||
conn.write_line(&format!("{tag} OK LSUB done"))?;
|
||||
let (tag, name) = read_select_mailbox(conn)?;
|
||||
assert_eq!(name, FRENCH_SENT_MUTF7);
|
||||
conn.write_line(&format!("{tag} NO [NONEXISTENT] Mailbox does not exist."))?;
|
||||
let (tag, name) = read_select_mailbox(conn)?;
|
||||
assert_eq!(
|
||||
name, FRENCH_SENT_UTF8,
|
||||
"a refused modified UTF-7 name must be retried as UTF-8"
|
||||
name, listed,
|
||||
"the name must go back exactly as the server listed it"
|
||||
);
|
||||
write_select(conn, &tag, 902, 2, 1)?;
|
||||
let (tag, cmd) = conn.read_command()?;
|
||||
@@ -1896,13 +1905,13 @@ fn utf8_name_from_a_server_that_never_enabled_utf8_falls_back_on_select() {
|
||||
drain_until_close(conn);
|
||||
Ok(())
|
||||
});
|
||||
let worker: Script = Box::new(|conn: &mut MockConn| -> std::io::Result<()> {
|
||||
let worker: Script = Box::new(move |conn: &mut MockConn| -> std::io::Result<()> {
|
||||
auth_preamble(conn, "IMAP4rev2 LITERAL+ AUTH=PLAIN")?;
|
||||
let (tag, name) = read_select_mailbox(conn)?;
|
||||
assert_eq!(name, FRENCH_SENT_MUTF7);
|
||||
conn.write_line(&format!("{tag} NO [NONEXISTENT] Mailbox does not exist."))?;
|
||||
let (tag, name) = read_select_mailbox(conn)?;
|
||||
assert_eq!(name, FRENCH_SENT_UTF8);
|
||||
assert_eq!(
|
||||
name, listed,
|
||||
"the fetch worker must agree with the coordinator"
|
||||
);
|
||||
write_select(conn, &tag, 902, 2, 1)?;
|
||||
let (tag, _) = conn.read_command()?;
|
||||
write_fetch_message(conn, 1, 1, MSG_BODY)?;
|
||||
@@ -1912,7 +1921,7 @@ fn utf8_name_from_a_server_that_never_enabled_utf8_falls_back_on_select() {
|
||||
});
|
||||
|
||||
let server = MockImap::start_scripts(vec![control, worker]);
|
||||
let archive = tempfile("utf8_no_enable");
|
||||
let archive = tempfile(archive_name);
|
||||
let summary = run_import(&server, "alice", archive.clone(), |_| {}).expect("import");
|
||||
let email = summary
|
||||
.per_type
|
||||
@@ -1925,7 +1934,7 @@ fn utf8_name_from_a_server_that_never_enabled_utf8_falls_back_on_select() {
|
||||
assert_eq!(
|
||||
conn.query_row::<String, _, _>("SELECT name FROM mailboxes", [], |r| r.get(0))
|
||||
.unwrap(),
|
||||
FRENCH_SENT_UTF8
|
||||
stored
|
||||
);
|
||||
let _ = std::fs::remove_file(&archive);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use base64::Engine;
|
||||
use encodify::base64::STANDARD;
|
||||
use serde_json::{Value, json};
|
||||
use ureq::Agent;
|
||||
use ureq::config::RedirectAuthHeaders;
|
||||
@@ -43,10 +43,9 @@ fn basic(user: &str, password: &str) -> String {
|
||||
raw.push_str(user);
|
||||
raw.push(':');
|
||||
raw.push_str(password);
|
||||
format!(
|
||||
"Basic {}",
|
||||
base64::engine::general_purpose::STANDARD.encode(raw.as_bytes())
|
||||
)
|
||||
let mut header = String::from("Basic ");
|
||||
STANDARD.encode_append(raw, &mut header);
|
||||
header
|
||||
}
|
||||
|
||||
impl Jmap {
|
||||
|
||||
+2
-4
@@ -9,6 +9,7 @@ mod seeder;
|
||||
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use encodify::base64::STANDARD;
|
||||
use integration::stalwart::shared as shared_stalwart;
|
||||
use rusqlite::Connection;
|
||||
use serde_json::{Map, Value, json};
|
||||
@@ -693,7 +694,6 @@ const ISSUE30_CARD_UID: &str = "vandelay-issue30-card";
|
||||
const ISSUE30_EVENT_UID: &str = "vandelay-issue30-event";
|
||||
|
||||
fn data_uri_bytes(resource: &Value, uri_key: &str, expect_media_type: &str) -> Vec<u8> {
|
||||
use base64::Engine;
|
||||
let uri = resource
|
||||
.get(uri_key)
|
||||
.and_then(Value::as_str)
|
||||
@@ -706,9 +706,7 @@ fn data_uri_bytes(resource: &Value, uri_key: &str, expect_media_type: &str) -> V
|
||||
let payload = uri
|
||||
.strip_prefix(&prefix)
|
||||
.unwrap_or_else(|| panic!("{uri_key} is not a {prefix}... data URI: {resource}"));
|
||||
base64::engine::general_purpose::STANDARD
|
||||
.decode(payload)
|
||||
.expect("base64 payload")
|
||||
STANDARD.decode(payload).expect("base64 payload")
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user