Skip to content

Commit

Permalink
Merge pull request #1097 from SamTV12345/1096-pulled-new-updated-unab…
Browse files Browse the repository at this point in the history
…le-to-see-podcasts

1096 pulled new updated unable to see podcasts
  • Loading branch information
SamTV12345 authored Jan 1, 2025
2 parents 1612399 + 83a79db commit 214aaf5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
33 changes: 29 additions & 4 deletions src/auth_middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ where

if let Some(admin_username) = ENVIRONMENT_SERVICE.username.clone() {
if unwrapped_user.username.clone() == admin_username {
return if let Some(password) = &ENVIRONMENT_SERVICE.password {
if &digest(password) == password {
return if let Some(env_password) = &ENVIRONMENT_SERVICE.password {
if &digest(password) == env_password {
req.extensions_mut().insert(unwrapped_user);
let service = Rc::clone(&self.service);
async move {
Expand Down Expand Up @@ -345,9 +345,34 @@ impl AuthFilter {
Ok((username.to_string(), password.to_string()))
}

pub fn basic_auth_login(rq: String) -> Result<(String, String), CustomError> {
let (u, p) = Self::extract_basic_auth(rq.as_str())?;
pub fn basic_auth_login(rq: &str) -> Result<(String, String), CustomError> {
let (u, p) = Self::extract_basic_auth(rq)?;

Ok((u.to_string(), p.to_string()))
}
}


#[cfg(test)]
mod test {
use crate::auth_middleware::AuthFilter;

#[test]
fn test_basic_auth_login() {
let result = AuthFilter::extract_basic_auth("Bearer dGVzdDp0ZXN0");
assert_eq!(result.is_err(), false);
let (u, p) = result.unwrap();
assert_eq!(u, "test");
assert_eq!(p, "test");
}


#[test]
fn test_basic_auth_login_with_special_characters() {
let result = AuthFilter::extract_basic_auth("Bearer dGVzdCTDvMOWOnRlc3Q=");
assert_eq!(result.is_err(), false);
let (u, p) = result.unwrap();
assert_eq!(u, "test$üÖ");
assert_eq!(p, "test");
}
}
2 changes: 1 addition & 1 deletion src/gpodder/auth/authentication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ fn handle_gpodder_basic_auth(
let authorization = opt_authorization.unwrap().to_str().unwrap();

let unwrapped_username = username.into_inner();
let (username_basic, password) = AuthFilter::basic_auth_login(authorization.to_string())?;
let (username_basic, password) = AuthFilter::basic_auth_login(authorization)?;
if username_basic != unwrapped_username {
return Err(CustomError::Forbidden);
}
Expand Down

0 comments on commit 214aaf5

Please sign in to comment.