mirror of
https://github.com/lennart-k/rustical.git
synced 2026-01-30 22:28:22 +00:00
Compare commits
2 Commits
f73658b32f
...
303f9aff68
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
303f9aff68 | ||
|
|
3460a2821e |
@@ -26,7 +26,10 @@ pub async fn route_import<C: CalendarStore, S: SubscriptionStore>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let parser = ical::IcalParser::from_slice(body.as_bytes());
|
let parser = ical::IcalParser::from_slice(body.as_bytes());
|
||||||
let mut cal = parser.expect_one()?.mutable();
|
let mut cal = match parser.expect_one() {
|
||||||
|
Ok(cal) => cal.mutable(),
|
||||||
|
Err(err) => return Ok((StatusCode::BAD_REQUEST, err.to_string()).into_response()),
|
||||||
|
};
|
||||||
|
|
||||||
// Extract calendar metadata
|
// Extract calendar metadata
|
||||||
let displayname = cal
|
let displayname = cal
|
||||||
@@ -67,7 +70,10 @@ pub async fn route_import<C: CalendarStore, S: SubscriptionStore>(
|
|||||||
cal_components.push(CalendarObjectType::Todo);
|
cal_components.push(CalendarObjectType::Todo);
|
||||||
}
|
}
|
||||||
|
|
||||||
let objects = cal.into_objects()?.into_iter().map(Into::into).collect();
|
let objects = match cal.into_objects() {
|
||||||
|
Ok(objects) => objects.into_iter().map(Into::into).collect(),
|
||||||
|
Err(err) => return Ok((StatusCode::BAD_REQUEST, err.to_string()).into_response()),
|
||||||
|
};
|
||||||
let new_cal = Calendar {
|
let new_cal = Calendar {
|
||||||
principal,
|
principal,
|
||||||
id: cal_id,
|
id: cal_id,
|
||||||
|
|||||||
@@ -52,9 +52,6 @@ pub enum Error {
|
|||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
XmlDecodeError(#[from] rustical_xml::XmlError),
|
XmlDecodeError(#[from] rustical_xml::XmlError),
|
||||||
|
|
||||||
#[error(transparent)]
|
|
||||||
IcalError(#[from] rustical_ical::Error),
|
|
||||||
|
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
PreconditionFailed(Precondition),
|
PreconditionFailed(Precondition),
|
||||||
}
|
}
|
||||||
@@ -75,8 +72,6 @@ impl Error {
|
|||||||
Self::XmlDecodeError(_) => StatusCode::BAD_REQUEST,
|
Self::XmlDecodeError(_) => StatusCode::BAD_REQUEST,
|
||||||
Self::ChronoParseError(_) | Self::NotImplemented => StatusCode::INTERNAL_SERVER_ERROR,
|
Self::ChronoParseError(_) | Self::NotImplemented => StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
Self::NotFound => StatusCode::NOT_FOUND,
|
Self::NotFound => StatusCode::NOT_FOUND,
|
||||||
// TODO: Can also be Bad Request, if it's used input
|
|
||||||
Self::IcalError(_err) => StatusCode::INTERNAL_SERVER_ERROR,
|
|
||||||
Self::PreconditionFailed(_err) => StatusCode::PRECONDITION_FAILED,
|
Self::PreconditionFailed(_err) => StatusCode::PRECONDITION_FAILED,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -103,7 +103,10 @@ pub async fn put_object<AS: AddressbookStore>(
|
|||||||
true
|
true
|
||||||
};
|
};
|
||||||
|
|
||||||
let object = AddressObject::from_vcf(body)?;
|
let object = match AddressObject::from_vcf(body) {
|
||||||
|
Ok(object) => object,
|
||||||
|
Err(err) => return Ok((StatusCode::BAD_REQUEST, err.to_string()).into_response()),
|
||||||
|
};
|
||||||
let etag = object.get_etag();
|
let etag = object.get_etag();
|
||||||
addr_store
|
addr_store
|
||||||
.put_object(&principal, &addressbook_id, &object_id, object, overwrite)
|
.put_object(&principal, &addressbook_id, &object_id, object, overwrite)
|
||||||
|
|||||||
@@ -23,9 +23,6 @@ pub enum Error {
|
|||||||
|
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
XmlDecodeError(#[from] rustical_xml::XmlError),
|
XmlDecodeError(#[from] rustical_xml::XmlError),
|
||||||
|
|
||||||
#[error(transparent)]
|
|
||||||
IcalError(#[from] rustical_ical::Error),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Error {
|
impl Error {
|
||||||
@@ -43,8 +40,6 @@ impl Error {
|
|||||||
Self::XmlDecodeError(_) => StatusCode::BAD_REQUEST,
|
Self::XmlDecodeError(_) => StatusCode::BAD_REQUEST,
|
||||||
Self::ChronoParseError(_) | Self::NotImplemented => StatusCode::INTERNAL_SERVER_ERROR,
|
Self::ChronoParseError(_) | Self::NotImplemented => StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
Self::NotFound => StatusCode::NOT_FOUND,
|
Self::NotFound => StatusCode::NOT_FOUND,
|
||||||
// TODO: Can also be Bad Request, if it's used input
|
|
||||||
Self::IcalError(_err) => StatusCode::INTERNAL_SERVER_ERROR,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,12 +6,15 @@ use axum::{
|
|||||||
extract::{MatchedPath, Path, State},
|
extract::{MatchedPath, Path, State},
|
||||||
response::{IntoResponse, Response},
|
response::{IntoResponse, Response},
|
||||||
};
|
};
|
||||||
|
use axum_extra::TypedHeader;
|
||||||
|
use headers::Host;
|
||||||
use http::{HeaderMap, StatusCode, Uri};
|
use http::{HeaderMap, StatusCode, Uri};
|
||||||
use matchit_serde::ParamsDeserializer;
|
use matchit_serde::ParamsDeserializer;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use tracing::instrument;
|
use tracing::instrument;
|
||||||
|
|
||||||
#[instrument(skip(path, resource_service,))]
|
#[instrument(skip(path, resource_service,))]
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub async fn axum_route_copy<R: ResourceService>(
|
pub async fn axum_route_copy<R: ResourceService>(
|
||||||
Path(path): Path<R::PathComponents>,
|
Path(path): Path<R::PathComponents>,
|
||||||
State(resource_service): State<R>,
|
State(resource_service): State<R>,
|
||||||
@@ -20,6 +23,7 @@ pub async fn axum_route_copy<R: ResourceService>(
|
|||||||
Overwrite(overwrite): Overwrite,
|
Overwrite(overwrite): Overwrite,
|
||||||
matched_path: MatchedPath,
|
matched_path: MatchedPath,
|
||||||
header_map: HeaderMap,
|
header_map: HeaderMap,
|
||||||
|
TypedHeader(host): TypedHeader<Host>,
|
||||||
) -> Result<Response, R::Error> {
|
) -> Result<Response, R::Error> {
|
||||||
let destination = header_map
|
let destination = header_map
|
||||||
.get("Destination")
|
.get("Destination")
|
||||||
@@ -27,7 +31,11 @@ pub async fn axum_route_copy<R: ResourceService>(
|
|||||||
.to_str()
|
.to_str()
|
||||||
.map_err(|_| crate::Error::Forbidden)?;
|
.map_err(|_| crate::Error::Forbidden)?;
|
||||||
let destination_uri: Uri = destination.parse().map_err(|_| crate::Error::Forbidden)?;
|
let destination_uri: Uri = destination.parse().map_err(|_| crate::Error::Forbidden)?;
|
||||||
// TODO: Check that host also matches
|
if let Some(authority) = destination_uri.authority()
|
||||||
|
&& host != authority.clone().into()
|
||||||
|
{
|
||||||
|
return Err(crate::Error::Forbidden.into());
|
||||||
|
}
|
||||||
let destination = destination_uri.path();
|
let destination = destination_uri.path();
|
||||||
|
|
||||||
let mut router = matchit::Router::new();
|
let mut router = matchit::Router::new();
|
||||||
|
|||||||
@@ -6,12 +6,15 @@ use axum::{
|
|||||||
extract::{MatchedPath, Path, State},
|
extract::{MatchedPath, Path, State},
|
||||||
response::{IntoResponse, Response},
|
response::{IntoResponse, Response},
|
||||||
};
|
};
|
||||||
|
use axum_extra::TypedHeader;
|
||||||
|
use headers::Host;
|
||||||
use http::{HeaderMap, StatusCode, Uri};
|
use http::{HeaderMap, StatusCode, Uri};
|
||||||
use matchit_serde::ParamsDeserializer;
|
use matchit_serde::ParamsDeserializer;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use tracing::instrument;
|
use tracing::instrument;
|
||||||
|
|
||||||
#[instrument(skip(path, resource_service,))]
|
#[instrument(skip(path, resource_service,))]
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub async fn axum_route_move<R: ResourceService>(
|
pub async fn axum_route_move<R: ResourceService>(
|
||||||
Path(path): Path<R::PathComponents>,
|
Path(path): Path<R::PathComponents>,
|
||||||
State(resource_service): State<R>,
|
State(resource_service): State<R>,
|
||||||
@@ -20,6 +23,7 @@ pub async fn axum_route_move<R: ResourceService>(
|
|||||||
Overwrite(overwrite): Overwrite,
|
Overwrite(overwrite): Overwrite,
|
||||||
matched_path: MatchedPath,
|
matched_path: MatchedPath,
|
||||||
header_map: HeaderMap,
|
header_map: HeaderMap,
|
||||||
|
TypedHeader(host): TypedHeader<Host>,
|
||||||
) -> Result<Response, R::Error> {
|
) -> Result<Response, R::Error> {
|
||||||
let destination = header_map
|
let destination = header_map
|
||||||
.get("Destination")
|
.get("Destination")
|
||||||
@@ -27,7 +31,11 @@ pub async fn axum_route_move<R: ResourceService>(
|
|||||||
.to_str()
|
.to_str()
|
||||||
.map_err(|_| crate::Error::Forbidden)?;
|
.map_err(|_| crate::Error::Forbidden)?;
|
||||||
let destination_uri: Uri = destination.parse().map_err(|_| crate::Error::Forbidden)?;
|
let destination_uri: Uri = destination.parse().map_err(|_| crate::Error::Forbidden)?;
|
||||||
// TODO: Check that host also matches
|
if let Some(authority) = destination_uri.authority()
|
||||||
|
&& host != authority.clone().into()
|
||||||
|
{
|
||||||
|
return Err(crate::Error::Forbidden.into());
|
||||||
|
}
|
||||||
let destination = destination_uri.path();
|
let destination = destination_uri.path();
|
||||||
|
|
||||||
let mut router = matchit::Router::new();
|
let mut router = matchit::Router::new();
|
||||||
|
|||||||
Reference in New Issue
Block a user