mirror of
https://gitlab.com/hagrid-keyserver/hagrid.git
synced 2023-02-13 20:55:02 -05:00
adapt tests to /vks/manage
This commit is contained in:
parent
2b1722c540
commit
eb80b66264
1 changed files with 38 additions and 32 deletions
|
@ -522,7 +522,7 @@ pub mod tests {
|
||||||
assert!(response.body_string().unwrap().contains("upload"));
|
assert!(response.body_string().unwrap().contains("upload"));
|
||||||
|
|
||||||
// Check that we see the deletion form.
|
// Check that we see the deletion form.
|
||||||
let mut response = client.get("/delete").dispatch();
|
let mut response = client.get("/vks/manage").dispatch();
|
||||||
assert_eq!(response.status(), Status::Ok);
|
assert_eq!(response.status(), Status::Ok);
|
||||||
assert_eq!(response.content_type(), Some(ContentType::HTML));
|
assert_eq!(response.content_type(), Some(ContentType::HTML));
|
||||||
assert!(response.body_string().unwrap().contains("email"));
|
assert!(response.body_string().unwrap().contains("email"));
|
||||||
|
@ -531,7 +531,7 @@ pub mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn upload() {
|
fn upload_single() {
|
||||||
let (tmpdir, client) = client().unwrap();
|
let (tmpdir, client) = client().unwrap();
|
||||||
let filemail_into = tmpdir.path().join("filemail");
|
let filemail_into = tmpdir.path().join("filemail");
|
||||||
|
|
||||||
|
@ -568,7 +568,7 @@ pub mod tests {
|
||||||
vks_manage(&client, "foo@invalid.example.com");
|
vks_manage(&client, "foo@invalid.example.com");
|
||||||
|
|
||||||
// Confirm deletion.
|
// Confirm deletion.
|
||||||
check_mails_and_confirm_deletion(&client, filemail_into.as_path());
|
check_mails_and_confirm_deletion(&client, filemail_into.as_path(), "foo@invalid.example.com");
|
||||||
|
|
||||||
// Now, we should no longer be able to look it up by email
|
// Now, we should no longer be able to look it up by email
|
||||||
// address.
|
// address.
|
||||||
|
@ -619,20 +619,18 @@ pub mod tests {
|
||||||
check_hr_responses_by_fingerprint(&client, &tpk_1, 0);
|
check_hr_responses_by_fingerprint(&client, &tpk_1, 0);
|
||||||
|
|
||||||
// Now check for the verification mails.
|
// Now check for the verification mails.
|
||||||
check_mails_and_verify_email(&client, filemail_into.as_path());
|
check_mails_and_verify_email(&client, &filemail_into);
|
||||||
check_mails_and_verify_email(&client, filemail_into.as_path());
|
check_mails_and_verify_email(&client, &filemail_into);
|
||||||
|
|
||||||
// Now lookups using the mail address should work.
|
// Now lookups using the mail address should work.
|
||||||
check_responses_by_email(&client, "foo@invalid.example.com", &tpk_0, 1);
|
check_responses_by_email(&client, "foo@invalid.example.com", &tpk_0, 1);
|
||||||
check_responses_by_email(&client, "bar@invalid.example.com", &tpk_1, 1);
|
check_responses_by_email(&client, "bar@invalid.example.com", &tpk_1, 1);
|
||||||
|
|
||||||
// Request deletion of the bindings.
|
// Request deletion of the bindings.
|
||||||
vks_manage(&client, &tpk_0.fingerprint().to_string());
|
vks_manage(&client, "foo@invalid.example.com");
|
||||||
vks_manage(&client, &tpk_1.fingerprint().to_keyid().to_string());
|
check_mails_and_confirm_deletion(&client, &filemail_into, "foo@invalid.example.com");
|
||||||
|
vks_manage(&client, "bar@invalid.example.com");
|
||||||
// Confirm deletion.
|
check_mails_and_confirm_deletion(&client, &filemail_into, "bar@invalid.example.com");
|
||||||
check_mails_and_confirm_deletion(&client, filemail_into.as_path());
|
|
||||||
check_mails_and_confirm_deletion(&client, filemail_into.as_path());
|
|
||||||
|
|
||||||
// Now, we should no longer be able to look it up by email
|
// Now, we should no longer be able to look it up by email
|
||||||
// address.
|
// address.
|
||||||
|
@ -792,31 +790,27 @@ pub mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_mails_and_verify_email(client: &Client, filemail_path: &Path) {
|
fn check_mails_and_verify_email(client: &Client, filemail_path: &Path) {
|
||||||
let confirm_re = regex::bytes::Regex::new(
|
let pattern = format!("{}(/publish/[^ \t\n]*)", BASE_URI);
|
||||||
&format!("{}(/publish/[^ \t\n]*)", BASE_URI)).unwrap();
|
let confirm_uri = pop_mail_capture_pattern(filemail_path, &pattern);
|
||||||
let confirm_mail = pop_mail(filemail_path).unwrap().unwrap();
|
|
||||||
let confirm_bytes = confirm_mail.message();
|
|
||||||
// eprintln!("{}", String::from_utf8_lossy(&confirm_bytes));
|
|
||||||
let confirm_link =
|
|
||||||
confirm_re.captures(&confirm_bytes).unwrap()
|
|
||||||
.get(1).unwrap().as_bytes();
|
|
||||||
let confirm_uri = String::from_utf8_lossy(confirm_link).to_string();
|
|
||||||
let response = client.get(&confirm_uri).dispatch();
|
let response = client.get(&confirm_uri).dispatch();
|
||||||
assert_eq!(response.status(), Status::Ok);
|
assert_eq!(response.status(), Status::Ok);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_mails_and_confirm_deletion(client: &Client, filemail_path: &Path) {
|
fn check_mails_and_confirm_deletion(client: &Client, filemail_path: &Path, address: &str) {
|
||||||
let confirm_re = regex::bytes::Regex::new(
|
let pattern = format!("{}/vks/manage/([^ \t\n]*)", BASE_URI);
|
||||||
&format!("{}(/delete/[^ \t\n]*)", BASE_URI)).unwrap();
|
let token = pop_mail_capture_pattern(filemail_path, &pattern);
|
||||||
let confirm_mail = pop_mail(filemail_path).unwrap().unwrap();
|
vks_manage_delete(client, &token, address);
|
||||||
let confirm_bytes = confirm_mail.message();
|
}
|
||||||
// eprintln!("{}", String::from_utf8_lossy(&confirm_bytes));
|
|
||||||
let confirm_link =
|
fn pop_mail_capture_pattern(filemail_path: &Path, pattern: &str) -> String {
|
||||||
confirm_re.captures(&confirm_bytes).unwrap()
|
let mail_message = pop_mail(filemail_path).unwrap().unwrap();
|
||||||
|
let mail_content = mail_message.message();
|
||||||
|
|
||||||
|
let capture_re = regex::bytes::Regex::new(pattern).unwrap();
|
||||||
|
let capture_content = capture_re .captures(&mail_content).unwrap()
|
||||||
.get(1).unwrap().as_bytes();
|
.get(1).unwrap().as_bytes();
|
||||||
let confirm_uri = String::from_utf8_lossy(confirm_link).to_string();
|
String::from_utf8_lossy(capture_content).to_string()
|
||||||
let response = client.get(&confirm_uri).dispatch();
|
|
||||||
assert_eq!(response.status(), Status::Ok);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns and removes the first mail it finds from the given
|
/// Returns and removes the first mail it finds from the given
|
||||||
|
@ -871,7 +865,19 @@ pub mod tests {
|
||||||
let encoded = ::url::form_urlencoded::Serializer::new(String::new())
|
let encoded = ::url::form_urlencoded::Serializer::new(String::new())
|
||||||
.append_pair("search_term", search_term)
|
.append_pair("search_term", search_term)
|
||||||
.finish();
|
.finish();
|
||||||
let response = client.post("/delete")
|
let response = client.post("/vks/manage")
|
||||||
|
.header(ContentType::Form)
|
||||||
|
.body(encoded.as_bytes())
|
||||||
|
.dispatch();
|
||||||
|
assert_eq!(response.status(), Status::Ok);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn vks_manage_delete(client: &Client, token: &str, address: &str) {
|
||||||
|
let encoded = ::url::form_urlencoded::Serializer::new(String::new())
|
||||||
|
.append_pair("token", token)
|
||||||
|
.append_pair("address", address)
|
||||||
|
.finish();
|
||||||
|
let response = client.post("/vks/manage/unpublish")
|
||||||
.header(ContentType::Form)
|
.header(ContentType::Form)
|
||||||
.body(encoded.as_bytes())
|
.body(encoded.as_bytes())
|
||||||
.dispatch();
|
.dispatch();
|
||||||
|
|
Loading…
Reference in a new issue