use std::borrow::Cow;
use super::defs::*;
use crate::support::error::Error;
#[test]
fn capability_declared() {
test_require_capability("xcrycapa", "XCRY");
}
#[test]
fn user_configuration() {
let setup = set_up_new_root();
let mut client = setup.connect("xcryucfg");
quick_log_in(&mut client);
command!(
[response] = client,
c("XCRY SET-USER-CONFIG INTERNAL-KEY-PATTERN \"../foo\"")
);
assert_error_response(
response,
Some(s::RespTextCode::Cannot(())),
Error::UnsafeName,
);
command!(
[response] = client,
c("XCRY SET-USER-CONFIG EXTERNAL-KEY-PATTERN \"../foo\"")
);
assert_error_response(
response,
Some(s::RespTextCode::Cannot(())),
Error::UnsafeName,
);
command!(
[response] = client,
c("XCRY SET-USER-CONFIG EXTERNAL-KEY-PATTERN \"foo%\"")
);
assert_error_response(
response,
Some(s::RespTextCode::Cannot(())),
Error::UnsafeName,
);
command!(mut responses = client,
c("XCRY SET-USER-CONFIG INTERNAL-KEY-PATTERN \"ikp%Y\" \
EXTERNAL-KEY-PATTERN \"ekp%d\""));
assert_tagged_ok(responses.pop().unwrap());
has_untagged_response_matching! {
s::Response::XCryBackupFile(..) in responses
};
command!(mut responses = client, c("XCRY GET-USER-CONFIG"));
assert_tagged_ok(responses.pop().unwrap());
has_untagged_response_matching! {
s::Response::XCryUserConfig(ref cfg) in responses => {
assert_eq!("ikp%Y", cfg.internal_key_pattern);
assert_eq!("ekp%d", cfg.external_key_pattern);
assert!(cfg.password_changed.is_none());
}
};
command!(mut responses = client,
c("XCRY SET-USER-CONFIG PASSWORD hunter3"));
assert_tagged_ok(responses.pop().unwrap());
has_untagged_response_matching! {
s::Response::XCryBackupFile(..) in responses
};
let mut client = setup.connect("xcryucfg");
ok_command!(client, c("LOGIN azure hunter3"));
command!(mut responses = client, c("XCRY GET-USER-CONFIG"));
assert_tagged_ok(responses.pop().unwrap());
has_untagged_response_matching! {
s::Response::XCryUserConfig(ref cfg) in responses => {
assert_eq!("ikp%Y", cfg.internal_key_pattern);
assert_eq!("ekp%d", cfg.external_key_pattern);
assert!(cfg.password_changed.is_some());
}
};
ok_command!(
client,
c("XCRY SET-USER-CONFIG SMTP-OUT-SAVE \"Sent\" \
SMTP-OUT-SUCCESS-RECEIPTS \"Sent/Success\" \
SMTP-OUT-FAILURE-RECEIPTS \"Sent/Failure\"")
);
command!(mut responses = client, c("XCRY GET-USER-CONFIG"));
assert_tagged_ok(responses.pop().unwrap());
has_untagged_response_matching! {
s::Response::XCryUserConfig(ref cfg) in responses => {
assert!(cfg.extended.contains(
&s::XCry2UserConfigData::SmtpOutSave(
Some(Cow::Borrowed("Sent")))));
assert!(cfg.extended.contains(
&s::XCry2UserConfigData::SmtpOutSuccessReceipts(
Some(Cow::Borrowed("Sent/Success")))));
assert!(cfg.extended.contains(
&s::XCry2UserConfigData::SmtpOutFailureReceipts(
Some(Cow::Borrowed("Sent/Failure")))));
}
};
ok_command!(
client,
c("XCRY SET-USER-CONFIG SMTP-OUT-SAVE NIL \
SMTP-OUT-SUCCESS-RECEIPTS NIL \
SMTP-OUT-FAILURE-RECEIPTS NIL")
);
command!(mut responses = client, c("XCRY GET-USER-CONFIG"));
assert_tagged_ok(responses.pop().unwrap());
has_untagged_response_matching! {
s::Response::XCryUserConfig(ref cfg) in responses => {
assert!(cfg.extended.contains(
&s::XCry2UserConfigData::SmtpOutSave(None)));
assert!(cfg.extended.contains(
&s::XCry2UserConfigData::SmtpOutSuccessReceipts(None)));
assert!(cfg.extended.contains(
&s::XCry2UserConfigData::SmtpOutFailureReceipts(None)));
}
};
}
#[test]
fn foreign_smtp_tls() {
let setup = set_up();
let mut client = setup.connect("xcryfstl");
quick_log_in(&mut client);
ok_command!(client, c("XCRY SMTP-OUT FOREIGN-TLS INIT-TEST"));
command!(mut responses = client, c("XCRY SMTP-OUT FOREIGN-TLS LIST"));
assert_eq!(3, responses.len());
assert_tagged_ok(responses.pop().unwrap());
let mut stati = responses
.into_iter()
.map(|line| match line.response {
s::Response::XCryForeignSmtpTls(data) => data,
r => panic!("unexpected response: {r:?}"),
})
.collect::<Vec<_>>();
stati.sort_by_key(|s| s.domain.clone());
assert_eq!(
vec![
s::XCryForeignSmtpTlsData {
domain: Cow::Borrowed("insecure.example.com"),
starttls: false,
valid_certificate: false,
tls_version: None,
},
s::XCryForeignSmtpTlsData {
domain: Cow::Borrowed("secure.example.com"),
starttls: true,
valid_certificate: true,
tls_version: Some(Cow::Borrowed("TLS 1.3")),
},
],
stati,
);
ok_command!(
client,
c("XCRY SMTP-OUT FOREIGN-TLS DELETE INSECURE.EXAMPLE.COM")
);
command!(mut responses = client, c("XCRY SMTP-OUT FOREIGN-TLS LIST"));
assert_eq!(2, responses.len());
assert_tagged_ok(responses.pop().unwrap());
}
#[test]
fn spool_execute() {
let setup = set_up();
let mut client = setup.connect("xcryspex");
quick_log_in(&mut client);
command!([response] = client, c("XCRY SMTP-OUT SPOOL EXECUTE 42"));
assert_error_response(
response,
Some(s::RespTextCode::Nonexistent(())),
Error::NxMessage,
);
quick_select(&mut client, "INBOX");
}