mirror of
https://github.com/pimalaya/himalaya.git
synced 2026-06-17 13:17:55 +08:00
refactor(jmap): improve errors management
This commit is contained in:
@@ -72,9 +72,7 @@ fn parse_output<T: DeserializeOwned>(config: &Path, args: &[&str]) -> T {
|
||||
///
|
||||
/// Exercises every command in a single ordered flow. Pass a path to a
|
||||
/// valid TOML config file with a default JMAP account configured.
|
||||
pub fn run(config: &Path) {
|
||||
let email = env::var("EMAIL").expect("EMAIL env var");
|
||||
|
||||
pub fn run(config: &Path, email: String) {
|
||||
let ts = SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap()
|
||||
|
||||
@@ -6,9 +6,10 @@ use std::{env, io::Write};
|
||||
use tempfile::NamedTempFile;
|
||||
|
||||
#[test]
|
||||
#[ignore = "requires BEARER_TOKEN env var and --ignored"]
|
||||
#[ignore = "requires FASTMAIL_{EMAIL,BEARER_TOKEN} env vars and --ignored"]
|
||||
fn fastmail_jmap() {
|
||||
let token = env::var("BEARER_TOKEN").expect("BEARER_TOKEN env var");
|
||||
let email = env::var("FASTMAIL_EMAIL").expect("FASTMAIL_EMAIL env var");
|
||||
let token = env::var("FASTMAIL_BEARER_TOKEN").expect("FASTMAIL_BEARER_TOKEN env var");
|
||||
|
||||
let mut config = NamedTempFile::new().unwrap();
|
||||
let config_tpl = format!(
|
||||
@@ -20,5 +21,5 @@ jmap.auth.bearer.token.raw = "{token}""#
|
||||
|
||||
config.write(&config_tpl.into_bytes()).unwrap();
|
||||
|
||||
jmap::run(config.path());
|
||||
jmap::run(config.path(), email);
|
||||
}
|
||||
|
||||
@@ -6,14 +6,14 @@ use std::{env, io::Write};
|
||||
use tempfile::NamedTempFile;
|
||||
|
||||
#[test]
|
||||
#[ignore = "requires URL, USER, PASS env vars and --ignored"]
|
||||
#[ignore = "requires STALWART_{EMAIL,URL,USER,PASS} env vars and --ignored"]
|
||||
fn stalwart_jmap() {
|
||||
let email = env::var("STALWART_EMAIL").unwrap_or("test@pimalaya.org".into());
|
||||
let url = env::var("STALWART_URL").unwrap_or("http://localhost:8080/jmap/session".into());
|
||||
let user = env::var("STALWART_USER").unwrap_or("test".into());
|
||||
let pass = env::var("STALWART_PASS").unwrap_or("test".into());
|
||||
|
||||
let mut config = NamedTempFile::new().unwrap();
|
||||
|
||||
let url = env::var("URL").unwrap_or("http://localhost:8080/jmap/session".into());
|
||||
let user = env::var("USER").unwrap_or("test".into());
|
||||
let pass = env::var("PASS").unwrap_or("test".into());
|
||||
|
||||
let config_tpl = format!(
|
||||
r#"[accounts.stalwart]
|
||||
default = true
|
||||
@@ -24,5 +24,5 @@ jmap.auth.basic.password.raw = "{pass}""#
|
||||
|
||||
config.write(&config_tpl.into_bytes()).unwrap();
|
||||
|
||||
jmap::run(config.path());
|
||||
jmap::run(config.path(), email);
|
||||
}
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
|
||||
docker run -d --rm --name stalwart-test-for-himalaya -p 8080:8080 stalwartlabs/stalwart:latest-alpine
|
||||
|
||||
sleep 1
|
||||
|
||||
admin_password=$(docker logs stalwart-test-for-himalaya 2>&1 | grep -oP "(?<=with password ')[^']+")
|
||||
|
||||
curl -u "admin:${admin_password}" -X POST -H 'Content-Type: application/json' -d '{"type":"domain","name":"pimalaya.org","description":"","quota":0,"secrets":[],"emails":[],"urls":[],"memberOf":[],"roles":[],"lists":[],"members":[],"enabledPermissions":[],"disabledPermissions":[],"externalMembers":[]}' http://localhost:8080/api/principal
|
||||
|
||||
curl -u "admin:${admin_password}" -X POST -H 'Content-Type: application/json' -d '{"type":"individual","name":"test","description":"","quota":0,"secrets":["test"],"emails":["test@pimalaya.org"],"memberOf":[],"roles":["user"],"lists":[],"enabledPermissions":[],"disabledPermissions":[],"externalMembers":[]}' http://localhost:8080/api/principal
|
||||
Reference in New Issue
Block a user