REST API cleanup
This commit is contained in:
@@ -202,13 +202,14 @@ pub async fn test(params: &mut JMAPTest) {
|
||||
|
||||
#[tokio::test]
|
||||
pub async fn import_certs_and_encrypt() {
|
||||
for (name, expected_method, expected_certs) in [
|
||||
for (name, method, expected_certs) in [
|
||||
("cert_pgp.pem", EncryptionMethod::PGP, 1),
|
||||
//("cert_pgp.der", EncryptionMethod::PGP, 1),
|
||||
("cert_smime.pem", EncryptionMethod::SMIME, 3),
|
||||
("cert_smime.der", EncryptionMethod::SMIME, 1),
|
||||
] {
|
||||
let (method, mut certs) = try_parse_certs(
|
||||
let mut certs = try_parse_certs(
|
||||
method,
|
||||
std::fs::read(
|
||||
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
|
||||
.join("resources")
|
||||
@@ -219,7 +220,6 @@ pub async fn import_certs_and_encrypt() {
|
||||
)
|
||||
.expect(name);
|
||||
|
||||
assert_eq!(method, expected_method);
|
||||
assert_eq!(certs.len(), expected_certs);
|
||||
|
||||
if method == EncryptionMethod::PGP && certs.len() == 2 {
|
||||
@@ -245,6 +245,7 @@ pub async fn import_certs_and_encrypt() {
|
||||
|
||||
// S/MIME and PGP should not be allowed mixed
|
||||
assert!(try_parse_certs(
|
||||
EncryptionMethod::PGP,
|
||||
std::fs::read(
|
||||
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
|
||||
.join("resources")
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
use std::time::Duration;
|
||||
|
||||
use jmap_proto::error::request::RequestError;
|
||||
use reqwest::{header::AUTHORIZATION, Method};
|
||||
use serde::{de::DeserializeOwned, Deserialize};
|
||||
|
||||
@@ -32,8 +33,9 @@ pub mod report;
|
||||
#[derive(Deserialize)]
|
||||
#[serde(untagged)]
|
||||
pub enum Response<T> {
|
||||
Data { data: T },
|
||||
RequestError(RequestError),
|
||||
Error { error: String, details: String },
|
||||
Data { data: T },
|
||||
}
|
||||
|
||||
pub async fn send_manage_request<T: DeserializeOwned>(
|
||||
@@ -69,16 +71,22 @@ impl<T> Response<T> {
|
||||
Response::Error { error, details } => {
|
||||
panic!("Expected data, found error {error:?}: {details:?}")
|
||||
}
|
||||
Response::RequestError(err) => {
|
||||
panic!("Expected data, found error {err:?}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn try_unwrap_data(self) -> Option<T> {
|
||||
match self {
|
||||
Response::Data { data } => Some(data),
|
||||
Response::Error { error, .. } if error == "not-found" => None,
|
||||
Response::RequestError(error) if error.status == 404 => None,
|
||||
Response::Error { error, details } => {
|
||||
panic!("Expected data, found error {error:?}: {details:?}")
|
||||
}
|
||||
Response::RequestError(err) => {
|
||||
panic!("Expected data, found error {err:?}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,6 +94,9 @@ impl<T> Response<T> {
|
||||
match self {
|
||||
Response::Error { error, details } => (error, details),
|
||||
Response::Data { .. } => panic!("Expected error, found data."),
|
||||
Response::RequestError(err) => {
|
||||
panic!("Expected error, found request error {err:?}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,15 +26,13 @@ use std::time::{Duration, Instant};
|
||||
use ahash::{AHashMap, HashMap, HashSet};
|
||||
use common::config::server::ServerProtocol;
|
||||
|
||||
use jmap::api::management::queue::Message;
|
||||
use mail_auth::MX;
|
||||
use mail_parser::DateTime;
|
||||
use reqwest::{header::AUTHORIZATION, Method, StatusCode};
|
||||
|
||||
use crate::smtp::{management::send_manage_request, outbound::TestServer, session::TestSession};
|
||||
use smtp::{
|
||||
core::management::Message,
|
||||
queue::{manager::SpawnQueue, QueueId, Status},
|
||||
};
|
||||
use smtp::queue::{manager::SpawnQueue, QueueId, Status};
|
||||
|
||||
const LOCAL: &str = r#"
|
||||
[storage]
|
||||
@@ -465,7 +463,7 @@ async fn manage_queue() {
|
||||
.danger_accept_invalid_certs(true)
|
||||
.build()
|
||||
.unwrap()
|
||||
.get("https://127.0.0.1:9980/list")
|
||||
.get("https://127.0.0.1:9980/api/queue/messages")
|
||||
.header(AUTHORIZATION, "Basic YWRtaW46aGVsbG93b3JsZA==")
|
||||
.send()
|
||||
.await
|
||||
|
||||
@@ -26,6 +26,7 @@ use std::sync::Arc;
|
||||
use ahash::{AHashMap, HashSet};
|
||||
use common::config::{server::ServerProtocol, smtp::report::AggregateFrequency};
|
||||
|
||||
use jmap::api::management::queue::Report;
|
||||
use mail_auth::{
|
||||
common::parse::TxtRecordParser,
|
||||
dmarc::Dmarc,
|
||||
@@ -41,10 +42,7 @@ use crate::smtp::{
|
||||
management::{queue::List, send_manage_request},
|
||||
outbound::TestServer,
|
||||
};
|
||||
use smtp::{
|
||||
core::management::Report,
|
||||
reporting::{scheduler::SpawnReport, DmarcEvent, TlsEvent},
|
||||
};
|
||||
use smtp::reporting::{scheduler::SpawnReport, DmarcEvent, TlsEvent};
|
||||
|
||||
const CONFIG: &str = r#"
|
||||
[storage]
|
||||
|
||||
@@ -25,12 +25,11 @@ use common::{
|
||||
config::server::{ServerProtocol, Servers},
|
||||
Core,
|
||||
};
|
||||
use jmap::{api::JmapSessionManager, JMAP};
|
||||
use store::{BlobStore, Store, Stores};
|
||||
use tokio::sync::{mpsc, watch};
|
||||
|
||||
use ::smtp::core::{
|
||||
Inner, Session, SmtpAdminSessionManager, SmtpInstance, SmtpSessionManager, SMTP,
|
||||
};
|
||||
use ::smtp::core::{Inner, Session, SmtpInstance, SmtpSessionManager, SMTP};
|
||||
use utils::config::Config;
|
||||
|
||||
use crate::AssertConfig;
|
||||
@@ -147,10 +146,18 @@ impl TestServer {
|
||||
|
||||
// Start servers
|
||||
servers.bind_and_drop_priv(&mut config);
|
||||
config.assert_no_errors();
|
||||
let instance = self.instance.clone();
|
||||
let smtp_manager = SmtpSessionManager::new(instance.clone());
|
||||
let smtp_admin_manager = SmtpAdminSessionManager::new(instance.clone());
|
||||
let jmap = JMAP::init(
|
||||
&mut config,
|
||||
mpsc::channel(1).1,
|
||||
instance.core.clone(),
|
||||
instance.inner.clone(),
|
||||
)
|
||||
.await;
|
||||
let jmap_manager = JmapSessionManager::new(jmap);
|
||||
config.assert_no_errors();
|
||||
|
||||
servers.spawn(|server, acceptor, shutdown_rx| {
|
||||
match &server.protocol {
|
||||
ServerProtocol::Smtp | ServerProtocol::Lmtp => server.spawn(
|
||||
@@ -160,7 +167,7 @@ impl TestServer {
|
||||
shutdown_rx,
|
||||
),
|
||||
ServerProtocol::Http => server.spawn(
|
||||
smtp_admin_manager.clone(),
|
||||
jmap_manager.clone(),
|
||||
instance.core.clone(),
|
||||
acceptor,
|
||||
shutdown_rx,
|
||||
|
||||
Reference in New Issue
Block a user