mirror of
https://github.com/lennart-k/rustical.git
synced 2026-01-30 08:08:23 +00:00
74 lines
2.1 KiB
Rust
74 lines
2.1 KiB
Rust
use crate::integration_tests::{ResponseExtractString, get_app};
|
|
use axum::body::Body;
|
|
use axum::extract::Request;
|
|
use headers::{Authorization, HeaderMapExt};
|
|
use http::StatusCode;
|
|
use rstest::rstest;
|
|
use rustical_store_sqlite::tests::{TestStoreContext, test_store_context};
|
|
use tower::ServiceExt;
|
|
|
|
#[rstest]
|
|
#[tokio::test]
|
|
async fn test_import(
|
|
#[from(test_store_context)]
|
|
#[future]
|
|
context: TestStoreContext,
|
|
) {
|
|
let context = context.await;
|
|
let app = get_app(context.clone());
|
|
|
|
let (principal, addr_id) = ("user", "contacts");
|
|
let url = format!("/carddav/principal/{principal}/{addr_id}");
|
|
|
|
let request_template = || {
|
|
Request::builder()
|
|
.method("IMPORT")
|
|
.uri(&url)
|
|
.body(Body::from(
|
|
r"BEGIN:VCARD
|
|
VERSION:4.0
|
|
FN:Simon Perreault
|
|
N:Perreault;Simon;;;ing. jr,M.Sc.
|
|
BDAY:--0203
|
|
GENDER:M
|
|
EMAIL;TYPE=work:simon.perreault@viagenie.ca
|
|
END:VCARD",
|
|
))
|
|
.unwrap()
|
|
};
|
|
|
|
// Try without authentication
|
|
let request = request_template();
|
|
let response = app.clone().oneshot(request).await.unwrap();
|
|
assert_eq!(response.status(), StatusCode::UNAUTHORIZED);
|
|
|
|
// Try with correct credentials
|
|
let mut request = request_template();
|
|
request
|
|
.headers_mut()
|
|
.typed_insert(Authorization::basic("user", "pass"));
|
|
let response = app.clone().oneshot(request).await.unwrap();
|
|
assert_eq!(response.status(), StatusCode::OK);
|
|
let body = response.extract_string().await;
|
|
insta::assert_snapshot!("import_body", body);
|
|
|
|
let mut request = Request::builder()
|
|
.method("GET")
|
|
.uri(&url)
|
|
.body(Body::empty())
|
|
.unwrap();
|
|
request
|
|
.headers_mut()
|
|
.typed_insert(Authorization::basic("user", "pass"));
|
|
let response = app.clone().oneshot(request).await.unwrap();
|
|
assert_eq!(response.status(), StatusCode::OK);
|
|
let body = response.extract_string().await;
|
|
insta::with_settings!({
|
|
filters => vec![
|
|
(r"UID:.+", "UID:[UID]")
|
|
]
|
|
}, {
|
|
insta::assert_snapshot!("get_body", body);
|
|
});
|
|
}
|