Skip to content

Commit

Permalink
Merge #755: fix: check errors
Browse files Browse the repository at this point in the history
0aaf2b5 fix: check errors (Jose Celano)

Pull request description:

  Fix check errors.

ACKs for top commit:
  josecelano:
    ACK 0aaf2b5

Tree-SHA512: 62d88216f2f9d09610a1e36779bd2982f03f39bf9bcbea19a264eae20a93180d7cc14859d821d6fe7c04e5f9830e3c12687ee70cb1c34c287254657609297be1
  • Loading branch information
josecelano committed Oct 25, 2024
2 parents d8af067 + 0aaf2b5 commit cad72ae
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 22 deletions.
6 changes: 3 additions & 3 deletions packages/located-error/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ where
location: Box<Location<'a>>,
}

impl<'a, E> std::fmt::Display for LocatedError<'a, E>
impl<E> std::fmt::Display for LocatedError<'_, E>
where
E: Error + ?Sized + Send + Sync,
{
Expand All @@ -57,7 +57,7 @@ where
}
}

impl<'a, E> Error for LocatedError<'a, E>
impl<E> Error for LocatedError<'_, E>
where
E: Error + ?Sized + Send + Sync + 'static,
{
Expand All @@ -66,7 +66,7 @@ where
}
}

impl<'a, E> Clone for LocatedError<'a, E>
impl<E> Clone for LocatedError<'_, E>
where
E: Error + ?Sized + Send + Sync,
{
Expand Down
4 changes: 2 additions & 2 deletions src/mailer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,14 @@ fn build_letter(verification_url: &str, username: &str, builder: MessageBuilder)

fn build_content(verification_url: &str, username: &str) -> Result<(String, String), tera::Error> {
let plain_body = format!(
r#"
"
Welcome to Torrust, {username}!
Please click the confirmation link below to verify your account.
{verification_url}
If this account wasn't made by you, you can ignore this email.
"#
"
);
let mut context = Context::new();
context.insert("verification", &verification_url);
Expand Down
2 changes: 1 addition & 1 deletion src/models/info_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ impl<'de> serde::de::Deserialize<'de> for InfoHash {

struct InfoHashVisitor;

impl<'v> serde::de::Visitor<'v> for InfoHashVisitor {
impl serde::de::Visitor<'_> for InfoHashVisitor {
type Value = InfoHash;

fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
Expand Down
6 changes: 3 additions & 3 deletions src/web/api/server/v1/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl Authentication {
/// # Errors
///
/// This function will return an error if it can get claims from the request
pub async fn get_user_id_from_bearer_token(&self, maybe_token: &Option<BearerToken>) -> Result<UserId, ServiceError> {
pub async fn get_user_id_from_bearer_token(&self, maybe_token: Option<BearerToken>) -> Result<UserId, ServiceError> {
let claims = self.get_claims_from_bearer_token(maybe_token).await?;
Ok(claims.user.user_id)
}
Expand All @@ -130,7 +130,7 @@ impl Authentication {
///
/// - Return an `ServiceError::TokenNotFound` if `HeaderValue` is `None`.
/// - Pass through the `ServiceError::TokenInvalid` if unable to verify the JWT.
async fn get_claims_from_bearer_token(&self, maybe_token: &Option<BearerToken>) -> Result<UserClaims, ServiceError> {
async fn get_claims_from_bearer_token(&self, maybe_token: Option<BearerToken>) -> Result<UserClaims, ServiceError> {
match maybe_token {
Some(token) => match self.verify_jwt(&token.value()).await {
Ok(claims) => Ok(claims),
Expand Down Expand Up @@ -166,7 +166,7 @@ pub async fn get_optional_logged_in_user(
app_data: Arc<AppData>,
) -> Result<Option<UserId>, ServiceError> {
match maybe_bearer_token {
Some(bearer_token) => match app_data.auth.get_user_id_from_bearer_token(&Some(bearer_token)).await {
Some(bearer_token) => match app_data.auth.get_user_id_from_bearer_token(Some(bearer_token)).await {
Ok(user_id) => Ok(Some(user_id)),
Err(error) => Err(error),
},
Expand Down
7 changes: 1 addition & 6 deletions src/web/api/server/v1/extractors/optional_user_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ where
type Rejection = Response;

async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {
/* let maybe_bearer_token = match bearer_token::Extract::from_request_parts(parts, state).await {
Ok(maybe_bearer_token) => maybe_bearer_token.0,
Err(_) => return Err(ServiceError::TokenNotFound.into_response()),
}; */

let bearer_token = match bearer_token::Extract::from_request_parts(parts, state).await {
Ok(bearer_token) => bearer_token.0,
Err(_) => None,
Expand All @@ -33,7 +28,7 @@ where
//Extracts the app state
let app_data = Arc::from_ref(state);

match app_data.auth.get_user_id_from_bearer_token(&bearer_token).await {
match app_data.auth.get_user_id_from_bearer_token(bearer_token).await {
Ok(user_id) => Ok(ExtractOptionalLoggedInUser(Some(user_id))),
Err(_) => Ok(ExtractOptionalLoggedInUser(None)),
}
Expand Down
2 changes: 1 addition & 1 deletion src/web/api/server/v1/extractors/user_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ where
//Extracts the app state
let app_data = Arc::from_ref(state);

match app_data.auth.get_user_id_from_bearer_token(&maybe_bearer_token).await {
match app_data.auth.get_user_id_from_bearer_token(maybe_bearer_token).await {
Ok(user_id) => Ok(ExtractLoggedInUser(user_id)),
Err(_) => Err(ServiceError::LoggedInUserNotFound.into_response()),
}
Expand Down
10 changes: 5 additions & 5 deletions tests/e2e/web/api/v1/contexts/torrent/asserts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::e2e::environment::TestEnv;
pub async fn canonical_torrent_for(
mut uploaded_torrent: Torrent,
env: &TestEnv,
downloader: &Option<LoggedInUserData>,
downloader: Option<&LoggedInUserData>,
) -> Torrent {
let tracker_url = env.server_settings().unwrap().tracker.url.to_string();

Expand All @@ -23,8 +23,8 @@ pub async fn canonical_torrent_for(
None => None,
};

uploaded_torrent.announce = Some(build_announce_url(&tracker_url, &tracker_key));
uploaded_torrent.announce_list = Some(build_announce_list(&tracker_url, &tracker_key));
uploaded_torrent.announce = Some(build_announce_url(&tracker_url, tracker_key.as_ref()));
uploaded_torrent.announce_list = Some(build_announce_list(&tracker_url, tracker_key.as_ref()));

uploaded_torrent
}
Expand Down Expand Up @@ -56,15 +56,15 @@ pub async fn get_user_tracker_key(logged_in_user: &LoggedInUserData, env: &TestE
Some(tracker_key)
}

pub fn build_announce_url(tracker_url: &str, tracker_key: &Option<TrackerKey>) -> String {
pub fn build_announce_url(tracker_url: &str, tracker_key: Option<&TrackerKey>) -> String {
if let Some(key) = &tracker_key {
format!("{tracker_url}/{}", key.key)
} else {
tracker_url.to_string()
}
}

fn build_announce_list(tracker_url: &str, tracker_key: &Option<TrackerKey>) -> Vec<Vec<String>> {
fn build_announce_list(tracker_url: &str, tracker_key: Option<&TrackerKey>) -> Vec<Vec<String>> {
if let Some(key) = &tracker_key {
vec![vec![format!("{tracker_url}/{}", key.key)], vec![format!("{tracker_url}")]]
} else {
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/web/api/v1/contexts/torrent/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ mod for_guests {

let downloaded_torrent = decode_torrent(&response.bytes).expect("could not decode downloaded torrent");

let expected_downloaded_torrent = canonical_torrent_for(uploaded_torrent, &env, &None).await;
let expected_downloaded_torrent = canonical_torrent_for(uploaded_torrent, &env, None).await;

assert_eq!(downloaded_torrent, expected_downloaded_torrent);
}
Expand Down

0 comments on commit cad72ae

Please sign in to comment.